[gnome-builder] shortcuts: add ctrl+shift+w to close all documents



commit c737d3140e09f11d602334698f71edd2764864ff
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jun 28 12:46:25 2018 -0700

    shortcuts: add ctrl+shift+w to close all documents
    
    Fixes #557

 src/libide/editor/ide-editor-perspective-actions.c | 44 ++++++++++++++++++++++
 .../editor/ide-editor-perspective-shortcuts.c      | 12 ++++++
 src/libide/gtk/menus.ui                            |  7 ++++
 src/libide/keybindings/ide-shortcuts-window.ui     |  7 ++++
 4 files changed, 70 insertions(+)
---
diff --git a/src/libide/editor/ide-editor-perspective-actions.c 
b/src/libide/editor/ide-editor-perspective-actions.c
index 468b2a3c6..287e21635 100644
--- a/src/libide/editor/ide-editor-perspective-actions.c
+++ b/src/libide/editor/ide-editor-perspective-actions.c
@@ -102,9 +102,53 @@ ide_editor_perspective_actions_open_file (GSimpleAction *action,
   gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (chooser));
 }
 
+static void
+collect_views (GtkWidget *widget,
+               gpointer   user_data)
+{
+  IdeLayoutView *view = (IdeLayoutView *)widget;
+  GPtrArray *views = user_data;
+
+  g_assert (views != NULL);
+  g_assert (IDE_IS_LAYOUT_VIEW (view));
+
+  g_ptr_array_add (views, g_object_ref (view));
+}
+
+static void
+ide_editor_perspective_actions_close_all (GSimpleAction *action,
+                                          GVariant      *param,
+                                          gpointer       user_data)
+{
+  IdeEditorPerspective *self = user_data;
+  g_autoptr(GPtrArray) views = NULL;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (IDE_IS_EDITOR_PERSPECTIVE (self));
+
+  /* First collect all the views and hold a reference to them
+   * so that we do not need to worry about contains being destroyed
+   * as we work through the list.
+   */
+  views = g_ptr_array_new_full (0, g_object_unref);
+  ide_layout_grid_foreach_view (self->grid, collect_views, views);
+
+  for (guint i = 0; i < views->len; i++)
+    {
+      IdeLayoutView *view = g_ptr_array_index (views, i);
+
+      /* TODO: Should we allow suspending the close with
+       *       agree_to_close_async()?
+       */
+
+      gtk_widget_destroy (GTK_WIDGET (view));
+    }
+}
+
 static const GActionEntry editor_actions[] = {
   { "new-file", ide_editor_perspective_actions_new_file },
   { "open-file", ide_editor_perspective_actions_open_file },
+  { "close-all", ide_editor_perspective_actions_close_all },
 };
 
 void
diff --git a/src/libide/editor/ide-editor-perspective-shortcuts.c 
b/src/libide/editor/ide-editor-perspective-shortcuts.c
index 58cf381b5..e293149ca 100644
--- a/src/libide/editor/ide-editor-perspective-shortcuts.c
+++ b/src/libide/editor/ide-editor-perspective-shortcuts.c
@@ -51,6 +51,12 @@ static const DzlShortcutEntry editor_perspective_entries[] = {
     NC_("shortcut window", "Editor shortcuts"),
     NC_("shortcut window", "Panels"),
     NC_("shortcut window", "Toggle utilities panel") },
+
+  { "org.gnome.builder.editor.close-all",
+    0, NULL,
+    NC_("shortcut window", "Editor shortcuts"),
+    NC_("shortcut window", "Files"),
+    NC_("shortcut window", "Close all files") },
 };
 
 void
@@ -86,6 +92,12 @@ _ide_editor_perspective_init_shortcuts (IdeEditorPerspective *self)
                                               DZL_SHORTCUT_PHASE_CAPTURE | DZL_SHORTCUT_PHASE_GLOBAL,
                                               I_("dockbin.bottom-visible"));
 
+  dzl_shortcut_controller_add_command_action (controller,
+                                              I_("org.gnome.builder.editor.close-all"),
+                                              I_("<Primary><Shift>w"),
+                                              DZL_SHORTCUT_PHASE_GLOBAL,
+                                              I_("editor.close-all"));
+
   dzl_shortcut_manager_add_shortcut_entries (NULL,
                                              editor_perspective_entries,
                                              G_N_ELEMENTS (editor_perspective_entries),
diff --git a/src/libide/gtk/menus.ui b/src/libide/gtk/menus.ui
index ff32b6cc4..7dbcefdf7 100644
--- a/src/libide/gtk/menus.ui
+++ b/src/libide/gtk/menus.ui
@@ -75,6 +75,13 @@
         <attribute name="accel">&lt;primary&gt;&lt;alt&gt;s</attribute>
       </item>
     </section>
+    <section id="pages-menu-close-section">
+      <item>
+        <attribute name="label" translatable="yes">Close _All</attribute>
+        <attribute name="action">editor.close-all</attribute>
+        <attribute name="accel">&lt;primary&gt;&lt;shift&gt;w</attribute>
+      </item>
+    </section>
   </menu>
   <menu id="gear-menu">
   </menu>
diff --git a/src/libide/keybindings/ide-shortcuts-window.ui b/src/libide/keybindings/ide-shortcuts-window.ui
index 7a92b18fe..5ce4a1709 100644
--- a/src/libide/keybindings/ide-shortcuts-window.ui
+++ b/src/libide/keybindings/ide-shortcuts-window.ui
@@ -115,6 +115,13 @@
                 <property name="title" translatable="yes" context="shortcut window">Close the 
document</property>
               </object>
             </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">true</property>
+                <property name="accelerator">&lt;primary&gt;&lt;shift&gt;w</property>
+                <property name="title" translatable="yes" context="shortcut window">Close all 
documents</property>
+              </object>
+            </child>
             <child>
               <object class="GtkShortcutsShortcut">
                 <property name="visible">true</property>


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