]> spindle.queued.net Git - midori/commitdiff
Provide midori_browser_(un)block_action for extensions
authorChristian Dywan <christian@twotoasts.de>
Sat, 30 Apr 2011 10:17:55 +0000 (12:17 +0200)
committerChristian Dywan <christian@twotoasts.de>
Sat, 30 Apr 2011 10:17:55 +0000 (12:17 +0200)
So extensions can override individual actions without hacks.

midori/midori-browser.c
midori/midori-browser.h
midori/midori.vapi

index 87905cd7646e2cc044d846e700fbf27424aefbac..98c7c13e94e70636b1c5c8616d2e17fd4531a06c 100644 (file)
@@ -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
index 2b07dd0577e66a275aa54a59b3be5e1f40de0d03..a3cc979dcf2061d05cf8c6600e9541163a35c701 100644 (file)
@@ -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,
index cadda5594781423fc54d6fbce5ff77d2baca78ed..4e2098d1778b14145d76fdfb4151a5d1ff0e3fee 100644 (file)
@@ -39,6 +39,8 @@ namespace Midori {
         public int add_uri (string uri);
         public unowned View get_nth_tab (int n);
         public GLib.List<weak View> 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 ();