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.
This commit is contained in:
Enrico Tröger 2009-05-03 12:42:47 +02:00 committed by Christian Dywan
parent dfef979499
commit ae23ae0583
3 changed files with 71 additions and 6 deletions

View file

@ -1,5 +1,6 @@
/* /*
Copyright (C) 2008 Christian Dywan <christian@twotoasts.de> 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 This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
@ -13,6 +14,7 @@
#include "katze-net.h" #include "katze-net.h"
#include "katze-utils.h" #include "katze-utils.h"
#include "marshal.h"
#include <string.h> #include <string.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
@ -44,6 +46,7 @@ enum
{ {
POPULATE_POPUP, POPULATE_POPUP,
ACTIVATE_ITEM, ACTIVATE_ITEM,
ACTIVATE_ITEM_ALT,
LAST_SIGNAL LAST_SIGNAL
}; };
@ -107,6 +110,30 @@ katze_array_action_class_init (KatzeArrayActionClass* class)
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
KATZE_TYPE_ITEM); 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 = G_OBJECT_CLASS (class);
gobject_class->finalize = katze_array_action_finalize; gobject_class->finalize = katze_array_action_finalize;
gobject_class->set_property = katze_array_action_set_property; 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); GTK_ACTION_CLASS (katze_array_action_parent_class)->activate (action);
} }
static void static gboolean
katze_array_action_menu_item_activate_cb (GtkWidget* proxy, katze_array_action_menu_button_press_cb (GtkWidget* proxy,
KatzeArrayAction* array_action) GdkEventButton* event,
KatzeArrayAction* array_action)
{ {
KatzeItem* item = g_object_get_data (G_OBJECT (proxy), "KatzeItem"); 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 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); G_CALLBACK (katze_array_action_menu_item_select_cb), array_action);
} }
else 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); gtk_widget_show (menuitem);
} }
if (!i) if (!i)

View file

@ -1 +1,2 @@
VOID:POINTER,INT VOID:POINTER,INT
BOOLEAN:OBJECT,UINT

View file

@ -2226,6 +2226,31 @@ _action_bookmarks_activate_item (GtkAction* action,
gtk_widget_grab_focus (midori_browser_get_current_tab (browser)); 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 static void
_action_window_populate_popup (GtkAction* action, _action_window_populate_popup (GtkAction* action,
GtkMenu* menu, GtkMenu* menu,
@ -4151,6 +4176,8 @@ midori_browser_init (MidoriBrowser* browser)
_action_bookmarks_populate_popup, browser, _action_bookmarks_populate_popup, browser,
"signal::activate-item", "signal::activate-item",
_action_bookmarks_activate_item, browser, _action_bookmarks_activate_item, browser,
"signal::activate-item-alt",
_action_bookmarks_activate_item_alt, browser,
NULL); NULL);
gtk_action_group_add_action_with_accel (browser->action_group, action, ""); gtk_action_group_add_action_with_accel (browser->action_group, action, "");
g_object_unref (action); g_object_unref (action);