Mercurial > octave
diff libgui/src/m-editor/file-editor.cc @ 19411:ed0df431631b gui-release
allow to cancel exiting if editor tabs are modified and exit is requested in gui
* file-editor-interface.h: new function check_closing
* file-editor-tab.cc (ctor): set default for app_closing to 0 (not closing);
(check_file_modified): dialog boxes for modified editor tabs depending on
app closing or not;
(conditional_close): no slot, but ordinary function returning close result;
* file-editor-tab.h: conditional_close is function, not a slot;
_app_closing is now int for closing from gui, from octave, not closing
* file-editor.cc (dtor): calling new function check_closing if there are
open tabs (exit requested octave), do not save session here since the tabs
might already have been closed;
(check_closing): new function saving session info and closing all tabs,
stop closing tabs and returning false if user cancels exiting if there is
a modified tab;
(request_close_file, request_close_all_files, request_close_other_files,
handle_tab_close_request):
use conditional_close instead of signal;
(construct): do not connect old signal for closing the tabs
* file-editor.h: remove signal fetab_close_request, new function check_closing
* main-window.cc (confirm_exit_octave): call file_editor::check_closing
before really closing the app
author | Torsten <ttl@justmail.de> |
---|---|
date | Sat, 20 Dec 2014 17:26:53 +0100 |
parents | 2b708273548d |
children | 3c038da18218 |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.cc Mon Dec 15 20:59:21 2014 -0800 +++ b/libgui/src/m-editor/file-editor.cc Sat Dec 20 17:26:53 2014 +0100 @@ -63,6 +63,20 @@ file_editor::~file_editor (void) { + // Close open tabs, if existing. In this case app closing must be + // initiated by octave. All tabs will be definetly closed and the + // user can not cancel exiting (close state -1) + if (_tab_widget->count ()) + check_closing (-1); + + if (_mru_file_menu) + delete _mru_file_menu; +} + +bool +file_editor::check_closing (int closing_state) +{ + // Save open files for restoring in next session; this only is possible QSettings *settings = resource_manager::get_settings (); // Have all file editor tabs signal what their file names are. @@ -82,16 +96,23 @@ settings->setValue ("editor/savedSessionTabs", fetFileNames); settings->sync (); + // Close all tabs. If exit is requested by the gui (octave still running) + // check whether closing a tab is successful or whether user wnats to cancel + // exiting the program. Return false in the latter case. + file_editor_tab *editor_tab; + for (int index = _tab_widget->count ()-1; index >= 0; index--) { - // true: app closing - emit fetab_close_request (_tab_widget->widget (index), true); + editor_tab = static_cast <file_editor_tab *> (_tab_widget->widget (index)); + if ((! editor_tab->conditional_close (closing_state)) && closing_state == 1) + return false; } - if (_mru_file_menu) - delete _mru_file_menu; + // Here, we really want to exit and all tabs are closed + return true; } + void file_editor::focus (void) { @@ -919,26 +940,39 @@ void file_editor::request_close_file (bool) { - emit fetab_close_request (_tab_widget->currentWidget ()); + file_editor_tab *editor_tab = + static_cast <file_editor_tab *> (_tab_widget->currentWidget ()); + editor_tab->conditional_close (0); // 0: app is not closing, only tab } void file_editor::request_close_all_files (bool) { + file_editor_tab *editor_tab; + // loop over all tabs starting from last one otherwise deletion changes index for (int index = _tab_widget->count ()-1; index >= 0; index--) - emit fetab_close_request (_tab_widget->widget (index)); + { + editor_tab = static_cast <file_editor_tab *> (_tab_widget->widget (index)); + editor_tab->conditional_close (0); // 0: app is not closing, only tab + } } void file_editor::request_close_other_files (bool) { + file_editor_tab *editor_tab; QWidget *tabID = _tab_widget->currentWidget (); + // loop over all tabs starting from last one otherwise deletion changes index for (int index = _tab_widget->count ()-1; index >= 0; index--) { if (tabID != _tab_widget->widget (index)) - emit fetab_close_request (_tab_widget->widget (index)); + { + editor_tab = + static_cast <file_editor_tab *> (_tab_widget->widget (index)); + editor_tab->conditional_close (0); // 0: app is not closing, only tab + } } } @@ -946,12 +980,9 @@ void file_editor::handle_tab_close_request (int index) { - // Signal to the tabs a request to close whomever matches the identifying - // tag (i.e., unique widget pointer). The reason for this indirection is - // that it will enable a file editor widget to toss up a non-static - // dialog box and later signal that it wants to be removed. - QWidget *tabID = _tab_widget->widget (index); - emit fetab_close_request (tabID); + file_editor_tab *editor_tab = + static_cast <file_editor_tab *> (_tab_widget->widget (index)); + editor_tab->conditional_close (0); // 0: app is not closing, only tab } void @@ -1596,9 +1627,6 @@ connect (this, SIGNAL (fetab_settings_changed (const QSettings *)), f, SLOT (notice_settings (const QSettings *))); - connect (this, SIGNAL (fetab_close_request (const QWidget*,bool)), - f, SLOT (conditional_close (const QWidget*,bool))); - connect (this, SIGNAL (fetab_change_request (const QWidget*)), f, SLOT (change_editor_state (const QWidget*)));