diff options
author | Christian Dywan <christian@twotoasts.de> | 2019-03-15 23:18:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-15 23:18:42 +0100 |
commit | afb13d522b6f06e7babc68ca3aa6acb57667ab24 (patch) | |
tree | 158e4b377f249d21a087f895ec9625b3c76cfa45 | |
parent | 7e7d4d8749674f75cc84d1150c7d91782c74c26d (diff) | |
download | midori-git-afb13d522b6f06e7babc68ca3aa6acb57667ab24.tar.gz |
Support for sidebar action WebExtension API (#297)
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
@@ -276,6 +276,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 987e221e..f12fdb6d 100644 --- a/core/browser.vala +++ b/core/browser.vala @@ -224,14 +224,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); @@ -391,6 +391,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) { @@ -419,6 +421,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; |