[gnome-builder] editor: fix side-by-side loading of documents
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] editor: fix side-by-side loading of documents
- Date: Wed, 19 Jul 2017 11:09:38 +0000 (UTC)
commit 1330012970584bddfae72f031e48a87ff7295491
Author: Christian Hergert <chergert redhat com>
Date: Wed Jul 5 06:02:33 2017 -0700
editor: fix side-by-side loading of documents
libide/editor/ide-editor-perspective.c | 58 ++++++++++++++++++++++++----
libide/editor/ide-editor-perspective.h | 2 +
libide/editor/ide-editor-workbench-addin.c | 2 +-
3 files changed, 53 insertions(+), 9 deletions(-)
---
diff --git a/libide/editor/ide-editor-perspective.c b/libide/editor/ide-editor-perspective.c
index 5027d27..7ee7e67 100644
--- a/libide/editor/ide-editor-perspective.c
+++ b/libide/editor/ide-editor-perspective.c
@@ -269,31 +269,73 @@ locate_view_for_buffer (GtkWidget *widget,
}
}
-void
-ide_editor_perspective_focus_buffer_in_current_stack (IdeEditorPerspective *self,
- IdeBuffer *buffer)
+static gboolean
+ide_editor_perspective_focus_if_found (IdeEditorPerspective *self,
+ IdeBuffer *buffer,
+ gboolean any_stack)
{
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));
+ g_return_val_if_fail (IDE_IS_EDITOR_PERSPECTIVE (self), FALSE);
+ g_return_val_if_fail (IDE_IS_BUFFER (buffer), FALSE);
stack = ide_layout_grid_get_current_stack (self->grid);
- ide_layout_stack_foreach_view (stack, locate_view_for_buffer, &lookup);
+ if (any_stack)
+ ide_layout_grid_foreach_view (self->grid, locate_view_for_buffer, &lookup);
+ else
+ ide_layout_stack_foreach_view (stack, locate_view_for_buffer, &lookup);
if (lookup.view != NULL)
{
+ stack = IDE_LAYOUT_STACK (gtk_widget_get_ancestor (GTK_WIDGET (lookup.view),
+ IDE_TYPE_LAYOUT_STACK));
ide_layout_stack_set_visible_child (stack, lookup.view);
gtk_widget_grab_focus (GTK_WIDGET (lookup.view));
- return;
+ return TRUE;
}
+ return FALSE;
+}
+
+void
+ide_editor_perspective_focus_buffer (IdeEditorPerspective *self,
+ IdeBuffer *buffer)
+{
+ IdeEditorView *view;
+
+ g_return_if_fail (IDE_IS_EDITOR_PERSPECTIVE (self));
+ g_return_if_fail (IDE_IS_BUFFER (buffer));
+
+ if (ide_editor_perspective_focus_if_found (self, buffer, TRUE))
+ return;
+
+ view = g_object_new (IDE_TYPE_EDITOR_VIEW,
+ "buffer", buffer,
+ "visible", TRUE,
+ NULL);
+ gtk_container_add (GTK_CONTAINER (self->grid), GTK_WIDGET (view));
+}
+
+void
+ide_editor_perspective_focus_buffer_in_current_stack (IdeEditorPerspective *self,
+ IdeBuffer *buffer)
+{
+ IdeLayoutStack *stack;
+ IdeEditorView *view;
+
+ g_return_if_fail (IDE_IS_EDITOR_PERSPECTIVE (self));
+ g_return_if_fail (IDE_IS_BUFFER (buffer));
+
+ if (ide_editor_perspective_focus_if_found (self, buffer, FALSE))
+ return;
+
+ stack = ide_layout_grid_get_current_stack (self->grid);
+
view = g_object_new (IDE_TYPE_EDITOR_VIEW,
"buffer", buffer,
"visible", TRUE,
diff --git a/libide/editor/ide-editor-perspective.h b/libide/editor/ide-editor-perspective.h
index c0ea205..bf63920 100644
--- a/libide/editor/ide-editor-perspective.h
+++ b/libide/editor/ide-editor-perspective.h
@@ -29,6 +29,8 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (IdeEditorPerspective, ide_editor_perspective, IDE, EDITOR_PERSPECTIVE, IdeLayout)
+void ide_editor_perspective_focus_buffer (IdeEditorPerspective *self,
+ IdeBuffer *buffer);
void ide_editor_perspective_focus_buffer_in_current_stack (IdeEditorPerspective *self,
IdeBuffer *buffer);
void ide_editor_perspective_focus_location (IdeEditorPerspective *self,
diff --git a/libide/editor/ide-editor-workbench-addin.c b/libide/editor/ide-editor-workbench-addin.c
index ace00ef..dd9e191 100644
--- a/libide/editor/ide-editor-workbench-addin.c
+++ b/libide/editor/ide-editor-workbench-addin.c
@@ -92,7 +92,7 @@ ide_editor_workbench_addin_on_load_buffer (IdeEditorWorkbenchAddin *self,
IDE_TRACE_MSG ("Loading %s", ide_buffer_get_title (buffer));
- ide_editor_perspective_focus_buffer_in_current_stack (self->perspective, buffer);
+ ide_editor_perspective_focus_buffer (self->perspective, buffer);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]