Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 14 additions & 3 deletions plugins/pastebin/pastebin.vala
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public class Scratch.Plugins.Pastebin : Peas.ExtensionBase, Scratch.Services.Act
Scratch.Services.Document? doc = null;
Scratch.Services.Interface plugins;

private MainWindow? window = null;

const string ACTION_GROUP = "pastebin";
const string ACTION_PREFIX = ACTION_GROUP + ".";
const string ACTION_SHOW = "action-show";
Expand All @@ -101,6 +103,13 @@ public class Scratch.Plugins.Pastebin : Peas.ExtensionBase, Scratch.Services.Act
public void activate () {
plugins = (Scratch.Services.Interface) object;

plugins.hook_window.connect ((w) => {
// For simplicity, only the first window has share menu button
if (window == null) {
window = w;
}
});

plugins.hook_document.connect ((doc) => {
this.doc = doc;
});
Expand All @@ -120,9 +129,12 @@ public class Scratch.Plugins.Pastebin : Peas.ExtensionBase, Scratch.Services.Act
if (actions == null) {
actions = new SimpleActionGroup ();
actions.add_action_entries (ACTION_ENTRIES, this);
} else {
// Only insert action group once
return;
}

plugins.manager.window.insert_action_group (ACTION_GROUP, actions);
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);
Expand All @@ -141,14 +153,13 @@ public class Scratch.Plugins.Pastebin : Peas.ExtensionBase, Scratch.Services.Act
}
}

plugins.manager.window.insert_action_group (ACTION_GROUP, null);
window.insert_action_group (ACTION_GROUP, null);
}

void show_paste_bin_upload_dialog () {
if (pastebin_dialog != null) {
pastebin_dialog.present ();
} else {
MainWindow window = plugins.manager.window;
pastebin_dialog = new Dialogs.PasteBinDialog (window, doc);
pastebin_dialog.destroy.connect (() => {
pastebin_dialog = null;
Expand Down
8 changes: 7 additions & 1 deletion src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ namespace Scratch {

clipboard = Gtk.Clipboard.get_for_display (get_display (), Gdk.SELECTION_CLIPBOARD);

plugins = new Scratch.Services.PluginsManager (this);
plugins = new Scratch.Services.PluginsManager ();

key_controller = new Gtk.EventControllerKey (this) {
propagation_phase = TARGET
Expand Down Expand Up @@ -556,6 +556,12 @@ namespace Scratch {
plugins.hook_window (this);
plugins.hook_toolbar (toolbar);
plugins.hook_share_menu (toolbar.share_menu);
// Ensure new plugin active on any existing current doc
var doc = get_current_document ();
if (doc != null) {
plugins.hook_document (doc);
}

};

plugins.extension_added.connect (() => {
Expand Down
14 changes: 0 additions & 14 deletions src/Services/PluginManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ public class Scratch.Services.Interface : GLib.Object {
manager: _manager
);
}

public Scratch.Services.Document open_file (File file) {
var doc = new Scratch.Services.Document (manager.window.actions, file);
manager.window.open_document.begin (doc);
return doc;
}

public void close_document (Scratch.Services.Document doc) {
manager.window.close_document (doc);
}
}

public class Scratch.Services.PluginsManager : GLib.Object {
Expand All @@ -56,11 +46,7 @@ public class Scratch.Services.PluginsManager : GLib.Object {
private Peas.ExtensionSet extension_set;

public Scratch.Services.Interface plugin_iface { get; private set; }
public weak Scratch.MainWindow window { get; construct; }

public PluginsManager (Scratch.MainWindow _window) {
Object (window: _window);
}

construct {
plugin_iface = new Scratch.Services.Interface (this);
Expand Down