diff options
author | Christiam Dywan <christian@twotoasts.de> | 2019-03-06 02:32:02 +0100 |
---|---|---|
committer | Christiam Dywan <christian@twotoasts.de> | 2019-03-06 02:32:02 +0100 |
commit | bd9d7897b408cef9e0c292c5d8335d91a3eb55e0 (patch) | |
tree | 43d4354183bdc824a12e0a1b763bbfaf52190669 | |
parent | cebfef08c3be5a041890245ee0af11f1f3d41a77 (diff) | |
download | midori-git-web_extensions_sidebar_action.tar.gz |
Support for sidebar action WebExtension APIweb_extensions_sidebar_action
Analoguous to browser actions a sidebar action defines a page
to be displayed in the panel.
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | core/browser.vala | 20 | ||||
-rw-r--r-- | extensions/web-extensions.vala | 20 |
3 files changed, 39 insertions, 5 deletions
@@ -272,6 +272,10 @@ The following API specification is supported by Midori: default_popup: *.html default_icon: *.png default_title + sidebar_action: + default_panel: *.html + default_icon: *.png + default_title content_scripts: js: - *.js diff --git a/core/browser.vala b/core/browser.vala index f0c4e254..5d2d9a52 100644 --- a/core/browser.vala +++ b/core/browser.vala @@ -220,14 +220,14 @@ namespace Midori { fullscreen.activate.connect (fullscreen_activated); add_action (fullscreen); // Action for panel toggling - action = new SimpleAction.stateful ("panel", null, false); - action.set_enabled (false); - action.change_state.connect (panel_activated); - add_action (action); + var panel_action = new SimpleAction.stateful ("panel", null, false); + panel_action.set_enabled (false); + panel_action.change_state.connect (panel_activated); + add_action (panel_action); // Reveal panel toggle after panels are added panel.add.connect ((widget) => { panel_toggle.show (); - action.set_enabled (true); + panel_action.set_enabled (true); }); // Page actions var go_back = new SimpleAction ("go-back", null); @@ -384,6 +384,8 @@ namespace Midori { } else { tabbar.decoration_layout = null; } + ((Gtk.Container)tabbar.parent).child_set_property (tabbar, "shrink", !panel.visible); + ((Gtk.Container)navigationbar.parent.parent).child_set_property (navigationbar.parent, "shrink", panel.visible); } public override bool configure_event (Gdk.EventConfigure event) { @@ -412,6 +414,14 @@ namespace Midori { } /* + * Add a panel to be displayed in the sidebar. + */ + public void add_panel (Gtk.Widget widget) { + panel.add_named (widget, "%p".printf (widget)); + panel.visible_child = widget; + } + + /* * Requests a default tab to be added to an otherwise empty window. * * Connect, adding one or more windows, and return true to override. diff --git a/extensions/web-extensions.vala b/extensions/web-extensions.vala index 67ff9c79..3fc06b49 100644 --- a/extensions/web-extensions.vala +++ b/extensions/web-extensions.vala @@ -21,6 +21,7 @@ namespace WebExtension { public List<string> content_scripts { get; owned set; } public List<string> content_styles { get; owned set; } public Action? browser_action { get; set; } + public Action? sidebar { get; set; } public Extension (File file) { Object (file: file, name: file.get_basename ()); @@ -192,6 +193,16 @@ namespace WebExtension { } } + if (manifest.has_member ("sidebar_action")) { + var sidebar = manifest.has_member ("sidebar_action") ? manifest.get_object_member ("sidebar_action") : null; + if (sidebar != null) { + extension.sidebar = new Action ( + pick_default_icon (sidebar), + sidebar.has_member ("default_title") ? sidebar.get_string_member ("default_title") : null, + sidebar.has_member ("default_panel") ? sidebar.get_string_member ("default_panel") : null); + } + } + if (manifest.has_member ("content_scripts")) { foreach (var element in manifest.get_array_member ("content_scripts").get_elements ()) { var content_script = element.get_object (); @@ -423,6 +434,15 @@ namespace WebExtension { browser.add_button (new Button (extension as Extension)); } + if (extension.sidebar != null) { + var scrolled = new Gtk.ScrolledWindow (null, null); + var web_view = new WebView (extension, extension.browser_action.popup); + scrolled.show (); + scrolled.add (web_view); + browser.add_panel (scrolled); + scrolled.parent.child_set (scrolled, "title", extension.sidebar.title); + } + // Employ a delay to avoid delaying startup with many extensions uint src = Timeout.add (500, install_extension.callback); yield; |