]> spindle.queued.net Git - midori/commitdiff
Implement middle click on array actions, ie. bookmark menu items
authorEnrico Tröger <enrico.troeger@uvena.de>
Sun, 3 May 2009 10:42:47 +0000 (12:42 +0200)
committerChristian Dywan <christian@twotoasts.de>
Sun, 3 May 2009 10:42:47 +0000 (12:42 +0200)
Add a new signal activate-item-alt to KatzeArrayAction which has
a button argument specifying the mouse button that was pressed. If
this signal is handled one can special case middle or right
clicks, and return TRUE to suppress the emission of activate-item.

The browser utilizes this to open new tabs when middle clicking
on bookmark menu items.

katze/katze-arrayaction.c
katze/marshal.list
midori/midori-browser.c

index 7d704b84d68c640871a1741bbb987dae6b3ddbab..0969c5d7677d15836c5fdb16bc62d80710596cf0 100644 (file)
@@ -1,5 +1,6 @@
 /*
  Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
+ Copyright (C) 2009 Enrico Tröger <enrico.troeger@uvena.de>
 
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
@@ -13,6 +14,7 @@
 
 #include "katze-net.h"
 #include "katze-utils.h"
+#include "marshal.h"
 
 #include <string.h>
 #include <glib/gi18n.h>
@@ -44,6 +46,7 @@ enum
 {
     POPULATE_POPUP,
     ACTIVATE_ITEM,
+    ACTIVATE_ITEM_ALT,
     LAST_SIGNAL
 };
 
@@ -107,6 +110,30 @@ katze_array_action_class_init (KatzeArrayActionClass* class)
                                        G_TYPE_NONE, 1,
                                        KATZE_TYPE_ITEM);
 
+    /**
+     * KatzeArrayAction::activate-item-alt:
+     * @array: the object on which the signal is emitted
+     * @item: the item being activated
+     * @button: the mouse button pressed
+     *
+     * An item was clicked with a particular button. Use this if you need
+     * to handle middle or right clicks specially.
+     *
+     * Return value: %TRUE if the event was handled. If %FALSE is returned,
+     *               the default "activate-item" signal is emitted.
+     *
+     * Since: 0.1.7
+     **/
+    signals[ACTIVATE_ITEM_ALT] = g_signal_new ("activate-item-alt",
+                                       G_TYPE_FROM_CLASS (class),
+                                       (GSignalFlags) (G_SIGNAL_RUN_LAST),
+                                       0,
+                                       0,
+                                       NULL,
+                                       katze_cclosure_marshal_BOOLEAN__OBJECT_UINT,
+                                       G_TYPE_BOOLEAN, 2,
+                                       KATZE_TYPE_ITEM, G_TYPE_UINT);
+
     gobject_class = G_OBJECT_CLASS (class);
     gobject_class->finalize = katze_array_action_finalize;
     gobject_class->set_property = katze_array_action_set_property;
@@ -205,12 +232,20 @@ katze_array_action_activate (GtkAction* action)
         GTK_ACTION_CLASS (katze_array_action_parent_class)->activate (action);
 }
 
-static void
-katze_array_action_menu_item_activate_cb (GtkWidget*        proxy,
-                                          KatzeArrayAction* array_action)
+static gboolean
+katze_array_action_menu_button_press_cb (GtkWidget*        proxy,
+                                         GdkEventButton*   event,
+                                         KatzeArrayAction* array_action)
 {
     KatzeItem* item = g_object_get_data (G_OBJECT (proxy), "KatzeItem");
-    g_signal_emit (array_action, signals[ACTIVATE_ITEM], 0, item);
+    gboolean handled;
+
+    g_signal_emit (array_action, signals[ACTIVATE_ITEM_ALT], 0, item, event->button, &handled);
+
+    if (!handled)
+        g_signal_emit (array_action, signals[ACTIVATE_ITEM], 0, item);
+
+    return TRUE;
 }
 
 static void
@@ -268,8 +303,10 @@ katze_array_action_generate_menu (KatzeArrayAction* array_action,
                 G_CALLBACK (katze_array_action_menu_item_select_cb), array_action);
         }
         else
-            g_signal_connect (menuitem, "activate",
-                G_CALLBACK (katze_array_action_menu_item_activate_cb), array_action);
+        {
+            g_signal_connect (menuitem, "button-press-event",
+                G_CALLBACK (katze_array_action_menu_button_press_cb), array_action);
+        }
         gtk_widget_show (menuitem);
     }
     if (!i)
index ce752891c8dcc64dca17e0835d6fb037e23dab45..f2d1b07cadaafc08b37dd09c7016acbe9811661b 100644 (file)
@@ -1 +1,2 @@
 VOID:POINTER,INT
+BOOLEAN:OBJECT,UINT
index 606fed52c16d636c7f090510165bc5694ecc60de..890ab773c68ee2cd0245e1b899de7bbba7ff3202 100644 (file)
@@ -2226,6 +2226,31 @@ _action_bookmarks_activate_item (GtkAction*     action,
     gtk_widget_grab_focus (midori_browser_get_current_tab (browser));
 }
 
+static gboolean
+_action_bookmarks_activate_item_alt (GtkAction*     action,
+                                     KatzeItem*     item,
+                                     guint          button,
+                                     MidoriBrowser* browser)
+{
+    if (button == 2)
+    {
+        gint n;
+        gboolean open_in_background;
+
+        g_object_get (browser->settings, "open-tabs-in-the-background",
+            &open_in_background, NULL);
+
+        n = midori_browser_add_uri (browser, katze_item_get_uri (item));
+
+        if (!open_in_background)
+            midori_browser_set_current_page (browser, n);
+
+        return TRUE;
+    }
+
+    return FALSE;
+}
+
 static void
 _action_window_populate_popup (GtkAction*     action,
                                GtkMenu*       menu,
@@ -4151,6 +4176,8 @@ midori_browser_init (MidoriBrowser* browser)
                       _action_bookmarks_populate_popup, browser,
                       "signal::activate-item",
                       _action_bookmarks_activate_item, browser,
+                      "signal::activate-item-alt",
+                      _action_bookmarks_activate_item_alt, browser,
                       NULL);
     gtk_action_group_add_action_with_accel (browser->action_group, action, "");
     g_object_unref (action);