Mercurial > octave
diff libgui/src/m-editor/file-editor-tab.cc @ 27605:60cecb3fed04
fix saving modified files when closing editor tabs or octave
* file-editor-tab.cc (closeEvent) also ignore evnet when file has
to be saved, it is directly removed after saving now; in case closing is
accepted, emit the related signal to the editor;
(check_modified_file): call check_file_modified with false as new boolean
parameter indicating that file should not be closed afterwards
(check_file_modified): new boolean parameter for removing the file after
checking for modification and possibly saving; use exec for the dialog
for directly getting the result without extra finish signal/slot; if
desired, call save_file from here;
(handle_file_modified_answer): removed obsolete slot for dialog result
(do_save_file): emit signal that tab could be closed now
* file-editor-tab.h: new signal tab_ready_to_close, removed slo
handle_file_modified_answer, slot check_file_modified with new
boolean parameter
* file-editor.cc (check_closing): if closing is not canceled connect
tab signals on being ready to close instead of directly closing all tabs
and store the number of tabs that have to be closed;
(handle_tab_ready_to_close): slot for tab ready to close signal, decreasing
number of tabs to be closed until it reaches zero and then close all tabs
and the editor itself;
(closeEvent): ignore event even when all tabs should be closed because
editor will close itself after all tabs are closed
* file-editor.h: new slot handle_tab_ready_to_close, new class variable
m_number_of_tabs for the number of tabs, for which the editor has to
wait for closing
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Fri, 01 Nov 2019 09:26:22 +0100 |
parents | 315c35e6037c |
children | 0495b64288f7 |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc Thu Oct 31 15:42:13 2019 -0400 +++ b/libgui/src/m-editor/file-editor-tab.cc Fri Nov 01 09:26:22 2019 +0100 @@ -309,15 +309,19 @@ m_cancelled = false; // prevent unwanted interaction of previous // exits of octave which were canceled by the user - if (check_file_modified () == QMessageBox::Cancel) + int save_dialog = check_file_modified (true); + if ((save_dialog == QMessageBox::Cancel) || + (save_dialog == QMessageBox::Save)) { - // ignore close event if file is not saved and user cancels - // closing this window + // Ignore close event if file is saved or user cancels + // closing this window. In case of saving, tab is closed after + // successful saving. e->ignore (); } else { e->accept (); + emit tab_ready_to_close (); emit tab_remove_request (); } } @@ -998,7 +1002,7 @@ if (m_cancelled) return; - if (check_file_modified () == QMessageBox::Cancel) + if (check_file_modified (false) == QMessageBox::Cancel) m_cancelled = true; } @@ -1827,7 +1831,7 @@ } } - int file_editor_tab::check_file_modified (void) + int file_editor_tab::check_file_modified (bool remove) { int decision = QMessageBox::Yes; if (m_edit_area->isModified ()) @@ -1862,44 +1866,21 @@ msgBox->setDefaultButton (QMessageBox::Save); m_edit_area->setReadOnly (true); - connect (msgBox, SIGNAL (finished (int)), - this, SLOT (handle_file_modified_answer (int))); - - show_dialog (msgBox, true); - - if (m_cancelled) - return QMessageBox::Cancel; - else - return decision; - } - else - { - // Nothing was modified. Leave tab present in case user - // decides to cancel some point further along. + + decision = msgBox->exec (); // show_dialog (msgBox, true); + + if (decision == QMessageBox::Cancel) + { + m_cancelled = true; + m_edit_area->setReadOnly (false); + } + else if (decision == QMessageBox::Save) + save_file (m_file_name, remove, false); // Remove on success } return decision; } - void file_editor_tab::handle_file_modified_answer (int decision) - { - if (decision == QMessageBox::Save) - { - // Save file, but do not remove from editor. - save_file (m_file_name, false, false); - } - else if (decision == QMessageBox::Discard) - { - // User doesn't want to save, leave tab and remove subsequently. - } - else - { - // User canceled, allow editing again. - m_edit_area->setReadOnly (false); - m_cancelled = true; - } - } - void file_editor_tab::set_modified (bool modified) { m_edit_area->setModified (modified); @@ -2432,6 +2413,8 @@ m_edit_area->setModified (false); m_enc_indicator->setText (m_encoding); + emit tab_ready_to_close (); + if (remove_on_success) { emit tab_remove_request ();