Mercurial > octave
diff libgui/src/m-editor/file-editor.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 | 3fcc650de22f |
children | 0495b64288f7 |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.cc Thu Oct 31 15:42:13 2019 -0400 +++ b/libgui/src/m-editor/file-editor.cc Fri Nov 01 09:26:22 2019 +0100 @@ -401,6 +401,28 @@ return false; } + // Wait for all editor tabs to have saved their files if required + m_number_of_tabs = m_editor_tab_map.size (); + + for (auto p = m_editor_tab_map.cbegin (); + p != m_editor_tab_map.cend (); p++) + { + QString file_name = p->first; // get file name of tab + connect (static_cast<file_editor_tab *> (m_editor_tab_map[file_name].fet_ID), + SIGNAL (tab_ready_to_close (void)), + this, SLOT (handle_tab_ready_to_close (void))); + } + + return true; + } + + void file_editor::handle_tab_ready_to_close (void) + { + m_number_of_tabs--; + + if (m_number_of_tabs > 0) + return; + // Here, the application or the editor will be closed -> store the session // Save open files for restoring in next session; this only is possible @@ -415,7 +437,7 @@ // save all open tabs before they are definitely closed for (auto p = m_editor_tab_map.cbegin (); - p != m_editor_tab_map.cend (); p++) + p != m_editor_tab_map.cend (); p++) { QString file_name = p->first; // get file name of tab if (! file_name.isEmpty ()) // do not append unnamed files @@ -427,7 +449,7 @@ file_editor_tab *editor_tab = static_cast<file_editor_tab *> (m_editor_tab_map[file_name].fet_ID); fet_index.append (index.setNum - (m_tab_widget->indexOf (editor_tab))); + (m_tab_widget->indexOf (editor_tab))); int l, c; editor_tab->qsci_edit_area ()->getCursorPosition (&l, &c); @@ -456,7 +478,7 @@ setVisible (vis); - return true; + octave_dock_widget::close (); } void file_editor::request_new_file (const QString& commands) @@ -1646,7 +1668,7 @@ // all tabs are closed without cancelling, // store closing state for restoring session when shown again m_closed = true; - e->accept (); + e->ignore (); } else {