summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Dywan <christian@twotoasts.de>2018-10-19 14:00:23 +0200
committerGitHub <noreply@github.com>2018-10-19 14:00:23 +0200
commit5fedca68e8821b7e497d47a14d02902895665369 (patch)
tree6c6dd9018f373873a264a96dbb11d62d8e3fa66e
parent8aed3a418ec668d1ff2be8edbf103d57aaeaa8e9 (diff)
downloadmidori-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)
-rw-r--r--core/browser.vala12
-rw-r--r--core/settings.vala10
-rw-r--r--core/statusbar.vala21
-rw-r--r--data/gtk3.css3
-rw-r--r--extensions/statusbar-features.plugin.in6
-rw-r--r--extensions/statusbar-features.vala58
-rw-r--r--po/POTFILES.in2
7 files changed, 101 insertions, 11 deletions
diff --git a/core/browser.vala b/core/browser.vala
index 9db122f8..74bee1f6 100644
--- a/core/browser.vala
+++ b/core/browser.vala
@@ -72,7 +72,7 @@ namespace Midori {
[GtkChild]
public Gtk.Overlay overlay;
[GtkChild]
- Statusbar statusbar;
+ public Statusbar statusbar;
[GtkChild]
Gtk.SearchBar search;
[GtkChild]
@@ -88,9 +88,12 @@ namespace Midori {
navigationbar.show ();
navigationbar.urlbar.grab_focus ();
}
- statusbar.hide ();
- statusbar.halign = statusbar.halign == Gtk.Align.START ? Gtk.Align.END : Gtk.Align.START;
- statusbar.show ();
+ if (!statusbar.has_children) {
+ statusbar.hide ();
+ // Flip overlay to evade the mouse pointer
+ statusbar.halign = statusbar.halign == Gtk.Align.START ? Gtk.Align.END : Gtk.Align.START;
+ statusbar.show ();
+ }
return false;
});
navigationbar.urlbar.focus_out_event.connect ((event) => {
@@ -141,6 +144,7 @@ namespace Midori {
// Plug only after the app is connected and everything is setup
var extensions = Plugins.get_default ().plug<BrowserActivatable> ("browser", this);
extensions.extension_added.connect ((info, extension) => ((BrowserActivatable)extension).activate ());
+ extensions.extension_removed.connect ((info, extension) => ((BrowserActivatable)extension).deactivate ());
extensions.foreach ((extensions, info, extension) => { extensions.extension_added (info, extension); });
});
diff --git a/core/settings.vala b/core/settings.vala
index 6875a3c2..85d658f6 100644
--- a/core/settings.vala
+++ b/core/settings.vala
@@ -39,11 +39,21 @@ namespace Midori {
} set {
set_boolean ("settings", "enable-spell-checking", value, true);
} }
+ public bool auto_load_images { get {
+ return get_boolean ("settings", "auto-load-images", true);
+ } set {
+ set_boolean ("settings", "auto-load-images", value, true);
+ } }
public bool enable_javascript { get {
return get_boolean ("settings", "enable-javascript", true);
} set {
set_boolean ("settings", "enable-javascript", value, true);
} }
+ public bool enable_plugins { get {
+ return get_boolean ("settings", "enable-plugins", true);
+ } set {
+ set_boolean ("settings", "enable-plugins", value, true);
+ } }
public bool close_buttons_on_tabs { get {
return get_boolean ("settings", "close-buttons-on-tabs", true);
diff --git a/core/statusbar.vala b/core/statusbar.vala
index 954adee7..797574d8 100644
--- a/core/statusbar.vala
+++ b/core/statusbar.vala
@@ -11,16 +11,23 @@
namespace Midori {
public class Statusbar : Gtk.Statusbar {
+ internal bool has_children = false;
+
string? _label = null;
public string? label { get { return _label; } set {
- if (value != null && value != "") {
- _label = value;
- show ();
- } else {
- _label = "";
- hide ();
- }
+ _label = value ?? "";
+ visible = has_children || label != "";
push (1, _label);
} }
+
+
+ construct {
+ // Persistent statusbar mode with child widgets
+ add.connect ((widget) => { has_children = true; show (); });
+ ((Gtk.Box)this).remove.connect ((widget) => {
+ has_children = get_children ().length () > 0;
+ visible = !has_children && label != null && label != "";
+ });
+ }
}
}
diff --git a/data/gtk3.css b/data/gtk3.css
index 1d7de89d..c082ffcb 100644
--- a/data/gtk3.css
+++ b/data/gtk3.css
@@ -39,4 +39,7 @@
.incognito .split_headerbar * {
background: transparent;
color: #eee;
+statusbar button {
+ margin: 4px;
+ padding: 0 4px;
}
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));
+}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index de4dfe2e..d757ffe4 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -28,6 +28,8 @@ extensions/bookmarks.plugin.in
extensions/bookmarks.vala
extensions/status-clock.plugin.in
extensions/status-clock.vala
+extensions/statusbar-features.in
+extensions/statusbar-features.vala
ui/bookmarks-button.ui
ui/browser.ui
ui/clear-private-data.ui