[gnome-builder] grid: add focus left/right actions
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] grid: add focus left/right actions
- Date: Thu, 11 Dec 2014 00:10:39 +0000 (UTC)
commit fc7e62c0edcd0ae867d6c8481f81bebf1675a80f
Author: Christian Hergert <christian hergert me>
Date: Mon Dec 8 13:34:35 2014 -0800
grid: add focus left/right actions
src/documents/gb-document-grid.c | 35 ++++++++++++++++++++++++
src/documents/gb-document-stack.c | 48 +++++++++++++++++++++++++++++++++
src/resources/keybindings/default.ini | 2 +
3 files changed, 85 insertions(+), 0 deletions(-)
---
diff --git a/src/documents/gb-document-grid.c b/src/documents/gb-document-grid.c
index c2c5bb2..2480ab8 100644
--- a/src/documents/gb-document-grid.c
+++ b/src/documents/gb-document-grid.c
@@ -189,6 +189,35 @@ cleanup:
g_list_free (stacks);
}
+static void
+gb_document_grid_focus_neighbor (GbDocumentGrid *grid,
+ GtkDirectionType dir,
+ GbDocumentStack *stack)
+{
+ GtkWidget *neighbor;
+
+ g_return_if_fail (GB_IS_DOCUMENT_GRID (grid));
+ g_return_if_fail (GB_IS_DOCUMENT_STACK (stack));
+
+ switch ((int)dir)
+ {
+ case GTK_DIR_LEFT:
+ neighbor = gb_document_grid_get_stack_before (grid, stack);
+ break;
+
+ case GTK_DIR_RIGHT:
+ neighbor = gb_document_grid_get_stack_after (grid, stack);
+ break;
+
+ default:
+ neighbor = NULL;
+ break;
+ }
+
+ if (neighbor != NULL)
+ gtk_widget_grab_focus (neighbor);
+}
+
static GtkPaned *
gb_document_grid_create_paned (GbDocumentGrid *grid)
{
@@ -220,6 +249,12 @@ gb_document_grid_create_stack (GbDocumentGrid *grid)
grid,
G_CONNECT_SWAPPED);
+ g_signal_connect_object (stack,
+ "focus-neighbor",
+ G_CALLBACK (gb_document_grid_focus_neighbor),
+ grid,
+ G_CONNECT_SWAPPED);
+
return stack;
}
diff --git a/src/documents/gb-document-stack.c b/src/documents/gb-document-stack.c
index 8cfdf40..b244cdf 100644
--- a/src/documents/gb-document-stack.c
+++ b/src/documents/gb-document-stack.c
@@ -52,6 +52,7 @@ enum {
enum {
CREATE_VIEW,
EMPTY,
+ FOCUS_NEIGHBOR,
LAST_SIGNAL
};
@@ -508,6 +509,40 @@ gb_document_stack_split_document_right (GSimpleAction *action,
}
static void
+gb_document_stack_focus_left (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GbDocumentStack *stack = user_data;
+ GbDocumentView *view;
+
+ g_return_if_fail (GB_IS_DOCUMENT_STACK (stack));
+
+ view = gb_document_stack_get_active_view (stack);
+ if (!view)
+ return;
+
+ g_signal_emit (stack, gSignals [FOCUS_NEIGHBOR], 0, GTK_DIR_LEFT);
+}
+
+static void
+gb_document_stack_focus_right (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GbDocumentStack *stack = user_data;
+ GbDocumentView *view;
+
+ g_return_if_fail (GB_IS_DOCUMENT_STACK (stack));
+
+ view = gb_document_stack_get_active_view (stack);
+ if (!view)
+ return;
+
+ g_signal_emit (stack, gSignals [FOCUS_NEIGHBOR], 0, GTK_DIR_RIGHT);
+}
+
+static void
gb_document_stack_finalize (GObject *object)
{
GbDocumentStackPrivate *priv = GB_DOCUMENT_STACK (object)->priv;
@@ -630,6 +665,17 @@ gb_document_stack_class_init (GbDocumentStackClass *klass)
G_TYPE_NONE,
0);
+ gSignals [FOCUS_NEIGHBOR] =
+ g_signal_new ("focus-neighbor",
+ GB_TYPE_DOCUMENT_STACK,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE,
+ 1,
+ GTK_TYPE_TEXT_DIRECTION);
+
g_type_ensure (GB_TYPE_DOCUMENT_MENU_BUTTON);
}
@@ -641,6 +687,8 @@ gb_document_stack_init (GbDocumentStack *self)
{ "move-document-right", gb_document_stack_move_document_right },
{ "split-document-left", gb_document_stack_split_document_left },
{ "split-document-right", gb_document_stack_split_document_right },
+ { "focus-left", gb_document_stack_focus_left },
+ { "focus-right", gb_document_stack_focus_right },
{ "close", gb_document_stack_close },
};
GSimpleActionGroup *actions;
diff --git a/src/resources/keybindings/default.ini b/src/resources/keybindings/default.ini
index 32b38a8..ef891f0 100644
--- a/src/resources/keybindings/default.ini
+++ b/src/resources/keybindings/default.ini
@@ -33,5 +33,7 @@ switch-pane = <Control><Shift>K
[stack]
focus-search = <Control>J
+focus-left = <Control>H
+focus-right = <Control>L
move-document-left = <Control><Shift>H
move-document-right = <Control><Shift>L
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]