From 34da7c80909ab3195b526c2ecb50f649e41ab01e Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Sat, 30 Apr 2011 12:17:55 +0200 Subject: [PATCH] Provide midori_browser_(un)block_action for extensions So extensions can override individual actions without hacks. --- midori/midori-browser.c | 63 +++++++++++++++++++++++++++++++++++++++++ midori/midori-browser.h | 8 ++++++ midori/midori.vapi | 2 ++ 3 files changed, 73 insertions(+) diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 87905cd7..98c7c13e 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -7057,6 +7057,69 @@ midori_browser_set_action_visible (MidoriBrowser* browser, _action_set_sensitive (browser, name, visible); } +/** + * midori_browser_block_action: + * @browser: a #MidoriBrowser + * @name: the action to be blocked + * + * Blocks built-in behavior of the specified action without + * disabling it, which gives you a chance to connect your + * own signal handling. + * Call midori_browser_unblock_action() to undo the effect. + * + * Since: 0.3.4 + **/ +void +midori_browser_block_action (MidoriBrowser* browser, + GtkAction* action) +{ + const gchar* name; + guint i; + + g_return_if_fail (MIDORI_IS_BROWSER (browser)); + g_return_if_fail (GTK_IS_ACTION (action)); + + name = gtk_action_get_name (action); + for (i = 0; i < entries_n; i++) + if (g_str_equal (entries[i].name, name)) + { + g_signal_handlers_block_by_func (action, entries[i].callback, browser); + return; + } + g_critical ("%s: Action \"%s\" can't be blocked.", G_STRFUNC, name); +} + +/** + * midori_browser_unblock_action: + * @browser: a #MidoriBrowser + * @name: the action to be unblocked + * + * Restores built-in behavior of the specified action after + * previously blocking it with midori_browser_block_action(). + * + * Since: 0.3.4 + **/ +void +midori_browser_unblock_action (MidoriBrowser* browser, + GtkAction* action) +{ + const gchar* name; + guint i; + + g_return_if_fail (MIDORI_IS_BROWSER (browser)); + g_return_if_fail (GTK_IS_ACTION (action)); + + name = gtk_action_get_name (action); + for (i = 0; i < entries_n; i++) + if (g_str_equal (entries[i].name, name)) + { + g_signal_handlers_unblock_by_func (action, entries[i].callback, browser); + return; + } + g_critical ("%s: Action \"%s\" can't be unblocked.", G_STRFUNC, name); +} + + /** * midori_browser_get_action_group: * @browser: a #MidoriBrowser diff --git a/midori/midori-browser.h b/midori/midori-browser.h index 2b07dd05..a3cc979d 100644 --- a/midori/midori-browser.h +++ b/midori/midori-browser.h @@ -106,6 +106,14 @@ void midori_browser_activate_action (MidoriBrowser* browser, const gchar* name); +void +midori_browser_block_action (MidoriBrowser* browser, + GtkAction* action); + +void +midori_browser_unblock_action (MidoriBrowser* browser, + GtkAction* action); + void midori_browser_set_action_visible (MidoriBrowser* browser, const gchar* name, diff --git a/midori/midori.vapi b/midori/midori.vapi index cadda559..4e2098d1 100644 --- a/midori/midori.vapi +++ b/midori/midori.vapi @@ -39,6 +39,8 @@ namespace Midori { public int add_uri (string uri); public unowned View get_nth_tab (int n); public GLib.List get_tabs (); + public void block_action (Gtk.Action action); + public void unblock_action (Gtk.Action action); public unowned Gtk.ActionGroup get_action_group (); public unowned Browser get_for_widget (Gtk.Widget widget); public unowned string[] get_toolbar_actions ();