From ae23ae058333bcbcc8a9f94105969c48dfdae62b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Sun, 3 May 2009 12:42:47 +0200 Subject: [PATCH] Implement middle click on array actions, ie. bookmark menu items 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 | 49 ++++++++++++++++++++++++++++++++++----- katze/marshal.list | 1 + midori/midori-browser.c | 27 +++++++++++++++++++++ 3 files changed, 71 insertions(+), 6 deletions(-) diff --git a/katze/katze-arrayaction.c b/katze/katze-arrayaction.c index 7d704b84..0969c5d7 100644 --- a/katze/katze-arrayaction.c +++ b/katze/katze-arrayaction.c @@ -1,5 +1,6 @@ /* Copyright (C) 2008 Christian Dywan + Copyright (C) 2009 Enrico Tröger 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 #include @@ -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) diff --git a/katze/marshal.list b/katze/marshal.list index ce752891..f2d1b07c 100644 --- a/katze/marshal.list +++ b/katze/marshal.list @@ -1 +1,2 @@ VOID:POINTER,INT +BOOLEAN:OBJECT,UINT diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 606fed52..890ab773 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -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);