diff libgui/src/m-editor/file-editor-tab.cc @ 19608:ed0df431631b gui-release

allow to cancel exiting if editor tabs are modified and exit is requested in gui * file-editor-interface.h: new function check_closing * file-editor-tab.cc (ctor): set default for app_closing to 0 (not closing); (check_file_modified): dialog boxes for modified editor tabs depending on app closing or not; (conditional_close): no slot, but ordinary function returning close result; * file-editor-tab.h: conditional_close is function, not a slot; _app_closing is now int for closing from gui, from octave, not closing * file-editor.cc (dtor): calling new function check_closing if there are open tabs (exit requested octave), do not save session here since the tabs might already have been closed; (check_closing): new function saving session info and closing all tabs, stop closing tabs and returning false if user cancels exiting if there is a modified tab; (request_close_file, request_close_all_files, request_close_other_files, handle_tab_close_request): use conditional_close instead of signal; (construct): do not connect old signal for closing the tabs * file-editor.h: remove signal fetab_close_request, new function check_closing * main-window.cc (confirm_exit_octave): call file_editor::check_closing before really closing the app
author Torsten <ttl@justmail.de>
date Sat, 20 Dec 2014 17:26:53 +0100
parents c364b9a44580
children f90bb1e30de2
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc
+++ b/libgui/src/m-editor/file-editor-tab.cc
@@ -69,7 +69,7 @@
 {
   QString directory = directory_arg;
   _lexer_apis = 0;
-  _app_closing = false;
+  _app_closing = 0;   // app is not closing
   _is_octave_file = true;
   _modal_dialog = false;
 
@@ -1243,13 +1243,24 @@
                                              QMessageBox::Discard;
       QString available_actions;
 
-      if (_app_closing)
-        available_actions = tr ("Do you want to save or discard the changes?");
-      else
+      switch (_app_closing)
         {
-          buttons = buttons | QMessageBox::Cancel;  // cancel is allowed
-          available_actions
-            = tr ("Do you want to cancel closing, save or discard the changes?");
+          case -1:  // octave is exiting and so does the gui
+            available_actions =
+              tr ("Do you want to save or discard the changes?");
+            break;
+
+          case 1:   // gui is exiting
+            available_actions =
+              tr ("Do you want to cancel exiting octave, save or discard the changes?");
+            buttons = buttons | QMessageBox::Cancel;
+            break;
+
+          case 0:   // tab is closing
+            available_actions =
+              tr ("Do you want to cancel closing, save or discard the changes?");
+            buttons = buttons | QMessageBox::Cancel;
+            break;
         }
 
       QString file;
@@ -1917,14 +1928,16 @@
   _edit_area->setMarginWidth (2, "1"+QString::number (_edit_area->lines ()));
 }
 
-void
-file_editor_tab::conditional_close (const QWidget *ID, bool app_closing)
+// the following close request was changed from a signal slot into a
+// normal function because we need the return value from close whether
+// the tab really was closed (for canceling exiting octave).
+// When emitting a signal, only the return value from the last slot
+// goes back to the sender
+bool
+file_editor_tab::conditional_close (int app_closing)
 {
-  if (ID != this)
-    return;
-
   _app_closing = app_closing;
-  close ();
+  return close ();
 }
 
 void