# HG changeset patch # User Torsten # Date 1368289231 -7200 # Node ID 3c2e457eeb72988e3559539956297611e97ba3c7 # Parent b3f4bdd7e5f46550e7b5799487300b517d1e2b07 ask for saving modified editor files if octave is closed (bug #38689) * files-editor-tab.cc(constrctor): init new flag indicating if app is closing, (check_file_modified): message box is modal if app is closing, no cancel, parent of box is the editor's tab widget for a correct palcement of the box, (conditional_close): new second arg: flag for closing app (default false), it is stored in the tab's class wide flag * file-editor-tab.h: second arg for conditional_close and new class wide flag * file-editor.cc(destructor): sending close requests to all editor tabs with flag indicating the application is closing (add_file_editor_tab): new arg for fetab_close_request and conditional_close * file-editor.h: new 2nd arg for fetab_close_request (closing app, def. false) * main-window.cc(destructor): delete editor window first for showing the message boxes for modified editor files in front of a complete gui diff -r b3f4bdd7e5f4 -r 3c2e457eeb72 libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc Sat May 11 14:01:15 2013 +0200 +++ b/libgui/src/m-editor/file-editor-tab.cc Sat May 11 18:20:31 2013 +0200 @@ -57,6 +57,8 @@ { QString directory = directory_arg; + _app_closing = false; + // Make sure there is a slash at the end of the directory name // for identification when saved later. if (directory.count () && directory.at (directory.count () - 1) != '/') @@ -708,22 +710,40 @@ // File is modified but not saved, ask user what to do. The file // editor tab can't be made parent because it may be deleted depending // upon the response. Instead, change the _edit_area to read only. + QMessageBox::StandardButtons buttons = QMessageBox::Save | + QMessageBox::Discard; + QString available_actions; + + if (_app_closing) + available_actions = tr ("Do you want to save or discard the changes?"); + else + { + buttons = buttons | QMessageBox::Cancel; // cancel is allowed + available_actions + = tr ("Do you want to cancel closing, save or discard the changes?"); + } + QMessageBox* msgBox = new QMessageBox (QMessageBox::Warning, tr ("Octave Editor"), tr ("The file\n" "%1\n" "is about to be closed but has been modified.\n" - "Do you want to cancel closing, save or discard the changes?"). - arg (_file_name), - QMessageBox::Save | QMessageBox::Cancel | QMessageBox::Discard, 0); + "%2"). + arg (_file_name). arg (available_actions), + buttons, qobject_cast (parent ())); msgBox->setDefaultButton (QMessageBox::Save); _edit_area->setReadOnly (true); connect (msgBox, SIGNAL (finished (int)), this, SLOT (handle_file_modified_answer (int))); - msgBox->setWindowModality (Qt::NonModal); msgBox->setAttribute (Qt::WA_DeleteOnClose); - msgBox->show (); + if (_app_closing) // app is closing, a non modal dialogs prevent + msgBox->exec (); // the app of being closed before an answer from user + else + { + msgBox->setWindowModality (Qt::NonModal); + msgBox->show (); + } return QMessageBox::Cancel; } @@ -1062,11 +1082,12 @@ } void -file_editor_tab::conditional_close (const QWidget *ID) +file_editor_tab::conditional_close (const QWidget *ID, bool app_closing) { if (ID != this) return; + _app_closing = app_closing; close (); } diff -r b3f4bdd7e5f4 -r 3c2e457eeb72 libgui/src/m-editor/file-editor-tab.h --- a/libgui/src/m-editor/file-editor-tab.h Sat May 11 14:01:15 2013 +0200 +++ b/libgui/src/m-editor/file-editor-tab.h Sat May 11 18:20:31 2013 +0200 @@ -55,7 +55,7 @@ void notice_settings (const QSettings *settings); // Will initiate close if associated with the identifier tag. - void conditional_close (const QWidget *ID); + void conditional_close (const QWidget *ID, bool app_closing = false); // Change to a different editor tab by identifier tag. void change_editor_state (const QWidget *ID); @@ -182,6 +182,7 @@ bool _long_title; bool _copy_available; + bool _app_closing; QFileSystemWatcher _file_system_watcher; diff -r b3f4bdd7e5f4 -r 3c2e457eeb72 libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc Sat May 11 14:01:15 2013 +0200 +++ b/libgui/src/m-editor/file-editor.cc Sat May 11 18:20:31 2013 +0200 @@ -72,6 +72,9 @@ settings->setValue ("editor/savedSessionTabs", fetFileNames); settings->sync (); + for (int index = _tab_widget->count ()-1; index >= 0; index--) + emit fetab_close_request (_tab_widget->widget (index),true); // true: app closing + if (_mru_file_menu) delete _mru_file_menu; } @@ -1083,8 +1086,8 @@ connect (this, SIGNAL (fetab_settings_changed (const QSettings *)), f, SLOT (notice_settings (const QSettings *))); - connect (this, SIGNAL (fetab_close_request (const QWidget*)), - f, SLOT (conditional_close (const QWidget*))); + 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*))); diff -r b3f4bdd7e5f4 -r 3c2e457eeb72 libgui/src/m-editor/file-editor.h --- a/libgui/src/m-editor/file-editor.h Sat May 11 14:01:15 2013 +0200 +++ b/libgui/src/m-editor/file-editor.h Sat May 11 18:20:31 2013 +0200 @@ -62,7 +62,7 @@ signals: void fetab_settings_changed (const QSettings *settings); - void fetab_close_request (const QWidget* ID); + void fetab_close_request (const QWidget* ID, bool app_closing = false); void fetab_change_request (const QWidget* ID); void fetab_file_name_query (const QWidget* ID); // Save is a ping-pong type of communication diff -r b3f4bdd7e5f4 -r 3c2e457eeb72 libgui/src/main-window.cc --- a/libgui/src/main-window.cc Sat May 11 14:01:15 2013 +0200 +++ b/libgui/src/main-window.cc Sat May 11 18:20:31 2013 +0200 @@ -87,9 +87,9 @@ // Destroy the terminal first so that STDERR stream is redirected back // to its original pipe to capture error messages at exit. + delete editor_window; // first one for dialogs of modified editor-tabs delete command_window; delete workspace_window; - delete editor_window; delete doc_browser_window; delete file_browser_window; delete history_window;