[gnome-builder/wip/chergert/layout] shortcuts: plumb in more shortcuts for the editor



commit 9710f2dba5b1bafcc2b32a58bc15350d1b0eeed4
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jun 27 20:41:57 2017 -0700

    shortcuts: plumb in more shortcuts for the editor

 libide/editor/ide-editor-perspective-actions.c   |   61 +++++++++++++++++-
 libide/editor/ide-editor-perspective-shortcuts.c |   67 ++++++++++++++++++++
 libide/editor/ide-editor-perspective.c           |    1 +
 libide/editor/ide-editor-private.h               |   33 ++++++++--
 libide/editor/ide-editor-search-bar.c            |   12 ++++
 libide/editor/ide-editor-view-shortcuts.c        |    2 +-
 libide/editor/ide-editor-view.c                  |   34 ++++------
 libide/editor/ide-editor-view.ui                 |    1 +
 libide/editor/ide-editor-workbench-addin.c       |    2 +-
 libide/layout/ide-layout-stack-shortcuts.c       |   73 ++++++++++-----------
 libide/meson.build                               |    3 +-
 11 files changed, 217 insertions(+), 72 deletions(-)
---
diff --git a/libide/editor/ide-editor-perspective-actions.c b/libide/editor/ide-editor-perspective-actions.c
index 4af5cd2..969ee8e 100644
--- a/libide/editor/ide-editor-perspective-actions.c
+++ b/libide/editor/ide-editor-perspective-actions.c
@@ -18,14 +18,16 @@
 
 #define G_LOG_DOMAIN "ide-editor-perspective-actions"
 
+#include <glib/gi18n.h>
+
 #include "buffers/ide-buffer-manager.h"
 #include "editor/ide-editor-private.h"
 #include "util/ide-gtk.h"
 
 static void
-ide_editor_perspective_actions_new_document (GSimpleAction *action,
-                                             GVariant      *variant,
-                                             gpointer       user_data)
+ide_editor_perspective_actions_new_file (GSimpleAction *action,
+                                         GVariant      *variant,
+                                         gpointer       user_data)
 {
   IdeEditorPerspective *self = user_data;
   IdeWorkbench *workbench;
@@ -44,8 +46,59 @@ ide_editor_perspective_actions_new_document (GSimpleAction *action,
   g_clear_object (&buffer);
 }
 
+static void
+ide_editor_perspective_actions_open_file (GSimpleAction *action,
+                                          GVariant      *variant,
+                                          gpointer       user_data)
+{
+  IdeEditorPerspective *self = user_data;
+  GtkFileChooserNative *chooser;
+  IdeWorkbench *workbench;
+  gint ret;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (IDE_IS_EDITOR_PERSPECTIVE (self));
+
+  workbench = ide_widget_get_workbench (GTK_WIDGET (self));
+
+  if (workbench == NULL)
+    {
+      g_warning ("Failed to locate workbench");
+      return;
+    }
+
+  chooser = gtk_file_chooser_native_new (_("Open File"),
+                                         GTK_WINDOW (workbench),
+                                         GTK_FILE_CHOOSER_ACTION_OPEN,
+                                         _("Open"),
+                                         _("Cancel"));
+  gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), FALSE);
+
+  ret = gtk_native_dialog_run (GTK_NATIVE_DIALOG (chooser));
+
+  if (ret == GTK_RESPONSE_ACCEPT)
+    {
+      g_autoptr(GFile) file = NULL;
+
+      file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (chooser));
+
+      if (file != NULL)
+        {
+          ide_workbench_open_files_async (workbench,
+                                          &file,
+                                          1,
+                                          "editor",
+                                          IDE_WORKBENCH_OPEN_FLAGS_NONE,
+                                          NULL, NULL, NULL);
+        }
+    }
+
+  gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (chooser));
+}
+
 static const GActionEntry editor_actions[] = {
-  { "new-document", ide_editor_perspective_actions_new_document },
+  { "new-file", ide_editor_perspective_actions_new_file },
+  { "open-file", ide_editor_perspective_actions_open_file },
 };
 
 void
diff --git a/libide/editor/ide-editor-perspective-shortcuts.c 
b/libide/editor/ide-editor-perspective-shortcuts.c
new file mode 100644
index 0000000..3b0f1b8
--- /dev/null
+++ b/libide/editor/ide-editor-perspective-shortcuts.c
@@ -0,0 +1,67 @@
+/* ide-editor-perspective-shortcuts.c
+ *
+ * Copyright (C) 2017 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define G_LOG_DOMAIN "ide-editor-perspective-shortcuts"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+#include <dazzle.h>
+
+#include "ide-editor-private.h"
+
+#define I_(s) g_intern_static_string(s)
+
+static const DzlShortcutEntry editor_perspective_entries[] = {
+  { "org.gnome.builder.editor.new-file",
+    NULL,
+    N_("Editor"),
+    N_("Files"),
+    N_("Create a new document") },
+
+  { "org.gnome.builder.editor.open-file",
+    NULL,
+    N_("Editor"),
+    N_("Files"),
+    N_("Open a document") },
+};
+
+void
+_ide_editor_perspective_init_shortcuts (IdeEditorPerspective *self)
+{
+  DzlShortcutController *controller;
+
+  g_assert (IDE_IS_EDITOR_PERSPECTIVE (self));
+
+  controller = dzl_shortcut_controller_find (GTK_WIDGET (self));
+
+  dzl_shortcut_controller_add_command_action (controller,
+                                              I_("org.gnome.builder.editor.new-file"),
+                                              I_("<Primary>n"),
+                                              I_("editor.new-file"));
+
+  dzl_shortcut_controller_add_command_action (controller,
+                                              I_("org.gnome.builder.editor.open-file"),
+                                              I_("<Primary>o"),
+                                              I_("editor.open-file"));
+
+  dzl_shortcut_manager_add_shortcut_entries (NULL,
+                                             editor_perspective_entries,
+                                             G_N_ELEMENTS (editor_perspective_entries),
+                                             GETTEXT_PACKAGE);
+}
diff --git a/libide/editor/ide-editor-perspective.c b/libide/editor/ide-editor-perspective.c
index 394bce6..db90446 100644
--- a/libide/editor/ide-editor-perspective.c
+++ b/libide/editor/ide-editor-perspective.c
@@ -53,6 +53,7 @@ ide_editor_perspective_init (IdeEditorPerspective *self)
   gtk_widget_init_template (GTK_WIDGET (self));
 
   _ide_editor_perspective_init_actions (self);
+  _ide_editor_perspective_init_shortcuts (self);
 }
 
 /**
diff --git a/libide/editor/ide-editor-private.h b/libide/editor/ide-editor-private.h
index 02a572a..275f238 100644
--- a/libide/editor/ide-editor-private.h
+++ b/libide/editor/ide-editor-private.h
@@ -18,14 +18,35 @@
 
 #pragma once
 
-#include "ide-editor-perspective.h"
-#include "ide-editor-view.h"
+#include "editor/ide-editor-perspective.h"
+#include "editor/ide-editor-search-bar.h"
+#include "editor/ide-editor-view-addin.h"
+#include "editor/ide-editor-view.h"
+#include "plugins/ide-extension-set-adapter.h"
 
 G_BEGIN_DECLS
 
-void _ide_editor_view_init_actions        (IdeEditorView        *self);
-void _ide_editor_view_init_settings       (IdeEditorView        *self);
-void _ide_editor_view_init_shortcuts      (IdeEditorView        *self);
-void _ide_editor_perspective_init_actions (IdeEditorPerspective *self);
+struct _IdeEditorView
+{
+  IdeLayoutView            parent_instance;
+
+  IdeExtensionSetAdapter  *addins;
+
+  IdeBuffer               *buffer;
+  DzlBindingGroup         *buffer_bindings;
+  DzlSignalGroup          *buffer_signals;
+
+  GtkOverlay              *overlay;
+  IdeSourceView           *source_view;
+  GtkScrolledWindow       *scroller;
+  IdeEditorSearchBar      *search_bar;
+  GtkRevealer             *search_revealer;
+};
+
+void _ide_editor_view_init_actions          (IdeEditorView        *self);
+void _ide_editor_view_init_settings         (IdeEditorView        *self);
+void _ide_editor_view_init_shortcuts        (IdeEditorView        *self);
+void _ide_editor_perspective_init_actions   (IdeEditorPerspective *self);
+void _ide_editor_perspective_init_shortcuts (IdeEditorPerspective *self);
 
 G_END_DECLS
diff --git a/libide/editor/ide-editor-search-bar.c b/libide/editor/ide-editor-search-bar.c
index 8b844b7..765f297 100644
--- a/libide/editor/ide-editor-search-bar.c
+++ b/libide/editor/ide-editor-search-bar.c
@@ -350,6 +350,16 @@ on_notify_regex_enabled (IdeEditorSearchBar      *self,
 }
 
 static void
+ide_editor_search_bar_grab_focus (GtkWidget *widget)
+{
+  IdeEditorSearchBar *self = (IdeEditorSearchBar *)widget;
+
+  g_assert (IDE_IS_EDITOR_SEARCH_BAR (self));
+
+  gtk_widget_grab_focus (GTK_WIDGET (self->search_entry));
+}
+
+static void
 ide_editor_search_bar_finalize (GObject *object)
 {
   IdeEditorSearchBar *self = (IdeEditorSearchBar *)object;
@@ -421,6 +431,8 @@ ide_editor_search_bar_class_init (IdeEditorSearchBarClass *klass)
   object_class->get_property = ide_editor_search_bar_get_property;
   object_class->set_property = ide_editor_search_bar_set_property;
 
+  widget_class->grab_focus = ide_editor_search_bar_grab_focus;
+
   gtk_widget_class_set_template_from_resource (widget_class,
                                                "/org/gnome/builder/ui/ide-editor-search-bar.ui");
   gtk_widget_class_bind_template_child (widget_class, IdeEditorSearchBar, case_sensitive);
diff --git a/libide/editor/ide-editor-view-shortcuts.c b/libide/editor/ide-editor-view-shortcuts.c
index 1e07455..bae9053 100644
--- a/libide/editor/ide-editor-view-shortcuts.c
+++ b/libide/editor/ide-editor-view-shortcuts.c
@@ -65,7 +65,7 @@ ide_editor_view_shortcuts_find (GtkWidget *widget,
 
   g_assert (IDE_IS_EDITOR_VIEW (self));
 
-  g_print ("TYPE: %s\n", G_OBJECT_TYPE_NAME (widget));
+  gtk_revealer_set_reveal_child (self->search_revealer, TRUE);
 }
 
 void
diff --git a/libide/editor/ide-editor-view.c b/libide/editor/ide-editor-view.c
index f1fe964..99e74be 100644
--- a/libide/editor/ide-editor-view.c
+++ b/libide/editor/ide-editor-view.c
@@ -22,29 +22,8 @@
 #include <libpeas/peas.h>
 
 #include "editor/ide-editor-private.h"
-#include "editor/ide-editor-search-bar.h"
-#include "editor/ide-editor-view.h"
-#include "editor/ide-editor-view-addin.h"
-#include "plugins/ide-extension-set-adapter.h"
 #include "util/ide-gtk.h"
 
-struct _IdeEditorView
-{
-  IdeLayoutView            parent_instance;
-
-  IdeExtensionSetAdapter  *addins;
-
-  IdeBuffer               *buffer;
-  DzlBindingGroup         *buffer_bindings;
-  DzlSignalGroup          *buffer_signals;
-
-  GtkOverlay              *overlay;
-  IdeSourceView           *source_view;
-  GtkScrolledWindow       *scroller;
-  IdeEditorSearchBar      *search_bar;
-  GtkRevealer             *search_revealer;
-};
-
 enum {
   PROP_0,
   PROP_BUFFER,
@@ -61,6 +40,18 @@ G_DEFINE_TYPE (IdeEditorView, ide_editor_view, IDE_TYPE_LAYOUT_VIEW)
 static GParamSpec *properties [N_PROPS];
 
 static void
+ide_editor_view_notify_child_revealed (IdeEditorView *self,
+                                       GParamSpec    *pspec,
+                                       GtkRevealer   *revealer)
+{
+  g_assert (IDE_IS_EDITOR_VIEW (self));
+  g_assert (GTK_IS_REVEALER (revealer));
+
+  if (gtk_revealer_get_child_revealed (revealer))
+    gtk_widget_grab_focus (GTK_WIDGET (self->search_bar));
+}
+
+static void
 ide_editor_view_drag_data_received (IdeEditorView    *self,
                                     GdkDragContext   *context,
                                     gint              x,
@@ -421,6 +412,7 @@ ide_editor_view_class_init (IdeEditorViewClass *klass)
   gtk_widget_class_bind_template_child (widget_class, IdeEditorView, search_bar);
   gtk_widget_class_bind_template_child (widget_class, IdeEditorView, search_revealer);
   gtk_widget_class_bind_template_child (widget_class, IdeEditorView, source_view);
+  gtk_widget_class_bind_template_callback (widget_class, ide_editor_view_notify_child_revealed);
 
   g_type_ensure (IDE_TYPE_SOURCE_VIEW);
   g_type_ensure (IDE_TYPE_EDITOR_SEARCH_BAR);
diff --git a/libide/editor/ide-editor-view.ui b/libide/editor/ide-editor-view.ui
index f236815..e6b6122 100644
--- a/libide/editor/ide-editor-view.ui
+++ b/libide/editor/ide-editor-view.ui
@@ -11,6 +11,7 @@
             <property name="reveal-child">false</property>
             <property name="valign">start</property>
             <property name="visible">true</property>
+            <signal name="notify::child-revealed" handler="ide_editor_view_notify_child_revealed" 
swapped="true" object="IdeEditorView"/>
             <child>
               <object class="IdeEditorSearchBar" id="search_bar">
                 <property name="visible">true</property>
diff --git a/libide/editor/ide-editor-workbench-addin.c b/libide/editor/ide-editor-workbench-addin.c
index 44d943d..66e5c55 100644
--- a/libide/editor/ide-editor-workbench-addin.c
+++ b/libide/editor/ide-editor-workbench-addin.c
@@ -148,7 +148,7 @@ ide_editor_workbench_addin_load (IdeWorkbenchAddin *addin,
   header = ide_workbench_get_headerbar (workbench);
 
   self->new_document_button = g_object_new (GTK_TYPE_BUTTON,
-                                            "action-name", "editor.new-document",
+                                            "action-name", "editor.new-file",
                                             "child", g_object_new (GTK_TYPE_IMAGE,
                                                                    "visible", TRUE,
                                                                    "icon-name", "document-new-symbolic",
diff --git a/libide/layout/ide-layout-stack-shortcuts.c b/libide/layout/ide-layout-stack-shortcuts.c
index 581f607..46cb770 100644
--- a/libide/layout/ide-layout-stack-shortcuts.c
+++ b/libide/layout/ide-layout-stack-shortcuts.c
@@ -23,41 +23,38 @@
 #include "ide-layout-stack.h"
 #include "ide-layout-private.h"
 
+#define I_(s) g_intern_static_string(s)
+
 static const DzlShortcutEntry stack_shortcuts[] = {
   { "org.gnome.builder.layoutstack.move-right",
     NULL,
-    N_("Editing"),
-    N_("Navigation"),
-    N_("Move document right"),
-    N_("Move the document to the frame on the right") },
+    N_("Editor"),
+    N_("Files"),
+    N_("Move document to the right") },
 
   { "org.gnome.builder.layoutstack.move-left",
     NULL,
-    N_("Editing"),
-    N_("Navigation"),
-    N_("Move document left"),
-    N_("Move the document to the frame on the left") },
+    N_("Editor"),
+    N_("Files"),
+    N_("Move document to the left") },
 
   { "org.gnome.builder.layoutstack.previous-document",
     NULL,
-    N_("Editing"),
-    N_("Navigation"),
-    N_("Focus next document"),
-    N_("Focus the next document in the stack") },
+    N_("Editor"),
+    N_("Files"),
+    N_("Search to the previous document") },
 
-  { "org.gnome.builder.layoutstack.previous-document",
+  { "org.gnome.builder.layoutstack.next-document",
     NULL,
-    N_("Editing"),
-    N_("Navigation"),
-    N_("Focus next document"),
-    N_("Focus the next document in the stack") },
+    N_("Editor"),
+    N_("Files"),
+    N_("Switch to the next document") },
 
   { "org.gnome.builder.layoutstack.close-view",
     NULL,
-    N_("Editing"),
-    N_("Navigation"),
-    N_("Close current view"),
-    N_("Closes the currently focused view") },
+    N_("Editor"),
+    N_("Files"),
+    N_("Close the document") },
 };
 
 void
@@ -75,29 +72,29 @@ _ide_layout_stack_init_shortcuts (IdeLayoutStack *self)
   controller = dzl_shortcut_controller_find (GTK_WIDGET (self));
 
   dzl_shortcut_controller_add_command_action (controller,
-                                              "org.gnome.builder.layoutstack.move-right",
-                                              "<Control><Alt>Page_Down",
-                                              "layoutstack.move-right");
+                                              I_("org.gnome.builder.layoutstack.move-right"),
+                                              I_("<Primary><Alt>Page_Down"),
+                                              I_("layoutstack.move-right"));
 
   dzl_shortcut_controller_add_command_action (controller,
-                                              "org.gnome.builder.layoutstack.move-left",
-                                              "<Control><Alt>Page_Up",
-                                              "layoutstack.move-left");
+                                              I_("org.gnome.builder.layoutstack.move-left"),
+                                              I_("<Primary><Alt>Page_Up"),
+                                              I_("layoutstack.move-left"));
 
   dzl_shortcut_controller_add_command_signal (controller,
-                                              "org.gnome.builder.layoutstack.next-document",
-                                              "<Control><Shift>Page_Down",
-                                              "change-current-page", 1,
-                                              G_TYPE_INT, 1);
+                                              I_("org.gnome.builder.layoutstack.next-document"),
+                                              I_("<Primary><Shift>Page_Down"),
+                                              I_("change-current-page"),
+                                              1, G_TYPE_INT, 1);
 
   dzl_shortcut_controller_add_command_signal (controller,
-                                              "org.gnome.builder.layoutstack.previous-document",
-                                              "<Control><Shift>Page_Up",
-                                              "change-current-page", 1,
-                                              G_TYPE_INT, -1);
+                                              I_("org.gnome.builder.layoutstack.previous-document"),
+                                              I_("<Primary><Shift>Page_Up"),
+                                              I_("change-current-page"),
+                                              1, G_TYPE_INT, -1);
 
   dzl_shortcut_controller_add_command_action (controller,
-                                              "org.gnome.builder.layoutstack.close-view",
-                                              "<Control>w",
-                                              "layoutstack.close-view");
+                                              I_("org.gnome.builder.layoutstack.close-view"),
+                                              I_("<Primary>w"),
+                                              I_("layoutstack.close-view"));
 }
diff --git a/libide/meson.build b/libide/meson.build
index 3eedb90..5c870a5 100644
--- a/libide/meson.build
+++ b/libide/meson.build
@@ -290,7 +290,6 @@ libide_public_sources = [
   'doap/ide-doap-person.c',
   'doap/ide-doap.c',
   'editor/ide-editor-perspective.c',
-  'editor/ide-editor-perspective-actions.c',
   'editor/ide-editor-view-addin.c',
   'editor/ide-editor-view.c',
   'files/ide-file-settings.c',
@@ -457,6 +456,8 @@ libide_sources = libide_generated_headers + libide_public_sources + [
   'buildui/ide-environment-editor-row.h',
   'buildui/ide-environment-editor.c',
   'buildui/ide-environment-editor.h',
+  'editor/ide-editor-perspective-actions.c',
+  'editor/ide-editor-perspective-shortcuts.c',
   'editor/ide-editor-plugin.c',
   'editor/ide-editor-print-operation.c',
   'editor/ide-editor-print-operation.h',


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