[geary/mjog/mail-merge-plugin: 140/157] Components.PreferencesWindow: Update plugin rows when deps change
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/mail-merge-plugin: 140/157] Components.PreferencesWindow: Update plugin rows when deps change
- Date: Fri, 3 Jul 2020 08:13:20 +0000 (UTC)
commit d75afbc6f4da488701e8f9fe2fd00fa27ac4a090
Author: Michael Gratton <mike vee net>
Date: Wed Apr 29 22:50:55 2020 +1000
Components.PreferencesWindow: Update plugin rows when deps change
Hook up to PluginManager's signals and ensure plugin rows are updated
when a plugin's dependencies are also loaded or unloaded.
.../components/components-preferences-window.vala | 122 ++++++++++++---------
1 file changed, 73 insertions(+), 49 deletions(-)
---
diff --git a/src/client/components/components-preferences-window.vala
b/src/client/components/components-preferences-window.vala
index 17119f52c..598745265 100644
--- a/src/client/components/components-preferences-window.vala
+++ b/src/client/components/components-preferences-window.vala
@@ -16,6 +16,78 @@ public class Components.PreferencesWindow : Hdy.PreferencesWindow {
{ ACTION_CLOSE, on_close },
};
+ private class PluginRow : Hdy.ActionRow {
+
+ private Peas.PluginInfo plugin;
+ private Application.PluginManager plugins;
+ private Gtk.Switch sw = new Gtk.Switch();
+
+
+ public PluginRow(Peas.PluginInfo plugin,
+ Application.PluginManager plugins) {
+ this.plugin = plugin;
+ this.plugins = plugins;
+
+ this.sw.active = plugin.is_loaded();
+ this.sw.notify["active"].connect_after(() => update_plugin());
+ this.sw.valign = CENTER;
+
+ var row = new Hdy.ActionRow();
+ this.title = plugin.get_name();
+ this.subtitle = plugin.get_description();
+ this.activatable_widget = this.sw;
+ this.add_action(this.sw);
+
+ plugins.plugin_activated.connect((info) => {
+ if (this.plugin == info) {
+ this.sw.active = true;
+ }
+ });
+ plugins.plugin_deactivated.connect((info) => {
+ if (this.plugin == info) {
+ this.sw.active = false;
+ }
+ });
+ plugins.plugin_error.connect((info) => {
+ if (this.plugin == info) {
+ this.sw.active = false;
+ this.sw.sensitive = false;
+ }
+ });
+ }
+
+ private void update_plugin() {
+ if (this.sw.active && !this.plugin.is_loaded()) {
+ bool loaded = false;
+ try {
+ loaded = this.plugins.load_optional(this.plugin);
+ } catch (GLib.Error err) {
+ warning(
+ "Plugin %s not able to be loaded: %s",
+ plugin.get_name(), err.message
+ );
+ }
+ if (!loaded) {
+ this.sw.active = false;
+ }
+ } else if (!sw.active && this.plugin.is_loaded()) {
+ bool unloaded = false;
+ try {
+ unloaded = this.plugins.unload_optional(this.plugin);
+ } catch (GLib.Error err) {
+ warning(
+ "Plugin %s not able to be loaded: %s",
+ plugin.get_name(), err.message
+ );
+ }
+ if (!unloaded) {
+ this.sw.active = true;
+ }
+ }
+ }
+
+ }
+
public static void add_accelerators(Application.Client app) {
app.add_window_accelerators(ACTION_CLOSE, { "Escape" } );
@@ -171,7 +243,7 @@ public class Components.PreferencesWindow : Hdy.PreferencesWindow {
if (application != null) {
foreach (Peas.PluginInfo plugin in
this.plugins.get_optional_plugins()) {
- group.add(new_plugin_row(plugin));
+ group.add(new PluginRow(plugin, this.plugins));
}
}
@@ -186,54 +258,6 @@ public class Components.PreferencesWindow : Hdy.PreferencesWindow {
add(page);
}
- private Hdy.ActionRow new_plugin_row(Peas.PluginInfo plugin) {
- var @switch = new Gtk.Switch();
- @switch.active = plugin.is_loaded();
- @switch.notify["active"].connect_after(
- () => enable_plugin(plugin, switch)
- );
- @switch.valign = CENTER;
-
- var row = new Hdy.ActionRow();
- row.title = plugin.get_name();
- row.subtitle = plugin.get_description();
- row.activatable_widget = @switch;
- row.add_action(@switch);
-
- return row;
- }
-
- private void enable_plugin(Peas.PluginInfo plugin, Gtk.Switch @switch) {
- if (@switch.active && !plugin.is_loaded()) {
- bool loaded = false;
- try {
- loaded = this.plugins.load_optional(plugin);
- } catch (GLib.Error err) {
- warning(
- "Plugin %s not able to be loaded: %s",
- plugin.get_name(), err.message
- );
- }
- if (!loaded) {
- @switch.active = false;
- }
- } else if (!@switch.active && plugin.is_loaded()) {
- bool unloaded = false;
- try {
- unloaded = this.plugins.unload_optional(plugin);
- } catch (GLib.Error err) {
- warning(
- "Plugin %s not able to be loaded: %s",
- plugin.get_name(), err.message
- );
- }
- if (!unloaded) {
- @switch.active = true;
- }
- }
- }
-
-
private void on_close() {
close();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]