diff libgui/src/m-editor/file-editor.cc @ 27651:c9ebcb9050b4

fix broken storing of editor session data at shutdown * file-editor-tab.cc (closeEvent): do not emit ready to close signal here; (check_modified_file): but here when closing was not canceled or file is not modified (do_save_file): and here after having saved the file * file-editor.cc (check_closing): store number of tabs and connect their signals for being ready to close with the related slot, if closing was canceled, disconnect these signals; (handle_tab_ready_to_close): immediately return from this slot when closing was canceled
author Torsten Lilge <ttl-octave@mailbox.org>
date Thu, 07 Nov 2019 10:03:25 +0100
parents 2a03fa568feb
children a36443e94f8a
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.cc	Wed Nov 06 18:18:51 2019 -0800
+++ b/libgui/src/m-editor/file-editor.cc	Thu Nov 07 10:03:25 2019 +0100
@@ -396,6 +396,18 @@
     // definitely closing.
 
     std::list<file_editor_tab *> fe_tab_lst = m_tab_widget->tab_list ();
+    m_number_of_tabs = fe_tab_lst.size ();
+
+    for (auto fe_tab : fe_tab_lst)
+      {
+        // Wait for all editor tabs to have saved their files if required
+
+        connect (fe_tab, SIGNAL (tab_ready_to_close (void)),
+                 this, SLOT (handle_tab_ready_to_close (void)),
+                 Qt::UniqueConnection);
+      }
+
+    m_closing_canceled = false;
 
     for (auto fe_tab : fe_tab_lst)
       {
@@ -408,23 +420,24 @@
         if (fe_tab->check_file_modified (false) == QMessageBox::Cancel)
           {
             emit fetab_recover_from_exit ();
+
+            m_closing_canceled = true;
+
+            for (auto fet : fe_tab_lst)
+              disconnect (fet, SIGNAL (tab_ready_to_close (void)), 0, 0 );
+
             return false;
           }
       }
 
-    for (auto fe_tab : fe_tab_lst)
-      {
-        // Wait for all editor tabs to have saved their files if required
-
-        connect (fe_tab, 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)
   {
+    if (m_closing_canceled)
+      return;
+
     m_number_of_tabs--;
 
     if (m_number_of_tabs > 0)
@@ -1663,8 +1676,9 @@
       {
         if (check_closing ())
           {
-            // all tabs are closed without cancelling,
-            // store closing state for restoring session when shown again
+            // All tabs are closed without cancelling,
+            // store closing state for restoring session when shown again.
+            // Editor is closing when session data is stored in preferences
             m_closed = true;
             e->ignore ();
           }