Mercurial > octave
diff libgui/src/m-editor/file-editor-tab.cc @ 16638:3c2e457eeb72
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
author | Torsten <ttl@justmail.de> |
---|---|
date | Sat, 11 May 2013 18:20:31 +0200 |
parents | 25e418d23a4b |
children | 025bc6b5080e |
line wrap: on
line diff
--- 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<QWidget *> (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 (); }