changeset 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 2c8fc292ff2c
children f18e48749a7a
files libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h
diffstat 3 files changed, 32 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Wed Nov 06 18:18:51 2019 -0800
+++ b/libgui/src/m-editor/file-editor-tab.cc	Thu Nov 07 10:03:25 2019 +0100
@@ -319,7 +319,6 @@
     else
       {
         e->accept ();
-        emit tab_ready_to_close ();
         emit tab_remove_request ();
       }
   }
@@ -1863,7 +1862,13 @@
         if (decision == QMessageBox::Cancel)
           m_edit_area->setReadOnly (false);
         else if (decision == QMessageBox::Save)
-          save_file (m_file_name, remove, false);   // Remove on success
+          save_file (m_file_name, remove, false);
+        else
+          emit tab_ready_to_close ();
+      }
+    else
+      {
+        emit tab_ready_to_close ();
       }
 
     return decision;
--- 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 ();
           }
--- a/libgui/src/m-editor/file-editor.h	Wed Nov 06 18:18:51 2019 -0800
+++ b/libgui/src/m-editor/file-editor.h	Thu Nov 07 10:03:25 2019 +0100
@@ -448,6 +448,7 @@
 
     int m_marker_breakpoint;
 
+    bool m_closing_canceled;
     bool m_closed;
     bool m_no_focus;