Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lose libpeas dependency #1502

Closed
wants to merge 20 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move is_active to plugin, ensure correctly set
Jeremy Wootten authored and Jeremy Wootten committed Dec 26, 2024
commit cde7fde15e90eff48f664e9297bfe055a3fb64f4
6 changes: 2 additions & 4 deletions plugins/brackets-completion/brackets-completion.vala
Original file line number Diff line number Diff line change
@@ -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<string, string> ();
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);
}

9 changes: 1 addition & 8 deletions plugins/detect-indent/detect-indent.vala
Original file line number Diff line number Diff line change
@@ -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 (
8 changes: 1 addition & 7 deletions plugins/editorconfig/editorconfig.vala
Original file line number Diff line number Diff line change
@@ -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 (
5 changes: 2 additions & 3 deletions plugins/fuzzy-search/fuzzy-search.vala
Original file line number Diff line number Diff line change
@@ -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) {
Original file line number Diff line number Diff line change
@@ -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);
5 changes: 2 additions & 3 deletions plugins/markdown-actions/markdown-actions.vala
Original file line number Diff line number Diff line change
@@ -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);
2 changes: 1 addition & 1 deletion plugins/pastebin/pastebin.plugin
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Plugin]
Module=libpastebin
Module=pastebin
Loader=C
IAge=2
Name=Pastebin
5 changes: 2 additions & 3 deletions plugins/pastebin/pastebin.vala
Original file line number Diff line number Diff line change
@@ -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,15 +41,15 @@ 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;
});

plugins.hook_share_menu.connect (on_hook_share_menu);
}

public override void deactivate () {
protected override void deactivate_internal () {
remove_actions ();
}

5 changes: 2 additions & 3 deletions plugins/preserve-indent/preserve-indent.vala
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@
***/

public class Scratch.Plugins.PreserveIndent : Scratch.Plugins.PluginBase {
private Scratch.Plugins.Interface plugins;
private Gee.TreeSet<weak Services.Document> 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<weak Services.Document> ();

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

5 changes: 2 additions & 3 deletions plugins/spell/spell.vala
Original file line number Diff line number Diff line change
@@ -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);
}
6 changes: 2 additions & 4 deletions plugins/vim-emulation/vim-emulation.vala
Original file line number Diff line number Diff line change
@@ -34,8 +34,6 @@ public class Scratch.Plugins.VimEmulation : Scratch.Plugins.PluginBase {
Gee.TreeSet<Scratch.Widgets.SourceView> 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<Scratch.Widgets.SourceView> ();
}

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);
}
8 changes: 2 additions & 6 deletions plugins/word-completion/plugin.vala
Original file line number Diff line number Diff line change
@@ -20,15 +20,12 @@
*/

public class Scratch.Plugins.Completion : Scratch.Plugins.PluginBase {
public Object object { owned get; construct; }

private List<Gtk.SourceView> text_view_list = new List<Gtk.SourceView> ();
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);
}

1 change: 1 addition & 0 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
@@ -573,6 +573,7 @@ namespace Scratch {
};

plugins.extension_added.connect (() => {
warning ("hook func");
hook_func ();
});

26 changes: 19 additions & 7 deletions src/Services/PluginManager.vala
Original file line number Diff line number Diff line change
@@ -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
};