From e4d85cc76bedf4d4a39453095f2ed9a97ce398ff Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 2 Jul 2004 09:40:09 +0000 Subject: Implement topic context menu. 2004-07-02 Marco Pesenti Gritti * src/bookmarks/ephy-topic-action.c: (remove_activate_cb), (add_open_in_tabs_menu), (build_bookmarks_menu), (show_context_menu), (button_press_cb), (connect_proxy): Implement topic context menu. --- ChangeLog | 8 ++++ src/bookmarks/ephy-topic-action.c | 84 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 86 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1af2bda98..566e6af1b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-07-02 Marco Pesenti Gritti + + * src/bookmarks/ephy-topic-action.c: (remove_activate_cb), + (add_open_in_tabs_menu), (build_bookmarks_menu), + (show_context_menu), (button_press_cb), (connect_proxy): + + Implement topic context menu. + 2004-07-02 Marco Pesenti Gritti * src/bookmarks/ephy-favorites-menu.c: diff --git a/src/bookmarks/ephy-topic-action.c b/src/bookmarks/ephy-topic-action.c index 76503124a..436b1f5ca 100644 --- a/src/bookmarks/ephy-topic-action.c +++ b/src/bookmarks/ephy-topic-action.c @@ -29,6 +29,7 @@ #include "ephy-topic-action.h" #include "ephy-node-common.h" #include "ephy-bookmarks.h" +#include "ephy-bookmarksbar.h" #include "ephy-favicon-cache.h" #include "ephy-shell.h" #include "ephy-debug.h" @@ -338,6 +339,41 @@ open_in_tabs_activate_cb (GtkWidget *menu, EphyTopicAction *action) g_list_free (uri_list); } +static void +remove_activate_cb (GtkWidget *menu, GtkWidget *proxy) +{ + EphyBookmarks *bookmarks; + EggToolbarsModel *model; + GtkWidget *item, *toolbar; + int pos; + + item = gtk_widget_get_ancestor (proxy, GTK_TYPE_TOOL_ITEM); + g_return_if_fail (item != NULL); + + toolbar = gtk_widget_get_ancestor (proxy, GTK_TYPE_TOOLBAR); + g_return_if_fail (toolbar != NULL); + + pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (toolbar), + GTK_TOOL_ITEM (item)); + + bookmarks = ephy_shell_get_bookmarks (ephy_shell); + model = ephy_bookmarks_get_toolbars_model (bookmarks); + egg_toolbars_model_remove_item (model, 0, pos); +} + +static void +add_open_in_tabs_menu (EphyTopicAction *action, GtkWidget *menu) +{ + GtkWidget *item; + + item = gtk_menu_item_new_with_mnemonic (_("_Open in Tabs")); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + + g_signal_connect (item, "activate", + G_CALLBACK (open_in_tabs_activate_cb), action); +} + static GtkWidget * build_bookmarks_menu (EphyTopicAction *action, EphyNode *node) { @@ -356,12 +392,7 @@ build_bookmarks_menu (EphyTopicAction *action, EphyNode *node) gtk_widget_show (item); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - item = gtk_menu_item_new_with_mnemonic (_("_Open in Tabs")); - gtk_widget_show (item); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - - g_signal_connect (item, "activate", - G_CALLBACK (open_in_tabs_activate_cb), action); + add_open_in_tabs_menu (action, menu); } return menu; @@ -530,6 +561,44 @@ create_menu_item (GtkAction *action) return menu_item; } +static void +show_context_menu (EphyTopicAction *action, GtkWidget *proxy) +{ + GtkWidget *menu, *item; + + menu = gtk_menu_new (); + + add_open_in_tabs_menu (action, menu); + + item = gtk_separator_menu_item_new (); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + + item = gtk_image_menu_item_new_from_stock (GTK_STOCK_REMOVE, NULL); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + g_signal_connect (item, "activate", + G_CALLBACK (remove_activate_cb), proxy); + + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 3, + gtk_get_current_event_time ()); +} + +static gboolean +button_press_cb (GtkWidget *widget, + GdkEventButton *event, + EphyTopicAction *action) +{ + if (event->button == 3 && + gtk_widget_get_ancestor (widget, EPHY_TYPE_BOOKMARKSBAR)) + { + show_context_menu (action, widget); + return TRUE; + } + + return FALSE; +} + static void connect_proxy (GtkAction *action, GtkWidget *proxy) { @@ -549,6 +618,9 @@ connect_proxy (GtkAction *action, GtkWidget *proxy) g_signal_connect (button, "toggled", G_CALLBACK (button_toggled_cb), action); + g_signal_connect (button, "button-press-event", + G_CALLBACK (button_press_cb), action); + /* We want the menu to popup up on mouse down */ g_signal_connect (button, "pressed", G_CALLBACK (button_pressed_cb), action); -- cgit