From 264713f8dd1436aabb5bd009188324fdfa23f0aa Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Thu, 26 Dec 2024 14:02:39 +0000 Subject: [PATCH 01/20] Temporary commit --- .../brackets-completion.vala | 24 +- plugins/detect-indent/detect-indent.vala | 29 +- plugins/editorconfig/editorconfig.vala | 22 +- plugins/fuzzy-search/fuzzy-search.vala | 47 +-- .../highlight-word-selection.vala | 39 ++- .../markdown-actions/markdown-actions.vala | 37 ++- plugins/pastebin/pastebin.vala | 34 +- plugins/preserve-indent/preserve-indent.vala | 20 +- plugins/spell/spell.vala | 40 +-- plugins/vim-emulation/vim-emulation.vala | 26 +- plugins/word-completion/plugin.vala | 22 +- src/Dialogs/PreferencesDialog.vala | 4 +- src/Services/PluginManager.vala | 299 ++++++++++++++---- 13 files changed, 431 insertions(+), 212 deletions(-) diff --git a/plugins/brackets-completion/brackets-completion.vala b/plugins/brackets-completion/brackets-completion.vala index bf3f4cf15c..787c005f8f 100644 --- a/plugins/brackets-completion/brackets-completion.vala +++ b/plugins/brackets-completion/brackets-completion.vala @@ -18,7 +18,7 @@ END LICENSE ***/ -public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Peas.Activatable { +public class Scratch.Plugins.BracketsCompletion : PluginBase { Gee.HashMap brackets; Gee.HashMap keys; const string[] VALID_NEXT_CHARS = { @@ -30,10 +30,8 @@ public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Peas.Activ private string previous_selection = ""; - Scratch.Services.Interface plugins; - public Object object { owned get; construct; } - - public void update_state () {} + Scratch.Plugins.Interface plugins; + // public Object object { owned get; construct; } public void activate () { brackets = new Gee.HashMap (); @@ -55,7 +53,7 @@ public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Peas.Activ keys[Gdk.Key.quotedbl] = "\""; keys[Gdk.Key.grave] = "`"; - plugins = (Scratch.Services.Interface) object; + // plugins = (Scratch.Plugins.Interface) object; plugins.hook_document.connect (on_hook_document); } @@ -275,9 +273,13 @@ public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Peas.Activ } } -[ModuleInit] -public void peas_register_types (GLib.TypeModule module) { - var objmodule = module as Peas.ObjectModule; - objmodule.register_extension_type (typeof (Peas.Activatable), - typeof (Scratch.Plugins.BracketsCompletion)); +public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { + return new Scratch.Plugins.BracketsCompletion (info); } + +// [ModuleInit] +// public void peas_register_types (GLib.TypeModule module) { +// var objmodule = module as Peas.ObjectModule; +// objmodule.register_extension_type (typeof (Peas.Activatable), +// typeof (Scratch.Plugins.BracketsCompletion)); +// } diff --git a/plugins/detect-indent/detect-indent.vala b/plugins/detect-indent/detect-indent.vala index 09fe9c1d24..1ae48b4ee6 100644 --- a/plugins/detect-indent/detect-indent.vala +++ b/plugins/detect-indent/detect-indent.vala @@ -1,14 +1,11 @@ -public class Scratch.Plugins.DetectIndent: Peas.ExtensionBase, Peas.Activatable { +public class Scratch.Plugins.DetectIndent: PluginBase { const int MAX_LINES = 500; - Scratch.Services.Interface plugins; - public Object object {owned get; construct;} - - public void update_state () { - } + Scratch.Plugins.Interface plugins; + // public Object object {owned get; construct;} public void activate () { - plugins = (Scratch.Services.Interface) object; + plugins = (Scratch.Plugins.Interface) object; plugins.hook_document.connect ((d) => { var view = d.source_view; @@ -75,11 +72,15 @@ public class Scratch.Plugins.DetectIndent: Peas.ExtensionBase, Peas.Activatable } -[ModuleInit] -public void peas_register_types (GLib.TypeModule module) { - var objmodule = module as Peas.ObjectModule; - objmodule.register_extension_type ( - typeof (Peas.Activatable), - typeof (Scratch.Plugins.DetectIndent) - ); +public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { + return new Scratch.Plugins.DetectIndent (info); } + +// [ModuleInit] +// public void peas_register_types (GLib.TypeModule module) { +// var objmodule = module as Peas.ObjectModule; +// objmodule.register_extension_type ( +// typeof (Peas.Activatable), +// typeof (Scratch.Plugins.DetectIndent) +// ); +// } diff --git a/plugins/editorconfig/editorconfig.vala b/plugins/editorconfig/editorconfig.vala index 8a5b8f4285..08ac781f58 100644 --- a/plugins/editorconfig/editorconfig.vala +++ b/plugins/editorconfig/editorconfig.vala @@ -17,15 +17,15 @@ * Boston, MA 02110-1301 USA */ -public class Scratch.Plugins.EditorConfigPlugin: Peas.ExtensionBase, Peas.Activatable { - Scratch.Services.Interface plugins; - public Object object { owned get; construct; } +public class Scratch.Plugins.EditorConfigPlugin: PluginBase { + Scratch.Plugins.Interface plugins; + // public Object object { owned get; construct; } private Code.FormatBar format_bar; - public void update_state () { } + // public void update_state () { } public void activate () { - plugins = (Scratch.Services.Interface) object; + plugins = (Scratch.Plugins.Interface) object; plugins.hook_toolbar.connect ((tb) => { format_bar = tb.format_bar; @@ -88,8 +88,12 @@ public class Scratch.Plugins.EditorConfigPlugin: Peas.ExtensionBase, Peas.Activa public void deactivate () { } } -[ModuleInit] -public void peas_register_types (GLib.TypeModule module) { - var objmodule = module as Peas.ObjectModule; - objmodule.register_extension_type (typeof (Peas.Activatable), typeof (Scratch.Plugins.EditorConfigPlugin)); +public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { + return new Scratch.Plugins.EditorConfigPlugin (info); } + +// [ModuleInit] +// public void peas_register_types (GLib.TypeModule module) { +// var objmodule = module as Peas.ObjectModule; +// objmodule.register_extension_type (typeof (Peas.Activatable), typeof (Scratch.Plugins.EditorConfigPlugin)); +// } diff --git a/plugins/fuzzy-search/fuzzy-search.vala b/plugins/fuzzy-search/fuzzy-search.vala index 2cff1cf2b7..a4d44dadef 100644 --- a/plugins/fuzzy-search/fuzzy-search.vala +++ b/plugins/fuzzy-search/fuzzy-search.vala @@ -6,14 +6,14 @@ */ -public class Scratch.Plugins.FuzzySearch: Peas.ExtensionBase, Peas.Activatable { - public Object object { owned get; construct; } +public class Scratch.Plugins.FuzzySearch: PluginBase { + // public Object object { owned get; construct; } private const uint ACCEL_KEY = Gdk.Key.F; private const Gdk.ModifierType ACCEL_MODTYPE = Gdk.ModifierType.MOD1_MASK; private Scratch.Services.FuzzySearchIndexer indexer; private MainWindow window = null; - private Scratch.Services.Interface plugins; + private Scratch.Plugins.Interface plugins; private GLib.MenuItem fuzzy_menuitem; private GLib.Cancellable cancellable; @@ -33,12 +33,12 @@ public class Scratch.Plugins.FuzzySearch: Peas.ExtensionBase, Peas.Activatable { action_accelerators.set (ACTION_SHOW, @"$(Gdk.keyval_name (ACCEL_KEY))"); } - public void update_state () { + // public void update_state () { - } + // } public void activate () { - plugins = (Scratch.Services.Interface) object; + // plugins = (Scratch.Plugins.Interface) object; plugins.hook_window.connect ((w) => { if (window != null) { @@ -68,6 +68,14 @@ public class Scratch.Plugins.FuzzySearch: Peas.ExtensionBase, Peas.Activatable { }); } + public void deactivate () { + folder_settings.changed["opened-folders"].disconnect (handle_opened_projects_change); + remove_actions (); + if (cancellable != null) { + cancellable.cancel (); + } + } + private void add_actions () { if (actions == null) { actions = new SimpleActionGroup (); @@ -138,15 +146,6 @@ public class Scratch.Plugins.FuzzySearch: Peas.ExtensionBase, Peas.Activatable { popover.popup (); } - public void deactivate () { - folder_settings.changed["opened-folders"].disconnect (handle_opened_projects_change); - remove_actions (); - if (cancellable != null) { - cancellable.cancel (); - } - } - - private void handle_opened_projects_change () { var show_action = Utils.action_from_group (ACTION_SHOW, actions); string[] opened_folders = folder_settings.get_strv ("opened-folders"); @@ -154,11 +153,15 @@ public class Scratch.Plugins.FuzzySearch: Peas.ExtensionBase, Peas.Activatable { } } -[ModuleInit] -public void peas_register_types (GLib.TypeModule module) { - var objmodule = module as Peas.ObjectModule; - objmodule.register_extension_type ( - typeof (Peas.Activatable), - typeof (Scratch.Plugins.FuzzySearch) - ); +public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { + return new Scratch.Plugins.FuzzySearch (info); } + +// [ModuleInit] +// public void peas_register_types (GLib.TypeModule module) { +// var objmodule = module as Peas.ObjectModule; +// objmodule.register_extension_type ( +// typeof (Peas.Activatable), +// typeof (Scratch.Plugins.FuzzySearch) +// ); +// } diff --git a/plugins/highlight-word-selection/highlight-word-selection.vala b/plugins/highlight-word-selection/highlight-word-selection.vala index 5896b5d43e..3c3dd9a05d 100644 --- a/plugins/highlight-word-selection/highlight-word-selection.vala +++ b/plugins/highlight-word-selection/highlight-word-selection.vala @@ -18,7 +18,7 @@ END LICENSE ***/ -public class Scratch.Plugins.HighlightSelectedWords : Peas.ExtensionBase, Peas.Activatable { +public class Scratch.Plugins.HighlightSelectedWords : PluginBase { Scratch.Widgets.SourceView current_source; Scratch.MainWindow? main_window = null; Gtk.SourceSearchContext? current_search_context = null; @@ -27,13 +27,13 @@ public class Scratch.Plugins.HighlightSelectedWords : Peas.ExtensionBase, Peas.A // Pneumonoultramicroscopicsilicovolcanoconiosis longest word in a major dictionary @ 45 private const uint SELECTION_HIGHLIGHT_MAX_CHARS = 45; - Scratch.Services.Interface plugins; - public Object object { owned get; construct; } + Scratch.Plugins.Interface plugins; + // public Object object { owned get; construct; } - public void update_state () {} + // public void update_state () {} public void activate () { - plugins = (Scratch.Services.Interface) object; + // plugins = (Scratch.Plugins.Interface) object; plugins.hook_document.connect ((doc) => { if (current_source != null) { current_source.deselected.disconnect (on_deselection); @@ -50,6 +50,14 @@ public class Scratch.Plugins.HighlightSelectedWords : Peas.ExtensionBase, Peas.A }); } + + public void deactivate () { + if (current_source != null) { + current_source.deselected.disconnect (on_deselection); + current_source.selection_changed.disconnect (on_selection_changed); + } + } + public void on_selection_changed (ref Gtk.TextIter start, ref Gtk.TextIter end) { var window_search_context = main_window != null ? main_window.search_bar.search_context : null; @@ -139,18 +147,15 @@ public class Scratch.Plugins.HighlightSelectedWords : Peas.ExtensionBase, Peas.A current_search_context = null; } } - - public void deactivate () { - if (current_source != null) { - current_source.deselected.disconnect (on_deselection); - current_source.selection_changed.disconnect (on_selection_changed); - } - } } -[ModuleInit] -public void peas_register_types (TypeModule module) { - var objmodule = module as Peas.ObjectModule; - objmodule.register_extension_type (typeof (Peas.Activatable), - typeof (Scratch.Plugins.HighlightSelectedWords)); +public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { + return new Scratch.Plugins.FuzzySearch (info); } + +// [ModuleInit] +// public void peas_register_types (TypeModule module) { +// var objmodule = module as Peas.ObjectModule; +// objmodule.register_extension_type (typeof (Peas.Activatable), +// typeof (Scratch.Plugins.HighlightSelectedWords)); +// } diff --git a/plugins/markdown-actions/markdown-actions.vala b/plugins/markdown-actions/markdown-actions.vala index 024e97c3b6..5a720a8be8 100644 --- a/plugins/markdown-actions/markdown-actions.vala +++ b/plugins/markdown-actions/markdown-actions.vala @@ -18,16 +18,15 @@ END LICENSE ***/ -public class Code.Plugins.MarkdownActions : Peas.ExtensionBase, Peas.Activatable { +public class Code.Plugins.MarkdownActions : PluginBase { Scratch.Widgets.SourceView current_source; - Scratch.Services.Interface plugins; + Scratch.Plugins.Interface plugins; - public Object object { owned get; construct; } + // public Object object { owned get; construct; } - public void update_state () {} + // public void update_state () {} public void activate () { - plugins = (Scratch.Services.Interface) object; plugins.hook_document.connect ((doc) => { if (current_source != null) { current_source.key_press_event.disconnect (shortcut_handler); @@ -41,6 +40,13 @@ public class Code.Plugins.MarkdownActions : Peas.ExtensionBase, Peas.Activatable }); } + public void deactivate () { + if (current_source != null) { + current_source.key_press_event.disconnect (shortcut_handler); + current_source.notify["language"].disconnect (configure_shortcuts); + } + } + private void configure_shortcuts () { var lang = current_source.language; if (lang != null && lang.id == "markdown") { @@ -231,18 +237,15 @@ public class Code.Plugins.MarkdownActions : Peas.ExtensionBase, Peas.Activatable current_buffer.end_user_action (); go_back_n_chars (tag.length); } - - public void deactivate () { - if (current_source != null) { - current_source.key_press_event.disconnect (shortcut_handler); - current_source.notify["language"].disconnect (configure_shortcuts); - } - } } -[ModuleInit] -public void peas_register_types (TypeModule module) { - var objmodule = module as Peas.ObjectModule; - objmodule.register_extension_type (typeof (Peas.Activatable), - typeof (Code.Plugins.MarkdownActions)); +public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { + return new Scratch.Plugins.MarkdownActions (info); } + +// [ModuleInit] +// public void peas_register_types (TypeModule module) { +// var objmodule = module as Peas.ObjectModule; +// objmodule.register_extension_type (typeof (Peas.Activatable), +// typeof (Code.Plugins.MarkdownActions)); +// } diff --git a/plugins/pastebin/pastebin.vala b/plugins/pastebin/pastebin.vala index 3a4471dc21..16cf75f496 100644 --- a/plugins/pastebin/pastebin.vala +++ b/plugins/pastebin/pastebin.vala @@ -18,7 +18,7 @@ END LICENSE ***/ -namespace Scratch.Services { +namespace Scratch.Plugins { public class PasteBin : GLib.Object { public const string NEVER = "N"; public const string TEN_MINUTES = "10M"; @@ -68,10 +68,10 @@ namespace Scratch.Services { } } -public class Scratch.Plugins.Pastebin : Peas.ExtensionBase, Peas.Activatable { +public class Scratch.Plugins.Pastebin : PluginBase { GLib.MenuItem? menuitem = null; GLib.Menu? share_menu = null; - public Object object { owned get; construct; } + // public Object object { owned get; construct; } Scratch.Services.Document? doc = null; Scratch.Services.Interface plugins; @@ -85,11 +85,11 @@ public class Scratch.Plugins.Pastebin : Peas.ExtensionBase, Peas.Activatable { {ACTION_SHOW, show_paste_bin_upload_dialog } }; - public void update_state () { - } + // public void update_state () { + // } public void activate () { - plugins = (Scratch.Services.Interface) object; + // plugins = (Scratch.Services.Interface) object; plugins.hook_document.connect ((doc) => { this.doc = doc; @@ -98,6 +98,10 @@ public class Scratch.Plugins.Pastebin : Peas.ExtensionBase, Peas.Activatable { plugins.hook_share_menu.connect (on_hook_share_menu); } + public void deactivate () { + remove_actions (); + } + void on_hook_share_menu (GLib.MenuModel menu) { if (menuitem != null) { return; @@ -138,15 +142,15 @@ public class Scratch.Plugins.Pastebin : Peas.ExtensionBase, Peas.Activatable { MainWindow window = plugins.manager.window; new Dialogs.PasteBinDialog (window, doc); } - - public void deactivate () { - remove_actions (); - } } -[ModuleInit] -public void peas_register_types (GLib.TypeModule module) { - var objmodule = module as Peas.ObjectModule; - objmodule.register_extension_type (typeof (Peas.Activatable), - typeof (Scratch.Plugins.Pastebin)); +public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { + return new Scratch.Plugins.Pastebin (info); } + +// [ModuleInit] +// public void peas_register_types (GLib.TypeModule module) { +// var objmodule = module as Peas.ObjectModule; +// objmodule.register_extension_type (typeof (Peas.Activatable), +// typeof (Scratch.Plugins.Pastebin)); +// } diff --git a/plugins/preserve-indent/preserve-indent.vala b/plugins/preserve-indent/preserve-indent.vala index 6f07e0c3d3..b5a6baed67 100644 --- a/plugins/preserve-indent/preserve-indent.vala +++ b/plugins/preserve-indent/preserve-indent.vala @@ -18,7 +18,7 @@ END LICENSE ***/ -public class Scratch.Plugins.PreserveIndent : Peas.ExtensionBase, Peas.Activatable { +public class Scratch.Plugins.PreserveIndent : PluginBase { private Scratch.Services.Interface plugins; private Gee.TreeSet documents; @@ -26,11 +26,11 @@ public class Scratch.Plugins.PreserveIndent : Peas.ExtensionBase, Peas.Activatab private int last_clipboard_indent_level = 0; private bool waiting_for_clipboard_text = false; - public Object object { owned get; construct; } + // public Object object { owned get; construct; } public void activate () { this.documents = new Gee.TreeSet (); - plugins = (Scratch.Services.Interface) object; + // plugins = (Scratch.Services.Interface) object; plugins.hook_document.connect ((d) => { this.active_document = d; @@ -241,9 +241,13 @@ public class Scratch.Plugins.PreserveIndent : Peas.ExtensionBase, Peas.Activatab } } -[ModuleInit] -public void peas_register_types (GLib.TypeModule module) { - var objmodule = module as Peas.ObjectModule; - objmodule.register_extension_type (typeof (Peas.Activatable), - typeof (Scratch.Plugins.PreserveIndent)); +public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { + return new Scratch.Plugins.PreserveIndent (info); } + +// [ModuleInit] +// public void peas_register_types (GLib.TypeModule module) { +// var objmodule = module as Peas.ObjectModule; +// objmodule.register_extension_type (typeof (Peas.Activatable), +// typeof (Scratch.Plugins.PreserveIndent)); +// } diff --git a/plugins/spell/spell.vala b/plugins/spell/spell.vala index 6e90e60e2f..2d41625d38 100644 --- a/plugins/spell/spell.vala +++ b/plugins/spell/spell.vala @@ -13,9 +13,9 @@ * with this program. If not, see */ -public class Scratch.Plugins.Spell: Peas.ExtensionBase, Peas.Activatable { +public class Scratch.Plugins.Spell: PluginBase { - Scratch.Services.Interface plugins; + Scratch.Plugins.Interface plugins; private GLib.Settings settings; @@ -29,10 +29,10 @@ public class Scratch.Plugins.Spell: Peas.ExtensionBase, Peas.Activatable { GtkSpell.Checker spell = null; #endif - public Object object {owned get; construct;} + // public Object object {owned get; construct;} - public void update_state () { - } + // public void update_state () { + // } public void activate () { settings = new GLib.Settings (Constants.PROJECT_NAME + ".plugins.spell"); @@ -42,7 +42,7 @@ public class Scratch.Plugins.Spell: Peas.ExtensionBase, Peas.Activatable { settings.changed.connect (settings_changed); - plugins = (Scratch.Services.Interface) object; + // plugins = (Scratch.Services.Interface) object; plugins.hook_document.connect ((d) => { var view = d.source_view; @@ -126,7 +126,10 @@ public class Scratch.Plugins.Spell: Peas.ExtensionBase, Peas.Activatable { } - + public void deactivate () { + save_settings (); + window.destroy.disconnect (save_settings); + } private void language_changed_spell (Scratch.Widgets.SourceView view) { if (view.language != null) @@ -149,18 +152,17 @@ public class Scratch.Plugins.Spell: Peas.ExtensionBase, Peas.Activatable { settings.set_string ("language", lang_dict); } - public void deactivate () { - save_settings (); - window.destroy.disconnect (save_settings); - } - } -[ModuleInit] -public void peas_register_types (GLib.TypeModule module) { - var objmodule = module as Peas.ObjectModule; - objmodule.register_extension_type ( - typeof (Peas.Activatable), - typeof (Scratch.Plugins.Spell) - ); +public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { + return new Scratch.Plugins.Spell (info); } + +// [ModuleInit] +// public void peas_register_types (GLib.TypeModule module) { +// var objmodule = module as Peas.ObjectModule; +// objmodule.register_extension_type ( +// typeof (Peas.Activatable), +// typeof (Scratch.Plugins.Spell) +// ); +// } diff --git a/plugins/vim-emulation/vim-emulation.vala b/plugins/vim-emulation/vim-emulation.vala index 32ec3c397a..6145039660 100644 --- a/plugins/vim-emulation/vim-emulation.vala +++ b/plugins/vim-emulation/vim-emulation.vala @@ -18,7 +18,7 @@ END LICENSE ***/ -public class Scratch.Plugins.VimEmulation : Peas.ExtensionBase, Peas.Activatable { +public class Scratch.Plugins.VimEmulation : PluginBase { public enum Mode { COMMAND, INSERT, @@ -33,19 +33,19 @@ public class Scratch.Plugins.VimEmulation : Peas.ExtensionBase, Peas.Activatable Gee.TreeSet views; Scratch.Widgets.SourceView? view = null; - Scratch.Services.Interface plugins; - public Object object { owned get; construct; } + Scratch.Plugins.Interface plugins; + // public Object object { owned get; construct; } construct { views = new Gee.TreeSet (); } - public void update_state () { + // public void update_state () { - } + // } public void activate () { - plugins = (Scratch.Services.Interface) object; + plugins = (Scratch.Plugins.Interface) object; plugins.hook_document.connect ((doc) => { this.view = doc.source_view; this.view.key_press_event.disconnect (handle_key_press); @@ -295,9 +295,13 @@ public class Scratch.Plugins.VimEmulation : Peas.ExtensionBase, Peas.Activatable } } -[ModuleInit] -public void peas_register_types (GLib.TypeModule module) { - var objmodule = module as Peas.ObjectModule; - objmodule.register_extension_type (typeof (Peas.Activatable), - typeof (Scratch.Plugins.VimEmulation)); +public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { + return new Scratch.Plugins.VimEmulation (info); } + +// [ModuleInit] +// public void peas_register_types (GLib.TypeModule module) { +// var objmodule = module as Peas.ObjectModule; +// objmodule.register_extension_type (typeof (Peas.Activatable), +// typeof (Scratch.Plugins.VimEmulation)); +// } diff --git a/plugins/word-completion/plugin.vala b/plugins/word-completion/plugin.vala index d227d12a6a..04ce552894 100644 --- a/plugins/word-completion/plugin.vala +++ b/plugins/word-completion/plugin.vala @@ -18,7 +18,7 @@ * */ -public class Scratch.Plugins.Completion : Peas.ExtensionBase, Peas.Activatable { +public class Scratch.Plugins.Completion : PluginBase { public Object object { owned get; construct; } private List text_view_list = new List (); @@ -27,7 +27,7 @@ public class Scratch.Plugins.Completion : Peas.ExtensionBase, Peas.Activatable { public Scratch.Services.Document current_document {get; private set;} private MainWindow main_window; - private Scratch.Services.Interface plugins; + private Scratch.Plugins.Interface plugins; private bool completion_in_progress = false; private const uint [] ACTIVATE_KEYS = { @@ -44,7 +44,7 @@ public class Scratch.Plugins.Completion : Peas.ExtensionBase, Peas.Activatable { private uint timeout_id = 0; public void activate () { - plugins = (Scratch.Services.Interface) object; + // plugins = (Scratch.Services.Interface) object; parser = new Euclide.Completion.Parser (); plugins.hook_window.connect ((w) => { this.main_window = w; @@ -53,7 +53,7 @@ public class Scratch.Plugins.Completion : Peas.ExtensionBase, Peas.Activatable { plugins.hook_document.connect (on_new_source_view); } - public void deactivate () { + public override void deactivate () { text_view_list.@foreach (cleanup); } @@ -182,9 +182,13 @@ public class Scratch.Plugins.Completion : Peas.ExtensionBase, Peas.Activatable { } } -[ModuleInit] -public void peas_register_types (GLib.TypeModule module) { - var objmodule = module as Peas.ObjectModule; - objmodule.register_extension_type (typeof (Peas.Activatable), - typeof (Scratch.Plugins.Completion)); +public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { + return new Scratch.Plugins.Completion (info); } + +// [ModuleInit] +// public void peas_register_types (GLib.TypeModule module) { +// var objmodule = module as Peas.ObjectModule; +// objmodule.register_extension_type (typeof (Peas.Activatable), +// typeof (Scratch.Plugins.Completion)); +// } diff --git a/src/Dialogs/PreferencesDialog.vala b/src/Dialogs/PreferencesDialog.vala index 96f2de4590..35921f7cee 100644 --- a/src/Dialogs/PreferencesDialog.vala +++ b/src/Dialogs/PreferencesDialog.vala @@ -8,9 +8,9 @@ */ public class Scratch.Dialogs.Preferences : Granite.Dialog { - public Services.PluginsManager plugins { get; construct; } + public Scratch.Services.PluginsManager plugins { get; construct; } - public Preferences (Gtk.Window? parent, Services.PluginsManager plugins) { + public Preferences (Gtk.Window? parent, Scratch.Services.PluginsManager plugins) { Object ( title: _("Preferences"), transient_for: parent, diff --git a/src/Services/PluginManager.vala b/src/Services/PluginManager.vala index 26729a2400..101694e303 100644 --- a/src/Services/PluginManager.vala +++ b/src/Services/PluginManager.vala @@ -18,11 +18,24 @@ END LICENSE ***/ -namespace Scratch.Services { - public class Interface : GLib.Object { +// namespace Scratch.Plugins { + public abstract class Scratch.Plugins.PluginBase : GLib.Object { + public PluginInfo plugin_info { get; construct; } + public Interface plugin_iface { get; construct; } + public abstract void activate (); + public abstract void deactivate (); + // public abstract PluginBase module_init (PluginInfo plugin_info); + public virtual void update_state () {} + } - public PluginsManager manager; + public struct Scratch.Plugins.PluginInfo { + string name; + string description; + string icon_name; + } + public class Scratch.Plugins.Interface : GLib.Object { + public Scratch.Services.PluginsManager manager; // Signals public signal void hook_window (Scratch.MainWindow window); public signal void hook_share_menu (GLib.MenuModel menu); @@ -33,31 +46,31 @@ namespace Scratch.Services { public Scratch.TemplateManager template_manager { private set; get; } - public Interface (PluginsManager manager) { + public Interface (Scratch.Services.PluginsManager manager) { this.manager = manager; 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 (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 { - Peas.Engine engine; - Peas.ExtensionSet exts; + public class Scratch.Services.PluginsManager : GLib.Object { + // Peas.Engine engine; + // Peas.ExtensionSet exts; - string settings_field; + // string settings_field; - public Interface plugin_iface { private set; public get; } + public Scratch.Plugins.Interface plugin_iface { private set; public get; } public weak MainWindow window; @@ -70,71 +83,241 @@ namespace Scratch.Services { public signal void hook_folder_item_change (File file, File? other_file, FileMonitorEvent event_type); public signal void extension_added (Peas.PluginInfo info); - public signal void extension_removed (Peas.PluginInfo info); + // public signal void extension_removed (Peas.PluginInfo info); + + /* FROM FILES PLUGIN SYSTEM */ + + delegate Scratch.Plugins.PluginBase ModuleInitFunc (Scratch.Plugins.PluginInfo info); + Gee.HashMap plugin_hash; + Gee.List names; + // bool in_available = false; + bool update_queued = false; + // bool is_admin = false; + public Gee.List menuitem_references { get; private set; } public PluginsManager (MainWindow window) { this.window = window; - settings_field = "plugins-enabled"; + // settings_field = "plugins-enabled"; - plugin_iface = new Interface (this); + plugin_iface = new Scratch.Plugins.Interface (this); - /* Let's init the engine */ - engine = Peas.Engine.get_default (); - engine.enable_loader ("python"); - engine.add_search_path (Constants.PLUGINDIR, null); - Scratch.settings.bind ("plugins-enabled", engine, "loaded-plugins", SettingsBindFlags.DEFAULT); + /* From Files PluginManager construct */ + plugin_hash = new Gee.HashMap (); + names = new Gee.ArrayList (); + menuitem_references = new Gee.LinkedList (); - /* Our extension set */ - exts = new Peas.ExtensionSet (engine, typeof (Peas.Activatable), "object", plugin_iface, null); + // Code has only one plugin directory. - exts.extension_added.connect ((info, ext) => { - ((Peas.Activatable)ext).activate (); - extension_added (info); - }); + // if (!is_admin) { + // plugin_dirs += Path.build_filename (plugin_dir, "core"); + // plugin_dirs += plugin_dir; - exts.extension_removed.connect ((info, ext) => { - ((Peas.Activatable)ext).deactivate (); - extension_removed (info); - }); + // load_plugins (); + load_modules_from_dir (Constants.PLUGINDIR); - exts.foreach (on_extension_foreach); + // No need to monitor plugin directory - we do not allow third party plugins - // Connect managers signals to interface's signals - this.hook_window.connect ((w) => { - plugin_iface.hook_window (w); - }); + // /* Monitor plugin dirs */ + // foreach (string path in plugin_dirs) { + // set_directory_monitor (path); + // } + // } - this.hook_share_menu.connect ((m) => { - plugin_iface.hook_share_menu (m); - }); + // /* Let's init the engine */ + // engine = Peas.Engine.get_default (); + // engine.enable_loader ("python"); + // engine.add_search_path (Constants.PLUGINDIR, null); + // Scratch.settings.bind ("plugins-enabled", engine, "loaded-plugins", SettingsBindFlags.DEFAULT); - this.hook_toolbar.connect ((t) => { - plugin_iface.hook_toolbar (t); - }); + // /* Our extension set */ + // exts = new Peas.ExtensionSet (engine, typeof (Peas.Activatable), "object", plugin_iface, null); - this.hook_document.connect ((d) => { - plugin_iface.hook_document (d); - }); + // exts.extension_added.connect ((info, ext) => { + // ((Peas.Activatable)ext).activate (); + // extension_added (info); + // }); - this.hook_preferences_dialog.connect ((d) => { - plugin_iface.hook_preferences_dialog (d); - }); + // exts.extension_removed.connect ((info, ext) => { + // ((Peas.Activatable)ext).deactivate (); + // extension_removed (info); + // }); - this.hook_folder_item_change.connect ((source, dest, event) => { - plugin_iface.hook_folder_item_change (source, dest, event); - }); - } + // exts.foreach (on_extension_foreach); + + // // Connect managers signals to interface's signals + // this.hook_window.connect ((w) => { + // plugin_iface.hook_window (w); + // }); + + // this.hook_share_menu.connect ((m) => { + // plugin_iface.hook_share_menu (m); + // }); + + // this.hook_toolbar.connect ((t) => { + // plugin_iface.hook_toolbar (t); + // }); + + // this.hook_document.connect ((d) => { + // plugin_iface.hook_document (d); + // }); + + // this.hook_preferences_dialog.connect ((d) => { + // plugin_iface.hook_preferences_dialog (d); + // }); - void on_extension_foreach (Peas.ExtensionSet set, Peas.PluginInfo info, Peas.Extension extension) { - ((Peas.Activatable)extension).activate (); + // this.hook_folder_item_change.connect ((source, dest, event) => { + // plugin_iface.hook_folder_item_change (source, dest, event); + // }); } + // void on_extension_foreach (Peas.ExtensionSet set, Peas.PluginInfo info, Peas.Extension extension) { + // ((Peas.Activatable)extension).activate (); + // } + public Gtk.Widget get_view () { - var view = new PeasGtk.PluginManager (engine); - var bottom_box = view.get_children ().nth_data (1); - bottom_box.no_show_all = true; - return view; + // var view = new PeasGtk.PluginManager (engine); + // var bottom_box = view.get_children ().nth_data (1); + // bottom_box.no_show_all = true; + return new Gtk.Frame (null); + } + + + + // [Version (deprecated = true, deprecated_since = "0.2", replacement = "Files.PluginManager.menuitem_references")] + // public GLib.List? menus; /* this doesn't manage GObject references properly */ + + + // private void load_plugins () { + // in_available = true; + // load_modules_from_dir (plugin_dirs[1]); + // in_available = false; + // } + + // private void set_directory_monitor (string path) { + // var dir = GLib.File.new_for_path (path); + + // try { + // var monitor = dir.monitor_directory (FileMonitorFlags.NONE, null); + // monitor.changed.connect (on_plugin_directory_change); + // monitor.ref (); /* keep alive */ + // } catch (IOError e) { + // critical ("Could not setup monitor for '%s': %s", dir.get_path (), e.message); + // } + // } + + // private async void on_plugin_directory_change (GLib.File file, GLib.File? other_file, FileMonitorEvent event) { + // if (update_queued) { + // return; + // } + + // update_queued = true; + + // Idle.add_full (Priority.LOW, on_plugin_directory_change.callback); + // yield; + + // load_plugins (); + // update_queued = false; + // } + + private void load_modules_from_dir (string path) { + string attributes = FileAttribute.STANDARD_NAME + "," + + FileAttribute.STANDARD_TYPE; + + FileInfo info; + FileEnumerator enumerator; + + try { + var dir = GLib.File.new_for_path (path); + + enumerator = dir.enumerate_children + (attributes, + FileQueryInfoFlags.NONE); + + info = enumerator.next_file (); + + while (info != null) { + string file_name = info.get_name (); + var plugin_file = dir.get_child_for_display_name (file_name); + + if (file_name.has_suffix (".plug")) { + load_plugin_keyfile (plugin_file.get_path (), path); + } + + info = enumerator.next_file (); + } + } catch (Error error) { + critical ("Error listing contents of folder '%s': %s", path, error.message); + } + } + + private bool load_module (string file_path, Scratch.Plugins.PluginInfo plugin_info) { + if (plugin_hash.has_key (file_path)) { + debug ("plugin for %s already loaded. Not adding again", file_path); + return false; + } + + debug ("Loading plugin for %s", file_path); + + Module module = Module.open (file_path, ModuleFlags.LOCAL); + if (module == null) { + warning ("Failed to load module from path '%s': %s", + file_path, + Module.error ()); + return false; + } + + void* function; + + if (!module.symbol ("module_init", out function)) { + warning ("Failed to find entry point function '%s' in '%s': %s", + "module_init", + file_path, + Module.error ()); + return false; + } + + unowned ModuleInitFunc module_init = (ModuleInitFunc) function; + assert (module_init != null); + + //TODO Reconsider for Code plugins + /* We don't want our modules to ever unload */ + module.make_resident (); + Scratch.Plugins.PluginBase plug = module_init (plugin_info); + + debug ("Loaded module source: '%s'", module.name ()); + + if (plug != null) { + plugin_hash.set (file_path, plug); + return true; + } + + // if (in_available) { + // names.add (name); + // } + return false; + } + + // Load the .plugin file from each plugin folder + private void load_plugin_keyfile (string path, string parent) { + var keyfile = new KeyFile (); + var plugin_info = Scratch.Plugins.PluginInfo (); + try { + keyfile.load_from_file (path, KeyFileFlags.NONE); + plugin_info.name = keyfile.get_string ("Plugin", "Name"); + plugin_info.description = keyfile.get_string ("Plugin", "Description"); + plugin_info.icon_name = keyfile.get_string ("Plugin", "Icon"); + // Should we expose the author(s)? + var plug_path = Path.build_filename (parent, keyfile.get_string ("Plugin", "File")); + load_module (plug_path, plugin_info); + } catch (Error e) { + warning ("Couldn't open the keyfile '%s': %s", path, e.message); + + } + } + + public Gee.List get_available_plugins () { + return names; } } -} +// } From 1922f5050e3057bbad2e4adfd68a1ce5b433e748 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Thu, 26 Dec 2024 15:56:50 +0000 Subject: [PATCH 02/20] First compilable version --- .../brackets-completion.vala | 17 +- plugins/detect-indent/detect-indent.vala | 20 +- plugins/editorconfig/editorconfig.vala | 21 +- plugins/fuzzy-search/fuzzy-search.vala | 18 +- .../highlight-word-selection.vala | 18 +- .../markdown-actions/markdown-actions.vala | 19 +- plugins/pastebin/pastebin.vala | 69 +-- plugins/pastebin/pastebin_dialog.vala | 60 ++- plugins/preserve-indent/preserve-indent.vala | 25 +- plugins/spell/spell.vala | 23 +- plugins/vim-emulation/vim-emulation.vala | 20 +- plugins/word-completion/plugin.vala | 22 +- src/Services/PluginManager.vala | 473 +++++++++--------- 13 files changed, 441 insertions(+), 364 deletions(-) diff --git a/plugins/brackets-completion/brackets-completion.vala b/plugins/brackets-completion/brackets-completion.vala index 787c005f8f..7c4576e646 100644 --- a/plugins/brackets-completion/brackets-completion.vala +++ b/plugins/brackets-completion/brackets-completion.vala @@ -18,7 +18,7 @@ END LICENSE ***/ -public class Scratch.Plugins.BracketsCompletion : PluginBase { +public class Scratch.Plugins.BracketsCompletion : Scratch.Plugins.PluginBase { Gee.HashMap brackets; Gee.HashMap keys; const string[] VALID_NEXT_CHARS = { @@ -33,7 +33,11 @@ public class Scratch.Plugins.BracketsCompletion : PluginBase { Scratch.Plugins.Interface plugins; // public Object object { owned get; construct; } - public void activate () { + public BracketsCompletion (PluginInfo info, Interface iface) { + base (info, iface); + } + + public override void activate () { brackets = new Gee.HashMap (); brackets["("] = ")"; brackets["["] = "]"; @@ -57,7 +61,7 @@ public class Scratch.Plugins.BracketsCompletion : PluginBase { plugins.hook_document.connect (on_hook_document); } - public void deactivate () { + public override void deactivate () { plugins.hook_document.disconnect (on_hook_document); } @@ -273,8 +277,11 @@ public class Scratch.Plugins.BracketsCompletion : PluginBase { } } -public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { - return new Scratch.Plugins.BracketsCompletion (info); +public Scratch.Plugins.PluginBase module_init ( + Scratch.Plugins.PluginInfo info, + Scratch.Plugins.Interface iface +) { + return new Scratch.Plugins.BracketsCompletion (info, iface); } // [ModuleInit] diff --git a/plugins/detect-indent/detect-indent.vala b/plugins/detect-indent/detect-indent.vala index 1ae48b4ee6..3696088cb0 100644 --- a/plugins/detect-indent/detect-indent.vala +++ b/plugins/detect-indent/detect-indent.vala @@ -1,11 +1,15 @@ -public class Scratch.Plugins.DetectIndent: PluginBase { +public class Scratch.Plugins.DetectIndent: Scratch.Plugins.PluginBase { const int MAX_LINES = 500; Scratch.Plugins.Interface plugins; // public Object object {owned get; construct;} - public void activate () { - plugins = (Scratch.Plugins.Interface) object; + public DetectIndent (PluginInfo info, Interface iface) { + base (info, iface); + } + + public override void activate () { + // plugins = (Scratch.Plugins.Interface) object; plugins.hook_document.connect ((d) => { var view = d.source_view; @@ -66,16 +70,20 @@ public class Scratch.Plugins.DetectIndent: PluginBase { }); } - public void deactivate () { + public override void deactivate () { } } -public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { - return new Scratch.Plugins.DetectIndent (info); +public Scratch.Plugins.PluginBase module_init ( + Scratch.Plugins.PluginInfo info, + Scratch.Plugins.Interface iface +) { + return new Scratch.Plugins.DetectIndent (info, iface); } + // [ModuleInit] // public void peas_register_types (GLib.TypeModule module) { // var objmodule = module as Peas.ObjectModule; diff --git a/plugins/editorconfig/editorconfig.vala b/plugins/editorconfig/editorconfig.vala index 08ac781f58..f212ad2426 100644 --- a/plugins/editorconfig/editorconfig.vala +++ b/plugins/editorconfig/editorconfig.vala @@ -17,15 +17,18 @@ * Boston, MA 02110-1301 USA */ -public class Scratch.Plugins.EditorConfigPlugin: PluginBase { +public class Scratch.Plugins.EditorConfigPlugin: Scratch.Plugins.PluginBase { Scratch.Plugins.Interface plugins; // public Object object { owned get; construct; } private Code.FormatBar format_bar; // public void update_state () { } - - public void activate () { - plugins = (Scratch.Plugins.Interface) object; + public EditorConfigPlugin (PluginInfo info, Interface iface) { + base (info, iface); + } + + public override void activate () { + // plugins = (Scratch.Plugins.Interface) object; plugins.hook_toolbar.connect ((tb) => { format_bar = tb.format_bar; @@ -85,13 +88,17 @@ public class Scratch.Plugins.EditorConfigPlugin: PluginBase { }); } - public void deactivate () { } + public override void deactivate () { } } -public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { - return new Scratch.Plugins.EditorConfigPlugin (info); +public Scratch.Plugins.PluginBase module_init ( + Scratch.Plugins.PluginInfo info, + Scratch.Plugins.Interface iface +) { + return new Scratch.Plugins.EditorConfigPlugin (info, iface); } + // [ModuleInit] // public void peas_register_types (GLib.TypeModule module) { // var objmodule = module as Peas.ObjectModule; diff --git a/plugins/fuzzy-search/fuzzy-search.vala b/plugins/fuzzy-search/fuzzy-search.vala index a4d44dadef..9ced69466f 100644 --- a/plugins/fuzzy-search/fuzzy-search.vala +++ b/plugins/fuzzy-search/fuzzy-search.vala @@ -6,7 +6,7 @@ */ -public class Scratch.Plugins.FuzzySearch: PluginBase { +public class Scratch.Plugins.FuzzySearch: Scratch.Plugins.PluginBase { // public Object object { owned get; construct; } private const uint ACCEL_KEY = Gdk.Key.F; private const Gdk.ModifierType ACCEL_MODTYPE = Gdk.ModifierType.MOD1_MASK; @@ -36,8 +36,11 @@ public class Scratch.Plugins.FuzzySearch: PluginBase { // public void update_state () { // } - - public void activate () { + public FuzzySearch (PluginInfo info, Interface iface) { + base (info, iface); + } + + public override void activate () { // plugins = (Scratch.Plugins.Interface) object; plugins.hook_window.connect ((w) => { @@ -68,7 +71,7 @@ public class Scratch.Plugins.FuzzySearch: PluginBase { }); } - public void deactivate () { + public override void deactivate () { folder_settings.changed["opened-folders"].disconnect (handle_opened_projects_change); remove_actions (); if (cancellable != null) { @@ -153,8 +156,11 @@ public class Scratch.Plugins.FuzzySearch: PluginBase { } } -public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { - return new Scratch.Plugins.FuzzySearch (info); +public Scratch.Plugins.PluginBase module_init ( + Scratch.Plugins.PluginInfo info, + Scratch.Plugins.Interface iface +) { + return new Scratch.Plugins.FuzzySearch (info, iface); } // [ModuleInit] diff --git a/plugins/highlight-word-selection/highlight-word-selection.vala b/plugins/highlight-word-selection/highlight-word-selection.vala index 3c3dd9a05d..83a86b073a 100644 --- a/plugins/highlight-word-selection/highlight-word-selection.vala +++ b/plugins/highlight-word-selection/highlight-word-selection.vala @@ -18,7 +18,7 @@ END LICENSE ***/ -public class Scratch.Plugins.HighlightSelectedWords : PluginBase { +public class Scratch.Plugins.HighlightSelectedWords : Scratch.Plugins.PluginBase { Scratch.Widgets.SourceView current_source; Scratch.MainWindow? main_window = null; Gtk.SourceSearchContext? current_search_context = null; @@ -31,8 +31,11 @@ public class Scratch.Plugins.HighlightSelectedWords : PluginBase { // public Object object { owned get; construct; } // public void update_state () {} - - public void activate () { + public HighlightSelectedWords (PluginInfo info, Interface iface) { + base (info, iface); + } + + public override void activate () { // plugins = (Scratch.Plugins.Interface) object; plugins.hook_document.connect ((doc) => { if (current_source != null) { @@ -51,7 +54,7 @@ public class Scratch.Plugins.HighlightSelectedWords : PluginBase { } - public void deactivate () { + public override void deactivate () { if (current_source != null) { current_source.deselected.disconnect (on_deselection); current_source.selection_changed.disconnect (on_selection_changed); @@ -149,8 +152,11 @@ public class Scratch.Plugins.HighlightSelectedWords : PluginBase { } } -public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { - return new Scratch.Plugins.FuzzySearch (info); +public Scratch.Plugins.PluginBase module_init ( + Scratch.Plugins.PluginInfo info, + Scratch.Plugins.Interface iface +) { + return new Scratch.Plugins.HighlightSelectedWords (info, iface); } // [ModuleInit] diff --git a/plugins/markdown-actions/markdown-actions.vala b/plugins/markdown-actions/markdown-actions.vala index 5a720a8be8..4b2d83f1fe 100644 --- a/plugins/markdown-actions/markdown-actions.vala +++ b/plugins/markdown-actions/markdown-actions.vala @@ -18,15 +18,18 @@ END LICENSE ***/ -public class Code.Plugins.MarkdownActions : PluginBase { +public class Scratch.Plugins.MarkdownActions : Scratch.Plugins.PluginBase { Scratch.Widgets.SourceView current_source; Scratch.Plugins.Interface plugins; // public Object object { owned get; construct; } // public void update_state () {} - - public void activate () { + public MarkdownActions (PluginInfo info, Interface iface) { + base (info, iface); + } + + public override void activate () { plugins.hook_document.connect ((doc) => { if (current_source != null) { current_source.key_press_event.disconnect (shortcut_handler); @@ -40,7 +43,7 @@ public class Code.Plugins.MarkdownActions : PluginBase { }); } - public void deactivate () { + public override void deactivate () { if (current_source != null) { current_source.key_press_event.disconnect (shortcut_handler); current_source.notify["language"].disconnect (configure_shortcuts); @@ -239,10 +242,14 @@ public class Code.Plugins.MarkdownActions : PluginBase { } } -public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { - return new Scratch.Plugins.MarkdownActions (info); +public Scratch.Plugins.PluginBase module_init ( + Scratch.Plugins.PluginInfo info, + Scratch.Plugins.Interface iface +) { + return new Scratch.Plugins.MarkdownActions (info, iface); } + // [ModuleInit] // public void peas_register_types (TypeModule module) { // var objmodule = module as Peas.ObjectModule; diff --git a/plugins/pastebin/pastebin.vala b/plugins/pastebin/pastebin.vala index 16cf75f496..ee50a1092a 100644 --- a/plugins/pastebin/pastebin.vala +++ b/plugins/pastebin/pastebin.vala @@ -18,63 +18,15 @@ END LICENSE ***/ -namespace Scratch.Plugins { - public class PasteBin : GLib.Object { - public const string NEVER = "N"; - public const string TEN_MINUTES = "10M"; - public const string HOUR = "1H"; - public const string DAY = "1D"; - public const string MONTH = "1M"; - public const string PRIVATE = "1"; - public const string PUBLIC = "0"; - - public static bool submit (out string link, string paste_code, string paste_name, - string paste_private, string paste_expire_date, - string paste_format) { - - if (paste_code.length == 0) { link = "No text to paste"; return false; } - - string api_url = "https://pastebin.com/api/api_post.php"; - - var session = new Soup.Session (); - var message = new Soup.Message ("POST", api_url); - - string request = Soup.Form.encode ( - "api_option", "paste", - "api_dev_key", "67480801fa55fc0977f7561cf650a339", - "api_paste_code", paste_code, - "api_paste_name", paste_name, - "api_paste_private", paste_private, - "api_paste_expire_date", paste_expire_date, - "api_paste_format", paste_format); - - message.set_request ("application/x-www-form-urlencoded", Soup.MemoryUse.COPY, request.data); - message.set_flags (Soup.MessageFlags.NO_REDIRECT); - - session.send_message (message); - - var output = (string) message.response_body.data; - link = output; - - if (Uri.parse_scheme (output) == null || message.status_code != 200) { - // A URI was not returned - return false; - } - - return true; - } - } -} - -public class Scratch.Plugins.Pastebin : PluginBase { +public class Scratch.Plugins.Pastebin : Scratch.Plugins.PluginBase { GLib.MenuItem? menuitem = null; GLib.Menu? share_menu = null; // public Object object { owned get; construct; } Scratch.Services.Document? doc = null; - Scratch.Services.Interface plugins; + Scratch.Plugins.Interface plugins; const string ACTION_GROUP = "pastebin"; const string ACTION_PREFIX = ACTION_GROUP + "."; @@ -87,8 +39,11 @@ public class Scratch.Plugins.Pastebin : PluginBase { // public void update_state () { // } - - public void activate () { + public Pastebin (PluginInfo info, Interface iface) { + base (info, iface); + } + + public override void activate () { // plugins = (Scratch.Services.Interface) object; plugins.hook_document.connect ((doc) => { @@ -98,7 +53,7 @@ public class Scratch.Plugins.Pastebin : PluginBase { plugins.hook_share_menu.connect (on_hook_share_menu); } - public void deactivate () { + public override void deactivate () { remove_actions (); } @@ -144,10 +99,14 @@ public class Scratch.Plugins.Pastebin : PluginBase { } } -public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { - return new Scratch.Plugins.Pastebin (info); +public Scratch.Plugins.PluginBase module_init ( + Scratch.Plugins.PluginInfo info, + Scratch.Plugins.Interface iface +) { + return new Scratch.Plugins.Pastebin (info, iface); } + // [ModuleInit] // public void peas_register_types (GLib.TypeModule module) { // var objmodule = module as Peas.ObjectModule; diff --git a/plugins/pastebin/pastebin_dialog.vala b/plugins/pastebin/pastebin_dialog.vala index db4ad5d5be..0cd514b9e9 100644 --- a/plugins/pastebin/pastebin_dialog.vala +++ b/plugins/pastebin/pastebin_dialog.vala @@ -21,7 +21,53 @@ using Scratch.Services; namespace Scratch.Dialogs { + public class PasteBinSubmitter : GLib.Object { + public const string NEVER = "N"; + public const string TEN_MINUTES = "10M"; + public const string HOUR = "1H"; + public const string DAY = "1D"; + public const string MONTH = "1M"; + public const string PRIVATE = "1"; + public const string PUBLIC = "0"; + + + public static bool submit (out string link, string paste_code, string paste_name, + string paste_private, string paste_expire_date, + string paste_format) { + + if (paste_code.length == 0) { link = "No text to paste"; return false; } + + string api_url = "https://pastebin.com/api/api_post.php"; + + var session = new Soup.Session (); + var message = new Soup.Message ("POST", api_url); + + string request = Soup.Form.encode ( + "api_option", "paste", + "api_dev_key", "67480801fa55fc0977f7561cf650a339", + "api_paste_code", paste_code, + "api_paste_name", paste_name, + "api_paste_private", paste_private, + "api_paste_expire_date", paste_expire_date, + "api_paste_format", paste_format); + + message.set_request ("application/x-www-form-urlencoded", Soup.MemoryUse.COPY, request.data); + message.set_flags (Soup.MessageFlags.NO_REDIRECT); + + session.send_message (message); + + var output = (string) message.response_body.data; + link = output; + + if (Uri.parse_scheme (output) == null || message.status_code != 200) { + // A URI was not returned + return false; + } + + return true; + } + } public class PasteBinDialog : Granite.Dialog { public string[,] languages = { @@ -457,18 +503,18 @@ namespace Scratch.Dialogs { string paste_code = this.doc.get_text (); string paste_name = name_entry.text; string paste_format = format_combo.get_active_id (); - string paste_private = private_check.get_active () == true ? PasteBin.PRIVATE : PasteBin.PUBLIC; + string paste_private = private_check.get_active () == true ? PasteBinSubmitter.PRIVATE : PasteBinSubmitter.PUBLIC; string paste_expire_date = expiry_combo.get_active_id (); - return PasteBin.submit (out link, paste_code, paste_name, paste_private, paste_expire_date, paste_format); + return PasteBinSubmitter.submit (out link, paste_code, paste_name, paste_private, paste_expire_date, paste_format); } private void populate_expiry_combo () { - expiry_combo.append (PasteBin.NEVER, _("Never")); - expiry_combo.append (PasteBin.TEN_MINUTES, _("Ten minutes")); - expiry_combo.append (PasteBin.HOUR, _("One hour")); - expiry_combo.append (PasteBin.DAY, _("One day")); - expiry_combo.append (PasteBin.MONTH, _("One month")); + expiry_combo.append (PasteBinSubmitter.NEVER, _("Never")); + expiry_combo.append (PasteBinSubmitter.TEN_MINUTES, _("Ten minutes")); + expiry_combo.append (PasteBinSubmitter.HOUR, _("One hour")); + expiry_combo.append (PasteBinSubmitter.DAY, _("One day")); + expiry_combo.append (PasteBinSubmitter.MONTH, _("One month")); } } } diff --git a/plugins/preserve-indent/preserve-indent.vala b/plugins/preserve-indent/preserve-indent.vala index b5a6baed67..21a37d3fa0 100644 --- a/plugins/preserve-indent/preserve-indent.vala +++ b/plugins/preserve-indent/preserve-indent.vala @@ -18,17 +18,19 @@ END LICENSE ***/ -public class Scratch.Plugins.PreserveIndent : PluginBase { - - private Scratch.Services.Interface plugins; +public class Scratch.Plugins.PreserveIndent : Scratch.Plugins.PluginBase { + private Scratch.Plugins.Interface plugins; private Gee.TreeSet documents; private Services.Document active_document; private int last_clipboard_indent_level = 0; private bool waiting_for_clipboard_text = false; // public Object object { owned get; construct; } - - public void activate () { + public PreserveIndent (PluginInfo info, Interface iface) { + base (info, iface); + } + + public override void activate () { this.documents = new Gee.TreeSet (); // plugins = (Scratch.Services.Interface) object; @@ -48,13 +50,10 @@ public class Scratch.Plugins.PreserveIndent : PluginBase { }); } - public void deactivate () { + public override void deactivate () { this.documents.clear (); } - public void update_state () { - } - // determine how many characters precede a given iterator position private int measure_indent_at_iter (Widgets.SourceView view, Gtk.TextIter iter) { Gtk.TextIter line_begin, pos; @@ -241,10 +240,14 @@ public class Scratch.Plugins.PreserveIndent : PluginBase { } } -public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { - return new Scratch.Plugins.PreserveIndent (info); +public Scratch.Plugins.PluginBase module_init ( + Scratch.Plugins.PluginInfo info, + Scratch.Plugins.Interface iface +) { + return new Scratch.Plugins.PreserveIndent (info, iface); } + // [ModuleInit] // public void peas_register_types (GLib.TypeModule module) { // var objmodule = module as Peas.ObjectModule; diff --git a/plugins/spell/spell.vala b/plugins/spell/spell.vala index 2d41625d38..3a5a3c0b4e 100644 --- a/plugins/spell/spell.vala +++ b/plugins/spell/spell.vala @@ -13,14 +13,10 @@ * with this program. If not, see */ -public class Scratch.Plugins.Spell: PluginBase { - +public class Scratch.Plugins.Spell: Scratch.Plugins.PluginBase { Scratch.Plugins.Interface plugins; - private GLib.Settings settings; - MainWindow window = null; - private string lang_dict; #if SPELLLEGACY @@ -29,12 +25,15 @@ public class Scratch.Plugins.Spell: PluginBase { GtkSpell.Checker spell = null; #endif + public Spell (PluginInfo info, Interface iface) { + base (info, iface); + } // public Object object {owned get; construct;} // public void update_state () { // } - public void activate () { + public override void activate () { settings = new GLib.Settings (Constants.PROJECT_NAME + ".plugins.spell"); // Restore the last dictionary used. @@ -93,7 +92,7 @@ public class Scratch.Plugins.Spell: PluginBase { #endif // Deactivate Spell checker when it is no longer needed plugins.manager.extension_removed.connect ((info) => { - if (info.get_module_name () == "spell") + if (info.module_name == "spell") spell.detach (); }); @@ -126,7 +125,7 @@ public class Scratch.Plugins.Spell: PluginBase { } - public void deactivate () { + public override void deactivate () { save_settings (); window.destroy.disconnect (save_settings); } @@ -154,10 +153,14 @@ public class Scratch.Plugins.Spell: PluginBase { } -public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { - return new Scratch.Plugins.Spell (info); +public Scratch.Plugins.PluginBase module_init ( + Scratch.Plugins.PluginInfo info, + Scratch.Plugins.Interface iface +) { + return new Scratch.Plugins.Spell (info, iface); } + // [ModuleInit] // public void peas_register_types (GLib.TypeModule module) { // var objmodule = module as Peas.ObjectModule; diff --git a/plugins/vim-emulation/vim-emulation.vala b/plugins/vim-emulation/vim-emulation.vala index 6145039660..830ce966e5 100644 --- a/plugins/vim-emulation/vim-emulation.vala +++ b/plugins/vim-emulation/vim-emulation.vala @@ -18,7 +18,7 @@ END LICENSE ***/ -public class Scratch.Plugins.VimEmulation : PluginBase { +public class Scratch.Plugins.VimEmulation : Scratch.Plugins.PluginBase { public enum Mode { COMMAND, INSERT, @@ -36,6 +36,10 @@ public class Scratch.Plugins.VimEmulation : PluginBase { Scratch.Plugins.Interface plugins; // public Object object { owned get; construct; } + public VimEmulation (PluginInfo info, Interface iface) { + base (info, iface); + } + construct { views = new Gee.TreeSet (); } @@ -44,8 +48,8 @@ public class Scratch.Plugins.VimEmulation : PluginBase { // } - public void activate () { - plugins = (Scratch.Plugins.Interface) object; + public override void activate () { + // plugins = (Scratch.Plugins.Interface) object; plugins.hook_document.connect ((doc) => { this.view = doc.source_view; this.view.key_press_event.disconnect (handle_key_press); @@ -54,7 +58,7 @@ public class Scratch.Plugins.VimEmulation : PluginBase { }); } - public void deactivate () { + public override void deactivate () { foreach (var v in views) { v.key_press_event.disconnect (handle_key_press); } @@ -295,10 +299,14 @@ public class Scratch.Plugins.VimEmulation : PluginBase { } } -public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { - return new Scratch.Plugins.VimEmulation (info); +public Scratch.Plugins.PluginBase module_init ( + Scratch.Plugins.PluginInfo info, + Scratch.Plugins.Interface iface +) { + return new Scratch.Plugins.VimEmulation (info, iface); } + // [ModuleInit] // public void peas_register_types (GLib.TypeModule module) { // var objmodule = module as Peas.ObjectModule; diff --git a/plugins/word-completion/plugin.vala b/plugins/word-completion/plugin.vala index 04ce552894..e89d0b4ad5 100644 --- a/plugins/word-completion/plugin.vala +++ b/plugins/word-completion/plugin.vala @@ -18,7 +18,7 @@ * */ -public class Scratch.Plugins.Completion : PluginBase { +public class Scratch.Plugins.Completion : Scratch.Plugins.PluginBase { public Object object { owned get; construct; } private List text_view_list = new List (); @@ -42,8 +42,12 @@ public class Scratch.Plugins.Completion : PluginBase { private const uint REFRESH_SHORTCUT = Gdk.Key.bar; //"|" in combination with will cause refresh private uint timeout_id = 0; - - public void activate () { + + public Completion (PluginInfo info, Interface iface) { + base (info, iface); + } + + public override void activate () { // plugins = (Scratch.Services.Interface) object; parser = new Euclide.Completion.Parser (); plugins.hook_window.connect ((w) => { @@ -57,10 +61,6 @@ public class Scratch.Plugins.Completion : PluginBase { text_view_list.@foreach (cleanup); } - public void update_state () { - - } - public void on_new_source_view (Scratch.Services.Document doc) { if (current_view != null) { if (current_view == doc.source_view) @@ -182,10 +182,14 @@ public class Scratch.Plugins.Completion : PluginBase { } } -public Scratch.Plugins.PluginBase module_init (Scratch.Plugins.PluginInfo info) { - return new Scratch.Plugins.Completion (info); +public Scratch.Plugins.PluginBase module_init ( + Scratch.Plugins.PluginInfo info, + Scratch.Plugins.Interface iface +) { + return new Scratch.Plugins.Completion (info, iface); } + // [ModuleInit] // public void peas_register_types (GLib.TypeModule module) { // var objmodule = module as Peas.ObjectModule; diff --git a/src/Services/PluginManager.vala b/src/Services/PluginManager.vala index 101694e303..1a13dd7a9f 100644 --- a/src/Services/PluginManager.vala +++ b/src/Services/PluginManager.vala @@ -19,305 +19,318 @@ ***/ // namespace Scratch.Plugins { - public abstract class Scratch.Plugins.PluginBase : GLib.Object { - public PluginInfo plugin_info { get; construct; } - public Interface plugin_iface { get; construct; } - public abstract void activate (); - public abstract void deactivate (); - // public abstract PluginBase module_init (PluginInfo plugin_info); - public virtual void update_state () {} +public abstract class Scratch.Plugins.PluginBase : GLib.Object { + public PluginInfo plugin_info { get; construct; } + public Interface plugin_iface { get; construct; } + public abstract void activate (); + public abstract void deactivate (); + // public abstract PluginBase module_init (PluginInfo plugin_info); + public virtual void update_state () {} + + protected PluginBase (PluginInfo info, Interface iface) { + Object ( + plugin_info: info, + plugin_iface: iface + ); } - - public struct Scratch.Plugins.PluginInfo { - string name; - string description; - string icon_name; +} + +public struct Scratch.Plugins.PluginInfo { + string name; + string module_name; + string description; + string icon_name; +} + +public class Scratch.Plugins.Interface : GLib.Object { + public Scratch.Services.PluginsManager manager; + // 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 { private set; get; } + + public Interface (Scratch.Services.PluginsManager manager) { + this.manager = manager; + + template_manager = new Scratch.TemplateManager (); } - public class Scratch.Plugins.Interface : GLib.Object { - public Scratch.Services.PluginsManager manager; - // 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 { private set; get; } - - public Interface (Scratch.Services.PluginsManager manager) { - this.manager = manager; - - 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 (doc); - return doc; - } + public Scratch.Services.Document open_file (File file) { + var doc = new Scratch.Services.Document (manager.window.actions, file); + manager.window.open_document (doc); + return doc; + } - public void close_document (Scratch.Services.Document doc) { - manager.window.close_document (doc); - } + public void close_document (Scratch.Services.Document doc) { + manager.window.close_document (doc); } +} +delegate Scratch.Plugins.PluginBase ModuleInitFunc ( + Scratch.Plugins.PluginInfo info, + Scratch.Plugins.Interface iface +); + +public class Scratch.Services.PluginsManager : GLib.Object { + // Peas.Engine engine; + // Peas.ExtensionSet exts; - public class Scratch.Services.PluginsManager : GLib.Object { - // Peas.Engine engine; - // Peas.ExtensionSet exts; + // string settings_field; - // string settings_field; + public Scratch.Plugins.Interface plugin_iface { private set; public get; } - public Scratch.Plugins.Interface plugin_iface { private set; public get; } + public weak MainWindow window; - public weak MainWindow window; + // 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); - // 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 signal void extension_added (Scratch.Plugins.PluginInfo info); + public signal void extension_removed (Scratch.Plugins.PluginInfo info); - public signal void extension_added (Peas.PluginInfo info); - // public signal void extension_removed (Peas.PluginInfo info); + /* FROM FILES PLUGIN SYSTEM */ - /* FROM FILES PLUGIN SYSTEM */ - delegate Scratch.Plugins.PluginBase ModuleInitFunc (Scratch.Plugins.PluginInfo info); - Gee.HashMap plugin_hash; - Gee.List names; - // bool in_available = false; - bool update_queued = false; - // bool is_admin = false; - public Gee.List menuitem_references { get; private set; } + Gee.HashMap plugin_hash; + Gee.List names; + // bool in_available = false; + bool update_queued = false; + // bool is_admin = false; + public Gee.List menuitem_references { get; private set; } - public PluginsManager (MainWindow window) { - this.window = window; + public PluginsManager (MainWindow window) { + this.window = window; - // settings_field = "plugins-enabled"; + // settings_field = "plugins-enabled"; - plugin_iface = new Scratch.Plugins.Interface (this); + plugin_iface = new Scratch.Plugins.Interface (this); - /* From Files PluginManager construct */ - plugin_hash = new Gee.HashMap (); - names = new Gee.ArrayList (); - menuitem_references = new Gee.LinkedList (); + /* From Files PluginManager construct */ + plugin_hash = new Gee.HashMap (); + names = new Gee.ArrayList (); + menuitem_references = new Gee.LinkedList (); - // Code has only one plugin directory. + // Code has only one plugin directory. - // if (!is_admin) { - // plugin_dirs += Path.build_filename (plugin_dir, "core"); - // plugin_dirs += plugin_dir; + // if (!is_admin) { + // plugin_dirs += Path.build_filename (plugin_dir, "core"); + // plugin_dirs += plugin_dir; - // load_plugins (); - load_modules_from_dir (Constants.PLUGINDIR); + // load_plugins (); + load_modules_from_dir (Constants.PLUGINDIR); - // No need to monitor plugin directory - we do not allow third party plugins + // No need to monitor plugin directory - we do not allow third party plugins - // /* Monitor plugin dirs */ - // foreach (string path in plugin_dirs) { - // set_directory_monitor (path); - // } - // } + // /* Monitor plugin dirs */ + // foreach (string path in plugin_dirs) { + // set_directory_monitor (path); + // } + // } - // /* Let's init the engine */ - // engine = Peas.Engine.get_default (); - // engine.enable_loader ("python"); - // engine.add_search_path (Constants.PLUGINDIR, null); - // Scratch.settings.bind ("plugins-enabled", engine, "loaded-plugins", SettingsBindFlags.DEFAULT); + // /* Let's init the engine */ + // engine = Peas.Engine.get_default (); + // engine.enable_loader ("python"); + // engine.add_search_path (Constants.PLUGINDIR, null); + // Scratch.settings.bind ("plugins-enabled", engine, "loaded-plugins", SettingsBindFlags.DEFAULT); - // /* Our extension set */ - // exts = new Peas.ExtensionSet (engine, typeof (Peas.Activatable), "object", plugin_iface, null); + // /* Our extension set */ + // exts = new Peas.ExtensionSet (engine, typeof (Peas.Activatable), "object", plugin_iface, null); - // exts.extension_added.connect ((info, ext) => { - // ((Peas.Activatable)ext).activate (); - // extension_added (info); - // }); + // exts.extension_added.connect ((info, ext) => { + // ((Peas.Activatable)ext).activate (); + // extension_added (info); + // }); - // exts.extension_removed.connect ((info, ext) => { - // ((Peas.Activatable)ext).deactivate (); - // extension_removed (info); - // }); + // exts.extension_removed.connect ((info, ext) => { + // ((Peas.Activatable)ext).deactivate (); + // extension_removed (info); + // }); - // exts.foreach (on_extension_foreach); + // exts.foreach (on_extension_foreach); - // // Connect managers signals to interface's signals - // this.hook_window.connect ((w) => { - // plugin_iface.hook_window (w); - // }); + // // Connect managers signals to interface's signals + // this.hook_window.connect ((w) => { + // plugin_iface.hook_window (w); + // }); - // this.hook_share_menu.connect ((m) => { - // plugin_iface.hook_share_menu (m); - // }); + // this.hook_share_menu.connect ((m) => { + // plugin_iface.hook_share_menu (m); + // }); - // this.hook_toolbar.connect ((t) => { - // plugin_iface.hook_toolbar (t); - // }); + // this.hook_toolbar.connect ((t) => { + // plugin_iface.hook_toolbar (t); + // }); - // this.hook_document.connect ((d) => { - // plugin_iface.hook_document (d); - // }); + // this.hook_document.connect ((d) => { + // plugin_iface.hook_document (d); + // }); - // this.hook_preferences_dialog.connect ((d) => { - // plugin_iface.hook_preferences_dialog (d); - // }); + // this.hook_preferences_dialog.connect ((d) => { + // plugin_iface.hook_preferences_dialog (d); + // }); - // this.hook_folder_item_change.connect ((source, dest, event) => { - // plugin_iface.hook_folder_item_change (source, dest, event); - // }); - } + // this.hook_folder_item_change.connect ((source, dest, event) => { + // plugin_iface.hook_folder_item_change (source, dest, event); + // }); + } - // void on_extension_foreach (Peas.ExtensionSet set, Peas.PluginInfo info, Peas.Extension extension) { - // ((Peas.Activatable)extension).activate (); - // } + // void on_extension_foreach (Peas.ExtensionSet set, Peas.PluginInfo info, Peas.Extension extension) { + // ((Peas.Activatable)extension).activate (); + // } - public Gtk.Widget get_view () { - // var view = new PeasGtk.PluginManager (engine); - // var bottom_box = view.get_children ().nth_data (1); - // bottom_box.no_show_all = true; - return new Gtk.Frame (null); - } + public Gtk.Widget get_view () { + // var view = new PeasGtk.PluginManager (engine); + // var bottom_box = view.get_children ().nth_data (1); + // bottom_box.no_show_all = true; + return new Gtk.Frame (null); + } - // [Version (deprecated = true, deprecated_since = "0.2", replacement = "Files.PluginManager.menuitem_references")] - // public GLib.List? menus; /* this doesn't manage GObject references properly */ +// [Version (deprecated = true, deprecated_since = "0.2", replacement = "Files.PluginManager.menuitem_references")] +// public GLib.List? menus; /* this doesn't manage GObject references properly */ - // private void load_plugins () { - // in_available = true; - // load_modules_from_dir (plugin_dirs[1]); - // in_available = false; - // } - - // private void set_directory_monitor (string path) { - // var dir = GLib.File.new_for_path (path); +// private void load_plugins () { +// in_available = true; +// load_modules_from_dir (plugin_dirs[1]); +// in_available = false; +// } - // try { - // var monitor = dir.monitor_directory (FileMonitorFlags.NONE, null); - // monitor.changed.connect (on_plugin_directory_change); - // monitor.ref (); /* keep alive */ - // } catch (IOError e) { - // critical ("Could not setup monitor for '%s': %s", dir.get_path (), e.message); - // } - // } +// private void set_directory_monitor (string path) { +// var dir = GLib.File.new_for_path (path); - // private async void on_plugin_directory_change (GLib.File file, GLib.File? other_file, FileMonitorEvent event) { - // if (update_queued) { - // return; - // } +// try { +// var monitor = dir.monitor_directory (FileMonitorFlags.NONE, null); +// monitor.changed.connect (on_plugin_directory_change); +// monitor.ref (); /* keep alive */ +// } catch (IOError e) { +// critical ("Could not setup monitor for '%s': %s", dir.get_path (), e.message); +// } +// } - // update_queued = true; +// private async void on_plugin_directory_change (GLib.File file, GLib.File? other_file, FileMonitorEvent event) { +// if (update_queued) { +// return; +// } - // Idle.add_full (Priority.LOW, on_plugin_directory_change.callback); - // yield; +// update_queued = true; - // load_plugins (); - // update_queued = false; - // } +// Idle.add_full (Priority.LOW, on_plugin_directory_change.callback); +// yield; - private void load_modules_from_dir (string path) { - string attributes = FileAttribute.STANDARD_NAME + "," + - FileAttribute.STANDARD_TYPE; +// load_plugins (); +// update_queued = false; +// } - FileInfo info; - FileEnumerator enumerator; + private void load_modules_from_dir (string path) { + string attributes = FileAttribute.STANDARD_NAME + "," + + FileAttribute.STANDARD_TYPE; - try { - var dir = GLib.File.new_for_path (path); + FileInfo info; + FileEnumerator enumerator; - enumerator = dir.enumerate_children - (attributes, - FileQueryInfoFlags.NONE); + try { + var dir = GLib.File.new_for_path (path); - info = enumerator.next_file (); + enumerator = dir.enumerate_children + (attributes, + FileQueryInfoFlags.NONE); - while (info != null) { - string file_name = info.get_name (); - var plugin_file = dir.get_child_for_display_name (file_name); + info = enumerator.next_file (); - if (file_name.has_suffix (".plug")) { - load_plugin_keyfile (plugin_file.get_path (), path); - } + while (info != null) { + string file_name = info.get_name (); + var plugin_file = dir.get_child_for_display_name (file_name); - info = enumerator.next_file (); + if (file_name.has_suffix (".plug")) { + load_plugin_keyfile (plugin_file.get_path (), path); } - } catch (Error error) { - critical ("Error listing contents of folder '%s': %s", path, error.message); + + info = enumerator.next_file (); } + } catch (Error error) { + critical ("Error listing contents of folder '%s': %s", path, error.message); } + } - private bool load_module (string file_path, Scratch.Plugins.PluginInfo plugin_info) { - if (plugin_hash.has_key (file_path)) { - debug ("plugin for %s already loaded. Not adding again", file_path); - return false; - } + private bool load_module (string file_path, Scratch.Plugins.PluginInfo plugin_info) { + if (plugin_hash.has_key (file_path)) { + debug ("plugin for %s already loaded. Not adding again", file_path); + return false; + } - debug ("Loading plugin for %s", file_path); + debug ("Loading plugin for %s", file_path); - Module module = Module.open (file_path, ModuleFlags.LOCAL); - if (module == null) { - warning ("Failed to load module from path '%s': %s", - file_path, - Module.error ()); - return false; - } + Module module = Module.open (file_path, ModuleFlags.LOCAL); + if (module == null) { + warning ("Failed to load module from path '%s': %s", + file_path, + Module.error ()); + return false; + } - void* function; + void* function; - if (!module.symbol ("module_init", out function)) { - warning ("Failed to find entry point function '%s' in '%s': %s", - "module_init", - file_path, - Module.error ()); - return false; - } - - unowned ModuleInitFunc module_init = (ModuleInitFunc) function; - assert (module_init != null); + if (!module.symbol ("module_init", out function)) { + warning ("Failed to find entry point function '%s' in '%s': %s", + "module_init", + file_path, + Module.error ()); + return false; + } - //TODO Reconsider for Code plugins - /* We don't want our modules to ever unload */ - module.make_resident (); - Scratch.Plugins.PluginBase plug = module_init (plugin_info); - - debug ("Loaded module source: '%s'", module.name ()); + unowned ModuleInitFunc module_init = (ModuleInitFunc) function; + assert (module_init != null); - if (plug != null) { - plugin_hash.set (file_path, plug); - return true; - } + //TODO Reconsider for Code plugins + /* We don't want our modules to ever unload */ + module.make_resident (); + Scratch.Plugins.PluginBase plug = module_init (plugin_info, plugin_iface); + + debug ("Loaded module source: '%s'", module.name ()); - // if (in_available) { - // names.add (name); - // } - return false; + if (plug != null) { + plugin_hash.set (file_path, plug); + return true; } - // Load the .plugin file from each plugin folder - private void load_plugin_keyfile (string path, string parent) { - var keyfile = new KeyFile (); - var plugin_info = Scratch.Plugins.PluginInfo (); - try { - keyfile.load_from_file (path, KeyFileFlags.NONE); - plugin_info.name = keyfile.get_string ("Plugin", "Name"); - plugin_info.description = keyfile.get_string ("Plugin", "Description"); - plugin_info.icon_name = keyfile.get_string ("Plugin", "Icon"); - // Should we expose the author(s)? - var plug_path = Path.build_filename (parent, keyfile.get_string ("Plugin", "File")); - load_module (plug_path, plugin_info); - } catch (Error e) { - warning ("Couldn't open the keyfile '%s': %s", path, e.message); + // if (in_available) { + // names.add (name); + // } + return false; + } - } - } + // Load the .plugin file from each plugin folder + private void load_plugin_keyfile (string path, string parent) { + var keyfile = new KeyFile (); + var plugin_info = Scratch.Plugins.PluginInfo (); + try { + keyfile.load_from_file (path, KeyFileFlags.NONE); + plugin_info.name = keyfile.get_string ("Plugin", "Name"); + plugin_info.module_name = keyfile.get_string ("Plugin", "Module"); + plugin_info.description = keyfile.get_string ("Plugin", "Description"); + plugin_info.icon_name = keyfile.get_string ("Plugin", "Icon"); + // Should we expose the author(s)? + var plug_path = Path.build_filename (parent, keyfile.get_string ("Plugin", "File")); + load_module (plug_path, plugin_info); + } catch (Error e) { + warning ("Couldn't open the keyfile '%s': %s", path, e.message); - public Gee.List get_available_plugins () { - return names; } } + + public Gee.List get_available_plugins () { + return names; + } +} // } From 25cf4822ee949776a6deec5919b758e696aff5e2 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Thu, 26 Dec 2024 18:17:31 +0000 Subject: [PATCH 03/20] Implement extensions dialog --- src/Dialogs/PreferencesDialog.vala | 2 +- src/MainWindow.vala | 1 + src/Services/PluginManager.vala | 326 ++++++++++++++++------------- 3 files changed, 181 insertions(+), 148 deletions(-) diff --git a/src/Dialogs/PreferencesDialog.vala b/src/Dialogs/PreferencesDialog.vala index 35921f7cee..8c3dc4957b 100644 --- a/src/Dialogs/PreferencesDialog.vala +++ b/src/Dialogs/PreferencesDialog.vala @@ -146,7 +146,7 @@ public class Scratch.Dialogs.Preferences : Granite.Dialog { plugins.hook_preferences_dialog (this); - if (Peas.Engine.get_default ().get_plugin_list ().length () > 0) { + if (plugins.get_n_plugins () > 0) { var pbox = plugins.get_view (); pbox.vexpand = true; diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 34fe7d93db..f39d1e6e95 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -281,6 +281,7 @@ namespace Scratch { clipboard = Gtk.Clipboard.get_for_display (get_display (), Gdk.SELECTION_CLIPBOARD); + warning ("creating new plugin manager"); plugins = new Scratch.Services.PluginsManager (this); key_controller = new Gtk.EventControllerKey (this) { diff --git a/src/Services/PluginManager.vala b/src/Services/PluginManager.vala index 1a13dd7a9f..06fd3faecb 100644 --- a/src/Services/PluginManager.vala +++ b/src/Services/PluginManager.vala @@ -40,6 +40,7 @@ public struct Scratch.Plugins.PluginInfo { string module_name; string description; string icon_name; + bool is_active; } public class Scratch.Plugins.Interface : GLib.Object { @@ -72,18 +73,16 @@ public class Scratch.Plugins.Interface : GLib.Object { } delegate Scratch.Plugins.PluginBase ModuleInitFunc ( - Scratch.Plugins.PluginInfo info, + Scratch.Plugins.PluginInfo info, Scratch.Plugins.Interface iface ); - -public class Scratch.Services.PluginsManager : GLib.Object { - // Peas.Engine engine; - // Peas.ExtensionSet exts; - // string settings_field; +public class Scratch.Services.PluginsManager : GLib.Object { + public const string ACTIVE_PLUGINS_KEY = "plugins-enabled"; + public const string PLUGIN_FILE_EXTENSION = ".plugin"; + public const string MODULE_FILE_EXTENSION = ".so"; public Scratch.Plugins.Interface plugin_iface { private set; public get; } - public weak MainWindow window; // Signals @@ -94,151 +93,101 @@ public class Scratch.Services.PluginsManager : GLib.Object { 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 signal void extension_added (Scratch.Plugins.PluginInfo info); + public signal void extension_added (); public signal void extension_removed (Scratch.Plugins.PluginInfo info); /* FROM FILES PLUGIN SYSTEM */ - - - Gee.HashMap plugin_hash; - Gee.List names; - // bool in_available = false; - bool update_queued = false; - // bool is_admin = false; + Gee.HashMap plugin_hash; // all plugins + public Gee.HashSet active_plugin_set; //active plugin names public Gee.List menuitem_references { get; private set; } public PluginsManager (MainWindow window) { + warning ("PluginsManager new"); this.window = window; - - // settings_field = "plugins-enabled"; - plugin_iface = new Scratch.Plugins.Interface (this); /* From Files PluginManager construct */ plugin_hash = new Gee.HashMap (); - names = new Gee.ArrayList (); + active_plugin_set = new Gee.HashSet (); + // names = new Gee.ArrayList (); menuitem_references = new Gee.LinkedList (); - // Code has only one plugin directory. - // if (!is_admin) { - // plugin_dirs += Path.build_filename (plugin_dir, "core"); - // plugin_dirs += plugin_dir; - - // load_plugins (); load_modules_from_dir (Constants.PLUGINDIR); - // No need to monitor plugin directory - we do not allow third party plugins - - // /* Monitor plugin dirs */ - // foreach (string path in plugin_dirs) { - // set_directory_monitor (path); - // } - // } - - // /* Let's init the engine */ - // engine = Peas.Engine.get_default (); - // engine.enable_loader ("python"); - // engine.add_search_path (Constants.PLUGINDIR, null); - // Scratch.settings.bind ("plugins-enabled", engine, "loaded-plugins", SettingsBindFlags.DEFAULT); - - // /* Our extension set */ - // exts = new Peas.ExtensionSet (engine, typeof (Peas.Activatable), "object", plugin_iface, null); - - // exts.extension_added.connect ((info, ext) => { - // ((Peas.Activatable)ext).activate (); - // extension_added (info); - // }); - - // exts.extension_removed.connect ((info, ext) => { - // ((Peas.Activatable)ext).deactivate (); - // extension_removed (info); - // }); - - // exts.foreach (on_extension_foreach); - // // Connect managers signals to interface's signals - // this.hook_window.connect ((w) => { - // plugin_iface.hook_window (w); - // }); - - // this.hook_share_menu.connect ((m) => { - // plugin_iface.hook_share_menu (m); - // }); - - // this.hook_toolbar.connect ((t) => { - // plugin_iface.hook_toolbar (t); - // }); - - // this.hook_document.connect ((d) => { - // plugin_iface.hook_document (d); - // }); + this.hook_window.connect ((w) => { + plugin_iface.hook_window (w); + }); + + this.hook_share_menu.connect ((m) => { + plugin_iface.hook_share_menu (m); + }); + + this.hook_toolbar.connect ((t) => { + plugin_iface.hook_toolbar (t); + }); + + this.hook_document.connect ((d) => { + plugin_iface.hook_document (d); + }); + + this.hook_preferences_dialog.connect ((d) => { + plugin_iface.hook_preferences_dialog (d); + }); + + this.hook_folder_item_change.connect ((source, dest, event) => { + plugin_iface.hook_folder_item_change (source, dest, event); + }); + + string[] active_plugins = settings.get_strv (ACTIVE_PLUGINS_KEY); + + // Activate plugins according to setting + foreach (var plugin_name in active_plugins) { + if (plugin_hash.has_key (plugin_name)) { + var plugin = plugin_hash.@get (plugin_name); + activate_plugin (plugin); + active_plugin_set.add (plugin_name); + } + } + } - // this.hook_preferences_dialog.connect ((d) => { - // plugin_iface.hook_preferences_dialog (d); - // }); + private void activate_plugin (Scratch.Plugins.PluginBase plugin) { + var info = plugin.plugin_info; + if (!info.is_active) { + plugin.activate (); + info.is_active = true; + active_plugin_set.add (info.name); + extension_added (); // Signals Window to run initial hook function + update_active_plugin_settings (); + } + } - // this.hook_folder_item_change.connect ((source, dest, event) => { - // plugin_iface.hook_folder_item_change (source, dest, event); - // }); + private void deactivate_plugin (Scratch.Plugins.PluginBase plugin) { + var info = plugin.plugin_info; + if (info.is_active) { + plugin.deactivate (); + info.is_active = false; + active_plugin_set.remove (info.name); + extension_removed (info); + update_active_plugin_settings (); + } } + private void update_active_plugin_settings () { + settings.set_strv (ACTIVE_PLUGINS_KEY, active_plugin_set.to_array ()); + } // void on_extension_foreach (Peas.ExtensionSet set, Peas.PluginInfo info, Peas.Extension extension) { // ((Peas.Activatable)extension).activate (); // } - public Gtk.Widget get_view () { - // var view = new PeasGtk.PluginManager (engine); - // var bottom_box = view.get_children ().nth_data (1); - // bottom_box.no_show_all = true; - return new Gtk.Frame (null); - } - - - -// [Version (deprecated = true, deprecated_since = "0.2", replacement = "Files.PluginManager.menuitem_references")] -// public GLib.List? menus; /* this doesn't manage GObject references properly */ - - -// private void load_plugins () { -// in_available = true; -// load_modules_from_dir (plugin_dirs[1]); -// in_available = false; -// } - -// private void set_directory_monitor (string path) { -// var dir = GLib.File.new_for_path (path); - -// try { -// var monitor = dir.monitor_directory (FileMonitorFlags.NONE, null); -// monitor.changed.connect (on_plugin_directory_change); -// monitor.ref (); /* keep alive */ -// } catch (IOError e) { -// critical ("Could not setup monitor for '%s': %s", dir.get_path (), e.message); -// } -// } - -// private async void on_plugin_directory_change (GLib.File file, GLib.File? other_file, FileMonitorEvent event) { -// if (update_queued) { -// return; -// } - -// update_queued = true; - -// Idle.add_full (Priority.LOW, on_plugin_directory_change.callback); -// yield; - -// load_plugins (); -// update_queued = false; -// } - private void load_modules_from_dir (string path) { string attributes = FileAttribute.STANDARD_NAME + "," + FileAttribute.STANDARD_TYPE; FileInfo info; FileEnumerator enumerator; - +warning ("load modules from %s", path); try { var dir = GLib.File.new_for_path (path); @@ -249,11 +198,16 @@ public class Scratch.Services.PluginsManager : GLib.Object { info = enumerator.next_file (); while (info != null) { - string file_name = info.get_name (); - var plugin_file = dir.get_child_for_display_name (file_name); - - if (file_name.has_suffix (".plug")) { - load_plugin_keyfile (plugin_file.get_path (), path); + if (info.get_file_type () == DIRECTORY) { + load_modules_from_dir (Path.build_filename (path, info.get_name ())); + } else { + string file_name = info.get_name (); + warning ("file name %s", file_name); + var plugin_file = dir.get_child_for_display_name (file_name); + + if (file_name.has_suffix (PLUGIN_FILE_EXTENSION)) { + load_plugin_keyfile (plugin_file, path); + } } info = enumerator.next_file (); @@ -263,13 +217,14 @@ public class Scratch.Services.PluginsManager : GLib.Object { } } - private bool load_module (string file_path, Scratch.Plugins.PluginInfo plugin_info) { - if (plugin_hash.has_key (file_path)) { - debug ("plugin for %s already loaded. Not adding again", file_path); + private bool load_module (File dir, Scratch.Plugins.PluginInfo info) { + if (plugin_hash.has_key (info.name)) { + warning ("plugin for %s already loaded. Not adding again", info.name); return false; } - debug ("Loading plugin for %s", file_path); + var file_path = dir.get_path ().concat (Path.DIR_SEPARATOR_S, "lib", info.module_name, MODULE_FILE_EXTENSION); + warning ("Loading plugin for %s", file_path); Module module = Module.open (file_path, ModuleFlags.LOCAL); if (module == null) { @@ -293,44 +248,121 @@ public class Scratch.Services.PluginsManager : GLib.Object { assert (module_init != null); //TODO Reconsider for Code plugins - /* We don't want our modules to ever unload */ - module.make_resident (); - Scratch.Plugins.PluginBase plug = module_init (plugin_info, plugin_iface); - - debug ("Loaded module source: '%s'", module.name ()); + // /* We don't want our modules to ever unload */ + // module.make_resident (); + Scratch.Plugins.PluginBase plug = module_init (info, plugin_iface); + + warning ("Loaded module source: '%s'", module.name ()); if (plug != null) { - plugin_hash.set (file_path, plug); + warning ("add plugin %s to hash", info.name); + plugin_hash.set (info.name, plug); + info.is_active = false; + // Plugins only become active via initial settings or preferences dialog return true; } - // if (in_available) { - // names.add (name); - // } return false; } // Load the .plugin file from each plugin folder - private void load_plugin_keyfile (string path, string parent) { + private void load_plugin_keyfile (File plugin_file, string parent) { var keyfile = new KeyFile (); var plugin_info = Scratch.Plugins.PluginInfo (); try { - keyfile.load_from_file (path, KeyFileFlags.NONE); + keyfile.load_from_file (plugin_file.get_path (), KeyFileFlags.NONE); plugin_info.name = keyfile.get_string ("Plugin", "Name"); plugin_info.module_name = keyfile.get_string ("Plugin", "Module"); plugin_info.description = keyfile.get_string ("Plugin", "Description"); - plugin_info.icon_name = keyfile.get_string ("Plugin", "Icon"); + if (keyfile.has_key ("Plugin", "Icon")) { + plugin_info.icon_name = keyfile.get_string ("Plugin", "Icon"); + } else { + plugin_info.icon_name = "extension"; + } // Should we expose the author(s)? - var plug_path = Path.build_filename (parent, keyfile.get_string ("Plugin", "File")); - load_module (plug_path, plugin_info); + load_module (plugin_file.get_parent (), plugin_info); } catch (Error e) { - warning ("Couldn't open the keyfile '%s': %s", path, e.message); + warning ("Couldn't open the keyfile '%s': %s", plugin_file.get_path (), e.message); } } + // Return an emulation of the discontinued libpeas-1.0 widget + public Gtk.Widget get_view () { + var list_box = new Gtk.ListBox (); + var scrolled_window = new Gtk.ScrolledWindow (null, null) { + hscrollbar_policy = NEVER, + vscrollbar_policy = AUTOMATIC, + max_content_height = 300, + child = list_box + }; + var frame = new Gtk.Frame (null) { + child = scrolled_window + }; + + foreach (var plugin in plugin_hash.values) { + var content = get_widget_for_plugin (plugin); + var row = new Gtk.ListBoxRow () { + child = content + }; + + list_box.add (row); + } + + // Could use a TreeMap (sortable) + list_box.set_sort_func ((r1, r2) => { + return strcmp ( + r1.get_child ().get_data ("name"), + r2.get_child ().get_data ("name") + ); + }); + frame.show_all (); + return frame; + } + + private Gtk.Widget get_widget_for_plugin (Scratch.Plugins.PluginBase plugin) { + var info = plugin.plugin_info; + var content = new Gtk.Box (HORIZONTAL, 6); + var checkbox = new Gtk.CheckButton () { + valign = Gtk.Align.CENTER, + active = info.is_active, + margin_start = 6 + }; + + checkbox.toggled.connect (() => { + if (checkbox.active) { + activate_plugin (plugin); + } else { + deactivate_plugin (plugin); + } + }); + var image = new Gtk.Image.from_icon_name (info.icon_name, LARGE_TOOLBAR) { + valign = Gtk.Align.CENTER + }; + var description_box = new Gtk.Box (VERTICAL, 0); + var name_label = new Granite.HeaderLabel (info.name); + //TODO In Granite-7 we can use secondary text property but emulate for now + var description_label = new Gtk.Label (info.description) { + use_markup = true, + wrap = true, + xalign = 0, + margin_start = 6, + margin_bottom = 6 + }; + description_label.get_style_context ().add_class (Granite.STYLE_CLASS_SMALL_LABEL); + description_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); + description_box.add (name_label); + description_box.add (description_label); + content.add (checkbox); + content.add (image); + content.add (description_box); + content.set_data ("name", info.name); + + return content; + } - public Gee.List get_available_plugins () { - return names; + public uint get_n_plugins () { + warning ("get n plugins %u", plugin_hash.size); + return plugin_hash.size; } } // } From 0c68c15e23353a97291e177d375c06f46a59864f Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Thu, 26 Dec 2024 18:20:03 +0000 Subject: [PATCH 04/20] Always start with behaviour page --- src/Dialogs/PreferencesDialog.vala | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Dialogs/PreferencesDialog.vala b/src/Dialogs/PreferencesDialog.vala index 8c3dc4957b..16a7dfbe34 100644 --- a/src/Dialogs/PreferencesDialog.vala +++ b/src/Dialogs/PreferencesDialog.vala @@ -160,6 +160,11 @@ public class Scratch.Dialogs.Preferences : Granite.Dialog { close_button.clicked.connect (() => { destroy (); }); + + // Always start with Behaviour page + realize.connect (() => { + stack.visible_child_name = "behavior"; + }); } private class SettingSwitch : Gtk.Grid { From b32ad39618b88e710da58171dc614c3094b52335 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Thu, 26 Dec 2024 18:35:52 +0000 Subject: [PATCH 05/20] Fix module loading, cleanup --- plugins/detect-indent/detect-indent.vala | 2 +- plugins/editorconfig/editorconfig.vala | 2 +- plugins/fuzzy-search/fuzzy-search.vala | 2 +- .../highlight-word-selection.vala | 4 +- .../markdown-actions/markdown-actions.vala | 2 +- plugins/pastebin/pastebin.vala | 2 +- plugins/preserve-indent/preserve-indent.vala | 2 +- plugins/vim-emulation/vim-emulation.vala | 2 +- plugins/word-completion/plugin.vala | 4 +- src/Dialogs/PreferencesDialog.vala | 2 +- src/Services/PluginManager.vala | 91 +++++++++---------- 11 files changed, 55 insertions(+), 60 deletions(-) diff --git a/plugins/detect-indent/detect-indent.vala b/plugins/detect-indent/detect-indent.vala index 3696088cb0..127b27f5b5 100644 --- a/plugins/detect-indent/detect-indent.vala +++ b/plugins/detect-indent/detect-indent.vala @@ -7,7 +7,7 @@ public class Scratch.Plugins.DetectIndent: Scratch.Plugins.PluginBase { public DetectIndent (PluginInfo info, Interface iface) { base (info, iface); } - + public override void activate () { // plugins = (Scratch.Plugins.Interface) object; diff --git a/plugins/editorconfig/editorconfig.vala b/plugins/editorconfig/editorconfig.vala index f212ad2426..2a2ebee25c 100644 --- a/plugins/editorconfig/editorconfig.vala +++ b/plugins/editorconfig/editorconfig.vala @@ -26,7 +26,7 @@ public class Scratch.Plugins.EditorConfigPlugin: Scratch.Plugins.PluginBase { public EditorConfigPlugin (PluginInfo info, Interface iface) { base (info, iface); } - + public override void activate () { // plugins = (Scratch.Plugins.Interface) object; diff --git a/plugins/fuzzy-search/fuzzy-search.vala b/plugins/fuzzy-search/fuzzy-search.vala index 9ced69466f..738a6ca936 100644 --- a/plugins/fuzzy-search/fuzzy-search.vala +++ b/plugins/fuzzy-search/fuzzy-search.vala @@ -39,7 +39,7 @@ public class Scratch.Plugins.FuzzySearch: Scratch.Plugins.PluginBase { public FuzzySearch (PluginInfo info, Interface iface) { base (info, iface); } - + public override void activate () { // plugins = (Scratch.Plugins.Interface) object; diff --git a/plugins/highlight-word-selection/highlight-word-selection.vala b/plugins/highlight-word-selection/highlight-word-selection.vala index 83a86b073a..625d3c5fd7 100644 --- a/plugins/highlight-word-selection/highlight-word-selection.vala +++ b/plugins/highlight-word-selection/highlight-word-selection.vala @@ -34,7 +34,7 @@ public class Scratch.Plugins.HighlightSelectedWords : Scratch.Plugins.PluginBase public HighlightSelectedWords (PluginInfo info, Interface iface) { base (info, iface); } - + public override void activate () { // plugins = (Scratch.Plugins.Interface) object; plugins.hook_document.connect ((doc) => { @@ -67,7 +67,7 @@ public class Scratch.Plugins.HighlightSelectedWords : Scratch.Plugins.PluginBase if (window_search_context == null || window_search_context.settings.search_text == "" || window_search_context.get_occurrences_count () == 0) { - // Perform plugin selection when there is no ongoing and successful search + // Perform plugin selection when there is no ongoing and successful search current_search_context = new Gtk.SourceSearchContext ( (Gtk.SourceBuffer)current_source.buffer, null diff --git a/plugins/markdown-actions/markdown-actions.vala b/plugins/markdown-actions/markdown-actions.vala index 4b2d83f1fe..0d9ee7d76e 100644 --- a/plugins/markdown-actions/markdown-actions.vala +++ b/plugins/markdown-actions/markdown-actions.vala @@ -28,7 +28,7 @@ public class Scratch.Plugins.MarkdownActions : Scratch.Plugins.PluginBase { public MarkdownActions (PluginInfo info, Interface iface) { base (info, iface); } - + public override void activate () { plugins.hook_document.connect ((doc) => { if (current_source != null) { diff --git a/plugins/pastebin/pastebin.vala b/plugins/pastebin/pastebin.vala index ee50a1092a..7ed9477c12 100644 --- a/plugins/pastebin/pastebin.vala +++ b/plugins/pastebin/pastebin.vala @@ -42,7 +42,7 @@ public class Scratch.Plugins.Pastebin : Scratch.Plugins.PluginBase { public Pastebin (PluginInfo info, Interface iface) { base (info, iface); } - + public override void activate () { // plugins = (Scratch.Services.Interface) object; diff --git a/plugins/preserve-indent/preserve-indent.vala b/plugins/preserve-indent/preserve-indent.vala index 21a37d3fa0..7833149b04 100644 --- a/plugins/preserve-indent/preserve-indent.vala +++ b/plugins/preserve-indent/preserve-indent.vala @@ -29,7 +29,7 @@ public class Scratch.Plugins.PreserveIndent : Scratch.Plugins.PluginBase { public PreserveIndent (PluginInfo info, Interface iface) { base (info, iface); } - + public override void activate () { this.documents = new Gee.TreeSet (); // plugins = (Scratch.Services.Interface) object; diff --git a/plugins/vim-emulation/vim-emulation.vala b/plugins/vim-emulation/vim-emulation.vala index 830ce966e5..d9f6efb8aa 100644 --- a/plugins/vim-emulation/vim-emulation.vala +++ b/plugins/vim-emulation/vim-emulation.vala @@ -39,7 +39,7 @@ public class Scratch.Plugins.VimEmulation : Scratch.Plugins.PluginBase { public VimEmulation (PluginInfo info, Interface iface) { base (info, iface); } - + construct { views = new Gee.TreeSet (); } diff --git a/plugins/word-completion/plugin.vala b/plugins/word-completion/plugin.vala index e89d0b4ad5..069fb42a02 100644 --- a/plugins/word-completion/plugin.vala +++ b/plugins/word-completion/plugin.vala @@ -42,11 +42,11 @@ public class Scratch.Plugins.Completion : Scratch.Plugins.PluginBase { private const uint REFRESH_SHORTCUT = Gdk.Key.bar; //"|" in combination with will cause refresh private uint timeout_id = 0; - + public Completion (PluginInfo info, Interface iface) { base (info, iface); } - + public override void activate () { // plugins = (Scratch.Services.Interface) object; parser = new Euclide.Completion.Parser (); diff --git a/src/Dialogs/PreferencesDialog.vala b/src/Dialogs/PreferencesDialog.vala index 16a7dfbe34..2e5f4b0b40 100644 --- a/src/Dialogs/PreferencesDialog.vala +++ b/src/Dialogs/PreferencesDialog.vala @@ -160,7 +160,7 @@ public class Scratch.Dialogs.Preferences : Granite.Dialog { close_button.clicked.connect (() => { destroy (); }); - + // Always start with Behaviour page realize.connect (() => { stack.visible_child_name = "behavior"; diff --git a/src/Services/PluginManager.vala b/src/Services/PluginManager.vala index 06fd3faecb..2f82b8d31b 100644 --- a/src/Services/PluginManager.vala +++ b/src/Services/PluginManager.vala @@ -24,7 +24,6 @@ public abstract class Scratch.Plugins.PluginBase : GLib.Object { public Interface plugin_iface { get; construct; } public abstract void activate (); public abstract void deactivate (); - // public abstract PluginBase module_init (PluginInfo plugin_info); public virtual void update_state () {} protected PluginBase (PluginInfo info, Interface iface) { @@ -79,7 +78,7 @@ delegate Scratch.Plugins.PluginBase ModuleInitFunc ( public class Scratch.Services.PluginsManager : GLib.Object { public const string ACTIVE_PLUGINS_KEY = "plugins-enabled"; - public const string PLUGIN_FILE_EXTENSION = ".plugin"; + public const string KEYFILE_FILE_EXTENSION = ".plugin"; public const string MODULE_FILE_EXTENSION = ".so"; public Scratch.Plugins.Interface plugin_iface { private set; public get; } @@ -96,26 +95,22 @@ public class Scratch.Services.PluginsManager : GLib.Object { public signal void extension_added (); public signal void extension_removed (Scratch.Plugins.PluginInfo info); - /* FROM FILES PLUGIN SYSTEM */ Gee.HashMap plugin_hash; // all plugins public Gee.HashSet active_plugin_set; //active plugin names public Gee.List menuitem_references { get; private set; } public PluginsManager (MainWindow window) { - warning ("PluginsManager new"); this.window = window; plugin_iface = new Scratch.Plugins.Interface (this); /* From Files PluginManager construct */ plugin_hash = new Gee.HashMap (); active_plugin_set = new Gee.HashSet (); - // names = new Gee.ArrayList (); menuitem_references = new Gee.LinkedList (); // Code has only one plugin directory. - load_modules_from_dir (Constants.PLUGINDIR); - // // Connect managers signals to interface's signals + // Connect managers signals to interface's signals this.hook_window.connect ((w) => { plugin_iface.hook_window (w); }); @@ -140,14 +135,11 @@ public class Scratch.Services.PluginsManager : GLib.Object { plugin_iface.hook_folder_item_change (source, dest, event); }); - string[] active_plugins = settings.get_strv (ACTIVE_PLUGINS_KEY); - // Activate plugins according to setting - foreach (var plugin_name in active_plugins) { + foreach (var plugin_name in settings.get_strv (ACTIVE_PLUGINS_KEY)) { if (plugin_hash.has_key (plugin_name)) { var plugin = plugin_hash.@get (plugin_name); activate_plugin (plugin); - active_plugin_set.add (plugin_name); } } } @@ -177,35 +169,29 @@ public class Scratch.Services.PluginsManager : GLib.Object { private void update_active_plugin_settings () { settings.set_strv (ACTIVE_PLUGINS_KEY, active_plugin_set.to_array ()); } - // void on_extension_foreach (Peas.ExtensionSet set, Peas.PluginInfo info, Peas.Extension extension) { - // ((Peas.Activatable)extension).activate (); - // } private void load_modules_from_dir (string path) { - string attributes = FileAttribute.STANDARD_NAME + "," + - FileAttribute.STANDARD_TYPE; + FileInfo info; FileEnumerator enumerator; -warning ("load modules from %s", path); try { + string attributes = FileAttribute.STANDARD_NAME + "," + + FileAttribute.STANDARD_TYPE; var dir = GLib.File.new_for_path (path); - - enumerator = dir.enumerate_children - (attributes, - FileQueryInfoFlags.NONE); + enumerator = dir.enumerate_children ( + attributes, + FileQueryInfoFlags.NONE + ); info = enumerator.next_file (); - while (info != null) { if (info.get_file_type () == DIRECTORY) { load_modules_from_dir (Path.build_filename (path, info.get_name ())); } else { string file_name = info.get_name (); - warning ("file name %s", file_name); var plugin_file = dir.get_child_for_display_name (file_name); - - if (file_name.has_suffix (PLUGIN_FILE_EXTENSION)) { + if (file_name.has_suffix (KEYFILE_FILE_EXTENSION)) { load_plugin_keyfile (plugin_file, path); } } @@ -223,70 +209,80 @@ warning ("load modules from %s", path); return false; } - var file_path = dir.get_path ().concat (Path.DIR_SEPARATOR_S, "lib", info.module_name, MODULE_FILE_EXTENSION); - warning ("Loading plugin for %s", file_path); + //TODO Add a File key in the same way that Files does so we do not + // have to construct the module path + var file_path = dir.get_path ().concat ( + Path.DIR_SEPARATOR_S, + "lib", + info.module_name, + MODULE_FILE_EXTENSION + ); + debug ("Loading plugin for %s", file_path); Module module = Module.open (file_path, ModuleFlags.LOCAL); if (module == null) { - warning ("Failed to load module from path '%s': %s", - file_path, - Module.error ()); + warning ( + "Failed to load module from path '%s': %s", + file_path, + Module.error () + ); return false; } void* function; - if (!module.symbol ("module_init", out function)) { - warning ("Failed to find entry point function '%s' in '%s': %s", - "module_init", - file_path, - Module.error ()); + warning ( + "Failed to find entry point function '%s' in '%s': %s", + "module_init", + file_path, + Module.error () + ); return false; } unowned ModuleInitFunc module_init = (ModuleInitFunc) function; assert (module_init != null); - //TODO Reconsider for Code plugins - // /* We don't want our modules to ever unload */ - // module.make_resident (); + //TODO Reconsider making all plugins resident for Code + module.make_resident (); Scratch.Plugins.PluginBase plug = module_init (info, plugin_iface); - - warning ("Loaded module source: '%s'", module.name ()); + debug ("Loaded module source: '%s'", module.name ()); if (plug != null) { - warning ("add plugin %s to hash", info.name); plugin_hash.set (info.name, plug); info.is_active = false; // Plugins only become active via initial settings or preferences dialog return true; + } else { + critical ("Module init failed for %s, it will not be available", module.name ()); } return false; } - // Load the .plugin file from each plugin folder - private void load_plugin_keyfile (File plugin_file, string parent) { + // Load the keyfile from specified location + private void load_plugin_keyfile (File keyfile_file, string parent) { var keyfile = new KeyFile (); var plugin_info = Scratch.Plugins.PluginInfo (); try { - keyfile.load_from_file (plugin_file.get_path (), KeyFileFlags.NONE); + keyfile.load_from_file (keyfile_file.get_path (), KeyFileFlags.NONE); plugin_info.name = keyfile.get_string ("Plugin", "Name"); plugin_info.module_name = keyfile.get_string ("Plugin", "Module"); plugin_info.description = keyfile.get_string ("Plugin", "Description"); if (keyfile.has_key ("Plugin", "Icon")) { plugin_info.icon_name = keyfile.get_string ("Plugin", "Icon"); } else { - plugin_info.icon_name = "extension"; + plugin_info.icon_name = "extension"; } // Should we expose the author(s)? load_module (plugin_file.get_parent (), plugin_info); } catch (Error e) { - warning ("Couldn't open the keyfile '%s': %s", plugin_file.get_path (), e.message); + warning ("Couldn't open the keyfile '%s': %s", keyfile_file.get_path (), e.message); } } - // Return an emulation of the discontinued libpeas-1.0 widget + + // Return an emulation of the libpeas-1.0 widget public Gtk.Widget get_view () { var list_box = new Gtk.ListBox (); var scrolled_window = new Gtk.ScrolledWindow (null, null) { @@ -365,4 +361,3 @@ warning ("load modules from %s", path); return plugin_hash.size; } } -// } From ff0b5cd5f1c72ab5c93eb6468dc3f57af965e1f7 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Thu, 26 Dec 2024 19:03:51 +0000 Subject: [PATCH 06/20] Remove commented out code; update headers --- .../brackets-completion.vala | 12 +---- plugins/detect-indent/detect-indent.vala | 33 ++++++++----- plugins/editorconfig/editorconfig.vala | 48 ++++++++----------- plugins/fuzzy-search/fuzzy-search.vala | 17 +------ .../highlight-word-selection.vala | 14 ++---- .../markdown-actions/markdown-actions.vala | 14 +----- plugins/pastebin/pastebin.vala | 17 ++----- plugins/preserve-indent/preserve-indent.vala | 15 ++---- plugins/spell/spell.vala | 22 ++------- plugins/vim-emulation/vim-emulation.vala | 17 +------ plugins/word-completion/plugin.vala | 11 +---- 11 files changed, 61 insertions(+), 159 deletions(-) diff --git a/plugins/brackets-completion/brackets-completion.vala b/plugins/brackets-completion/brackets-completion.vala index 7c4576e646..3204dde339 100644 --- a/plugins/brackets-completion/brackets-completion.vala +++ b/plugins/brackets-completion/brackets-completion.vala @@ -2,7 +2,8 @@ /*** BEGIN LICENSE - Copyright (C) 2013 Mario Guerriero + Copyright (C) 2019-24 elementary, Inc. + 2013 Mario Guerriero This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3, as published by the Free Software Foundation. @@ -31,7 +32,6 @@ public class Scratch.Plugins.BracketsCompletion : Scratch.Plugins.PluginBase { private string previous_selection = ""; Scratch.Plugins.Interface plugins; - // public Object object { owned get; construct; } public BracketsCompletion (PluginInfo info, Interface iface) { base (info, iface); @@ -57,7 +57,6 @@ public class Scratch.Plugins.BracketsCompletion : Scratch.Plugins.PluginBase { keys[Gdk.Key.quotedbl] = "\""; keys[Gdk.Key.grave] = "`"; - // plugins = (Scratch.Plugins.Interface) object; plugins.hook_document.connect (on_hook_document); } @@ -283,10 +282,3 @@ public Scratch.Plugins.PluginBase module_init ( ) { return new Scratch.Plugins.BracketsCompletion (info, iface); } - -// [ModuleInit] -// public void peas_register_types (GLib.TypeModule module) { -// var objmodule = module as Peas.ObjectModule; -// objmodule.register_extension_type (typeof (Peas.Activatable), -// typeof (Scratch.Plugins.BracketsCompletion)); -// } diff --git a/plugins/detect-indent/detect-indent.vala b/plugins/detect-indent/detect-indent.vala index 127b27f5b5..efecf7a042 100644 --- a/plugins/detect-indent/detect-indent.vala +++ b/plugins/detect-indent/detect-indent.vala @@ -1,16 +1,33 @@ +// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- +/*** + BEGIN LICENSE + + Copyright (C) 2019-24 elementary, Inc. + 2013 LemonBoy + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License version 3, as published + by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranties of + MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program. If not, see + + END LICENSE +***/ public class Scratch.Plugins.DetectIndent: Scratch.Plugins.PluginBase { const int MAX_LINES = 500; Scratch.Plugins.Interface plugins; - // public Object object {owned get; construct;} public DetectIndent (PluginInfo info, Interface iface) { base (info, iface); } public override void activate () { - // plugins = (Scratch.Plugins.Interface) object; - plugins.hook_document.connect ((d) => { var view = d.source_view; @@ -82,13 +99,3 @@ public Scratch.Plugins.PluginBase module_init ( ) { return new Scratch.Plugins.DetectIndent (info, iface); } - - -// [ModuleInit] -// public void peas_register_types (GLib.TypeModule module) { -// var objmodule = module as Peas.ObjectModule; -// objmodule.register_extension_type ( -// typeof (Peas.Activatable), -// typeof (Scratch.Plugins.DetectIndent) -// ); -// } diff --git a/plugins/editorconfig/editorconfig.vala b/plugins/editorconfig/editorconfig.vala index 2a2ebee25c..9e36948485 100644 --- a/plugins/editorconfig/editorconfig.vala +++ b/plugins/editorconfig/editorconfig.vala @@ -1,35 +1,32 @@ -/* -* Copyright (c) 2018 elementary LLC. (https://github.com/elementary) -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public -* License as published by the Free Software Foundation; either -* version 3 of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* General Public License for more details. -* -* You should have received a copy of the GNU General Public -* License along with this program; if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -*/ +// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- +/*** + BEGIN LICENSE + + Copyright (C) 2018-24 elementary, Inc. + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License version 3, as published + by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranties of + MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program. If not, see + + END LICENSE +***/ public class Scratch.Plugins.EditorConfigPlugin: Scratch.Plugins.PluginBase { Scratch.Plugins.Interface plugins; - // public Object object { owned get; construct; } private Code.FormatBar format_bar; - // public void update_state () { } public EditorConfigPlugin (PluginInfo info, Interface iface) { base (info, iface); } public override void activate () { - // plugins = (Scratch.Plugins.Interface) object; - plugins.hook_toolbar.connect ((tb) => { format_bar = tb.format_bar; }); @@ -97,10 +94,3 @@ public Scratch.Plugins.PluginBase module_init ( ) { return new Scratch.Plugins.EditorConfigPlugin (info, iface); } - - -// [ModuleInit] -// public void peas_register_types (GLib.TypeModule module) { -// var objmodule = module as Peas.ObjectModule; -// objmodule.register_extension_type (typeof (Peas.Activatable), typeof (Scratch.Plugins.EditorConfigPlugin)); -// } diff --git a/plugins/fuzzy-search/fuzzy-search.vala b/plugins/fuzzy-search/fuzzy-search.vala index 738a6ca936..9f444e1800 100644 --- a/plugins/fuzzy-search/fuzzy-search.vala +++ b/plugins/fuzzy-search/fuzzy-search.vala @@ -1,13 +1,12 @@ /* * SPDX-License-Identifier: GPL-3.0-or-later - * SPDX-FileCopyrightText: 2023 elementary, Inc. + * SPDX-FileCopyrightText: 2023-24 elementary, Inc. * * Authored by: Marvin Ahlgrimm */ public class Scratch.Plugins.FuzzySearch: Scratch.Plugins.PluginBase { - // public Object object { owned get; construct; } private const uint ACCEL_KEY = Gdk.Key.F; private const Gdk.ModifierType ACCEL_MODTYPE = Gdk.ModifierType.MOD1_MASK; @@ -33,16 +32,11 @@ public class Scratch.Plugins.FuzzySearch: Scratch.Plugins.PluginBase { action_accelerators.set (ACTION_SHOW, @"$(Gdk.keyval_name (ACCEL_KEY))"); } - // public void update_state () { - - // } public FuzzySearch (PluginInfo info, Interface iface) { base (info, iface); } public override void activate () { - // plugins = (Scratch.Plugins.Interface) object; - plugins.hook_window.connect ((w) => { if (window != null) { return; @@ -162,12 +156,3 @@ public Scratch.Plugins.PluginBase module_init ( ) { return new Scratch.Plugins.FuzzySearch (info, iface); } - -// [ModuleInit] -// public void peas_register_types (GLib.TypeModule module) { -// var objmodule = module as Peas.ObjectModule; -// objmodule.register_extension_type ( -// typeof (Peas.Activatable), -// typeof (Scratch.Plugins.FuzzySearch) -// ); -// } diff --git a/plugins/highlight-word-selection/highlight-word-selection.vala b/plugins/highlight-word-selection/highlight-word-selection.vala index 625d3c5fd7..e62dcbcff1 100644 --- a/plugins/highlight-word-selection/highlight-word-selection.vala +++ b/plugins/highlight-word-selection/highlight-word-selection.vala @@ -1,8 +1,9 @@ // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- /*** BEGIN LICENSE - - Copyright (C) 2013 Madelynn May + Copyright (C) 2019-24 elementary, Inc. + 2013 Madelynn May + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3, as published by the Free Software Foundation. @@ -28,9 +29,7 @@ public class Scratch.Plugins.HighlightSelectedWords : Scratch.Plugins.PluginBase private const uint SELECTION_HIGHLIGHT_MAX_CHARS = 45; Scratch.Plugins.Interface plugins; - // public Object object { owned get; construct; } - // public void update_state () {} public HighlightSelectedWords (PluginInfo info, Interface iface) { base (info, iface); } @@ -158,10 +157,3 @@ public Scratch.Plugins.PluginBase module_init ( ) { return new Scratch.Plugins.HighlightSelectedWords (info, iface); } - -// [ModuleInit] -// public void peas_register_types (TypeModule module) { -// var objmodule = module as Peas.ObjectModule; -// objmodule.register_extension_type (typeof (Peas.Activatable), -// typeof (Scratch.Plugins.HighlightSelectedWords)); -// } diff --git a/plugins/markdown-actions/markdown-actions.vala b/plugins/markdown-actions/markdown-actions.vala index 0d9ee7d76e..04c2f009fc 100644 --- a/plugins/markdown-actions/markdown-actions.vala +++ b/plugins/markdown-actions/markdown-actions.vala @@ -1,8 +1,9 @@ // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- /*** BEGIN LICENSE + Copyright (C) 2024 elementary, Inc. + 2020 Igor Montagner - Copyright (C) 2020 Igor Montagner This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3, as published by the Free Software Foundation. @@ -22,9 +23,6 @@ public class Scratch.Plugins.MarkdownActions : Scratch.Plugins.PluginBase { Scratch.Widgets.SourceView current_source; Scratch.Plugins.Interface plugins; - // public Object object { owned get; construct; } - - // public void update_state () {} public MarkdownActions (PluginInfo info, Interface iface) { base (info, iface); } @@ -248,11 +246,3 @@ public Scratch.Plugins.PluginBase module_init ( ) { return new Scratch.Plugins.MarkdownActions (info, iface); } - - -// [ModuleInit] -// public void peas_register_types (TypeModule module) { -// var objmodule = module as Peas.ObjectModule; -// objmodule.register_extension_type (typeof (Peas.Activatable), -// typeof (Code.Plugins.MarkdownActions)); -// } diff --git a/plugins/pastebin/pastebin.vala b/plugins/pastebin/pastebin.vala index 7ed9477c12..555d770377 100644 --- a/plugins/pastebin/pastebin.vala +++ b/plugins/pastebin/pastebin.vala @@ -1,8 +1,9 @@ // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- /*** BEGIN LICENSE - - Copyright (C) 2011-2012 Giulio Collura + Copyright (C) 2024 elementary, Inc. + 2011-2012 Giulio Collura + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3, as published by the Free Software Foundation. @@ -37,15 +38,11 @@ public class Scratch.Plugins.Pastebin : Scratch.Plugins.PluginBase { {ACTION_SHOW, show_paste_bin_upload_dialog } }; - // public void update_state () { - // } public Pastebin (PluginInfo info, Interface iface) { base (info, iface); } public override void activate () { - // plugins = (Scratch.Services.Interface) object; - plugins.hook_document.connect ((doc) => { this.doc = doc; }); @@ -105,11 +102,3 @@ public Scratch.Plugins.PluginBase module_init ( ) { return new Scratch.Plugins.Pastebin (info, iface); } - - -// [ModuleInit] -// public void peas_register_types (GLib.TypeModule module) { -// var objmodule = module as Peas.ObjectModule; -// objmodule.register_extension_type (typeof (Peas.Activatable), -// typeof (Scratch.Plugins.Pastebin)); -// } diff --git a/plugins/preserve-indent/preserve-indent.vala b/plugins/preserve-indent/preserve-indent.vala index 7833149b04..34ed5c68d7 100644 --- a/plugins/preserve-indent/preserve-indent.vala +++ b/plugins/preserve-indent/preserve-indent.vala @@ -1,8 +1,9 @@ // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- /*** BEGIN LICENSE - - Copyright (C) 2015 James Morgan + Copyright (C) 2024 elementary, Inc. + 2015 James Morgan + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3, as published by the Free Software Foundation. @@ -25,14 +26,12 @@ public class Scratch.Plugins.PreserveIndent : Scratch.Plugins.PluginBase { private int last_clipboard_indent_level = 0; private bool waiting_for_clipboard_text = false; - // public Object object { owned get; construct; } public PreserveIndent (PluginInfo info, Interface iface) { base (info, iface); } public override void activate () { this.documents = new Gee.TreeSet (); - // plugins = (Scratch.Services.Interface) object; plugins.hook_document.connect ((d) => { this.active_document = d; @@ -246,11 +245,3 @@ public Scratch.Plugins.PluginBase module_init ( ) { return new Scratch.Plugins.PreserveIndent (info, iface); } - - -// [ModuleInit] -// public void peas_register_types (GLib.TypeModule module) { -// var objmodule = module as Peas.ObjectModule; -// objmodule.register_extension_type (typeof (Peas.Activatable), -// typeof (Scratch.Plugins.PreserveIndent)); -// } diff --git a/plugins/spell/spell.vala b/plugins/spell/spell.vala index 3a5a3c0b4e..578738bd46 100644 --- a/plugins/spell/spell.vala +++ b/plugins/spell/spell.vala @@ -1,6 +1,7 @@ -/* - * Copyright (C) 2011-2012 Mario Guerriero This program - * is free software: you can redistribute it and/or modify it under the +/* Copyright (C) 2024 elementary, Inc. + * 2011-2012 Mario Guerriero + * + * This program is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * @@ -28,10 +29,6 @@ public class Scratch.Plugins.Spell: Scratch.Plugins.PluginBase { public Spell (PluginInfo info, Interface iface) { base (info, iface); } - // public Object object {owned get; construct;} - - // public void update_state () { - // } public override void activate () { settings = new GLib.Settings (Constants.PROJECT_NAME + ".plugins.spell"); @@ -41,7 +38,6 @@ public class Scratch.Plugins.Spell: Scratch.Plugins.PluginBase { settings.changed.connect (settings_changed); - // plugins = (Scratch.Services.Interface) object; plugins.hook_document.connect ((d) => { var view = d.source_view; @@ -159,13 +155,3 @@ public Scratch.Plugins.PluginBase module_init ( ) { return new Scratch.Plugins.Spell (info, iface); } - - -// [ModuleInit] -// public void peas_register_types (GLib.TypeModule module) { -// var objmodule = module as Peas.ObjectModule; -// objmodule.register_extension_type ( -// typeof (Peas.Activatable), -// typeof (Scratch.Plugins.Spell) -// ); -// } diff --git a/plugins/vim-emulation/vim-emulation.vala b/plugins/vim-emulation/vim-emulation.vala index d9f6efb8aa..8b9a522fcb 100644 --- a/plugins/vim-emulation/vim-emulation.vala +++ b/plugins/vim-emulation/vim-emulation.vala @@ -1,8 +1,9 @@ // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- /*** BEGIN LICENSE + Copyright (C) 2024 elementary, Inc. + 2013 Mario Guerriero - Copyright (C) 2013 Mario Guerriero This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3, as published by the Free Software Foundation. @@ -34,7 +35,6 @@ public class Scratch.Plugins.VimEmulation : Scratch.Plugins.PluginBase { Scratch.Widgets.SourceView? view = null; Scratch.Plugins.Interface plugins; - // public Object object { owned get; construct; } public VimEmulation (PluginInfo info, Interface iface) { base (info, iface); @@ -44,12 +44,7 @@ public class Scratch.Plugins.VimEmulation : Scratch.Plugins.PluginBase { views = new Gee.TreeSet (); } - // public void update_state () { - - // } - public override void activate () { - // plugins = (Scratch.Plugins.Interface) object; plugins.hook_document.connect ((doc) => { this.view = doc.source_view; this.view.key_press_event.disconnect (handle_key_press); @@ -305,11 +300,3 @@ public Scratch.Plugins.PluginBase module_init ( ) { return new Scratch.Plugins.VimEmulation (info, iface); } - - -// [ModuleInit] -// public void peas_register_types (GLib.TypeModule module) { -// var objmodule = module as Peas.ObjectModule; -// objmodule.register_extension_type (typeof (Peas.Activatable), -// typeof (Scratch.Plugins.VimEmulation)); -// } diff --git a/plugins/word-completion/plugin.vala b/plugins/word-completion/plugin.vala index 069fb42a02..7efac6ce61 100644 --- a/plugins/word-completion/plugin.vala +++ b/plugins/word-completion/plugin.vala @@ -1,5 +1,6 @@ /* - * Copyright (c) 2011 Lucas Baudin + * Copyright (C) 2024 elementary, Inc. + * 2011 Lucas Baudin * * This is a free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -188,11 +189,3 @@ public Scratch.Plugins.PluginBase module_init ( ) { return new Scratch.Plugins.Completion (info, iface); } - - -// [ModuleInit] -// public void peas_register_types (GLib.TypeModule module) { -// var objmodule = module as Peas.ObjectModule; -// objmodule.register_extension_type (typeof (Peas.Activatable), -// typeof (Scratch.Plugins.Completion)); -// } From 44d4b39eb3f87927cfd0c0116cea33b548270514 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Thu, 26 Dec 2024 19:05:09 +0000 Subject: [PATCH 07/20] Fix missed rename --- 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 2f82b8d31b..207c709325 100644 --- a/src/Services/PluginManager.vala +++ b/src/Services/PluginManager.vala @@ -275,7 +275,7 @@ public class Scratch.Services.PluginsManager : GLib.Object { plugin_info.icon_name = "extension"; } // Should we expose the author(s)? - load_module (plugin_file.get_parent (), plugin_info); + load_module (keyfile_file.get_parent (), plugin_info); } catch (Error e) { warning ("Couldn't open the keyfile '%s': %s", keyfile_file.get_path (), e.message); From cde7fde15e90eff48f664e9297bfe055a3fb64f4 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Thu, 26 Dec 2024 20:10:33 +0000 Subject: [PATCH 08/20] Move is_active to plugin, ensure correctly set --- .../brackets-completion.vala | 6 ++--- plugins/detect-indent/detect-indent.vala | 9 +------ plugins/editorconfig/editorconfig.vala | 8 +----- plugins/fuzzy-search/fuzzy-search.vala | 5 ++-- .../highlight-word-selection.vala | 6 ++--- .../markdown-actions/markdown-actions.vala | 5 ++-- plugins/pastebin/pastebin.plugin | 2 +- plugins/pastebin/pastebin.vala | 5 ++-- plugins/preserve-indent/preserve-indent.vala | 5 ++-- plugins/spell/spell.vala | 5 ++-- plugins/vim-emulation/vim-emulation.vala | 6 ++--- plugins/word-completion/plugin.vala | 8 ++---- src/MainWindow.vala | 1 + src/Services/PluginManager.vala | 26 ++++++++++++++----- 14 files changed, 41 insertions(+), 56 deletions(-) diff --git a/plugins/brackets-completion/brackets-completion.vala b/plugins/brackets-completion/brackets-completion.vala index 3204dde339..68fa75f6d5 100644 --- a/plugins/brackets-completion/brackets-completion.vala +++ b/plugins/brackets-completion/brackets-completion.vala @@ -31,13 +31,11 @@ public class Scratch.Plugins.BracketsCompletion : Scratch.Plugins.PluginBase { private string previous_selection = ""; - Scratch.Plugins.Interface plugins; - public BracketsCompletion (PluginInfo info, Interface iface) { base (info, iface); } - public override void activate () { + protected override void activate_internal () { brackets = new Gee.HashMap (); brackets["("] = ")"; brackets["["] = "]"; @@ -60,7 +58,7 @@ public class Scratch.Plugins.BracketsCompletion : Scratch.Plugins.PluginBase { plugins.hook_document.connect (on_hook_document); } - public override void deactivate () { + protected override void deactivate_internal () { plugins.hook_document.disconnect (on_hook_document); } diff --git a/plugins/detect-indent/detect-indent.vala b/plugins/detect-indent/detect-indent.vala index efecf7a042..24b922e784 100644 --- a/plugins/detect-indent/detect-indent.vala +++ b/plugins/detect-indent/detect-indent.vala @@ -21,13 +21,11 @@ public class Scratch.Plugins.DetectIndent: Scratch.Plugins.PluginBase { const int MAX_LINES = 500; - Scratch.Plugins.Interface plugins; - public DetectIndent (PluginInfo info, Interface iface) { base (info, iface); } - public override void activate () { + protected override void activate_internal () { plugins.hook_document.connect ((d) => { var view = d.source_view; @@ -86,11 +84,6 @@ public class Scratch.Plugins.DetectIndent: Scratch.Plugins.PluginBase { } }); } - - public override void deactivate () { - - } - } public Scratch.Plugins.PluginBase module_init ( diff --git a/plugins/editorconfig/editorconfig.vala b/plugins/editorconfig/editorconfig.vala index 9e36948485..91f85504b6 100644 --- a/plugins/editorconfig/editorconfig.vala +++ b/plugins/editorconfig/editorconfig.vala @@ -19,17 +19,13 @@ ***/ public class Scratch.Plugins.EditorConfigPlugin: Scratch.Plugins.PluginBase { - Scratch.Plugins.Interface plugins; private Code.FormatBar format_bar; public EditorConfigPlugin (PluginInfo info, Interface iface) { base (info, iface); } - public override void activate () { - plugins.hook_toolbar.connect ((tb) => { - format_bar = tb.format_bar; - }); + protected override void activate_internal () { plugins.hook_document.connect ((d) => { // Ensure use global settings by default @@ -84,8 +80,6 @@ public class Scratch.Plugins.EditorConfigPlugin: Scratch.Plugins.PluginBase { } }); } - - public override void deactivate () { } } public Scratch.Plugins.PluginBase module_init ( diff --git a/plugins/fuzzy-search/fuzzy-search.vala b/plugins/fuzzy-search/fuzzy-search.vala index 9f444e1800..72ec7931a8 100644 --- a/plugins/fuzzy-search/fuzzy-search.vala +++ b/plugins/fuzzy-search/fuzzy-search.vala @@ -12,7 +12,6 @@ public class Scratch.Plugins.FuzzySearch: Scratch.Plugins.PluginBase { private Scratch.Services.FuzzySearchIndexer indexer; private MainWindow window = null; - private Scratch.Plugins.Interface plugins; private GLib.MenuItem fuzzy_menuitem; private GLib.Cancellable cancellable; @@ -36,7 +35,7 @@ public class Scratch.Plugins.FuzzySearch: Scratch.Plugins.PluginBase { base (info, iface); } - public override void activate () { + protected override void activate_internal () { plugins.hook_window.connect ((w) => { if (window != null) { return; @@ -65,7 +64,7 @@ public class Scratch.Plugins.FuzzySearch: Scratch.Plugins.PluginBase { }); } - public override void deactivate () { + protected override void deactivate_internal () { folder_settings.changed["opened-folders"].disconnect (handle_opened_projects_change); remove_actions (); if (cancellable != null) { diff --git a/plugins/highlight-word-selection/highlight-word-selection.vala b/plugins/highlight-word-selection/highlight-word-selection.vala index e62dcbcff1..1c37d01574 100644 --- a/plugins/highlight-word-selection/highlight-word-selection.vala +++ b/plugins/highlight-word-selection/highlight-word-selection.vala @@ -28,13 +28,11 @@ public class Scratch.Plugins.HighlightSelectedWords : Scratch.Plugins.PluginBase // Pneumonoultramicroscopicsilicovolcanoconiosis longest word in a major dictionary @ 45 private const uint SELECTION_HIGHLIGHT_MAX_CHARS = 45; - Scratch.Plugins.Interface plugins; - public HighlightSelectedWords (PluginInfo info, Interface iface) { base (info, iface); } - public override void activate () { + protected override void activate_internal () { // plugins = (Scratch.Plugins.Interface) object; plugins.hook_document.connect ((doc) => { if (current_source != null) { @@ -53,7 +51,7 @@ public class Scratch.Plugins.HighlightSelectedWords : Scratch.Plugins.PluginBase } - public override void deactivate () { + protected override void deactivate_internal () { if (current_source != null) { current_source.deselected.disconnect (on_deselection); current_source.selection_changed.disconnect (on_selection_changed); diff --git a/plugins/markdown-actions/markdown-actions.vala b/plugins/markdown-actions/markdown-actions.vala index 04c2f009fc..58319e7324 100644 --- a/plugins/markdown-actions/markdown-actions.vala +++ b/plugins/markdown-actions/markdown-actions.vala @@ -21,13 +21,12 @@ public class Scratch.Plugins.MarkdownActions : Scratch.Plugins.PluginBase { Scratch.Widgets.SourceView current_source; - Scratch.Plugins.Interface plugins; public MarkdownActions (PluginInfo info, Interface iface) { base (info, iface); } - public override void activate () { + protected override void activate_internal () { plugins.hook_document.connect ((doc) => { if (current_source != null) { current_source.key_press_event.disconnect (shortcut_handler); @@ -41,7 +40,7 @@ public class Scratch.Plugins.MarkdownActions : Scratch.Plugins.PluginBase { }); } - public override void deactivate () { + protected override void deactivate_internal () { if (current_source != null) { current_source.key_press_event.disconnect (shortcut_handler); current_source.notify["language"].disconnect (configure_shortcuts); diff --git a/plugins/pastebin/pastebin.plugin b/plugins/pastebin/pastebin.plugin index 07a536c118..8bb8691cbe 100644 --- a/plugins/pastebin/pastebin.plugin +++ b/plugins/pastebin/pastebin.plugin @@ -1,5 +1,5 @@ [Plugin] -Module=libpastebin +Module=pastebin Loader=C IAge=2 Name=Pastebin diff --git a/plugins/pastebin/pastebin.vala b/plugins/pastebin/pastebin.vala index 555d770377..99f2f2f07b 100644 --- a/plugins/pastebin/pastebin.vala +++ b/plugins/pastebin/pastebin.vala @@ -27,7 +27,6 @@ public class Scratch.Plugins.Pastebin : Scratch.Plugins.PluginBase { // public Object object { owned get; construct; } Scratch.Services.Document? doc = null; - Scratch.Plugins.Interface plugins; const string ACTION_GROUP = "pastebin"; const string ACTION_PREFIX = ACTION_GROUP + "."; @@ -42,7 +41,7 @@ public class Scratch.Plugins.Pastebin : Scratch.Plugins.PluginBase { base (info, iface); } - public override void activate () { + protected override void activate_internal () { plugins.hook_document.connect ((doc) => { this.doc = doc; }); @@ -50,7 +49,7 @@ public class Scratch.Plugins.Pastebin : Scratch.Plugins.PluginBase { plugins.hook_share_menu.connect (on_hook_share_menu); } - public override void deactivate () { + protected override void deactivate_internal () { remove_actions (); } diff --git a/plugins/preserve-indent/preserve-indent.vala b/plugins/preserve-indent/preserve-indent.vala index 34ed5c68d7..6903e049f6 100644 --- a/plugins/preserve-indent/preserve-indent.vala +++ b/plugins/preserve-indent/preserve-indent.vala @@ -20,7 +20,6 @@ ***/ public class Scratch.Plugins.PreserveIndent : Scratch.Plugins.PluginBase { - private Scratch.Plugins.Interface plugins; private Gee.TreeSet documents; private Services.Document active_document; private int last_clipboard_indent_level = 0; @@ -30,7 +29,7 @@ public class Scratch.Plugins.PreserveIndent : Scratch.Plugins.PluginBase { base (info, iface); } - public override void activate () { + protected override void activate_internal () { this.documents = new Gee.TreeSet (); plugins.hook_document.connect ((d) => { @@ -49,7 +48,7 @@ public class Scratch.Plugins.PreserveIndent : Scratch.Plugins.PluginBase { }); } - public override void deactivate () { + protected override void deactivate_internal () { this.documents.clear (); } diff --git a/plugins/spell/spell.vala b/plugins/spell/spell.vala index 578738bd46..b3f1a05f50 100644 --- a/plugins/spell/spell.vala +++ b/plugins/spell/spell.vala @@ -15,7 +15,6 @@ */ public class Scratch.Plugins.Spell: Scratch.Plugins.PluginBase { - Scratch.Plugins.Interface plugins; private GLib.Settings settings; MainWindow window = null; private string lang_dict; @@ -30,7 +29,7 @@ public class Scratch.Plugins.Spell: Scratch.Plugins.PluginBase { base (info, iface); } - public override void activate () { + protected override void activate_internal () { settings = new GLib.Settings (Constants.PROJECT_NAME + ".plugins.spell"); // Restore the last dictionary used. @@ -121,7 +120,7 @@ public class Scratch.Plugins.Spell: Scratch.Plugins.PluginBase { } - public override void deactivate () { + protected override void deactivate_internal () { save_settings (); window.destroy.disconnect (save_settings); } diff --git a/plugins/vim-emulation/vim-emulation.vala b/plugins/vim-emulation/vim-emulation.vala index 8b9a522fcb..62d1bbd3fd 100644 --- a/plugins/vim-emulation/vim-emulation.vala +++ b/plugins/vim-emulation/vim-emulation.vala @@ -34,8 +34,6 @@ public class Scratch.Plugins.VimEmulation : Scratch.Plugins.PluginBase { Gee.TreeSet views; Scratch.Widgets.SourceView? view = null; - Scratch.Plugins.Interface plugins; - public VimEmulation (PluginInfo info, Interface iface) { base (info, iface); } @@ -44,7 +42,7 @@ public class Scratch.Plugins.VimEmulation : Scratch.Plugins.PluginBase { views = new Gee.TreeSet (); } - public override void activate () { + protected override void activate_internal () { plugins.hook_document.connect ((doc) => { this.view = doc.source_view; this.view.key_press_event.disconnect (handle_key_press); @@ -53,7 +51,7 @@ public class Scratch.Plugins.VimEmulation : Scratch.Plugins.PluginBase { }); } - public override void deactivate () { + protected override void deactivate_internal () { foreach (var v in views) { v.key_press_event.disconnect (handle_key_press); } diff --git a/plugins/word-completion/plugin.vala b/plugins/word-completion/plugin.vala index 7efac6ce61..5d0babb6f2 100644 --- a/plugins/word-completion/plugin.vala +++ b/plugins/word-completion/plugin.vala @@ -20,15 +20,12 @@ */ public class Scratch.Plugins.Completion : Scratch.Plugins.PluginBase { - public Object object { owned get; construct; } - private List text_view_list = new List (); public Euclide.Completion.Parser parser {get; private set;} public Gtk.SourceView? current_view {get; private set;} public Scratch.Services.Document current_document {get; private set;} private MainWindow main_window; - private Scratch.Plugins.Interface plugins; private bool completion_in_progress = false; private const uint [] ACTIVATE_KEYS = { @@ -48,8 +45,7 @@ public class Scratch.Plugins.Completion : Scratch.Plugins.PluginBase { base (info, iface); } - public override void activate () { - // plugins = (Scratch.Services.Interface) object; + protected override void activate_internal () { parser = new Euclide.Completion.Parser (); plugins.hook_window.connect ((w) => { this.main_window = w; @@ -58,7 +54,7 @@ public class Scratch.Plugins.Completion : Scratch.Plugins.PluginBase { plugins.hook_document.connect (on_new_source_view); } - public override void deactivate () { + protected override void deactivate_internal () { text_view_list.@foreach (cleanup); } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index f39d1e6e95..ebeebe85ec 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -573,6 +573,7 @@ namespace Scratch { }; plugins.extension_added.connect (() => { + warning ("hook func"); hook_func (); }); diff --git a/src/Services/PluginManager.vala b/src/Services/PluginManager.vala index 207c709325..83a58ee543 100644 --- a/src/Services/PluginManager.vala +++ b/src/Services/PluginManager.vala @@ -21,15 +21,28 @@ // namespace Scratch.Plugins { public abstract class Scratch.Plugins.PluginBase : GLib.Object { public PluginInfo plugin_info { get; construct; } - public Interface plugin_iface { get; construct; } - public abstract void activate (); - public abstract void deactivate (); - public virtual void update_state () {} + public Interface plugins { get; construct; } + public bool is_active { get; set; } + public void activate () { + warning ("plugin base activate"); + is_active = true; + activate_internal (); + } + + public void deactivate () { + is_active = false; + deactivate_internal (); + } + + protected abstract void activate_internal (); + protected virtual void deactivate_internal () {} // Not implemented by some plugins + public virtual void update_state () {} // Not currently used + protected PluginBase (PluginInfo info, Interface iface) { Object ( plugin_info: info, - plugin_iface: iface + plugins: iface ); } } @@ -39,7 +52,6 @@ public struct Scratch.Plugins.PluginInfo { string module_name; string description; string icon_name; - bool is_active; } public class Scratch.Plugins.Interface : GLib.Object { @@ -320,7 +332,7 @@ public class Scratch.Services.PluginsManager : GLib.Object { var content = new Gtk.Box (HORIZONTAL, 6); var checkbox = new Gtk.CheckButton () { valign = Gtk.Align.CENTER, - active = info.is_active, + active = plugin.is_active, margin_start = 6 }; From 1e87ef02fd9df2d1115e136c2ae9bfb7f7eb3cfb Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Thu, 26 Dec 2024 20:13:20 +0000 Subject: [PATCH 09/20] Fix compile and cleanup --- .../brackets-completion/brackets-completion.vala | 2 +- plugins/detect-indent/detect-indent.vala | 2 +- src/Services/PluginManager.vala | 14 ++++++-------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/plugins/brackets-completion/brackets-completion.vala b/plugins/brackets-completion/brackets-completion.vala index 68fa75f6d5..57b39463bb 100644 --- a/plugins/brackets-completion/brackets-completion.vala +++ b/plugins/brackets-completion/brackets-completion.vala @@ -58,7 +58,7 @@ public class Scratch.Plugins.BracketsCompletion : Scratch.Plugins.PluginBase { plugins.hook_document.connect (on_hook_document); } - protected override void deactivate_internal () { + protected override void deactivate_internal () { plugins.hook_document.disconnect (on_hook_document); } diff --git a/plugins/detect-indent/detect-indent.vala b/plugins/detect-indent/detect-indent.vala index 24b922e784..65f628bced 100644 --- a/plugins/detect-indent/detect-indent.vala +++ b/plugins/detect-indent/detect-indent.vala @@ -25,7 +25,7 @@ public class Scratch.Plugins.DetectIndent: Scratch.Plugins.PluginBase { base (info, iface); } - protected override void activate_internal () { + protected override void activate_internal () { plugins.hook_document.connect ((d) => { var view = d.source_view; diff --git a/src/Services/PluginManager.vala b/src/Services/PluginManager.vala index 83a58ee543..5fccfbc7de 100644 --- a/src/Services/PluginManager.vala +++ b/src/Services/PluginManager.vala @@ -28,17 +28,17 @@ public abstract class Scratch.Plugins.PluginBase : GLib.Object { is_active = true; activate_internal (); } - + public void deactivate () { is_active = false; deactivate_internal (); } - + protected abstract void activate_internal (); protected virtual void deactivate_internal () {} // Not implemented by some plugins public virtual void update_state () {} // Not currently used - + protected PluginBase (PluginInfo info, Interface iface) { Object ( plugin_info: info, @@ -158,9 +158,8 @@ public class Scratch.Services.PluginsManager : GLib.Object { private void activate_plugin (Scratch.Plugins.PluginBase plugin) { var info = plugin.plugin_info; - if (!info.is_active) { + if (!plugin.is_active) { plugin.activate (); - info.is_active = true; active_plugin_set.add (info.name); extension_added (); // Signals Window to run initial hook function update_active_plugin_settings (); @@ -169,9 +168,8 @@ public class Scratch.Services.PluginsManager : GLib.Object { private void deactivate_plugin (Scratch.Plugins.PluginBase plugin) { var info = plugin.plugin_info; - if (info.is_active) { + if (plugin.is_active) { plugin.deactivate (); - info.is_active = false; active_plugin_set.remove (info.name); extension_removed (info); update_active_plugin_settings (); @@ -262,7 +260,7 @@ public class Scratch.Services.PluginsManager : GLib.Object { if (plug != null) { plugin_hash.set (info.name, plug); - info.is_active = false; + plug.is_active = false; // Plugins only become active via initial settings or preferences dialog return true; } else { From d21c27a7ab8256b7f1b2296069cad379431f8cfd Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 27 Dec 2024 13:54:25 +0000 Subject: [PATCH 10/20] Disconnect on deactivate, plugins -> iface --- .../brackets-completion.vala | 4 +-- plugins/detect-indent/detect-indent.vala | 7 +++- plugins/editorconfig/editorconfig.vala | 8 +++-- plugins/fuzzy-search/fuzzy-search.vala | 10 ++++-- .../highlight-word-selection.vala | 10 ++++-- .../markdown-actions/markdown-actions.vala | 5 ++- plugins/pastebin/pastebin.vala | 14 +++++--- plugins/preserve-indent/preserve-indent.vala | 4 ++- plugins/spell/spell.vala | 28 ++++++++------- plugins/vim-emulation/vim-emulation.vala | 5 ++- plugins/word-completion/plugin.vala | 11 ++++-- src/Services/PluginManager.vala | 35 ++++++++++--------- 12 files changed, 91 insertions(+), 50 deletions(-) diff --git a/plugins/brackets-completion/brackets-completion.vala b/plugins/brackets-completion/brackets-completion.vala index 57b39463bb..7186134488 100644 --- a/plugins/brackets-completion/brackets-completion.vala +++ b/plugins/brackets-completion/brackets-completion.vala @@ -55,11 +55,11 @@ public class Scratch.Plugins.BracketsCompletion : Scratch.Plugins.PluginBase { keys[Gdk.Key.quotedbl] = "\""; keys[Gdk.Key.grave] = "`"; - plugins.hook_document.connect (on_hook_document); + iface.hook_document.connect (on_hook_document); } protected override void deactivate_internal () { - plugins.hook_document.disconnect (on_hook_document); + iface.hook_document.disconnect (on_hook_document); } void on_hook_document (Scratch.Services.Document doc) { diff --git a/plugins/detect-indent/detect-indent.vala b/plugins/detect-indent/detect-indent.vala index 65f628bced..5f2b201019 100644 --- a/plugins/detect-indent/detect-indent.vala +++ b/plugins/detect-indent/detect-indent.vala @@ -25,8 +25,9 @@ public class Scratch.Plugins.DetectIndent: Scratch.Plugins.PluginBase { base (info, iface); } + ulong doc_hook_handler = 0; protected override void activate_internal () { - plugins.hook_document.connect ((d) => { + doc_hook_handler = iface.hook_document.connect ((d) => { var view = d.source_view; if (!view.get_editable ()) { @@ -84,6 +85,10 @@ public class Scratch.Plugins.DetectIndent: Scratch.Plugins.PluginBase { } }); } + + protected override void deactivate_internal () { + this.disconnect (doc_hook_handler); + } } public Scratch.Plugins.PluginBase module_init ( diff --git a/plugins/editorconfig/editorconfig.vala b/plugins/editorconfig/editorconfig.vala index 91f85504b6..aab9bab707 100644 --- a/plugins/editorconfig/editorconfig.vala +++ b/plugins/editorconfig/editorconfig.vala @@ -25,9 +25,9 @@ public class Scratch.Plugins.EditorConfigPlugin: Scratch.Plugins.PluginBase { base (info, iface); } + ulong doc_hook_handler = 0; protected override void activate_internal () { - - plugins.hook_document.connect ((d) => { + doc_hook_handler = iface.hook_document.connect ((d) => { // Ensure use global settings by default format_bar.tab_style_set_by_editor_config = false; format_bar.tab_width_set_by_editor_config = false; @@ -80,6 +80,10 @@ public class Scratch.Plugins.EditorConfigPlugin: Scratch.Plugins.PluginBase { } }); } + + protected override void deactivate_internal () { + this.disconnect (doc_hook_handler); + } } public Scratch.Plugins.PluginBase module_init ( diff --git a/plugins/fuzzy-search/fuzzy-search.vala b/plugins/fuzzy-search/fuzzy-search.vala index 72ec7931a8..c4d6f65a5f 100644 --- a/plugins/fuzzy-search/fuzzy-search.vala +++ b/plugins/fuzzy-search/fuzzy-search.vala @@ -35,8 +35,11 @@ public class Scratch.Plugins.FuzzySearch: Scratch.Plugins.PluginBase { base (info, iface); } + ulong window_hook_handler = 0; + ulong folder_hook_handler = 0; protected override void activate_internal () { - plugins.hook_window.connect ((w) => { + window_hook_handler = iface.hook_window.connect ((w) => { + warning ("fuzzy search - hook window"); if (window != null) { return; } @@ -55,7 +58,7 @@ public class Scratch.Plugins.FuzzySearch: Scratch.Plugins.PluginBase { folder_settings.changed["opened-folders"].connect (handle_opened_projects_change); }); - plugins.hook_folder_item_change.connect ((src, dest, event) => { + folder_hook_handler = iface.hook_folder_item_change.connect ((src, dest, event) => { if (indexer == null) { return; } @@ -70,6 +73,9 @@ public class Scratch.Plugins.FuzzySearch: Scratch.Plugins.PluginBase { if (cancellable != null) { cancellable.cancel (); } + + this.disconnect (window_hook_handler); + this.disconnect (folder_hook_handler); } private void add_actions () { diff --git a/plugins/highlight-word-selection/highlight-word-selection.vala b/plugins/highlight-word-selection/highlight-word-selection.vala index 1c37d01574..40664238ad 100644 --- a/plugins/highlight-word-selection/highlight-word-selection.vala +++ b/plugins/highlight-word-selection/highlight-word-selection.vala @@ -32,9 +32,11 @@ public class Scratch.Plugins.HighlightSelectedWords : Scratch.Plugins.PluginBase base (info, iface); } + ulong window_hook_handler = 0; + ulong doc_hook_handler = 0; protected override void activate_internal () { // plugins = (Scratch.Plugins.Interface) object; - plugins.hook_document.connect ((doc) => { + doc_hook_handler = iface.hook_document.connect ((doc) => { if (current_source != null) { current_source.deselected.disconnect (on_deselection); current_source.selection_changed.disconnect (on_selection_changed); @@ -45,17 +47,19 @@ public class Scratch.Plugins.HighlightSelectedWords : Scratch.Plugins.PluginBase current_source.selection_changed.connect (on_selection_changed); }); - plugins.hook_window.connect ((w) => { + window_hook_handler = iface.hook_window.connect ((w) => { main_window = w; }); } - protected override void deactivate_internal () { if (current_source != null) { current_source.deselected.disconnect (on_deselection); current_source.selection_changed.disconnect (on_selection_changed); } + + this.disconnect (window_hook_handler); + this.disconnect (doc_hook_handler); } public void on_selection_changed (ref Gtk.TextIter start, ref Gtk.TextIter end) { diff --git a/plugins/markdown-actions/markdown-actions.vala b/plugins/markdown-actions/markdown-actions.vala index 58319e7324..f6649c7ab6 100644 --- a/plugins/markdown-actions/markdown-actions.vala +++ b/plugins/markdown-actions/markdown-actions.vala @@ -26,8 +26,9 @@ public class Scratch.Plugins.MarkdownActions : Scratch.Plugins.PluginBase { base (info, iface); } + ulong doc_hook_handler = 0; protected override void activate_internal () { - plugins.hook_document.connect ((doc) => { + doc_hook_handler = iface.hook_document.connect ((doc) => { if (current_source != null) { current_source.key_press_event.disconnect (shortcut_handler); current_source.notify["language"].disconnect (configure_shortcuts); @@ -45,6 +46,8 @@ public class Scratch.Plugins.MarkdownActions : Scratch.Plugins.PluginBase { current_source.key_press_event.disconnect (shortcut_handler); current_source.notify["language"].disconnect (configure_shortcuts); } + + this.disconnect (doc_hook_handler); } private void configure_shortcuts () { diff --git a/plugins/pastebin/pastebin.vala b/plugins/pastebin/pastebin.vala index 99f2f2f07b..6b34dcbdc1 100644 --- a/plugins/pastebin/pastebin.vala +++ b/plugins/pastebin/pastebin.vala @@ -41,16 +41,20 @@ public class Scratch.Plugins.Pastebin : Scratch.Plugins.PluginBase { base (info, iface); } + ulong doc_hook_handler = 0; + ulong menu_hook_handler = 0; protected override void activate_internal () { - plugins.hook_document.connect ((doc) => { + doc_hook_handler = iface.hook_document.connect ((doc) => { this.doc = doc; }); - plugins.hook_share_menu.connect (on_hook_share_menu); + menu_hook_handler = iface.hook_share_menu.connect (on_hook_share_menu); } protected override void deactivate_internal () { remove_actions (); + this.disconnect (menu_hook_handler); + this.disconnect (doc_hook_handler); } void on_hook_share_menu (GLib.MenuModel menu) { @@ -67,7 +71,7 @@ public class Scratch.Plugins.Pastebin : Scratch.Plugins.PluginBase { actions.add_action_entries (ACTION_ENTRIES, this); } - plugins.manager.window.insert_action_group (ACTION_GROUP, actions); + iface.manager.window.insert_action_group (ACTION_GROUP, actions); share_menu = (GLib.Menu) menu; menuitem = new GLib.MenuItem (_("Upload to Pastebin"), ACTION_PREFIX + ACTION_SHOW); share_menu.append_item (menuitem); @@ -86,11 +90,11 @@ public class Scratch.Plugins.Pastebin : Scratch.Plugins.PluginBase { } } - plugins.manager.window.insert_action_group (ACTION_GROUP, null); + iface.manager.window.insert_action_group (ACTION_GROUP, null); } void show_paste_bin_upload_dialog () { - MainWindow window = plugins.manager.window; + MainWindow window = iface.manager.window; new Dialogs.PasteBinDialog (window, doc); } } diff --git a/plugins/preserve-indent/preserve-indent.vala b/plugins/preserve-indent/preserve-indent.vala index 6903e049f6..474a00506f 100644 --- a/plugins/preserve-indent/preserve-indent.vala +++ b/plugins/preserve-indent/preserve-indent.vala @@ -29,10 +29,11 @@ public class Scratch.Plugins.PreserveIndent : Scratch.Plugins.PluginBase { base (info, iface); } + ulong doc_hook_handler = 0; protected override void activate_internal () { this.documents = new Gee.TreeSet (); - plugins.hook_document.connect ((d) => { + doc_hook_handler = iface.hook_document.connect ((d) => { this.active_document = d; if (documents.add (d)) { @@ -50,6 +51,7 @@ public class Scratch.Plugins.PreserveIndent : Scratch.Plugins.PluginBase { protected override void deactivate_internal () { this.documents.clear (); + this.disconnect (doc_hook_handler); } // determine how many characters precede a given iterator position diff --git a/plugins/spell/spell.vala b/plugins/spell/spell.vala index b3f1a05f50..7140348486 100644 --- a/plugins/spell/spell.vala +++ b/plugins/spell/spell.vala @@ -29,6 +29,8 @@ public class Scratch.Plugins.Spell: Scratch.Plugins.PluginBase { base (info, iface); } + ulong window_hook_handler = 0; + ulong doc_hook_handler = 0; protected override void activate_internal () { settings = new GLib.Settings (Constants.PROJECT_NAME + ".plugins.spell"); @@ -37,7 +39,16 @@ public class Scratch.Plugins.Spell: Scratch.Plugins.PluginBase { settings.changed.connect (settings_changed); - plugins.hook_document.connect ((d) => { + window_hook_handler = iface.hook_window.connect ((w) => { + if (window != null) { + return; + } + + window = w; + window.destroy.connect (save_settings); + }); + + doc_hook_handler = iface.hook_document.connect ((d) => { var view = d.source_view; // Create spell object @@ -86,7 +97,7 @@ public class Scratch.Plugins.Spell: Scratch.Plugins.PluginBase { } #endif // Deactivate Spell checker when it is no longer needed - plugins.manager.extension_removed.connect ((info) => { + iface.manager.extension_removed.connect ((info) => { if (info.module_name == "spell") spell.detach (); }); @@ -105,24 +116,15 @@ public class Scratch.Plugins.Spell: Scratch.Plugins.PluginBase { spell.language_changed.connect ((lang_dict) => { this.lang_dict = lang_dict; }); - } }); - - plugins.hook_window.connect ((w) => { - if (window != null) { - return; - } - - window = w; - window.destroy.connect (save_settings); - }); - } protected override void deactivate_internal () { save_settings (); window.destroy.disconnect (save_settings); + this.disconnect (window_hook_handler); + this.disconnect (doc_hook_handler); } private void language_changed_spell (Scratch.Widgets.SourceView view) { diff --git a/plugins/vim-emulation/vim-emulation.vala b/plugins/vim-emulation/vim-emulation.vala index 62d1bbd3fd..904359f4d1 100644 --- a/plugins/vim-emulation/vim-emulation.vala +++ b/plugins/vim-emulation/vim-emulation.vala @@ -42,8 +42,9 @@ public class Scratch.Plugins.VimEmulation : Scratch.Plugins.PluginBase { views = new Gee.TreeSet (); } + ulong doc_hook_handler = 0; protected override void activate_internal () { - plugins.hook_document.connect ((doc) => { + doc_hook_handler = iface.hook_document.connect ((doc) => { this.view = doc.source_view; this.view.key_press_event.disconnect (handle_key_press); this.view.key_press_event.connect (handle_key_press); @@ -55,6 +56,8 @@ public class Scratch.Plugins.VimEmulation : Scratch.Plugins.PluginBase { foreach (var v in views) { v.key_press_event.disconnect (handle_key_press); } + + this.disconnect (doc_hook_handler); } private bool handle_key_press (Gdk.EventKey event) { diff --git a/plugins/word-completion/plugin.vala b/plugins/word-completion/plugin.vala index 5d0babb6f2..81e37073bd 100644 --- a/plugins/word-completion/plugin.vala +++ b/plugins/word-completion/plugin.vala @@ -45,17 +45,24 @@ public class Scratch.Plugins.Completion : Scratch.Plugins.PluginBase { base (info, iface); } + ulong window_hook_handler = 0; + ulong doc_hook_handler = 0; protected override void activate_internal () { + if (window_hook_handler > 0) { + return; + } parser = new Euclide.Completion.Parser (); - plugins.hook_window.connect ((w) => { + window_hook_handler = iface.hook_window.connect ((w) => { this.main_window = w; }); - plugins.hook_document.connect (on_new_source_view); + doc_hook_handler = iface.hook_document.connect (on_new_source_view); } protected override void deactivate_internal () { text_view_list.@foreach (cleanup); + this.disconnect (window_hook_handler); + this.disconnect (doc_hook_handler); } public void on_new_source_view (Scratch.Services.Document doc) { diff --git a/src/Services/PluginManager.vala b/src/Services/PluginManager.vala index 5fccfbc7de..fef40fe1d2 100644 --- a/src/Services/PluginManager.vala +++ b/src/Services/PluginManager.vala @@ -21,10 +21,17 @@ // namespace Scratch.Plugins { public abstract class Scratch.Plugins.PluginBase : GLib.Object { public PluginInfo plugin_info { get; construct; } - public Interface plugins { get; construct; } + public Interface iface { get; construct; } public bool is_active { get; set; } + + protected PluginBase (PluginInfo info, Interface iface) { + Object ( + plugin_info: info, + iface: iface + ); + } + public void activate () { - warning ("plugin base activate"); is_active = true; activate_internal (); } @@ -38,13 +45,6 @@ public abstract class Scratch.Plugins.PluginBase : GLib.Object { protected abstract void activate_internal (); protected virtual void deactivate_internal () {} // Not implemented by some plugins public virtual void update_state () {} // Not currently used - - protected PluginBase (PluginInfo info, Interface iface) { - Object ( - plugin_info: info, - plugins: iface - ); - } } public struct Scratch.Plugins.PluginInfo { @@ -72,15 +72,15 @@ public class Scratch.Plugins.Interface : GLib.Object { 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 (doc); - return doc; - } + // public Scratch.Services.Document open_file (File file) { + // var doc = new Scratch.Services.Document (manager.window.actions, file); + // manager.window.open_document (doc); + // return doc; + // } - public void close_document (Scratch.Services.Document doc) { - manager.window.close_document (doc); - } + // public void close_document (Scratch.Services.Document doc) { + // manager.window.close_document (doc); + // } } delegate Scratch.Plugins.PluginBase ModuleInitFunc ( @@ -158,6 +158,7 @@ public class Scratch.Services.PluginsManager : GLib.Object { private void activate_plugin (Scratch.Plugins.PluginBase plugin) { var info = plugin.plugin_info; + warning ("activate plugin %s, active %s", info.name, plugin.is_active.to_string ()); if (!plugin.is_active) { plugin.activate (); active_plugin_set.add (info.name); From 739b46446473e81d1697550b7607bd5b8acec56e Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 27 Dec 2024 14:18:26 +0000 Subject: [PATCH 11/20] Fix saving to plugins-enabled --- plugins/detect-indent/detect-indent.vala | 2 +- plugins/editorconfig/editorconfig.vala | 2 +- plugins/fuzzy-search/fuzzy-search.vala | 2 +- plugins/markdown-actions/markdown-actions.vala | 2 +- plugins/vim-emulation/vim-emulation.vala | 2 +- src/MainWindow.vala | 1 - src/Services/PluginManager.vala | 16 ++++++++++------ 7 files changed, 15 insertions(+), 12 deletions(-) diff --git a/plugins/detect-indent/detect-indent.vala b/plugins/detect-indent/detect-indent.vala index 5f2b201019..f176a21646 100644 --- a/plugins/detect-indent/detect-indent.vala +++ b/plugins/detect-indent/detect-indent.vala @@ -85,7 +85,7 @@ public class Scratch.Plugins.DetectIndent: Scratch.Plugins.PluginBase { } }); } - + protected override void deactivate_internal () { this.disconnect (doc_hook_handler); } diff --git a/plugins/editorconfig/editorconfig.vala b/plugins/editorconfig/editorconfig.vala index aab9bab707..9fa052bd2c 100644 --- a/plugins/editorconfig/editorconfig.vala +++ b/plugins/editorconfig/editorconfig.vala @@ -80,7 +80,7 @@ public class Scratch.Plugins.EditorConfigPlugin: Scratch.Plugins.PluginBase { } }); } - + protected override void deactivate_internal () { this.disconnect (doc_hook_handler); } diff --git a/plugins/fuzzy-search/fuzzy-search.vala b/plugins/fuzzy-search/fuzzy-search.vala index c4d6f65a5f..dab367f21a 100644 --- a/plugins/fuzzy-search/fuzzy-search.vala +++ b/plugins/fuzzy-search/fuzzy-search.vala @@ -73,7 +73,7 @@ public class Scratch.Plugins.FuzzySearch: Scratch.Plugins.PluginBase { if (cancellable != null) { cancellable.cancel (); } - + this.disconnect (window_hook_handler); this.disconnect (folder_hook_handler); } diff --git a/plugins/markdown-actions/markdown-actions.vala b/plugins/markdown-actions/markdown-actions.vala index f6649c7ab6..9c02448bce 100644 --- a/plugins/markdown-actions/markdown-actions.vala +++ b/plugins/markdown-actions/markdown-actions.vala @@ -46,7 +46,7 @@ public class Scratch.Plugins.MarkdownActions : Scratch.Plugins.PluginBase { current_source.key_press_event.disconnect (shortcut_handler); current_source.notify["language"].disconnect (configure_shortcuts); } - + this.disconnect (doc_hook_handler); } diff --git a/plugins/vim-emulation/vim-emulation.vala b/plugins/vim-emulation/vim-emulation.vala index 904359f4d1..0db33f5674 100644 --- a/plugins/vim-emulation/vim-emulation.vala +++ b/plugins/vim-emulation/vim-emulation.vala @@ -56,7 +56,7 @@ public class Scratch.Plugins.VimEmulation : Scratch.Plugins.PluginBase { foreach (var v in views) { v.key_press_event.disconnect (handle_key_press); } - + this.disconnect (doc_hook_handler); } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index ebeebe85ec..f39d1e6e95 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -573,7 +573,6 @@ namespace Scratch { }; plugins.extension_added.connect (() => { - warning ("hook func"); hook_func (); }); diff --git a/src/Services/PluginManager.vala b/src/Services/PluginManager.vala index fef40fe1d2..7fc083e3b0 100644 --- a/src/Services/PluginManager.vala +++ b/src/Services/PluginManager.vala @@ -158,12 +158,10 @@ public class Scratch.Services.PluginsManager : GLib.Object { private void activate_plugin (Scratch.Plugins.PluginBase plugin) { var info = plugin.plugin_info; - warning ("activate plugin %s, active %s", info.name, plugin.is_active.to_string ()); if (!plugin.is_active) { plugin.activate (); active_plugin_set.add (info.name); extension_added (); // Signals Window to run initial hook function - update_active_plugin_settings (); } } @@ -173,17 +171,21 @@ public class Scratch.Services.PluginsManager : GLib.Object { plugin.deactivate (); active_plugin_set.remove (info.name); extension_removed (info); - update_active_plugin_settings (); } } private void update_active_plugin_settings () { - settings.set_strv (ACTIVE_PLUGINS_KEY, active_plugin_set.to_array ()); + // For some reason using active_plugin_set.to_array () does not work (crashes) + // So construct the string array ourselves + string[] plugins = {}; + foreach (string s in active_plugin_set) { + plugins += s; + } + + settings.set_strv (ACTIVE_PLUGINS_KEY, plugins); } private void load_modules_from_dir (string path) { - - FileInfo info; FileEnumerator enumerator; try { @@ -341,6 +343,8 @@ public class Scratch.Services.PluginsManager : GLib.Object { } else { deactivate_plugin (plugin); } + + update_active_plugin_settings (); }); var image = new Gtk.Image.from_icon_name (info.icon_name, LARGE_TOOLBAR) { valign = Gtk.Align.CENTER From 7e943c93bda9a3cae0199d391b0579da399323cc Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 27 Dec 2024 15:14:04 +0000 Subject: [PATCH 12/20] Ensure activate does not re-enter --- plugins/brackets-completion/brackets-completion.vala | 3 ++- .../highlight-word-selection.vala | 1 - plugins/word-completion/plugin.vala | 3 --- src/Services/PluginManager.vala | 8 ++++++++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/plugins/brackets-completion/brackets-completion.vala b/plugins/brackets-completion/brackets-completion.vala index 7186134488..01ff2f0f46 100644 --- a/plugins/brackets-completion/brackets-completion.vala +++ b/plugins/brackets-completion/brackets-completion.vala @@ -35,6 +35,7 @@ public class Scratch.Plugins.BracketsCompletion : Scratch.Plugins.PluginBase { base (info, iface); } + ulong doc_hook_handler = 0; protected override void activate_internal () { brackets = new Gee.HashMap (); brackets["("] = ")"; @@ -59,7 +60,7 @@ public class Scratch.Plugins.BracketsCompletion : Scratch.Plugins.PluginBase { } protected override void deactivate_internal () { - iface.hook_document.disconnect (on_hook_document); + this.disconnect (doc_hook_handler); } void on_hook_document (Scratch.Services.Document doc) { diff --git a/plugins/highlight-word-selection/highlight-word-selection.vala b/plugins/highlight-word-selection/highlight-word-selection.vala index 40664238ad..04ae00cede 100644 --- a/plugins/highlight-word-selection/highlight-word-selection.vala +++ b/plugins/highlight-word-selection/highlight-word-selection.vala @@ -35,7 +35,6 @@ public class Scratch.Plugins.HighlightSelectedWords : Scratch.Plugins.PluginBase ulong window_hook_handler = 0; ulong doc_hook_handler = 0; protected override void activate_internal () { - // plugins = (Scratch.Plugins.Interface) object; doc_hook_handler = iface.hook_document.connect ((doc) => { if (current_source != null) { current_source.deselected.disconnect (on_deselection); diff --git a/plugins/word-completion/plugin.vala b/plugins/word-completion/plugin.vala index 81e37073bd..8485792faa 100644 --- a/plugins/word-completion/plugin.vala +++ b/plugins/word-completion/plugin.vala @@ -48,9 +48,6 @@ public class Scratch.Plugins.Completion : Scratch.Plugins.PluginBase { ulong window_hook_handler = 0; ulong doc_hook_handler = 0; protected override void activate_internal () { - if (window_hook_handler > 0) { - return; - } parser = new Euclide.Completion.Parser (); window_hook_handler = iface.hook_window.connect ((w) => { this.main_window = w; diff --git a/src/Services/PluginManager.vala b/src/Services/PluginManager.vala index 7fc083e3b0..355fcc22c0 100644 --- a/src/Services/PluginManager.vala +++ b/src/Services/PluginManager.vala @@ -32,12 +32,20 @@ public abstract class Scratch.Plugins.PluginBase : GLib.Object { } public void activate () { + if (is_active) { + return; + } + is_active = true; activate_internal (); } public void deactivate () { + if (!is_active) { + return; + } + is_active = false; deactivate_internal (); } From 4a0c00df7c21e0a6de9a0ef7ea9a7e2e0613dd32 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 27 Dec 2024 15:35:32 +0000 Subject: [PATCH 13/20] Replace libpeas with libgmodule --- .github/workflows/ci.yml | 2 +- README.md | 1 - io.elementary.code.yml | 11 ----------- meson.build | 6 ++---- src/codecore.deps | 2 +- 5 files changed, 4 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9090e51f05..bd13093a0c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: - name: Install Dependencies run: | apt update - apt install -y exuberant-ctags libeditorconfig-dev libgail-3-dev libgee-0.8-dev libgit2-glib-1.0-dev libgranite-dev libgtk-3-dev libgtksourceview-4-dev libgtkspell3-3-dev libhandy-1-dev libpeas-dev libsoup2.4-dev libvala-dev libvte-2.91-dev meson valac polkitd libpolkit-gobject-1-dev + apt install -y exuberant-ctags libeditorconfig-dev libgail-3-dev libgee-0.8-dev libgit2-glib-1.0-dev libgranite-dev libgtk-3-dev libgtksourceview-4-dev libgtkspell3-3-dev libhandy-1-dev libsoup2.4-dev libvala-dev libvte-2.91-dev meson valac polkitd libpolkit-gobject-1-dev - name: Build env: DESTDIR: out diff --git a/README.md b/README.md index 9f440e8b3e..e218248392 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,6 @@ You'll need the following dependencies: * libgtkspell3-3-dev * libgranite-dev >= 6.0.0 * libhandy-1-dev >= 0.90.0 -* libpeas-dev * libsoup2.4-dev * libvala-0.48-dev (or higher) * libvte-2.91-dev diff --git a/io.elementary.code.yml b/io.elementary.code.yml index c0764fbf43..75c1e8599c 100644 --- a/io.elementary.code.yml +++ b/io.elementary.code.yml @@ -33,17 +33,6 @@ modules: url: https://gitlab.gnome.org/GNOME/gtksourceview.git tag: '4.8.4' - - name: peas - buildsystem: meson - config-opts: - - '-Dgtk_doc=false' - - '-Ddemos=false' - - '-Dvapi=true' - sources: - - type: git - url: https://gitlab.gnome.org/GNOME/libpeas.git - tag: libpeas-1.34.0 - - name: git2-glib buildsystem: meson builddir: true diff --git a/meson.build b/meson.build index b600a80667..51bbf227c8 100644 --- a/meson.build +++ b/meson.build @@ -27,14 +27,13 @@ gnome = import('gnome') i18n = import('i18n') glib_dep = dependency('glib-2.0', version: '>=2.30.0') +gmodule_dep = dependency('gmodule-2.0', version: '>=2.30.0') gio_unix_dep = dependency('gio-unix-2.0', version: '>=2.20') gee_dep = dependency('gee-0.8', version: '>=0.8.5') gtk_dep = dependency('gtk+-3.0', version: '>=3.6.0') granite_dep = dependency('granite', version: '>=6.0.0') handy_dep = dependency('libhandy-1', version: '>=0.90.0') gtksourceview_dep = dependency('gtksourceview-4') -peas_dep = dependency('libpeas-1.0') -peasgtk_dep = dependency('libpeas-gtk-1.0') git_dep = dependency('libgit2-glib-1.0') fontconfig_dep = dependency('fontconfig') pangofc_dep = dependency('pangoft2') @@ -52,14 +51,13 @@ vala_dep = dependency('libvala-@0@'.format(vala_version)) dependencies = [ glib_dep, + gmodule_dep, gio_unix_dep, gee_dep, gtk_dep, granite_dep, handy_dep, gtksourceview_dep, - peas_dep, - peasgtk_dep, git_dep, fontconfig_dep, pangofc_dep, diff --git a/src/codecore.deps b/src/codecore.deps index dcfdbb4614..b6cfd8dccc 100644 --- a/src/codecore.deps +++ b/src/codecore.deps @@ -2,7 +2,7 @@ codecore gtksourceview-4 gee-0.8 gobject-2.0 +gmodule-2.0 gio-2.0 gtk+-3.0 granite -libpeas-1.0 From efb8fb395f365927fda5c0c593a7527cae66cd64 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 27 Dec 2024 15:41:03 +0000 Subject: [PATCH 14/20] Make deactivate_internal abstract in base --- 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 355fcc22c0..263f0636b7 100644 --- a/src/Services/PluginManager.vala +++ b/src/Services/PluginManager.vala @@ -51,7 +51,7 @@ public abstract class Scratch.Plugins.PluginBase : GLib.Object { } protected abstract void activate_internal (); - protected virtual void deactivate_internal () {} // Not implemented by some plugins + protected abstract void deactivate_internal (); public virtual void update_state () {} // Not currently used } From 94a936433b671bde170f28b2fabaa6796a0fda97 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 27 Dec 2024 16:13:55 +0000 Subject: [PATCH 15/20] Cleanup --- plugins/fuzzy-search/fuzzy-search.vala | 1 - plugins/pastebin/pastebin.vala | 3 +-- plugins/preserve-indent/preserve-indent.vala | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/fuzzy-search/fuzzy-search.vala b/plugins/fuzzy-search/fuzzy-search.vala index dab367f21a..8710bea90b 100644 --- a/plugins/fuzzy-search/fuzzy-search.vala +++ b/plugins/fuzzy-search/fuzzy-search.vala @@ -39,7 +39,6 @@ public class Scratch.Plugins.FuzzySearch: Scratch.Plugins.PluginBase { ulong folder_hook_handler = 0; protected override void activate_internal () { window_hook_handler = iface.hook_window.connect ((w) => { - warning ("fuzzy search - hook window"); if (window != null) { return; } diff --git a/plugins/pastebin/pastebin.vala b/plugins/pastebin/pastebin.vala index 6b34dcbdc1..314e982efa 100644 --- a/plugins/pastebin/pastebin.vala +++ b/plugins/pastebin/pastebin.vala @@ -3,7 +3,7 @@ BEGIN LICENSE Copyright (C) 2024 elementary, Inc. 2011-2012 Giulio Collura - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3, as published by the Free Software Foundation. @@ -24,7 +24,6 @@ public class Scratch.Plugins.Pastebin : Scratch.Plugins.PluginBase { GLib.MenuItem? menuitem = null; GLib.Menu? share_menu = null; - // public Object object { owned get; construct; } Scratch.Services.Document? doc = null; diff --git a/plugins/preserve-indent/preserve-indent.vala b/plugins/preserve-indent/preserve-indent.vala index 474a00506f..c56b948513 100644 --- a/plugins/preserve-indent/preserve-indent.vala +++ b/plugins/preserve-indent/preserve-indent.vala @@ -3,7 +3,7 @@ BEGIN LICENSE Copyright (C) 2024 elementary, Inc. 2015 James Morgan - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3, as published by the Free Software Foundation. From b402872c92b011a38a5a7723da103756e78fb3c0 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 27 Dec 2024 17:11:03 +0000 Subject: [PATCH 16/20] Reinstate hook_toolbar handler in editorconfig.vala --- plugins/editorconfig/editorconfig.vala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/editorconfig/editorconfig.vala b/plugins/editorconfig/editorconfig.vala index 9fa052bd2c..c10cad9f1e 100644 --- a/plugins/editorconfig/editorconfig.vala +++ b/plugins/editorconfig/editorconfig.vala @@ -79,6 +79,10 @@ public class Scratch.Plugins.EditorConfigPlugin: Scratch.Plugins.PluginBase { } } }); + + iface.hook_toolbar.connect ((tb) => { + format_bar = tb.format_bar; + }); } protected override void deactivate_internal () { From 45a18b9d2ec8d7eb0514ce347b1d14171836768e Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 27 Dec 2024 17:14:55 +0000 Subject: [PATCH 17/20] Remove unused code --- src/MainWindow.vala | 1 - src/Services/PluginManager.vala | 12 ------------ 2 files changed, 13 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index f39d1e6e95..34fe7d93db 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -281,7 +281,6 @@ namespace Scratch { clipboard = Gtk.Clipboard.get_for_display (get_display (), Gdk.SELECTION_CLIPBOARD); - warning ("creating new plugin manager"); plugins = new Scratch.Services.PluginsManager (this); key_controller = new Gtk.EventControllerKey (this) { diff --git a/src/Services/PluginManager.vala b/src/Services/PluginManager.vala index 263f0636b7..29e89ec0dd 100644 --- a/src/Services/PluginManager.vala +++ b/src/Services/PluginManager.vala @@ -76,19 +76,8 @@ public class Scratch.Plugins.Interface : GLib.Object { public Interface (Scratch.Services.PluginsManager manager) { this.manager = manager; - 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 (doc); - // return doc; - // } - - // public void close_document (Scratch.Services.Document doc) { - // manager.window.close_document (doc); - // } } delegate Scratch.Plugins.PluginBase ModuleInitFunc ( @@ -380,7 +369,6 @@ public class Scratch.Services.PluginsManager : GLib.Object { } public uint get_n_plugins () { - warning ("get n plugins %u", plugin_hash.size); return plugin_hash.size; } } From bc81defc75a37f6190481626f513252dec20ff83 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 27 Dec 2024 17:23:22 +0000 Subject: [PATCH 18/20] Disconnect signals properly --- plugins/brackets-completion/brackets-completion.vala | 4 ++-- plugins/detect-indent/detect-indent.vala | 2 +- plugins/editorconfig/editorconfig.vala | 2 +- plugins/fuzzy-search/fuzzy-search.vala | 4 ++-- .../highlight-word-selection/highlight-word-selection.vala | 6 +++--- plugins/markdown-actions/markdown-actions.vala | 2 +- plugins/pastebin/pastebin.vala | 4 ++-- plugins/preserve-indent/preserve-indent.vala | 2 +- plugins/spell/spell.vala | 4 ++-- plugins/vim-emulation/vim-emulation.vala | 2 +- plugins/word-completion/plugin.vala | 4 ++-- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/plugins/brackets-completion/brackets-completion.vala b/plugins/brackets-completion/brackets-completion.vala index 01ff2f0f46..9ae06f9627 100644 --- a/plugins/brackets-completion/brackets-completion.vala +++ b/plugins/brackets-completion/brackets-completion.vala @@ -56,11 +56,11 @@ public class Scratch.Plugins.BracketsCompletion : Scratch.Plugins.PluginBase { keys[Gdk.Key.quotedbl] = "\""; keys[Gdk.Key.grave] = "`"; - iface.hook_document.connect (on_hook_document); + doc_hook_handler = iface.hook_document.connect (on_hook_document); } protected override void deactivate_internal () { - this.disconnect (doc_hook_handler); + iface.disconnect (doc_hook_handler); } void on_hook_document (Scratch.Services.Document doc) { diff --git a/plugins/detect-indent/detect-indent.vala b/plugins/detect-indent/detect-indent.vala index f176a21646..b7e37454c5 100644 --- a/plugins/detect-indent/detect-indent.vala +++ b/plugins/detect-indent/detect-indent.vala @@ -87,7 +87,7 @@ public class Scratch.Plugins.DetectIndent: Scratch.Plugins.PluginBase { } protected override void deactivate_internal () { - this.disconnect (doc_hook_handler); + iface.disconnect (doc_hook_handler); } } diff --git a/plugins/editorconfig/editorconfig.vala b/plugins/editorconfig/editorconfig.vala index c10cad9f1e..b1aa7fdf7f 100644 --- a/plugins/editorconfig/editorconfig.vala +++ b/plugins/editorconfig/editorconfig.vala @@ -86,7 +86,7 @@ public class Scratch.Plugins.EditorConfigPlugin: Scratch.Plugins.PluginBase { } protected override void deactivate_internal () { - this.disconnect (doc_hook_handler); + iface.disconnect (doc_hook_handler); } } diff --git a/plugins/fuzzy-search/fuzzy-search.vala b/plugins/fuzzy-search/fuzzy-search.vala index 8710bea90b..d0f341f35d 100644 --- a/plugins/fuzzy-search/fuzzy-search.vala +++ b/plugins/fuzzy-search/fuzzy-search.vala @@ -73,8 +73,8 @@ public class Scratch.Plugins.FuzzySearch: Scratch.Plugins.PluginBase { cancellable.cancel (); } - this.disconnect (window_hook_handler); - this.disconnect (folder_hook_handler); + iface.disconnect (window_hook_handler); + iface.disconnect (folder_hook_handler); } private void add_actions () { diff --git a/plugins/highlight-word-selection/highlight-word-selection.vala b/plugins/highlight-word-selection/highlight-word-selection.vala index 04ae00cede..8f851daee1 100644 --- a/plugins/highlight-word-selection/highlight-word-selection.vala +++ b/plugins/highlight-word-selection/highlight-word-selection.vala @@ -3,7 +3,7 @@ BEGIN LICENSE Copyright (C) 2019-24 elementary, Inc. 2013 Madelynn May - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3, as published by the Free Software Foundation. @@ -57,8 +57,8 @@ public class Scratch.Plugins.HighlightSelectedWords : Scratch.Plugins.PluginBase current_source.selection_changed.disconnect (on_selection_changed); } - this.disconnect (window_hook_handler); - this.disconnect (doc_hook_handler); + iface.disconnect (window_hook_handler); + iface.disconnect (doc_hook_handler); } public void on_selection_changed (ref Gtk.TextIter start, ref Gtk.TextIter end) { diff --git a/plugins/markdown-actions/markdown-actions.vala b/plugins/markdown-actions/markdown-actions.vala index 9c02448bce..6a105967af 100644 --- a/plugins/markdown-actions/markdown-actions.vala +++ b/plugins/markdown-actions/markdown-actions.vala @@ -47,7 +47,7 @@ public class Scratch.Plugins.MarkdownActions : Scratch.Plugins.PluginBase { current_source.notify["language"].disconnect (configure_shortcuts); } - this.disconnect (doc_hook_handler); + iface.disconnect (doc_hook_handler); } private void configure_shortcuts () { diff --git a/plugins/pastebin/pastebin.vala b/plugins/pastebin/pastebin.vala index 314e982efa..a64762a374 100644 --- a/plugins/pastebin/pastebin.vala +++ b/plugins/pastebin/pastebin.vala @@ -52,8 +52,8 @@ public class Scratch.Plugins.Pastebin : Scratch.Plugins.PluginBase { protected override void deactivate_internal () { remove_actions (); - this.disconnect (menu_hook_handler); - this.disconnect (doc_hook_handler); + iface.disconnect (menu_hook_handler); + iface.disconnect (doc_hook_handler); } void on_hook_share_menu (GLib.MenuModel menu) { diff --git a/plugins/preserve-indent/preserve-indent.vala b/plugins/preserve-indent/preserve-indent.vala index c56b948513..8204152e8a 100644 --- a/plugins/preserve-indent/preserve-indent.vala +++ b/plugins/preserve-indent/preserve-indent.vala @@ -51,7 +51,7 @@ public class Scratch.Plugins.PreserveIndent : Scratch.Plugins.PluginBase { protected override void deactivate_internal () { this.documents.clear (); - this.disconnect (doc_hook_handler); + iface.disconnect (doc_hook_handler); } // determine how many characters precede a given iterator position diff --git a/plugins/spell/spell.vala b/plugins/spell/spell.vala index 7140348486..77eea72c29 100644 --- a/plugins/spell/spell.vala +++ b/plugins/spell/spell.vala @@ -123,8 +123,8 @@ public class Scratch.Plugins.Spell: Scratch.Plugins.PluginBase { protected override void deactivate_internal () { save_settings (); window.destroy.disconnect (save_settings); - this.disconnect (window_hook_handler); - this.disconnect (doc_hook_handler); + iface.disconnect (window_hook_handler); + iface.disconnect (doc_hook_handler); } private void language_changed_spell (Scratch.Widgets.SourceView view) { diff --git a/plugins/vim-emulation/vim-emulation.vala b/plugins/vim-emulation/vim-emulation.vala index 0db33f5674..1a6c5cfdcb 100644 --- a/plugins/vim-emulation/vim-emulation.vala +++ b/plugins/vim-emulation/vim-emulation.vala @@ -57,7 +57,7 @@ public class Scratch.Plugins.VimEmulation : Scratch.Plugins.PluginBase { v.key_press_event.disconnect (handle_key_press); } - this.disconnect (doc_hook_handler); + iface.disconnect (doc_hook_handler); } private bool handle_key_press (Gdk.EventKey event) { diff --git a/plugins/word-completion/plugin.vala b/plugins/word-completion/plugin.vala index 8485792faa..45b92c6d33 100644 --- a/plugins/word-completion/plugin.vala +++ b/plugins/word-completion/plugin.vala @@ -58,8 +58,8 @@ public class Scratch.Plugins.Completion : Scratch.Plugins.PluginBase { protected override void deactivate_internal () { text_view_list.@foreach (cleanup); - this.disconnect (window_hook_handler); - this.disconnect (doc_hook_handler); + iface.disconnect (window_hook_handler); + iface.disconnect (doc_hook_handler); } public void on_new_source_view (Scratch.Services.Document doc) { From 4c0eaa0f9344d0b04415f7be045817114341e117 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 27 Dec 2024 17:46:54 +0000 Subject: [PATCH 19/20] Lose unused from Files --- src/Services/PluginManager.vala | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Services/PluginManager.vala b/src/Services/PluginManager.vala index 29e89ec0dd..b0fbbcde96 100644 --- a/src/Services/PluginManager.vala +++ b/src/Services/PluginManager.vala @@ -106,7 +106,6 @@ public class Scratch.Services.PluginsManager : GLib.Object { Gee.HashMap plugin_hash; // all plugins public Gee.HashSet active_plugin_set; //active plugin names - public Gee.List menuitem_references { get; private set; } public PluginsManager (MainWindow window) { this.window = window; @@ -115,7 +114,6 @@ public class Scratch.Services.PluginsManager : GLib.Object { /* From Files PluginManager construct */ plugin_hash = new Gee.HashMap (); active_plugin_set = new Gee.HashSet (); - menuitem_references = new Gee.LinkedList (); // Code has only one plugin directory. load_modules_from_dir (Constants.PLUGINDIR); From e9557362b43de4b6cc45cfeb15b9436381143f3b Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 27 Dec 2024 18:13:14 +0000 Subject: [PATCH 20/20] Use module-name for settings key as before --- src/Services/PluginManager.vala | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Services/PluginManager.vala b/src/Services/PluginManager.vala index b0fbbcde96..644f15f09b 100644 --- a/src/Services/PluginManager.vala +++ b/src/Services/PluginManager.vala @@ -143,9 +143,9 @@ public class Scratch.Services.PluginsManager : GLib.Object { }); // Activate plugins according to setting - foreach (var plugin_name in settings.get_strv (ACTIVE_PLUGINS_KEY)) { - if (plugin_hash.has_key (plugin_name)) { - var plugin = plugin_hash.@get (plugin_name); + foreach (var module_name in settings.get_strv (ACTIVE_PLUGINS_KEY)) { + if (plugin_hash.has_key (module_name)) { + var plugin = plugin_hash.@get (module_name); activate_plugin (plugin); } } @@ -155,7 +155,7 @@ public class Scratch.Services.PluginsManager : GLib.Object { var info = plugin.plugin_info; if (!plugin.is_active) { plugin.activate (); - active_plugin_set.add (info.name); + active_plugin_set.add (info.module_name); extension_added (); // Signals Window to run initial hook function } } @@ -164,7 +164,7 @@ public class Scratch.Services.PluginsManager : GLib.Object { var info = plugin.plugin_info; if (plugin.is_active) { plugin.deactivate (); - active_plugin_set.remove (info.name); + active_plugin_set.remove (info.module_name); extension_removed (info); } } @@ -172,12 +172,12 @@ public class Scratch.Services.PluginsManager : GLib.Object { private void update_active_plugin_settings () { // For some reason using active_plugin_set.to_array () does not work (crashes) // So construct the string array ourselves - string[] plugins = {}; - foreach (string s in active_plugin_set) { - plugins += s; + string[] module_names = {}; + foreach (string module in active_plugin_set) { + module_names += module; } - settings.set_strv (ACTIVE_PLUGINS_KEY, plugins); + settings.set_strv (ACTIVE_PLUGINS_KEY, module_names); } private void load_modules_from_dir (string path) { @@ -212,7 +212,7 @@ public class Scratch.Services.PluginsManager : GLib.Object { } private bool load_module (File dir, Scratch.Plugins.PluginInfo info) { - if (plugin_hash.has_key (info.name)) { + if (plugin_hash.has_key (info.module_name)) { warning ("plugin for %s already loaded. Not adding again", info.name); return false; } @@ -257,7 +257,7 @@ public class Scratch.Services.PluginsManager : GLib.Object { debug ("Loaded module source: '%s'", module.name ()); if (plug != null) { - plugin_hash.set (info.name, plug); + plugin_hash.set (info.module_name, plug); plug.is_active = false; // Plugins only become active via initial settings or preferences dialog return true;