[latexila: 8/8] app: implement the app.quit action



commit 9e05cf9cb94378f393ad188b9f535d2c069addaf
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Dec 18 16:01:24 2015 +0100

    app: implement the app.quit action
    
    The quit action implementation only closed the current MainWindow.
    Normally a quit action must quit the app. That's what is done now.

 src/latexila_app.vala |   31 +++++++++++++++++++++++++++++++
 src/main_window.vala  |   20 +++++++++++++++-----
 2 files changed, 46 insertions(+), 5 deletions(-)
---
diff --git a/src/latexila_app.vala b/src/latexila_app.vala
index ee33e01..e264054 100644
--- a/src/latexila_app.vala
+++ b/src/latexila_app.vala
@@ -221,6 +221,37 @@ public class LatexilaApp : Gtk.Application
 
             release ();
         });
+
+        /* Quit */
+        SimpleAction quit_action = new SimpleAction ("quit", null);
+        add_action (quit_action);
+
+        quit_action.activate.connect (() =>
+        {
+            hold ();
+
+            bool stop = false;
+            while (this.active_window != null && ! stop)
+            {
+                foreach (Gtk.Window window in get_windows ())
+                {
+                    if (window is MainWindow)
+                    {
+                        MainWindow main_window = window as MainWindow;
+                        main_window.present ();
+                        stop = ! main_window.quit ();
+                        break;
+                    }
+                }
+            }
+
+            while (this.active_window != null && ! stop)
+            {
+                this.active_window.destroy ();
+            }
+
+            release ();
+        });
     }
 
     public static LatexilaApp get_instance ()
diff --git a/src/main_window.vala b/src/main_window.vala
index 1192391..ecb8d93 100644
--- a/src/main_window.vala
+++ b/src/main_window.vala
@@ -261,7 +261,7 @@ public class MainWindow : ApplicationWindow
 
         delete_event.connect (() =>
         {
-            on_quit ();
+            quit ();
 
             // the destroy signal is not emitted
             return true;
@@ -1037,10 +1037,9 @@ public class MainWindow : ApplicationWindow
         action.set_sensitive (active_tab != null && active_document.project_id != -1);
     }
 
-    /*************************************************************************/
-    // Gtk.Action callbacks
-
-    public void on_quit ()
+    // Returns true if all the documents are closed.
+    // Quits only this window, not the whole app.
+    public bool quit ()
     {
         // save documents list
         string[] list_uris = {};
@@ -1057,7 +1056,18 @@ public class MainWindow : ApplicationWindow
         {
             save_state ();
             destroy ();
+            return true;
         }
+
+        return false;
+    }
+
+    /*************************************************************************/
+    // Gtk.Action callbacks
+
+    public void on_quit ()
+    {
+        LatexilaApp.get_instance ().activate_action ("quit", null);
     }
 
     /* View */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]