diff options
-rw-r--r-- | src/ephy-window.c | 10 | ||||
-rw-r--r-- | src/resources/gtk/notebook-context-menu.ui | 16 | ||||
-rw-r--r-- | src/window-commands.c | 56 | ||||
-rw-r--r-- | src/window-commands.h | 8 |
4 files changed, 76 insertions, 14 deletions
diff --git a/src/ephy-window.c b/src/ephy-window.c index d8d0e5b99..add022ea9 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -768,11 +768,11 @@ static const GActionEntry window_entries [] = static const GActionEntry tab_entries [] = { { "previous", window_cmd_tabs_previous }, { "next", window_cmd_tabs_next }, - { "move-left", window_cmd_tabs_move_left }, - { "move-right", window_cmd_tabs_move_right }, { "duplicate", window_cmd_tabs_duplicate }, { "detach", window_cmd_tabs_detach }, { "close", window_cmd_tabs_close }, + { "close-left", window_cmd_tabs_close_left }, + { "close-right", window_cmd_tabs_close_right }, { "close-others", window_cmd_tabs_close_others } }; @@ -2402,13 +2402,13 @@ show_notebook_popup_menu (GtkNotebook *notebook, n_pages = gtk_notebook_get_n_pages (notebook); page_num = gtk_notebook_page_num (notebook, tab); - /* enable/disable move left/right items*/ + /* enable/disable close others/left/right */ action = g_action_map_lookup_action (G_ACTION_MAP (action_group), - "move-left"); + "close-left"); g_simple_action_set_enabled (G_SIMPLE_ACTION (action), page_num > 0); action = g_action_map_lookup_action (G_ACTION_MAP (action_group), - "move-right"); + "close-right"); g_simple_action_set_enabled (G_SIMPLE_ACTION (action), page_num < n_pages - 1); action = g_action_map_lookup_action (G_ACTION_MAP (action_group), diff --git a/src/resources/gtk/notebook-context-menu.ui b/src/resources/gtk/notebook-context-menu.ui index b6255bfd7..3c79791bd 100644 --- a/src/resources/gtk/notebook-context-menu.ui +++ b/src/resources/gtk/notebook-context-menu.ui @@ -4,14 +4,6 @@ <menu id="notebook-menu"> <section> <item> - <attribute name="label" translatable="yes">Move Tab _Left</attribute> - <attribute name="action">tab.move-left</attribute> - </item> - <item> - <attribute name="label" translatable="yes">Move Tab _Right</attribute> - <attribute name="action">tab.move-right</attribute> - </item> - <item> <attribute name="label" translatable="yes">Du_plicate</attribute> <attribute name="action">tab.duplicate</attribute> </item> @@ -20,6 +12,14 @@ <attribute name="action">tab.close</attribute> </item> <item> + <attribute name="label" translatable="yes">Close Tabs to the _Left</attribute> + <attribute name="action">tab.close-left</attribute> + </item> + <item> + <attribute name="label" translatable="yes">Close Tabs to the _Right</attribute> + <attribute name="action">tab.close-right</attribute> + </item> + <item> <attribute name="label" translatable="yes">Close _Other Tabs</attribute> <attribute name="action">tab.close-others</attribute> </item> diff --git a/src/window-commands.c b/src/window-commands.c index 82906d361..177af0924 100644 --- a/src/window-commands.c +++ b/src/window-commands.c @@ -2359,6 +2359,62 @@ window_cmd_tabs_close (GSimpleAction *action, } void +window_cmd_tabs_close_left (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + EphyWindow *window = user_data; + GtkWidget *notebook; + EphyEmbed *embed; + int n_pages, current_page_no; + GSList *pages_to_close = NULL; + + notebook = ephy_window_get_notebook (window); + n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)); + current_page_no = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook)); + + for (int i = 0; i < current_page_no; i++) { + embed = EPHY_EMBED (gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), i)); + pages_to_close = g_slist_prepend (pages_to_close, embed); + } + + for (GSList *l = pages_to_close; l != NULL; l = l->next) { + g_assert (l->data != NULL); + g_signal_emit_by_name (GTK_NOTEBOOK (notebook), "tab-close-request", l->data); + } + + g_slist_free (pages_to_close); +} + +void +window_cmd_tabs_close_right (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + EphyWindow *window = user_data; + GtkWidget *notebook; + EphyEmbed *embed; + int n_pages, current_page_no; + GSList *pages_to_close = NULL; + + notebook = ephy_window_get_notebook (window); + n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)); + current_page_no = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook)); + + for (int i = current_page_no + 1; i < n_pages; i++) { + embed = EPHY_EMBED (gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), i)); + pages_to_close = g_slist_prepend (pages_to_close, embed); + } + + for (GSList *l = pages_to_close; l != NULL; l = l->next) { + g_assert (l->data != NULL); + g_signal_emit_by_name (GTK_NOTEBOOK (notebook), "tab-close-request", l->data); + } + + g_slist_free (pages_to_close); +} + +void window_cmd_tabs_close_others (GSimpleAction *action, GVariant *parameter, gpointer user_data) diff --git a/src/window-commands.h b/src/window-commands.h index fea215ae1..f02183787 100644 --- a/src/window-commands.h +++ b/src/window-commands.h @@ -169,7 +169,7 @@ void window_cmd_tabs_next (GSimpleAction *action, gpointer user_data); void window_cmd_tabs_move_left (GSimpleAction *action, GVariant *state, - gpointer user_data); + gpointer user_data); void window_cmd_tabs_move_right (GSimpleAction *action, GVariant *state, gpointer user_data); @@ -182,6 +182,12 @@ void window_cmd_tabs_detach (GSimpleAction *action, void window_cmd_tabs_close (GSimpleAction *action, GVariant *parameter, gpointer user_data); +void window_cmd_tabs_close_left (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void window_cmd_tabs_close_right (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); void window_cmd_tabs_close_others (GSimpleAction *action, GVariant *parameter, gpointer user_data); |