[gnome-builder/gnome-builder-3-26] layout: ensure focus returns to editor when leaving search



commit 85a79621b730f90de46027a699d38a329631b9ec
Author: Christian Hergert <chergert redhat com>
Date:   Tue Sep 19 13:42:05 2017 -0700

    layout: ensure focus returns to editor when leaving search
    
    The search bar will clear the focus when Escape is pressed. We want to
    ensure that the focus returns to the editor when possible. This adds the
    missing focus hooks along the hierarchy so that we will return to the
    proper editor.

 libide/editor/ide-editor-perspective.c |   11 +++++++++++
 libide/layout/ide-layout-grid.c        |   13 ++++++-------
 libide/layout/ide-layout-stack.c       |   17 +++++++++++++++++
 libide/workbench/ide-workbench.c       |    3 +++
 4 files changed, 37 insertions(+), 7 deletions(-)
---
diff --git a/libide/editor/ide-editor-perspective.c b/libide/editor/ide-editor-perspective.c
index 8d8ce8d..d9234c0 100644
--- a/libide/editor/ide-editor-perspective.c
+++ b/libide/editor/ide-editor-perspective.c
@@ -221,6 +221,16 @@ ide_editor_perspective_create_edge (DzlDockBin      *dock_bin,
 }
 
 static void
+ide_editor_perspective_grab_focus (GtkWidget *widget)
+{
+  IdeEditorPerspective *self = (IdeEditorPerspective *)widget;
+
+  g_assert (IDE_IS_EDITOR_PERSPECTIVE (self));
+
+  gtk_widget_grab_focus (GTK_WIDGET (self->grid));
+}
+
+static void
 ide_editor_perspective_destroy (GtkWidget *widget)
 {
   IdeEditorPerspective *self = (IdeEditorPerspective *)widget;
@@ -241,6 +251,7 @@ ide_editor_perspective_class_init (IdeEditorPerspectiveClass *klass)
 
   widget_class->destroy = ide_editor_perspective_destroy;
   widget_class->hierarchy_changed = ide_editor_perspective_hierarchy_changed;
+  widget_class->grab_focus = ide_editor_perspective_grab_focus;
 
   container_class->add = ide_editor_perspective_add;
 
diff --git a/libide/layout/ide-layout-grid.c b/libide/layout/ide-layout-grid.c
index 1bd66aa..72d5626 100644
--- a/libide/layout/ide-layout-grid.c
+++ b/libide/layout/ide-layout-grid.c
@@ -336,17 +336,16 @@ static void
 ide_layout_grid_grab_focus (GtkWidget *widget)
 {
   IdeLayoutGrid *self = (IdeLayoutGrid *)widget;
-  IdeLayoutView *view;
+  IdeLayoutStack *stack;
 
   g_assert (IDE_IS_LAYOUT_GRID (self));
 
-  if (NULL != (view = ide_layout_grid_get_current_view (self)))
-    {
-      gtk_widget_grab_focus (GTK_WIDGET (view));
-      return;
-    }
+  stack = ide_layout_grid_get_current_stack (self);
 
-  GTK_WIDGET_CLASS (ide_layout_grid_parent_class)->grab_focus (widget);
+  if (stack != NULL)
+    gtk_widget_grab_focus (GTK_WIDGET (stack));
+  else
+    GTK_WIDGET_CLASS (ide_layout_grid_parent_class)->grab_focus (widget);
 }
 
 static void
diff --git a/libide/layout/ide-layout-stack.c b/libide/layout/ide-layout-stack.c
index 67b0e00..6899412 100644
--- a/libide/layout/ide-layout-stack.c
+++ b/libide/layout/ide-layout-stack.c
@@ -418,6 +418,22 @@ ide_layout_stack_constructed (GObject *object)
 }
 
 static void
+ide_layout_stack_grab_focus (GtkWidget *widget)
+{
+  IdeLayoutStack *self = (IdeLayoutStack *)widget;
+  IdeLayoutView *child;
+
+  g_assert (IDE_IS_LAYOUT_STACK (self));
+
+  child = ide_layout_stack_get_visible_child (self);
+
+  if (child != NULL)
+    gtk_widget_grab_focus (GTK_WIDGET (child));
+  else
+    GTK_WIDGET_CLASS (ide_layout_stack_parent_class)->grab_focus (widget);
+}
+
+static void
 ide_layout_stack_destroy (GtkWidget *widget)
 {
   IdeLayoutStack *self = (IdeLayoutStack *)widget;
@@ -504,6 +520,7 @@ ide_layout_stack_class_init (IdeLayoutStackClass *klass)
   object_class->set_property = ide_layout_stack_set_property;
 
   widget_class->destroy = ide_layout_stack_destroy;
+  widget_class->grab_focus = ide_layout_stack_grab_focus;
 
   container_class->add = ide_layout_stack_add;
 
diff --git a/libide/workbench/ide-workbench.c b/libide/workbench/ide-workbench.c
index fdde2db..2ecd675 100644
--- a/libide/workbench/ide-workbench.c
+++ b/libide/workbench/ide-workbench.c
@@ -197,8 +197,11 @@ ide_workbench_grab_focus (GtkWidget *widget)
   g_assert (IDE_IS_WORKBENCH (self));
 
   child = gtk_stack_get_visible_child (self->perspectives_stack);
+
   if (child != NULL)
     gtk_widget_grab_focus (child);
+  else
+    GTK_WIDGET_CLASS (ide_workbench_parent_class)->grab_focus (widget);
 }
 
 static void


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