[epiphany] Add close other tabs



commit 463bc67e3ef19e7b1a6bc7e05096ae69ee2eb8b0
Author: Kieran Elmes <kieran elmes kolabnow com>
Date:   Fri Oct 26 16:58:19 2018 +1300

    Add close other tabs

 src/ephy-window.c                          |  7 ++++++-
 src/resources/gtk/notebook-context-menu.ui |  4 ++++
 src/window-commands.c                      | 30 ++++++++++++++++++++++++++++++
 src/window-commands.h                      |  3 +++
 4 files changed, 43 insertions(+), 1 deletion(-)
---
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 4657f9698..d8d0e5b99 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -772,7 +772,8 @@ static const GActionEntry tab_entries [] = {
   { "move-right", window_cmd_tabs_move_right },
   { "duplicate", window_cmd_tabs_duplicate },
   { "detach", window_cmd_tabs_detach },
-  { "close", window_cmd_tabs_close }
+  { "close", window_cmd_tabs_close },
+  { "close-others", window_cmd_tabs_close_others }
 };
 
 static const GActionEntry toolbar_entries [] = {
@@ -2410,6 +2411,10 @@ show_notebook_popup_menu (GtkNotebook    *notebook,
                                          "move-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),
+                                         "close-others");
+    g_simple_action_set_enabled (G_SIMPLE_ACTION (action), n_pages > 1);
+
     gtk_menu_popup_at_pointer (GTK_MENU (menu), (GdkEvent *)event);
   } else {
     tab = GTK_WIDGET (window->active_embed);
diff --git a/src/resources/gtk/notebook-context-menu.ui b/src/resources/gtk/notebook-context-menu.ui
index 7c46b35c7..b6255bfd7 100644
--- a/src/resources/gtk/notebook-context-menu.ui
+++ b/src/resources/gtk/notebook-context-menu.ui
@@ -19,6 +19,10 @@
         <attribute name="label" translatable="yes">_Close</attribute>
         <attribute name="action">tab.close</attribute>
       </item>
+      <item>
+        <attribute name="label" translatable="yes">Close _Other Tabs</attribute>
+        <attribute name="action">tab.close-others</attribute>
+      </item>
     </section>
   </menu>
 </interface>
diff --git a/src/window-commands.c b/src/window-commands.c
index 58e896582..82906d361 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -2358,6 +2358,36 @@ window_cmd_tabs_close (GSimpleAction *action,
   g_signal_emit_by_name (notebook, "tab-close-request", embed);
 }
 
+void
+window_cmd_tabs_close_others (GSimpleAction *action,
+                              GVariant      *parameter,
+                              gpointer       user_data)
+{
+  EphyWindow *window = user_data;
+  GtkWidget *notebook;
+  EphyEmbed *embed;
+  int n_pages, current_page;
+  GSList *pages_to_close = NULL;
+
+  notebook = ephy_window_get_notebook (window);
+  n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
+  current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
+
+  for (int i = 0; i < n_pages; i++) {
+    if (i != current_page) {
+      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_show_tab (GSimpleAction *action,
                      GVariant      *parameter,
diff --git a/src/window-commands.h b/src/window-commands.h
index 9da083357..fea215ae1 100644
--- a/src/window-commands.h
+++ b/src/window-commands.h
@@ -182,6 +182,9 @@ void window_cmd_tabs_detach                     (GSimpleAction *action,
 void window_cmd_tabs_close                      (GSimpleAction *action,
                                                  GVariant      *parameter,
                                                  gpointer       user_data);
+void window_cmd_tabs_close_others               (GSimpleAction *action,
+                                                 GVariant      *parameter,
+                                                 gpointer       user_data);
 void window_cmd_show_tab                        (GSimpleAction *action,
                                                  GVariant      *parameter,
                                                  gpointer       user_data);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]