diff options
author | Christian Dywan <christian@twotoasts.de> | 2018-10-19 14:00:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-19 14:00:23 +0200 |
commit | 5fedca68e8821b7e497d47a14d02902895665369 (patch) | |
tree | 6c6dd9018f373873a264a96dbb11d62d8e3fa66e /extensions | |
parent | 8aed3a418ec668d1ff2be8edbf103d57aaeaa8e9 (diff) | |
download | midori-git-5fedca68e8821b7e497d47a14d02902895665369.tar.gz |
Port Statusbar Features to Peas API (#106)
Statusbar Features are buttons providing quick access to oft-used settings, readily available in the statusbar. Traditionally only usable with a persistent statusbar the overlay automatically switches to a hybrid mode where the buttons remain accessible regardless of the main text.
![screenshot from 2018-10-19 00-58-24](https://user-images.githubusercontent.com/1204189/47191349-0718ba80-d347-11e8-86eb-2c8d7b7743fd.png)
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/statusbar-features.plugin.in | 6 | ||||
-rw-r--r-- | extensions/statusbar-features.vala | 58 |
2 files changed, 64 insertions, 0 deletions
diff --git a/extensions/statusbar-features.plugin.in b/extensions/statusbar-features.plugin.in new file mode 100644 index 00000000..92a15338 --- /dev/null +++ b/extensions/statusbar-features.plugin.in @@ -0,0 +1,6 @@ +[Plugin] +Module=statusbar-features +IAge=3 +Icon=checkbox-checked-symbolic +_Name=Statusbar Features +_Description=Easily toggle features on web pages on and off diff --git a/extensions/statusbar-features.vala b/extensions/statusbar-features.vala new file mode 100644 index 00000000..bdbdad49 --- /dev/null +++ b/extensions/statusbar-features.vala @@ -0,0 +1,58 @@ +/* + Copyright (C) 2008-2018 Christian Dywan <christian@twotoasts.de> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + See the file COPYING for the full license text. +*/ + +namespace StatusbarFeatures { + public class Frontend : Object, Midori.BrowserActivatable { + public Midori.Browser browser { owned get; set; } + + void add_toggle (string item, string? icon_name=null, string? tooltip=null) { + var button = new Gtk.ToggleButton (); + if (icon_name != null) { + button.add (new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.BUTTON)); + } else { + button.label = item; + } + button.tooltip_text = tooltip; + var settings = Midori.CoreSettings.get_default (); + if (settings.get_class ().find_property (item) != null) { + settings.bind_property (item, button, "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); + } else { + button.sensitive = false; + } + button.show_all (); + deactivate.connect (() => { + button.destroy (); + }); + browser.statusbar.add (button); + } + + public void activate () { + string items = "auto-load-images;enable-javascript;enable-plugins"; + foreach (string item in items.split (";")) { + if (item == "enable-javascript") { + add_toggle (item, "text-x-script", _("Enable scripts")); + } else if (item == "auto-load-images") { + add_toggle (item, "image-x-generic", _("Load images automatically")); + } else if (item == "enable-plugins") { + add_toggle (item, "libpeas-plugin", _("Enable Netscape plugins")); + } else { + add_toggle (item); + } + } + } + } +} + +[ModuleInit] +public void peas_register_types(TypeModule module) { + ((Peas.ObjectModule)module).register_extension_type ( + typeof (Midori.BrowserActivatable), typeof (StatusbarFeatures.Frontend)); +} |