From 2ceb1ffd9898e104bb63dbd769fd97a201387857 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 25 May 2025 12:16:58 +0100 Subject: [PATCH 1/5] Commit while working --- .../brackets-completion.vala | 2 + .../highlight-word-selection.vala | 2 + src/Services/PluginManager.vala | 91 ++++++++++++------- 3 files changed, 64 insertions(+), 31 deletions(-) diff --git a/plugins/brackets-completion/brackets-completion.vala b/plugins/brackets-completion/brackets-completion.vala index 5639b4460..001d24a47 100644 --- a/plugins/brackets-completion/brackets-completion.vala +++ b/plugins/brackets-completion/brackets-completion.vala @@ -19,6 +19,7 @@ public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Scratch.Se private string previous_selection = ""; public void activate () { +warning ("brackets completion activate"); brackets = new Gee.HashMap (); brackets["("] = ")"; brackets["["] = "]"; @@ -43,6 +44,7 @@ public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Scratch.Se } public void deactivate () { +warning ("brackets completion deactivate"); plugins.hook_document.disconnect (on_hook_document); } diff --git a/plugins/highlight-word-selection/highlight-word-selection.vala b/plugins/highlight-word-selection/highlight-word-selection.vala index 91303df71..2e679bc22 100644 --- a/plugins/highlight-word-selection/highlight-word-selection.vala +++ b/plugins/highlight-word-selection/highlight-word-selection.vala @@ -31,6 +31,7 @@ public class Scratch.Plugins.HighlightSelectedWords : Peas.ExtensionBase, Scratc public void update_state () {} public void activate () { + warning ("activate highlight"); plugins = (Scratch.Services.Interface) object; plugins.hook_document.connect ((doc) => { if (current_source != null) { @@ -135,6 +136,7 @@ public class Scratch.Plugins.HighlightSelectedWords : Peas.ExtensionBase, Scratc } public void deactivate () { + warning ("deactivate highlight"); if (current_source != null) { current_source.deselected.disconnect (on_deselection); current_source.selection_changed.disconnect (on_selection_changed); diff --git a/src/Services/PluginManager.vala b/src/Services/PluginManager.vala index 88cefff40..771a2ccab 100644 --- a/src/Services/PluginManager.vala +++ b/src/Services/PluginManager.vala @@ -4,9 +4,9 @@ * 2013 Mario Guerriero */ -namespace Scratch.Services { - // Interface implemented by all plugins - public interface ActivatablePlugin : Object { +// namespace Scratch.Services { +// // Interface implemented by all plugins + public interface Scratch.Services.ActivatablePlugin : Object { // Migrated from Peas.Activatable public abstract void activate (); public abstract void deactivate (); @@ -15,7 +15,7 @@ namespace Scratch.Services { } // Object shared with plugins providing signals and methods to interface with application - public class Interface : GLib.Object { + public class Scratch.Services.Interface : GLib.Object { // Signals public signal void hook_window (Scratch.MainWindow window); public signal void hook_share_menu (GLib.MenuModel menu); @@ -27,7 +27,7 @@ namespace Scratch.Services { public Scratch.TemplateManager template_manager { get; construct; } public Scratch.Services.PluginsManager manager { get; construct; } - public Interface (PluginsManager _manager) { + public Interface (Scratch.Services.PluginsManager _manager) { Object ( manager: _manager ); @@ -37,18 +37,18 @@ namespace Scratch.Services { template_manager = new Scratch.TemplateManager (); } - public Document open_file (File file) { - var doc = new Document (manager.window.actions, file); + public Scratch.Services.Document open_file (File file) { + var doc = new Scratch.Services.Document (manager.window.actions, file); manager.window.open_document.begin (doc); return doc; } - public void close_document (Document doc) { + public void close_document (Scratch.Services.Document doc) { manager.window.close_document (doc); } } - public class PluginsManager : GLib.Object { + public class Scratch.Services.PluginsManager : GLib.Object { public signal void hook_window (Scratch.MainWindow window); public signal void hook_share_menu (GLib.MenuModel menu); public signal void hook_toolbar (Scratch.HeaderBar toolbar); @@ -59,43 +59,68 @@ namespace Scratch.Services { public signal void extension_added (Peas.PluginInfo info); public signal void extension_removed (Peas.PluginInfo info); - private Peas.Engine engine; + public Peas.Engine engine { get; construct; } - public weak MainWindow window { get; construct; } - public Interface plugin_iface { get; private set; } + public weak Scratch.MainWindow window { get; construct; } + public Scratch.Services.Interface plugin_iface { get; construct; } - public PluginsManager (MainWindow _window) { + public PluginsManager (Scratch.MainWindow _window) { Object (window: _window); } construct { - plugin_iface = new Interface (this); + plugin_iface = new Scratch.Services.Interface (this); /* Let's init the engine */ engine = Peas.Engine.get_default (); engine.enable_loader ("python"); engine.add_search_path (Constants.PLUGINDIR, null); + // engine.loaded_plugins = {"highlight-word-selection"}; Scratch.settings.bind ("plugins-enabled", engine, "loaded-plugins", SettingsBindFlags.DEFAULT); /* Our extension set */ var exts = new Peas.ExtensionSet.with_properties ( engine, - typeof (ActivatablePlugin), + typeof (Scratch.Services.ActivatablePlugin), {"object"}, {plugin_iface} ); - exts.extension_added.connect ((info, ext) => { - ((ActivatablePlugin)ext).activate (); - extension_added (info); - }); - - exts.extension_removed.connect ((info, ext) => { - ((ActivatablePlugin)ext).deactivate (); - extension_removed (info); - }); - - exts.@foreach ((Peas.ExtensionSetForeachFunc) on_extension_foreach, null); + if (exts != null) { + exts.extension_added.connect ((info, ext) => { + warning ("extension added"); + ((ActivatablePlugin)ext).activate (); + extension_added (info); + }); + + exts.extension_removed.connect ((info, ext) => { + warning ("extension removed"); + // ((ActivatablePlugin)ext).deactivate (); + // extension_removed (info); + + warning ("number of extensions now %u", exts.get_n_items ()); + }); + + exts.@foreach ((exts, info, ext) => { + ((Scratch.Services.ActivatablePlugin)ext).activate (); + }, null); + // var pos = 0; + // while (pos < exts.get_n_items ()) { + // var obj = exts.get_item (pos); + // if (obj != null) { + // var eb = (Peas.ExtensionBase)obj; + // var info = eb.plugin_info; + // warning ("got ext %s", info.get_name ()); + // var ap = (Scratch.Services.ActivatablePlugin)obj; + // ap.activate (); + // } else { + // warning ("Object is null"); + // } + // pos++; + // } + } else { + warning ("ext set is null"); + } // Connect managers signals to interface's signals this.hook_window.connect ((w) => { @@ -123,12 +148,9 @@ namespace Scratch.Services { }); } - private void on_extension_foreach (Peas.ExtensionSet exts, Peas.PluginInfo info, Object ext, void* data) { - ((ActivatablePlugin)ext).activate (); - } - // Return an emulation of the discontinued libpeas-1.0 widget public Gtk.Widget get_view () { + warning ("get plugin view"); var list_box = new Gtk.ListBox (); list_box.get_accessible ().accessible_name = _("Extensions"); @@ -203,11 +225,18 @@ namespace Scratch.Services { content.set_data ("name", info.get_name ()); checkbox.toggled.connect (() => { + warning ("toggled"); if (checkbox.active) { + warning ("active - load"); engine.load_plugin (info); } else { + warning ("inactive - unload"); engine.unload_plugin (info); } + + foreach (string s in engine.loaded_plugins) { + warning ("loaded %s", s); + } }); return content; @@ -217,4 +246,4 @@ namespace Scratch.Services { return engine.get_n_items (); } } -} +// } From 33745ed70e7ccf608bcf91ae6a64d6241480b13f Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 25 May 2025 12:41:04 +0100 Subject: [PATCH 2/5] Reformat without namespace clause --- src/Services/PluginManager.vala | 435 ++++++++++++++++---------------- 1 file changed, 217 insertions(+), 218 deletions(-) diff --git a/src/Services/PluginManager.vala b/src/Services/PluginManager.vala index 771a2ccab..953d05528 100644 --- a/src/Services/PluginManager.vala +++ b/src/Services/PluginManager.vala @@ -4,246 +4,245 @@ * 2013 Mario Guerriero */ -// namespace Scratch.Services { // // Interface implemented by all plugins - public interface Scratch.Services.ActivatablePlugin : Object { - // Migrated from Peas.Activatable - public abstract void activate (); - public abstract void deactivate (); - public virtual void update_state () {} - public abstract GLib.Object object { owned get; construct; } +public interface Scratch.Services.ActivatablePlugin : Object { + // Migrated from Peas.Activatable + public abstract void activate (); + public abstract void deactivate (); + public virtual void update_state () {} + public abstract GLib.Object object { owned get; construct; } +} + +// Object shared with plugins providing signals and methods to interface with application +public class Scratch.Services.Interface : GLib.Object { + // Signals + public signal void hook_window (Scratch.MainWindow window); + public signal void hook_share_menu (GLib.MenuModel menu); + public signal void hook_toolbar (Scratch.HeaderBar toolbar); + public signal void hook_document (Scratch.Services.Document doc); + public signal void hook_preferences_dialog (Scratch.Dialogs.Preferences dialog); + public signal void hook_folder_item_change (File file, File? other_file, FileMonitorEvent event_type); + + public Scratch.TemplateManager template_manager { get; construct; } + public Scratch.Services.PluginsManager manager { get; construct; } + + public Interface (Scratch.Services.PluginsManager _manager) { + Object ( + manager: _manager + ); } - // Object shared with plugins providing signals and methods to interface with application - public class Scratch.Services.Interface : GLib.Object { - // Signals - public signal void hook_window (Scratch.MainWindow window); - public signal void hook_share_menu (GLib.MenuModel menu); - public signal void hook_toolbar (Scratch.HeaderBar toolbar); - public signal void hook_document (Scratch.Services.Document doc); - public signal void hook_preferences_dialog (Scratch.Dialogs.Preferences dialog); - public signal void hook_folder_item_change (File file, File? other_file, FileMonitorEvent event_type); - - public Scratch.TemplateManager template_manager { get; construct; } - public Scratch.Services.PluginsManager manager { get; construct; } - - public Interface (Scratch.Services.PluginsManager _manager) { - Object ( - manager: _manager - ); - } - - construct { - template_manager = new Scratch.TemplateManager (); - } - - public Scratch.Services.Document open_file (File file) { - var doc = new Scratch.Services.Document (manager.window.actions, file); - manager.window.open_document.begin (doc); - return doc; - } + construct { + template_manager = new Scratch.TemplateManager (); + } - public void close_document (Scratch.Services.Document doc) { - manager.window.close_document (doc); - } + public Scratch.Services.Document open_file (File file) { + var doc = new Scratch.Services.Document (manager.window.actions, file); + manager.window.open_document.begin (doc); + return doc; } - public class Scratch.Services.PluginsManager : GLib.Object { - public signal void hook_window (Scratch.MainWindow window); - public signal void hook_share_menu (GLib.MenuModel menu); - public signal void hook_toolbar (Scratch.HeaderBar toolbar); - public signal void hook_document (Scratch.Services.Document doc); - public signal void hook_preferences_dialog (Scratch.Dialogs.Preferences dialog); - public signal void hook_folder_item_change (File file, File? other_file, FileMonitorEvent event_type); + public void close_document (Scratch.Services.Document doc) { + manager.window.close_document (doc); + } +} - public signal void extension_added (Peas.PluginInfo info); - public signal void extension_removed (Peas.PluginInfo info); +public class Scratch.Services.PluginsManager : GLib.Object { + public signal void hook_window (Scratch.MainWindow window); + public signal void hook_share_menu (GLib.MenuModel menu); + public signal void hook_toolbar (Scratch.HeaderBar toolbar); + public signal void hook_document (Scratch.Services.Document doc); + public signal void hook_preferences_dialog (Scratch.Dialogs.Preferences dialog); + public signal void hook_folder_item_change (File file, File? other_file, FileMonitorEvent event_type); - public Peas.Engine engine { get; construct; } + public signal void extension_added (Peas.PluginInfo info); + public signal void extension_removed (Peas.PluginInfo info); - public weak Scratch.MainWindow window { get; construct; } - public Scratch.Services.Interface plugin_iface { get; construct; } + public Peas.Engine engine { get; construct; } - public PluginsManager (Scratch.MainWindow _window) { - Object (window: _window); - } + public weak Scratch.MainWindow window { get; construct; } + public Scratch.Services.Interface plugin_iface { get; construct; } - construct { - plugin_iface = new Scratch.Services.Interface (this); - - /* Let's init the engine */ - engine = Peas.Engine.get_default (); - engine.enable_loader ("python"); - engine.add_search_path (Constants.PLUGINDIR, null); - // engine.loaded_plugins = {"highlight-word-selection"}; - Scratch.settings.bind ("plugins-enabled", engine, "loaded-plugins", SettingsBindFlags.DEFAULT); - - /* Our extension set */ - var exts = new Peas.ExtensionSet.with_properties ( - engine, - typeof (Scratch.Services.ActivatablePlugin), - {"object"}, - {plugin_iface} - ); - - if (exts != null) { - exts.extension_added.connect ((info, ext) => { - warning ("extension added"); - ((ActivatablePlugin)ext).activate (); - extension_added (info); - }); - - exts.extension_removed.connect ((info, ext) => { - warning ("extension removed"); - // ((ActivatablePlugin)ext).deactivate (); - // extension_removed (info); - - warning ("number of extensions now %u", exts.get_n_items ()); - }); - - exts.@foreach ((exts, info, ext) => { - ((Scratch.Services.ActivatablePlugin)ext).activate (); - }, null); - // var pos = 0; - // while (pos < exts.get_n_items ()) { - // var obj = exts.get_item (pos); - // if (obj != null) { - // var eb = (Peas.ExtensionBase)obj; - // var info = eb.plugin_info; - // warning ("got ext %s", info.get_name ()); - // var ap = (Scratch.Services.ActivatablePlugin)obj; - // ap.activate (); - // } else { - // warning ("Object is null"); - // } - // pos++; - // } - } else { - warning ("ext set is null"); - } + public PluginsManager (Scratch.MainWindow _window) { + Object (window: _window); + } - // Connect managers signals to interface's signals - this.hook_window.connect ((w) => { - plugin_iface.hook_window (w); + construct { + plugin_iface = new Scratch.Services.Interface (this); + + /* Let's init the engine */ + engine = Peas.Engine.get_default (); + engine.enable_loader ("python"); + engine.add_search_path (Constants.PLUGINDIR, null); + // engine.loaded_plugins = {"highlight-word-selection"}; + Scratch.settings.bind ("plugins-enabled", engine, "loaded-plugins", SettingsBindFlags.DEFAULT); + + /* Our extension set */ + var exts = new Peas.ExtensionSet.with_properties ( + engine, + typeof (Scratch.Services.ActivatablePlugin), + {"object"}, + {plugin_iface} + ); + + if (exts != null) { + exts.extension_added.connect ((info, ext) => { + warning ("extension added"); + ((ActivatablePlugin)ext).activate (); + extension_added (info); }); - this.hook_share_menu.connect ((m) => { - plugin_iface.hook_share_menu (m); + exts.extension_removed.connect ((info, ext) => { + warning ("extension removed"); + // ((ActivatablePlugin)ext).deactivate (); + // extension_removed (info); + + warning ("number of extensions now %u", exts.get_n_items ()); }); - this.hook_toolbar.connect ((t) => { - plugin_iface.hook_toolbar (t); - }); + exts.@foreach ((exts, info, ext) => { + ((Scratch.Services.ActivatablePlugin)ext).activate (); + }, null); + // var pos = 0; + // while (pos < exts.get_n_items ()) { + // var obj = exts.get_item (pos); + // if (obj != null) { + // var eb = (Peas.ExtensionBase)obj; + // var info = eb.plugin_info; + // warning ("got ext %s", info.get_name ()); + // var ap = (Scratch.Services.ActivatablePlugin)obj; + // ap.activate (); + // } else { + // warning ("Object is null"); + // } + // pos++; + // } + } else { + warning ("ext set is null"); + } - this.hook_document.connect ((d) => { - plugin_iface.hook_document (d); - }); + // Connect managers signals to interface's signals + this.hook_window.connect ((w) => { + plugin_iface.hook_window (w); + }); - this.hook_preferences_dialog.connect ((d) => { - plugin_iface.hook_preferences_dialog (d); - }); + this.hook_share_menu.connect ((m) => { + plugin_iface.hook_share_menu (m); + }); - this.hook_folder_item_change.connect ((source, dest, event) => { - plugin_iface.hook_folder_item_change (source, dest, event); - }); - } + this.hook_toolbar.connect ((t) => { + plugin_iface.hook_toolbar (t); + }); - // Return an emulation of the discontinued libpeas-1.0 widget - public Gtk.Widget get_view () { - warning ("get plugin view"); - var list_box = new Gtk.ListBox (); - list_box.get_accessible ().accessible_name = _("Extensions"); - - var scrolled_window = new Gtk.ScrolledWindow (null, null) { - hscrollbar_policy = NEVER, - child = list_box - }; - - var frame = new Gtk.Frame (null) { - child = scrolled_window - }; - - // Bind the engine ListModel and use a row factory - list_box.bind_model (engine, get_widget_for_plugin_info); - - // Cannot sort a ListModel so sort the ListBox (is there a better way?) - // Gtk warns the function will be ignored but it does in fact work, at least - // on initial display. We know the model will not change while the view is used - // In Gtk4 could use SortListModel - list_box.set_sort_func ((r1, r2) => { - return strcmp ( - r1.get_child ().get_data ("name"), - r2.get_child ().get_data ("name") - ); - }); + this.hook_document.connect ((d) => { + plugin_iface.hook_document (d); + }); - frame.show_all (); - return frame; - } + this.hook_preferences_dialog.connect ((d) => { + plugin_iface.hook_preferences_dialog (d); + }); - private Gtk.Widget get_widget_for_plugin_info (Object obj) { - var info = (Peas.PluginInfo)obj; - - var checkbox = new Gtk.CheckButton () { - valign = CENTER, - active = info.is_loaded () - }; - - var image = new Gtk.Image.from_icon_name (info.get_icon_name (), LARGE_TOOLBAR) { - valign = START - }; - - var name_label = new Gtk.Label (info.name) { - ellipsize = MIDDLE, - xalign = 0 - }; - - var description_label = new Gtk.Label (info.get_description ()) { - ellipsize = END, - lines = 2, - wrap = true, - xalign = 0 - }; - description_label.get_style_context ().add_class (Granite.STYLE_CLASS_SMALL_LABEL); - description_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); - - var description_box = new Gtk.Box (VERTICAL, 0) { - hexpand = true - }; - description_box.add (name_label); - description_box.add (description_label); - - var content = new Gtk.Box (HORIZONTAL, 6) { - margin_top = 6, - margin_end = 12, - margin_bottom = 6, - margin_start = 6 - }; - content.add (image); - content.add (description_box); - content.add (checkbox); - content.set_data ("name", info.get_name ()); - - checkbox.toggled.connect (() => { - warning ("toggled"); - if (checkbox.active) { - warning ("active - load"); - engine.load_plugin (info); - } else { - warning ("inactive - unload"); - engine.unload_plugin (info); - } - - foreach (string s in engine.loaded_plugins) { - warning ("loaded %s", s); - } - }); + this.hook_folder_item_change.connect ((source, dest, event) => { + plugin_iface.hook_folder_item_change (source, dest, event); + }); + } - return content; - } + // Return an emulation of the discontinued libpeas-1.0 widget + public Gtk.Widget get_view () { + warning ("get plugin view"); + var list_box = new Gtk.ListBox (); + list_box.get_accessible ().accessible_name = _("Extensions"); + + var scrolled_window = new Gtk.ScrolledWindow (null, null) { + hscrollbar_policy = NEVER, + child = list_box + }; + + var frame = new Gtk.Frame (null) { + child = scrolled_window + }; + + // Bind the engine ListModel and use a row factory + list_box.bind_model (engine, get_widget_for_plugin_info); + + // Cannot sort a ListModel so sort the ListBox (is there a better way?) + // Gtk warns the function will be ignored but it does in fact work, at least + // on initial display. We know the model will not change while the view is used + // In Gtk4 could use SortListModel + list_box.set_sort_func ((r1, r2) => { + return strcmp ( + r1.get_child ().get_data ("name"), + r2.get_child ().get_data ("name") + ); + }); - public uint get_n_plugins () { - return engine.get_n_items (); - } + frame.show_all (); + return frame; } -// } + + private Gtk.Widget get_widget_for_plugin_info (Object obj) { + var info = (Peas.PluginInfo)obj; + + var checkbox = new Gtk.CheckButton () { + valign = CENTER, + active = info.is_loaded () + }; + + var image = new Gtk.Image.from_icon_name (info.get_icon_name (), LARGE_TOOLBAR) { + valign = START + }; + + var name_label = new Gtk.Label (info.name) { + ellipsize = MIDDLE, + xalign = 0 + }; + + var description_label = new Gtk.Label (info.get_description ()) { + ellipsize = END, + lines = 2, + wrap = true, + xalign = 0 + }; + description_label.get_style_context ().add_class (Granite.STYLE_CLASS_SMALL_LABEL); + description_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); + + var description_box = new Gtk.Box (VERTICAL, 0) { + hexpand = true + }; + description_box.add (name_label); + description_box.add (description_label); + + var content = new Gtk.Box (HORIZONTAL, 6) { + margin_top = 6, + margin_end = 12, + margin_bottom = 6, + margin_start = 6 + }; + content.add (image); + content.add (description_box); + content.add (checkbox); + content.set_data ("name", info.get_name ()); + + checkbox.toggled.connect (() => { + warning ("toggled"); + if (checkbox.active) { + warning ("active - load"); + engine.load_plugin (info); + } else { + warning ("inactive - unload"); + engine.unload_plugin (info); + } + + foreach (string s in engine.loaded_plugins) { + warning ("loaded %s", s); + } + }); + + return content; + } + + public uint get_n_plugins () { + return engine.get_n_items (); + } +} + From 162e64a53c0c60be9ed7a9748e76065bedc3589e Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 25 May 2025 13:22:40 +0100 Subject: [PATCH 3/5] Make ExtensionSet a construct property --- src/Services/PluginManager.vala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Services/PluginManager.vala b/src/Services/PluginManager.vala index 953d05528..a6f82de24 100644 --- a/src/Services/PluginManager.vala +++ b/src/Services/PluginManager.vala @@ -59,6 +59,7 @@ public class Scratch.Services.PluginsManager : GLib.Object { public signal void extension_removed (Peas.PluginInfo info); public Peas.Engine engine { get; construct; } + public Peas.ExtensionSet extension_set {get; construct; } public weak Scratch.MainWindow window { get; construct; } public Scratch.Services.Interface plugin_iface { get; construct; } @@ -78,7 +79,7 @@ public class Scratch.Services.PluginsManager : GLib.Object { Scratch.settings.bind ("plugins-enabled", engine, "loaded-plugins", SettingsBindFlags.DEFAULT); /* Our extension set */ - var exts = new Peas.ExtensionSet.with_properties ( + extension_set = new Peas.ExtensionSet.with_properties ( engine, typeof (Scratch.Services.ActivatablePlugin), {"object"}, From 23eaf5bbdb892adbd6e76862b92dbf6da633d584 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 25 May 2025 13:23:10 +0100 Subject: [PATCH 4/5] Cleanup --- .../brackets-completion.vala | 2 - .../highlight-word-selection.vala | 2 - src/Services/PluginManager.vala | 61 +++++-------------- 3 files changed, 14 insertions(+), 51 deletions(-) diff --git a/plugins/brackets-completion/brackets-completion.vala b/plugins/brackets-completion/brackets-completion.vala index 001d24a47..5639b4460 100644 --- a/plugins/brackets-completion/brackets-completion.vala +++ b/plugins/brackets-completion/brackets-completion.vala @@ -19,7 +19,6 @@ public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Scratch.Se private string previous_selection = ""; public void activate () { -warning ("brackets completion activate"); brackets = new Gee.HashMap (); brackets["("] = ")"; brackets["["] = "]"; @@ -44,7 +43,6 @@ warning ("brackets completion activate"); } public void deactivate () { -warning ("brackets completion deactivate"); plugins.hook_document.disconnect (on_hook_document); } diff --git a/plugins/highlight-word-selection/highlight-word-selection.vala b/plugins/highlight-word-selection/highlight-word-selection.vala index 2e679bc22..91303df71 100644 --- a/plugins/highlight-word-selection/highlight-word-selection.vala +++ b/plugins/highlight-word-selection/highlight-word-selection.vala @@ -31,7 +31,6 @@ public class Scratch.Plugins.HighlightSelectedWords : Peas.ExtensionBase, Scratc public void update_state () {} public void activate () { - warning ("activate highlight"); plugins = (Scratch.Services.Interface) object; plugins.hook_document.connect ((doc) => { if (current_source != null) { @@ -136,7 +135,6 @@ public class Scratch.Plugins.HighlightSelectedWords : Peas.ExtensionBase, Scratc } public void deactivate () { - warning ("deactivate highlight"); if (current_source != null) { current_source.deselected.disconnect (on_deselection); current_source.selection_changed.disconnect (on_selection_changed); diff --git a/src/Services/PluginManager.vala b/src/Services/PluginManager.vala index a6f82de24..fe7705227 100644 --- a/src/Services/PluginManager.vala +++ b/src/Services/PluginManager.vala @@ -4,9 +4,8 @@ * 2013 Mario Guerriero */ -// // Interface implemented by all plugins + // Interface implemented by all plugins (Migrated from Peas.Activatable) public interface Scratch.Services.ActivatablePlugin : Object { - // Migrated from Peas.Activatable public abstract void activate (); public abstract void deactivate (); public virtual void update_state () {} @@ -75,7 +74,6 @@ public class Scratch.Services.PluginsManager : GLib.Object { engine = Peas.Engine.get_default (); engine.enable_loader ("python"); engine.add_search_path (Constants.PLUGINDIR, null); - // engine.loaded_plugins = {"highlight-word-selection"}; Scratch.settings.bind ("plugins-enabled", engine, "loaded-plugins", SettingsBindFlags.DEFAULT); /* Our extension set */ @@ -86,41 +84,19 @@ public class Scratch.Services.PluginsManager : GLib.Object { {plugin_iface} ); - if (exts != null) { - exts.extension_added.connect ((info, ext) => { - warning ("extension added"); - ((ActivatablePlugin)ext).activate (); - extension_added (info); - }); - - exts.extension_removed.connect ((info, ext) => { - warning ("extension removed"); - // ((ActivatablePlugin)ext).deactivate (); - // extension_removed (info); - - warning ("number of extensions now %u", exts.get_n_items ()); - }); - - exts.@foreach ((exts, info, ext) => { - ((Scratch.Services.ActivatablePlugin)ext).activate (); - }, null); - // var pos = 0; - // while (pos < exts.get_n_items ()) { - // var obj = exts.get_item (pos); - // if (obj != null) { - // var eb = (Peas.ExtensionBase)obj; - // var info = eb.plugin_info; - // warning ("got ext %s", info.get_name ()); - // var ap = (Scratch.Services.ActivatablePlugin)obj; - // ap.activate (); - // } else { - // warning ("Object is null"); - // } - // pos++; - // } - } else { - warning ("ext set is null"); - } + extension_set.extension_added.connect ((info, ext) => { + ((Scratch.Services.ActivatablePlugin)ext).activate (); + extension_added (info); + }); + + extension_set.extension_removed.connect ((info, ext) => { + ((Scratch.Services.ActivatablePlugin)ext).deactivate (); + extension_removed (info); + }); + + extension_set.@foreach ((exts, info, ext) => { + ((Scratch.Services.ActivatablePlugin)ext).activate (); + }, null); // Connect managers signals to interface's signals this.hook_window.connect ((w) => { @@ -150,7 +126,6 @@ public class Scratch.Services.PluginsManager : GLib.Object { // Return an emulation of the discontinued libpeas-1.0 widget public Gtk.Widget get_view () { - warning ("get plugin view"); var list_box = new Gtk.ListBox (); list_box.get_accessible ().accessible_name = _("Extensions"); @@ -225,18 +200,11 @@ public class Scratch.Services.PluginsManager : GLib.Object { content.set_data ("name", info.get_name ()); checkbox.toggled.connect (() => { - warning ("toggled"); if (checkbox.active) { - warning ("active - load"); engine.load_plugin (info); } else { - warning ("inactive - unload"); engine.unload_plugin (info); } - - foreach (string s in engine.loaded_plugins) { - warning ("loaded %s", s); - } }); return content; @@ -246,4 +214,3 @@ public class Scratch.Services.PluginsManager : GLib.Object { return engine.get_n_items (); } } - From e6d47e86f0cb0296e2aa6b478af3b6b38b213c59 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Wed, 28 May 2025 11:02:57 +0100 Subject: [PATCH 5/5] Add comment --- src/Services/PluginManager.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/PluginManager.vala b/src/Services/PluginManager.vala index 60f9f6a82..4272ed10c 100644 --- a/src/Services/PluginManager.vala +++ b/src/Services/PluginManager.vala @@ -76,7 +76,7 @@ public class Scratch.Services.PluginsManager : GLib.Object { engine.add_search_path (Constants.PLUGINDIR, null); Scratch.settings.bind ("plugins-enabled", engine, "loaded-plugins", SettingsBindFlags.DEFAULT); - /* Our extension set */ + /* Our extension set. We need to keep a reference to this after migrating to libpeas-2 */ extension_set = new Peas.ExtensionSet.with_properties ( engine, typeof (Scratch.Services.ActivatablePlugin),