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.
This commit is contained in:
Michael Gratton 2020-03-18 18:52:38 +11:00 committed by Michael James Gratton
parent 254d10782c
commit c8dd0c94e7
3 changed files with 36 additions and 3 deletions

View file

@ -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);
}
}
}
}
}
}

View file

@ -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);

View file

@ -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();