[gnome-builder] editor: try harder to open buffers in the last focused stack



commit 9fb301c665ed199123c478c12894cc7d35863203
Author: Christian Hergert <christian hergert me>
Date:   Sun Feb 21 21:12:49 2016 -0800

    editor: try harder to open buffers in the last focused stack
    
    This also fixes things like "e foo/bar.c" from the command bar to show
    up in the view that was last focused.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=761393

 libide/editor/ide-editor-perspective.c     |   32 ++++++++++++++++++++++++++++
 libide/editor/ide-editor-perspective.h     |    6 +++-
 libide/editor/ide-editor-workbench-addin.c |    9 +++++++
 3 files changed, 45 insertions(+), 2 deletions(-)
---
diff --git a/libide/editor/ide-editor-perspective.c b/libide/editor/ide-editor-perspective.c
index 0fd3d56..e81dedf 100644
--- a/libide/editor/ide-editor-perspective.c
+++ b/libide/editor/ide-editor-perspective.c
@@ -228,6 +228,38 @@ ide_editor_perspective_locate_buffer (GtkWidget *view,
     }
 }
 
+void
+ide_editor_perspective_focus_buffer_in_current_stack (IdeEditorPerspective *self,
+                                                      IdeBuffer            *buffer)
+{
+  GtkWidget *focus_stack;
+
+  g_assert (IDE_IS_EDITOR_PERSPECTIVE (self));
+  g_assert (IDE_IS_BUFFER (buffer));
+
+  focus_stack = ide_layout_grid_get_last_focus (self->grid);
+  g_assert (!focus_stack || IDE_IS_LAYOUT_STACK (focus_stack));
+
+  if (focus_stack != NULL)
+    {
+      IdeBuffer *search_buffer = buffer;
+      GtkWidget *view;
+
+      ide_layout_stack_foreach_view (IDE_LAYOUT_STACK (focus_stack),
+                                     ide_editor_perspective_locate_buffer,
+                                     &search_buffer);
+
+      if (search_buffer != NULL)
+        {
+          view = g_object_new (IDE_TYPE_EDITOR_VIEW,
+                               "document", buffer,
+                               "visible", TRUE,
+                               NULL);
+          ide_editor_perspective_add (GTK_CONTAINER (self), view);
+        }
+    }
+}
+
 static void
 ide_editor_perspective_notify_focus_buffer (IdeEditorPerspective *self,
                                             GParamSpec           *pspec,
diff --git a/libide/editor/ide-editor-perspective.h b/libide/editor/ide-editor-perspective.h
index 30070b6..d36245d 100644
--- a/libide/editor/ide-editor-perspective.h
+++ b/libide/editor/ide-editor-perspective.h
@@ -31,8 +31,10 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (IdeEditorPerspective, ide_editor_perspective, IDE, EDITOR_PERSPECTIVE, IdeLayout)
 
-void ide_editor_perspective_focus_location (IdeEditorPerspective *self,
-                                            IdeSourceLocation    *location);
+void ide_editor_perspective_focus_location                (IdeEditorPerspective *self,
+                                                           IdeSourceLocation    *location);
+void ide_editor_perspective_focus_buffer_in_current_stack (IdeEditorPerspective *self,
+                                                           IdeBuffer            *buffer);
 
 G_END_DECLS
 
diff --git a/libide/editor/ide-editor-workbench-addin.c b/libide/editor/ide-editor-workbench-addin.c
index 262045d..f11b5fb 100644
--- a/libide/editor/ide-editor-workbench-addin.c
+++ b/libide/editor/ide-editor-workbench-addin.c
@@ -25,6 +25,7 @@
 #include "ide-buffer.h"
 #include "ide-buffer-manager.h"
 #include "ide-context.h"
+#include "ide-debug.h"
 #include "ide-editor-perspective.h"
 #include "ide-editor-workbench-addin.h"
 #include "ide-workbench-header-bar.h"
@@ -140,6 +141,7 @@ ide_editor_workbench_addin_open_cb (GObject      *object,
                                     gpointer      user_data)
 {
   IdeBufferManager *buffer_manager = (IdeBufferManager *)object;
+  IdeEditorWorkbenchAddin *self;
   g_autoptr(IdeBuffer) buffer = NULL;
   g_autoptr(GTask) task = user_data;
   GError *error = NULL;
@@ -149,10 +151,14 @@ ide_editor_workbench_addin_open_cb (GObject      *object,
   g_assert (IDE_IS_BUFFER_MANAGER (buffer_manager));
   g_assert (G_IS_TASK (task));
 
+  self = g_task_get_source_object (task);
+  g_assert (IDE_IS_EDITOR_WORKBENCH_ADDIN (self));
+
   buffer = ide_buffer_manager_load_file_finish (buffer_manager, result, &error);
 
   if (buffer == NULL)
     {
+      IDE_TRACE_MSG ("%s", error->message);
       g_task_return_error (task, error);
       return;
     }
@@ -175,6 +181,9 @@ ide_editor_workbench_addin_open_cb (GObject      *object,
         }
     }
 
+  if (self->perspective != NULL)
+    ide_editor_perspective_focus_buffer_in_current_stack (self->perspective, buffer);
+
   g_task_return_boolean (task, TRUE);
 }
 


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