Mercurial > octave-libtiff
changeset 23204:75515a7b1b4b
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
author | Torsten <mttl@mailbox.org> |
---|---|
date | Sun, 19 Feb 2017 12:06:23 +0100 |
parents | 03f1adaea50a |
children | 8fd8ed1e3aa2 |
files | libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/settings-dialog.cc libgui/src/settings-dialog.ui |
diffstat | 4 files changed, 184 insertions(+), 138 deletions(-) [+] |
line wrap: on
line diff
--- 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 ()
--- 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 };
--- 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 ());
--- 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 @@ <property name="geometry"> <rect> <x>0</x> - <y>0</y> + <y>-327</y> <width>642</width> - <height>900</height> + <height>927</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout_16"> @@ -525,135 +525,6 @@ </property> </widget> </item> - <item row="10" column="0"> - <widget class="QCheckBox" name="cb_show_hscrollbar"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Show horizontal scroll bar</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QCheckBox" name="editor_longWindowTitle"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Show complete path in window title</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <spacer name="horizontalSpacer_24"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Fixed</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>10</width> - <height>0</height> - </size> - </property> - </spacer> - </item> - <item row="2" column="0"> - <widget class="QCheckBox" name="editor_showLineNumbers"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Show line numbers</string> - </property> - </widget> - </item> - <item row="5" column="2"> - <layout class="QGridLayout" name="editor_grid_current_line" rowstretch="0" columnstretch="0,0,0,0,0"> - <property name="horizontalSpacing"> - <number>12</number> - </property> - <property name="verticalSpacing"> - <number>0</number> - </property> - <item row="0" column="1"> - <widget class="QLabel" name="editor_label_cl_color"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Color</string> - </property> - </widget> - </item> - <item row="0" column="3"> - <spacer name="horizontalSpacer_11"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Fixed</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>80</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="0" column="4"> - <spacer name="horizontalSpacer_9"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item row="5" column="0"> - <widget class="QCheckBox" name="editor_highlightCurrentLine"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Highlight current line</string> - </property> - </widget> - </item> <item row="1" column="2"> <layout class="QGridLayout" name="gridLayout_6"> <item row="0" column="0"> @@ -803,6 +674,135 @@ </property> </widget> </item> + <item row="5" column="2"> + <layout class="QGridLayout" name="editor_grid_current_line" rowstretch="0" columnstretch="0,0,0,0,0"> + <property name="horizontalSpacing"> + <number>12</number> + </property> + <property name="verticalSpacing"> + <number>0</number> + </property> + <item row="0" column="1"> + <widget class="QLabel" name="editor_label_cl_color"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Color</string> + </property> + </widget> + </item> + <item row="0" column="3"> + <spacer name="horizontalSpacer_11"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>80</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="0" column="4"> + <spacer name="horizontalSpacer_9"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item row="5" column="0"> + <widget class="QCheckBox" name="editor_highlightCurrentLine"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Highlight current line</string> + </property> + </widget> + </item> + <item row="10" column="0"> + <widget class="QCheckBox" name="cb_show_hscrollbar"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Show horizontal scroll bar</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QCheckBox" name="editor_longWindowTitle"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Show complete path in window title</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <spacer name="horizontalSpacer_24"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>10</width> + <height>0</height> + </size> + </property> + </spacer> + </item> + <item row="2" column="0"> + <widget class="QCheckBox" name="editor_showLineNumbers"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Show line numbers</string> + </property> + </widget> + </item> </layout> </item> <item> @@ -1480,7 +1480,7 @@ </sizepolicy> </property> <property name="text"> - <string>Restore editor tabs from previous session on startup</string> + <string>Restore editor tabs from previous session on startup or when editor is shown again after closing</string> </property> </widget> </item> @@ -1497,7 +1497,7 @@ </property> </widget> </item> - <item row="5" column="0"> + <item row="6" column="0"> <layout class="QHBoxLayout" name="horizontalLayout_2"> <property name="topMargin"> <number>0</number> @@ -1555,7 +1555,7 @@ </item> </layout> </item> - <item row="7" column="0"> + <item row="8" column="0"> <layout class="QHBoxLayout" name="horizontalLayout_16"> <item> <widget class="QLabel" name="label_16"> @@ -1582,6 +1582,13 @@ </item> </layout> </item> + <item row="5" column="0"> + <widget class="QCheckBox" name="editor_hiding_closes_files"> + <property name="text"> + <string>Close all files when the editor widget is closed/hidden</string> + </property> + </widget> + </item> </layout> </item> </layout>