[geary/mjog/mutiple-main-windows: 11/14] Add support for opening additional main windows



commit 8f8709f2afb80bf56d82060efddc257ba7b72a0f
Author: Michael Gratton <mike vee net>
Date:   Mon Nov 18 13:34:53 2019 +1100

    Add support for opening additional main windows
    
    Closes #139

 desktop/org.gnome.Geary.desktop.in.in          |  8 +++--
 src/client/application/application-client.vala | 49 +++++++++++++++++++++-----
 src/client/client-action.vala                  |  1 +
 3 files changed, 48 insertions(+), 10 deletions(-)
---
diff --git a/desktop/org.gnome.Geary.desktop.in.in b/desktop/org.gnome.Geary.desktop.in.in
index 40044627..27610305 100644
--- a/desktop/org.gnome.Geary.desktop.in.in
+++ b/desktop/org.gnome.Geary.desktop.in.in
@@ -14,9 +14,13 @@ Categories=GNOME;GTK;Network;Email;
 MimeType=x-scheme-handler/mailto;
 StartupNotify=true
 DBusActivatable=true
+Actions=compose;new-window
 X-GNOME-UsesNotifications=true
-Actions=Compose;
 
-[Desktop Action Compose]
+[Desktop Action compose]
 Name=Compose Message
 Exec=geary mailto:
+
+[Desktop Action new-window]
+Name=New Window
+Exec=geary --new-window
diff --git a/src/client/application/application-client.vala b/src/client/application/application-client.vala
index a217a9ea..c858076b 100644
--- a/src/client/application/application-client.vala
+++ b/src/client/application/application-client.vala
@@ -68,6 +68,7 @@ public class Application.Client : Gtk.Application {
     private const string OPTION_LOG_SERIALIZER = "log-serializer";
     private const string OPTION_LOG_SQL = "log-sql";
     private const string OPTION_HIDDEN = "hidden";
+    private const string OPTION_NEW_WINDOW = "new-window";
     private const string OPTION_QUIT = "quit";
     private const string OPTION_REVOKE_CERTS = "revoke-certs";
 
@@ -78,6 +79,7 @@ public class Application.Client : Gtk.Application {
         { Action.Application.HELP, on_activate_help},
         { Action.Application.INSPECT, on_activate_inspect},
         { Action.Application.MAILTO, on_activate_mailto, "s"},
+        { Action.Application.NEW_WINDOW, on_activate_new_window },
         { Action.Application.PREFERENCES, on_activate_preferences},
         { Action.Application.QUIT, on_activate_quit},
         { Action.Application.SHOW_EMAIL, on_activate_show_email, "(svv)"},
@@ -128,6 +130,8 @@ public class Application.Client : Gtk.Application {
         { OPTION_QUIT, 'q', 0, GLib.OptionArg.NONE, null,
           /// Command line option
           N_("Perform a graceful quit"), null },
+        { OPTION_NEW_WINDOW, 'n', 0, GLib.OptionArg.NONE, null,
+          N_("Open a new window"), null },
         { OPTION_REVOKE_CERTS, 0, 0, GLib.OptionArg.NONE, null,
           /// Command line option
           N_("Revoke all pinned TLS server certificates"), null },
@@ -406,6 +410,7 @@ public class Application.Client : Gtk.Application {
         add_app_accelerators(Action.Application.COMPOSE, { "<Ctrl>N" });
         add_app_accelerators(Action.Application.HELP, { "F1" });
         add_app_accelerators(Action.Application.INSPECT, { "<Alt><Shift>I" });
+        add_app_accelerators(Action.Application.NEW_WINDOW, { "<Ctrl><Shift>N" });
         add_app_accelerators(Action.Application.QUIT, { "<Ctrl>Q" });
 
         // Common window accels
@@ -493,14 +498,10 @@ public class Application.Client : Gtk.Application {
      * shows it.
      */
     public MainWindow get_active_main_window() {
-        MainWindow? active = this.last_active_main_window;
-        if (active == null) {
-            active = new MainWindow(this);
-            this.controller.register_window(active);
-            this.last_active_main_window = active;
-            active.show();
+        if (this.last_active_main_window == null) {
+            this.last_active_main_window = new_main_window();
         }
-        return active;
+        return last_active_main_window;
     }
 
     public void add_window_accelerators(string action,
@@ -549,7 +550,9 @@ public class Application.Client : Gtk.Application {
     public async void show_accounts() {
         yield this.present();
 
-        Accounts.Editor editor = new Accounts.Editor(this, get_active_window());
+        Accounts.Editor editor = new Accounts.Editor(
+            this, get_active_main_window()
+        );
         editor.run();
         editor.destroy();
         this.controller.expunge_accounts.begin();
@@ -595,6 +598,12 @@ public class Application.Client : Gtk.Application {
         this.controller.compose(mailto);
     }
 
+    public async void new_window() {
+        yield create_controller();
+
+        new_main_window().present();
+    }
+
     /** Returns the application's base user configuration directory. */
     public GLib.File get_user_config_directory() {
         return GLib.File.new_for_path(
@@ -749,6 +758,13 @@ public class Application.Client : Gtk.Application {
         return main;
     }
 
+    private MainWindow new_main_window() {
+        MainWindow window = new MainWindow(this);
+        this.controller.register_window(window);
+        window.focus_in_event.connect(on_main_window_focus_in);
+        return window;
+    }
+
     // Opens the controller
     private async void create_controller() {
         bool first_run = false;
@@ -839,6 +855,10 @@ public class Application.Client : Gtk.Application {
             this.create_controller.begin();
             activated = true;
         }
+        if (options.contains(OPTION_NEW_WINDOW)) {
+            activate_action(Action.Application.NEW_WINDOW, null);
+            activated = true;
+        }
 
         if (options.contains(GLib.OPTION_REMAINING)) {
             string[] args = options.lookup_value(
@@ -936,6 +956,10 @@ public class Application.Client : Gtk.Application {
         }
     }
 
+    private void on_activate_new_window() {
+        this.new_window.begin();
+    }
+
     private void on_activate_preferences() {
         this.show_preferences.begin();
     }
@@ -1014,6 +1038,15 @@ public class Application.Client : Gtk.Application {
         }
     }
 
+    private bool on_main_window_focus_in(Gtk.Widget widget,
+                                         Gdk.EventFocus event) {
+        MainWindow? main = widget as MainWindow;
+        if (main != null) {
+            this.last_active_main_window = main;
+        }
+        return Gdk.EVENT_PROPAGATE;
+    }
+
     private void on_window_removed(Gtk.Window window) {
         MainWindow? main = window as MainWindow;
         if (main != null) {
diff --git a/src/client/client-action.vala b/src/client/client-action.vala
index a5bcf047..70997d20 100644
--- a/src/client/client-action.vala
+++ b/src/client/client-action.vala
@@ -21,6 +21,7 @@ namespace Action {
         public const string INSPECT = "inspect";
         public const string HELP = "help";
         public const string MAILTO = "mailto";
+        public const string NEW_WINDOW = "new-window";
         public const string PREFERENCES = "preferences";
         public const string SHOW_EMAIL = "show-email";
         public const string SHOW_FOLDER = "show-folder";


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