[gnome-builder] layout: implement focus-neighbor actions



commit 75cc3c8bf2db3c9dd82a423008a9a7d1e658093a
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jul 20 17:51:29 2017 -0700

    layout: implement focus-neighbor actions
    
    This allows focusing a neighbor using a GAction which can be
    activated from signals.

 data/keybindings/emacs.css              |    4 +-
 data/keybindings/vim.css                |   20 +++++-----
 libide/layout/ide-layout-grid-actions.c |   68 +++++++++++++++++++++++++++++++
 libide/layout/ide-layout-grid.c         |    2 +
 libide/layout/ide-layout-private.h      |    1 +
 libide/meson.build                      |    1 +
 6 files changed, 84 insertions(+), 12 deletions(-)
---
diff --git a/data/keybindings/emacs.css b/data/keybindings/emacs.css
index 6ea5405..6020b9e 100644
--- a/data/keybindings/emacs.css
+++ b/data/keybindings/emacs.css
@@ -67,7 +67,7 @@
   bind "<alt>period" { "goto-definition" () };
   bind "<alt>n" { "move-error" (down) };
   bind "<alt>p" { "move-error" (up) };
-  bind "<ctrl>j" { "action" ("view-grid", "focus-neighbor", "3") };
+  bind "<ctrl>j" { "action" ("layoutgrid", "focus-neighbor", "3") };
   bind "<shift><ctrl>j" { "action" ("layoutstack", "split-view", "") };
   bind "F2" { "clear-selection" ()
               "movement" (previous-word-end, 0, 1, 1)
@@ -131,7 +131,7 @@
   bind "u" { "redo" () };
   bind "2" { "action" ("lyaoutstack", "split-view", "") };
   bind "3" { "action" ("layoutstack", "open-in-new-frame", "") };
-  bind "o" { "action" ("view-grid", "focus-neighbor", "0") };
+  bind "o" { "action" ("layoutgrid", "focus-neighbor", "0") };
   bind "grave" { "move-error" (down) };
   bind "h" { "select-all" (1) };
 }
diff --git a/data/keybindings/vim.css b/data/keybindings/vim.css
index 71e0851..f898798 100644
--- a/data/keybindings/vim.css
+++ b/data/keybindings/vim.css
@@ -1854,20 +1854,20 @@
 
   bind "s" { "action" ("layoutstack", "split-view", "") };
 
-  bind "w" { "action" ("view-grid", "focus-neighbor", "0") };
-  bind "<ctrl>w" { "action" ("view-grid", "focus-neighbor", "0") };
+  bind "w" { "action" ("layoutgrid", "focus-neighbor", "0") };
+  bind "<ctrl>w" { "action" ("layoutgrid", "focus-neighbor", "0") };
 
-  bind "l" { "action" ("view-grid", "focus-neighbor", "5") };
-  bind "Right" { "action" ("view-grid", "focus-neighbor", "5") };
+  bind "l" { "action" ("layoutgrid", "focus-neighbor", "5") };
+  bind "Right" { "action" ("layoutgrid", "focus-neighbor", "5") };
 
-  bind "h" { "action" ("view-grid", "focus-neighbor", "4") };
-  bind "Left" { "action" ("view-grid", "focus-neighbor", "4") };
+  bind "h" { "action" ("layoutgrid", "focus-neighbor", "4") };
+  bind "Left" { "action" ("layoutgrid", "focus-neighbor", "4") };
 
-  bind "j" { "action" ("view-grid", "focus-neighbor", "3") };
-  bind "Down" { "action" ("view-grid", "focus-neighbor", "3") };
+  bind "j" { "action" ("layoutgrid", "focus-neighbor", "3") };
+  bind "Down" { "action" ("layoutgrid", "focus-neighbor", "3") };
 
-  bind "k" { "action" ("view-grid", "focus-neighbor", "2") };
-  bind "Up" { "action" ("view-grid", "focus-neighbor", "2") };
+  bind "k" { "action" ("layoutgrid", "focus-neighbor", "2") };
+  bind "Up" { "action" ("layoutgrid", "focus-neighbor", "2") };
 }
 
 @binding-set builder-vim-source-view-visual-line-g
diff --git a/libide/layout/ide-layout-grid-actions.c b/libide/layout/ide-layout-grid-actions.c
new file mode 100644
index 0000000..7b25dbe
--- /dev/null
+++ b/libide/layout/ide-layout-grid-actions.c
@@ -0,0 +1,68 @@
+/* ide-layout-grid-actions.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-layout-grid"
+
+#include "ide-layout-grid.h"
+
+static void
+ide_layout_grid_actions_focus_neighbor (GSimpleAction *action,
+                                        GVariant      *variant,
+                                        gpointer       user_data)
+{
+  IdeLayoutGrid *self = user_data;
+  GtkDirectionType dir;
+
+  g_return_if_fail (G_IS_SIMPLE_ACTION (action));
+  g_return_if_fail (variant != NULL);
+  g_return_if_fail (g_variant_is_of_type (variant, G_VARIANT_TYPE_INT32));
+  g_return_if_fail (IDE_IS_LAYOUT_GRID (self));
+
+  dir = (GtkDirectionType)g_variant_get_int32 (variant);
+
+  switch (dir)
+    {
+    case GTK_DIR_TAB_FORWARD:
+    case GTK_DIR_TAB_BACKWARD:
+    case GTK_DIR_UP:
+    case GTK_DIR_DOWN:
+    case GTK_DIR_LEFT:
+    case GTK_DIR_RIGHT:
+      ide_layout_grid_focus_neighbor (self, dir);
+      break;
+
+    default:
+      g_return_if_reached ();
+    }
+}
+
+static const GActionEntry actions[] = {
+  { "focus-neighbor", ide_layout_grid_actions_focus_neighbor, "i" },
+};
+
+void
+_ide_layout_grid_init_actions (IdeLayoutGrid *self)
+{
+  g_autoptr(GSimpleActionGroup) group = NULL;
+
+  g_return_if_fail (IDE_IS_LAYOUT_GRID (self));
+
+  group = g_simple_action_group_new ();
+  g_action_map_add_action_entries (G_ACTION_MAP (group), actions, G_N_ELEMENTS (actions), self);
+  gtk_widget_insert_action_group (GTK_WIDGET (self), "layoutgrid", G_ACTION_GROUP (group));
+}
diff --git a/libide/layout/ide-layout-grid.c b/libide/layout/ide-layout-grid.c
index 4b7ce5c..cca244f 100644
--- a/libide/layout/ide-layout-grid.c
+++ b/libide/layout/ide-layout-grid.c
@@ -465,6 +465,8 @@ ide_layout_grid_init (IdeLayoutGrid *self)
                                    G_CALLBACK (ide_layout_grid_after_set_focus),
                                    self,
                                    G_CONNECT_SWAPPED | G_CONNECT_AFTER);
+
+  _ide_layout_grid_init_actions (self);
 }
 
 /**
diff --git a/libide/layout/ide-layout-private.h b/libide/layout/ide-layout-private.h
index d731a6e..b39bb05 100644
--- a/libide/layout/ide-layout-private.h
+++ b/libide/layout/ide-layout-private.h
@@ -43,6 +43,7 @@ IdeLayoutStack *_ide_layout_grid_get_nth_stack               (IdeLayoutGrid
 IdeLayoutStack *_ide_layout_grid_get_nth_stack_for_column    (IdeLayoutGrid        *self,
                                                               IdeLayoutGridColumn  *column,
                                                               gint                  nth);
+void            _ide_layout_grid_init_actions                (IdeLayoutGrid        *self);
 void            _ide_layout_grid_stack_added                 (IdeLayoutGrid        *self,
                                                               IdeLayoutStack       *stack);
 void            _ide_layout_grid_stack_removed               (IdeLayoutGrid        *self,
diff --git a/libide/meson.build b/libide/meson.build
index 2e3f812..cb03960 100644
--- a/libide/meson.build
+++ b/libide/meson.build
@@ -505,6 +505,7 @@ libide_sources = libide_generated_headers + libide_public_sources + [
   'keybindings/ide-keybindings.h',
   'keybindings/ide-shortcuts-window.c',
   'keybindings/ide-shortcuts-window.h',
+  'layout/ide-layout-grid-actions.c',
   'layout/ide-layout-grid-column-actions.c',
   'layout/ide-layout-private.h',
   'layout/ide-layout-stack-actions.c',


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