[geary/mjog/folder-actions: 2/7] Plugin.FolderContext: Add folder_selected signal



commit c8dd0c94e717dfcd893c25f3105cdb0d021e7bff
Author: Michael Gratton <mike vee net>
Date:   Wed Mar 18 18:52:38 2020 +1100

    Plugin.FolderContext: Add folder_selected signal
    
    Add new signal so folder plugins know when folders have changed, and
    implement emittig it when a folder is selected in the main window.

 .../application-folder-store-factory.vala          | 34 ++++++++++++++++++++--
 .../application/application-plugin-manager.vala    |  2 +-
 src/client/plugin/plugin-folder-store.vala         |  3 ++
 3 files changed, 36 insertions(+), 3 deletions(-)
---
diff --git a/src/client/application/application-folder-store-factory.vala 
b/src/client/application/application-folder-store-factory.vala
index 84384e3a..b5839f49 100644
--- a/src/client/application/application-folder-store-factory.vala
+++ b/src/client/application/application-folder-store-factory.vala
@@ -112,6 +112,7 @@ internal class Application.FolderStoreFactory : Geary.BaseObject {
     }
 
 
+    private Client application;
     private Geary.Engine engine;
 
     private Gee.Map<Geary.AccountInformation,AccountImpl> accounts =
@@ -125,17 +126,23 @@ internal class Application.FolderStoreFactory : Geary.BaseObject {
     /**
      * Constructs a new factory instance.
      */
-    public FolderStoreFactory(Geary.Engine engine) throws GLib.Error {
-        this.engine = engine;
+    public FolderStoreFactory(Client application) throws GLib.Error {
+        this.application = application;
+        this.engine = application.engine;
         this.engine.account_available.connect(on_account_available);
         this.engine.account_unavailable.connect(on_account_unavailable);
         foreach (Geary.Account account in this.engine.get_accounts()) {
             add_account(account.information);
         }
+        application.window_added.connect(on_window_added);
+        foreach (MainWindow main in this.application.get_main_windows()) {
+            main.notify["selected-folder"].connect(on_folder_selected);
+        }
     }
 
     /** Clearing all state of the store. */
     public void destroy() throws GLib.Error {
+        this.application.window_added.disconnect(on_window_added);
         foreach (FolderStoreImpl store in this.stores) {
             store.destroy();
         }
@@ -279,4 +286,27 @@ internal class Application.FolderStoreFactory : Geary.BaseObject {
         }
     }
 
+
+    private void on_window_added(Gtk.Window window) {
+        var main = window as MainWindow;
+        if (main != null) {
+            main.notify["selected-folder"].connect(on_folder_selected);
+        }
+    }
+
+    private void on_folder_selected(GLib.Object object, GLib.ParamSpec param) {
+        var main = object as MainWindow;
+        if (main != null) {
+            Geary.Folder? selected = main.selected_folder;
+            if (selected != null) {
+                var plugin = get_plugin_folder(selected);
+                if (plugin != null) {
+                    foreach (FolderStoreImpl store in this.stores) {
+                        store.folder_selected(plugin);
+                    }
+                }
+            }
+        }
+    }
+
 }
diff --git a/src/client/application/application-plugin-manager.vala 
b/src/client/application/application-plugin-manager.vala
index 829d673c..1967e1c1 100644
--- a/src/client/application/application-plugin-manager.vala
+++ b/src/client/application/application-plugin-manager.vala
@@ -97,7 +97,7 @@ public class Application.PluginManager : GLib.Object {
     public PluginManager(Client application) throws GLib.Error {
         this.application = application;
         this.plugins = Peas.Engine.get_default();
-        this.folders_factory = new FolderStoreFactory(application.engine);
+        this.folders_factory = new FolderStoreFactory(application);
 
         this.trusted_path = application.get_app_plugins_dir().get_path();
         this.plugins.add_search_path(trusted_path, null);
diff --git a/src/client/plugin/plugin-folder-store.vala b/src/client/plugin/plugin-folder-store.vala
index 982097e7..dd088e1e 100644
--- a/src/client/plugin/plugin-folder-store.vala
+++ b/src/client/plugin/plugin-folder-store.vala
@@ -24,6 +24,9 @@ public interface Plugin.FolderStore : Geary.BaseObject {
     /** Emitted when existing folders have become unavailable. */
     public signal void folders_type_changed(Gee.Collection<Folder> changed);
 
+    /** Emitted when a folder has been selected in any main window. */
+    public signal void folder_selected(Folder selected);
+
 
     /** Returns a read-only set of all known folders. */
     public abstract Gee.Collection<Folder> get_folders();


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