# HG changeset patch # User Torsten # Date 1487502383 -3600 # Node ID 75515a7b1b4b474a1594ddb77576c025fb3f4e04 # Parent 03f1adaea50a0f57d045c7f56b75b742a468a18c add preference for closing files when editor is closed/hidden (bug #50106) * file-editor.cc (file_editor): initializing class variable _closed to false; (check_closing): update comments related to editor closing; (handle_visibility): check whether editor was closed before when becoming visible again and restore the previous session if desired; (closeEvent): overload closeEvent for closing all files/tabs if desired, ignore event if closing is canceled by the user due to unsaved changes; * file-editor.h: added closeEvent and class variable _closed * settings-dialog.cc (settings_dialog): Initialize new checkbox from settings; (write_changed_settings): save checkbox state into settings file * settings-dialog.ui: new checkbox for closing files when hiding the editor diff -r 03f1adaea50a -r 75515a7b1b4b libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc Sat Feb 18 21:05:36 2017 -0800 +++ b/libgui/src/m-editor/file-editor.cc Sun Feb 19 12:06:23 2017 +0100 @@ -62,6 +62,7 @@ _copy_action = 0; _paste_action = 0; _selectall_action = 0; + _closed = false; construct (); @@ -84,7 +85,8 @@ bool file_editor::check_closing (void) { - // When the applications is closing all editor tabs are checked whether + // When the application or the editor is closing and the user wants to close + // all files in the latter case all editor tabs are checked whether // they need to be saved. During these ckecked the tabs are not closed // since the user might cancel closing octave during one of these saving // dialogs. Therefore, saving the session for restoring at next start @@ -101,14 +103,14 @@ // If there was a cancellation, make the already saved/discarded tabs // recovering from the exit by removing the read-only state and by // recovering the debugger breakpoints. Finally return false in order to - // cancel closing the application + // cancel closing the application or the editor if (file_editor_tab::was_cancelled ()) { emit fetab_recover_from_exit (); return false; } - // Here, the application will be closed -> store the session + // Here, the application or the editor will be closed -> store the session // Save open files for restoring in next session; this only is possible QSettings *settings = resource_manager::get_settings (); @@ -140,7 +142,7 @@ settings->sync (); // Finally close all the tabs and return indication that we can exit - // the application + // the application or close the editor for (int i = _tab_widget->count () - 1; i >= 0; i--) { // backwards loop since _tab_widget->count () changes during the loop @@ -2357,10 +2359,18 @@ void file_editor::handle_visibility (bool visible) { + if (_closed && visible) + { + _closed = false; + QSettings *settings = resource_manager::get_settings (); + restore_session (settings); + } + empty_script (false, visible); if (visible && ! isFloating ()) focus (); + } void @@ -2384,6 +2394,27 @@ } } +// handler for the close event +void +file_editor::closeEvent (QCloseEvent *e) +{ + QSettings *settings = resource_manager::get_settings (); + if (settings->value ("editor/hiding_closes_files",false).toBool ()) + { + if (check_closing ()) + { + // all tabs are closed without cancelling, + // store closing state for restoring session when shown again + _closed = true; + e->accept (); + } + else + e->ignore (); + } + else + e->accept (); +} + // slots for tab navigation void file_editor::switch_left_tab () diff -r 03f1adaea50a -r 75515a7b1b4b libgui/src/m-editor/file-editor.h --- a/libgui/src/m-editor/file-editor.h Sat Feb 18 21:05:36 2017 -0800 +++ b/libgui/src/m-editor/file-editor.h Sun Feb 19 12:06:23 2017 +0100 @@ -258,6 +258,7 @@ void update_octave_directory (const QString& dir); protected slots: + void copyClipboard (); void pasteClipboard (); void selectAll (); @@ -299,6 +300,7 @@ protected: + void closeEvent (QCloseEvent *event); void dragEnterEvent (QDragEnterEvent *event); void dropEvent (QDropEvent *event); @@ -432,6 +434,8 @@ int _marker_breakpoint; + bool _closed; + QString _file_encoding; enum { MaxMRUFiles = 10 }; diff -r 03f1adaea50a -r 75515a7b1b4b libgui/src/settings-dialog.cc --- a/libgui/src/settings-dialog.cc Sat Feb 18 21:05:36 2017 -0800 +++ b/libgui/src/settings-dialog.cc Sun Feb 19 12:06:23 2017 +0100 @@ -490,6 +490,8 @@ settings->value ("editor/create_new_file",false).toBool ()); ui->editor_reload_changed_files->setChecked ( settings->value ("editor/always_reload_changed_files",false).toBool ()); + ui->editor_hiding_closes_files->setChecked ( + settings->value ("editor/hiding_closes_files",false).toBool ()); // terminal ui->terminal_fontName->setCurrentFont (QFont ( @@ -866,6 +868,8 @@ ui->editor_restoreSession->isChecked ()); settings->setValue ("editor/create_new_file", ui->editor_create_new_file->isChecked ()); + settings->setValue ("editor/hiding_closes_files", + ui->editor_hiding_closes_files->isChecked ()); settings->setValue ("editor/always_reload_changed_files", ui->editor_reload_changed_files->isChecked ()); settings->setValue ("terminal/fontSize", ui->terminal_fontSize->value ()); diff -r 03f1adaea50a -r 75515a7b1b4b libgui/src/settings-dialog.ui --- a/libgui/src/settings-dialog.ui Sat Feb 18 21:05:36 2017 -0800 +++ b/libgui/src/settings-dialog.ui Sun Feb 19 12:06:23 2017 +0100 @@ -498,9 +498,9 @@ 0 - 0 + -327 642 - 900 + 927 @@ -525,135 +525,6 @@ - - - - true - - - - 0 - 0 - - - - Show horizontal scroll bar - - - true - - - - - - - - 0 - 0 - - - - Show complete path in window title - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 10 - 0 - - - - - - - - true - - - - 0 - 0 - - - - Show line numbers - - - - - - - 12 - - - 0 - - - - - false - - - Color - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 80 - 20 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - true - - - - 0 - 0 - - - - Highlight current line - - - @@ -803,6 +674,135 @@ + + + + 12 + + + 0 + + + + + false + + + Color + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 80 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + true + + + + 0 + 0 + + + + Highlight current line + + + + + + + true + + + + 0 + 0 + + + + Show horizontal scroll bar + + + true + + + + + + + + 0 + 0 + + + + Show complete path in window title + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 0 + + + + + + + + true + + + + 0 + 0 + + + + Show line numbers + + + @@ -1480,7 +1480,7 @@ - Restore editor tabs from previous session on startup + Restore editor tabs from previous session on startup or when editor is shown again after closing @@ -1497,7 +1497,7 @@ - + 0 @@ -1555,7 +1555,7 @@ - + @@ -1582,6 +1582,13 @@ + + + + Close all files when the editor widget is closed/hidden + + +