# HG changeset patch # User Torsten # Date 1360317339 -3600 # Node ID 06187a0b7a62cbf771a74f581203f251fcdbbc4e # Parent 9194bb707d63e904596a5a24b4c35f601102e45e gui: new handling when an editor file is deleted or renamed (bug #38282) * file-editor-tab.cc (file_has_changed): in case of deletion of opened file do not make the edit tab the parent of the dialog box, set read only instead; Add a warning if the editor contents is modified. * file-editor-tab.cc (handle_file_resave_answer): if decision is to save the file again, remove read only flag; do not add the file to the watcher since this is already done while saving; when closing the file delete the modified flag in order to prevent another dialog when the closed event is posted. diff -r 9194bb707d63 -r 06187a0b7a62 libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc Thu Feb 07 17:21:10 2013 -0800 +++ b/libgui/src/m-editor/file-editor-tab.cc Fri Feb 08 10:55:39 2013 +0100 @@ -975,12 +975,20 @@ } else { - // Create a WindowModal message that blocks the edit area - // by making _edit_area parent. + QString modified = ""; + if (_edit_area->isModified ()) + modified = tr ("\n\nWarning: The contents in the editor is modified!"); + // Create a WindowModal message. 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* msgBox = new QMessageBox ( QMessageBox::Warning, tr ("Octave Editor"), - tr ("It seems that \'%1\' has been deleted or renamed. Do you want to save it now?"). - arg (_file_name), QMessageBox::Save | QMessageBox::Close, this); + tr ("It seems that the file\n" + "%1\n" + "has been deleted or renamed. Do you want to save it now?%2"). + arg (_file_name).arg (modified), + QMessageBox::Save | QMessageBox::Close, 0); + _edit_area->setReadOnly (true); connect (msgBox, SIGNAL (finished (int)), this, SLOT (handle_file_resave_answer (int))); msgBox->setWindowModality (Qt::WindowModal); @@ -1090,21 +1098,21 @@ void file_editor_tab::handle_file_resave_answer (int decision) { + // check decision of user in dialog if (decision == QMessageBox::Save) { - save_file (_file_name); + save_file (_file_name); // readds file to watcher in set_file_name () + _edit_area->setReadOnly (false); // delete read only flag } else { - if (close ()) - { - emit tab_remove_request (); - return; // Don't touch member variables after removal - } + // Definitely close the file. + // Set modified to false to prevent the dialog box when the close event + // is posted. If the user cancels the close in this dialog the tab is + // left open with a non-existing file. + _edit_area->setModified (false); + close (); } - - // Start watching file once again. - _file_system_watcher.addPath (_file_name); } void