From 40dafa4179a4349c73c2acce6330970698159767 Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Wed, 5 Jan 2005 20:58:45 +0000 Subject: Add context menu on notebook. Fixes bug #132989. 2005-01-05 Christian Persch * data/ui/epiphany-ui.xml: * src/ephy-notebook.c: (button_press_cb): * src/ephy-window.c: (show_notebook_popup_menu), (notebook_button_press_cb), (notebook_popup_menu_cb), (setup_notebook): Add context menu on notebook. Fixes bug #132989. --- ChangeLog | 10 ++++++++ data/ui/epiphany-ui.xml | 10 +++++++- src/ephy-notebook.c | 15 ++++++++++++ src/ephy-window.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 97 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6157b60db..44731fea0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-01-05 Christian Persch + + * data/ui/epiphany-ui.xml: + * src/ephy-notebook.c: (button_press_cb): + * src/ephy-window.c: (show_notebook_popup_menu), + (notebook_button_press_cb), (notebook_popup_menu_cb), + (setup_notebook): + + Add context menu on notebook. Fixes bug #132989. + 2005-01-05 Christian Persch * data/Makefile.am: diff --git a/data/ui/epiphany-ui.xml b/data/ui/epiphany-ui.xml index 52aa5ccc9..788e088c7 100644 --- a/data/ui/epiphany-ui.xml +++ b/data/ui/epiphany-ui.xml @@ -13,7 +13,7 @@ - + @@ -181,6 +181,14 @@ + + + + + + + + diff --git a/src/ephy-notebook.c b/src/ephy-notebook.c index 893880f13..48d8856ef 100644 --- a/src/ephy-notebook.c +++ b/src/ephy-notebook.c @@ -549,6 +549,21 @@ button_press_cb (EphyNotebook *notebook, "motion-notify-event", G_CALLBACK (motion_notify_cb), NULL); } + else if (GDK_BUTTON_PRESS == event->type && 3 == event->button) + { + if (tab_clicked == -1) + { + /* consume event, so that we don't pop up the context menu when + * the mouse if not over a tab label + */ + return TRUE; + } + else + { + /* switch to the page the mouse is over, but don't consume the event */ + gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), tab_clicked); + } + } return FALSE; } diff --git a/src/ephy-window.c b/src/ephy-window.c index 9b5ab4f69..323637ddb 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -130,8 +130,8 @@ static GtkActionEntry ephy_menu_entries [] = { { "FileSendTo", STOCK_SEND_MAIL, N_("S_end To..."), "M", N_("Send a link of the current page"), G_CALLBACK (window_cmd_file_send_to) }, - { "FileCloseWindow", GTK_STOCK_CLOSE, N_("_Close"), "W", - N_("Close this window"), + { "FileCloseTab", GTK_STOCK_CLOSE, N_("_Close"), "W", + N_("Close this tab"), G_CALLBACK (window_cmd_file_close_window) }, /* Edit menu */ @@ -2046,6 +2046,62 @@ modal_alert_cb (EphyEmbed *embed, return FALSE; } +static gboolean +show_notebook_popup_menu (GtkNotebook *notebook, + EphyWindow *window, + GdkEventButton *event) +{ + GtkWidget *menu, *tab, *tab_label; + + menu = gtk_ui_manager_get_widget (window->priv->manager, "/EphyNotebookPopup"); + g_return_val_if_fail (menu != NULL, FALSE); + + if (event != NULL) + { + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, + NULL, NULL, + event->button, event->time); + } + else + { + tab = GTK_WIDGET (ephy_window_get_active_tab (window)); + tab_label = gtk_notebook_get_tab_label (notebook, tab); + + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, + ephy_gui_menu_position_under_widget, tab_label, + 0, gtk_get_current_event_time ()); + gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE); + } + + return TRUE; +} + +static gboolean +notebook_button_press_cb (GtkNotebook *notebook, + GdkEventButton *event, + EphyWindow *window) +{ + if (GDK_BUTTON_PRESS == event->type && 3 == event->button) + { + return show_notebook_popup_menu (notebook, window, event); + } + + return FALSE; +} + +static gboolean +notebook_popup_menu_cb (GtkNotebook *notebook, + EphyWindow *window) +{ + /* Only respond if the notebook is the actual focus */ + if (EPHY_IS_NOTEBOOK (gtk_window_get_focus (GTK_WINDOW (window)))) + { + return show_notebook_popup_menu (notebook, window, NULL); + } + + return FALSE; +} + static void tab_added_cb (EphyNotebook *notebook, EphyTab *tab, @@ -2165,6 +2221,11 @@ setup_notebook (EphyWindow *window) ephy_window_notebook_switch_page_cb), window); + g_signal_connect (notebook, "popup-menu", + G_CALLBACK (notebook_popup_menu_cb), window); + g_signal_connect (notebook, "button-press-event", + G_CALLBACK(notebook_button_press_cb), window); + g_signal_connect (G_OBJECT (notebook), "tab_added", G_CALLBACK (tab_added_cb), window); g_signal_connect (G_OBJECT (notebook), "tab_removed", -- cgit v1.2.3