From c76a468d1603e2d6b64101ecab46be24dfdd610a Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Sat, 27 Jun 2009 23:52:48 +0200 Subject: [PATCH] Refactor tab context menu into public midori_view_get_tab_menu --- midori/midori-view.c | 63 +++++++++++++++++++++++++++++--------------- midori/midori-view.h | 3 +++ 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/midori/midori-view.c b/midori/midori-view.c index fded8aa0..59fd4d83 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -2450,6 +2450,45 @@ midori_view_tab_label_menu_close_cb (GtkWidget* menuitem, gtk_widget_destroy (view); } +/** + * midori_view_get_tab_menu: + * @view: a #MidoriView + * + * Retrieves a menu that is typically shown when right-clicking + * a tab label or equivalent representation. + * + * Return value: a #GtkMenu + * + * Since: 0.1.8 + **/ +GtkWidget* +midori_view_get_tab_menu (MidoriView* view) +{ + GtkWidget* menu; + GtkWidget* menuitem; + + g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL); + + menu = gtk_menu_new (); + menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_OPEN, NULL); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); + g_signal_connect (menuitem, "activate", + G_CALLBACK (midori_view_tab_label_menu_open_cb), view); + menuitem = gtk_image_menu_item_new_from_stock (STOCK_WINDOW_NEW, NULL); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); + g_signal_connect (menuitem, "activate", + G_CALLBACK (midori_view_tab_label_menu_window_new_cb), view); + menuitem = gtk_separator_menu_item_new (); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); + menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLOSE, NULL); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); + g_signal_connect (menuitem, "activate", + G_CALLBACK (midori_view_tab_label_menu_close_cb), view); + gtk_widget_show_all (menu); + + return menu; +} + static gboolean midori_view_tab_label_button_release_event (GtkWidget* tab_label, GdkEventButton* event, @@ -2464,28 +2503,10 @@ midori_view_tab_label_button_release_event (GtkWidget* tab_label, else if (event->button == 3) { /* Show a context menu on right click */ - GtkWidget* menu; - GtkWidget* menuitem; + GtkWidget* menu = midori_view_get_tab_menu (MIDORI_VIEW (widget)); - menu = gtk_menu_new (); - menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_OPEN, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); - g_signal_connect (menuitem, "activate", - G_CALLBACK (midori_view_tab_label_menu_open_cb), widget); - menuitem = gtk_image_menu_item_new_from_stock (STOCK_WINDOW_NEW, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); - g_signal_connect (menuitem, "activate", - G_CALLBACK (midori_view_tab_label_menu_window_new_cb), widget); - menuitem = gtk_separator_menu_item_new (); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); - menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLOSE, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); - g_signal_connect (menuitem, "activate", - G_CALLBACK (midori_view_tab_label_menu_close_cb), widget); - gtk_widget_show_all (menu); - - sokoke_widget_popup (widget, GTK_MENU (menu), - event, SOKOKE_MENU_POSITION_CURSOR); + katze_widget_popup (widget, GTK_MENU (menu), + event, SOKOKE_MENU_POSITION_CURSOR); return TRUE; } diff --git a/midori/midori-view.h b/midori/midori-view.h index 74fa2834..017499a6 100644 --- a/midori/midori-view.h +++ b/midori/midori-view.h @@ -113,6 +113,9 @@ midori_view_can_paste_clipboard (MidoriView* view); GtkWidget* midori_view_get_proxy_menu_item (MidoriView* view); +GtkWidget* +midori_view_get_tab_menu (MidoriView* view); + GtkWidget* midori_view_get_proxy_tab_label (MidoriView* view);