[gnome-builder/wip/chergert/layout: 14/118] editor: locate previous view before creating new view



commit b820cc99933a4f635f896694d40598cb6d3bd4b5
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jun 27 16:08:40 2017 -0700

    editor: locate previous view before creating new view

 libide/editor/ide-editor-perspective.c |   32 +++++++++++++++++++++++++++++++-
 1 files changed, 31 insertions(+), 1 deletions(-)
---
diff --git a/libide/editor/ide-editor-perspective.c b/libide/editor/ide-editor-perspective.c
index 4aa65b0..839467d 100644
--- a/libide/editor/ide-editor-perspective.c
+++ b/libide/editor/ide-editor-perspective.c
@@ -81,19 +81,49 @@ ide_editor_perspective_focus_location (IdeEditorPerspective *self,
   /* TODO: */
 }
 
+static void
+locate_view_for_buffer (GtkWidget *widget,
+                        gpointer   user_data)
+{
+  struct {
+    IdeBuffer     *buffer;
+    IdeLayoutView *view;
+  } *lookup = user_data;
+
+  if (lookup->view != NULL)
+    return;
+
+  if (IDE_IS_EDITOR_VIEW (widget))
+    {
+      if (ide_editor_view_get_buffer (IDE_EDITOR_VIEW (widget)) == lookup->buffer)
+        lookup->view = IDE_LAYOUT_VIEW (widget);
+    }
+}
+
 void
 ide_editor_perspective_focus_buffer_in_current_stack (IdeEditorPerspective *self,
                                                       IdeBuffer            *buffer)
 {
   IdeLayoutStack *stack;
   IdeEditorView *view;
+  struct {
+    IdeBuffer     *buffer;
+    IdeLayoutView *view;
+  } lookup = { buffer };
 
   g_return_if_fail (IDE_IS_EDITOR_PERSPECTIVE (self));
   g_return_if_fail (IDE_IS_BUFFER (buffer));
 
   stack = ide_layout_grid_get_current_stack (self->grid);
 
-  /* TODO: Check if buffer is in stack */
+  ide_layout_stack_foreach_view (stack, locate_view_for_buffer, &lookup);
+
+  if (lookup.view != NULL)
+    {
+      ide_layout_stack_set_visible_child (stack, lookup.view);
+      gtk_widget_grab_focus (GTK_WIDGET (lookup.view));
+      return;
+    }
 
   view = g_object_new (IDE_TYPE_EDITOR_VIEW,
                        "buffer", buffer,


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