[gnome-builder] libide: add api to focus a source location



commit 60df21fce664ce2cd516d329d61d82b0fb812402
Author: Christian Hergert <chergert redhat com>
Date:   Sat Dec 5 22:33:37 2015 -0800

    libide: add api to focus a source location

 libide/editor/ide-editor-perspective.c |   58 ++++++++++++++++++++++++++++++++
 libide/editor/ide-editor-perspective.h |    4 ++
 libide/ide.h                           |    1 +
 3 files changed, 63 insertions(+), 0 deletions(-)
---
diff --git a/libide/editor/ide-editor-perspective.c b/libide/editor/ide-editor-perspective.c
index c1eaf1b..962c220 100644
--- a/libide/editor/ide-editor-perspective.c
+++ b/libide/editor/ide-editor-perspective.c
@@ -399,3 +399,61 @@ ide_perspective_iface_init (IdePerspectiveInterface *iface)
   iface->get_titlebar = ide_editor_perspective_get_titlebar;
   iface->views_foreach = ide_editor_perspective_views_foreach;
 }
+
+static void
+ide_editor_perspective_find_source_location (GtkWidget *widget,
+                                             gpointer   user_data)
+{
+  struct {
+    IdeFile       *file;
+    IdeEditorView *view;
+  } *lookup = user_data;
+  IdeBuffer *buffer;
+  IdeFile *file;
+
+  g_return_if_fail (IDE_IS_LAYOUT_VIEW (widget));
+
+  if (lookup->view != NULL)
+    return;
+
+  if (!IDE_IS_EDITOR_VIEW (widget))
+    return;
+
+  buffer = ide_editor_view_get_document (IDE_EDITOR_VIEW (widget));
+  file = ide_buffer_get_file (buffer);
+
+  if (ide_file_equal (file, lookup->file))
+    lookup->view = IDE_EDITOR_VIEW (widget);
+}
+
+void
+ide_editor_perspective_focus_location (IdeEditorPerspective *self,
+                                       IdeSourceLocation    *location)
+{
+  struct {
+    IdeFile       *file;
+    IdeEditorView *view;
+  } lookup = { 0 };
+  GtkWidget *stack;
+
+  g_return_if_fail (IDE_IS_EDITOR_PERSPECTIVE (self));
+  g_return_if_fail (location != NULL);
+
+  lookup.file = ide_source_location_get_file (location);
+  lookup.view = NULL;
+
+  ide_perspective_views_foreach (IDE_PERSPECTIVE (self),
+                                 ide_editor_perspective_find_source_location,
+                                 &lookup);
+
+  if (lookup.view == NULL)
+    {
+      /* TODO: create view */
+      return;
+    }
+
+  stack = gtk_widget_get_ancestor (GTK_WIDGET (lookup.view), IDE_TYPE_LAYOUT_STACK);
+  ide_layout_stack_set_active_view (IDE_LAYOUT_STACK (stack), GTK_WIDGET (lookup.view));
+  ide_layout_view_navigate_to (IDE_LAYOUT_VIEW (lookup.view), location);
+  gtk_widget_grab_focus (GTK_WIDGET (lookup.view));
+}
diff --git a/libide/editor/ide-editor-perspective.h b/libide/editor/ide-editor-perspective.h
index cb21067..30070b6 100644
--- a/libide/editor/ide-editor-perspective.h
+++ b/libide/editor/ide-editor-perspective.h
@@ -23,6 +23,7 @@
 
 #include "ide-layout.h"
 #include "ide-perspective.h"
+#include "ide-source-location.h"
 
 G_BEGIN_DECLS
 
@@ -30,6 +31,9 @@ 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);
+
 G_END_DECLS
 
 #endif /* IDE_EDITOR_PERSPECTIVE_H */
diff --git a/libide/ide.h b/libide/ide.h
index 387859e..3ee6497 100644
--- a/libide/ide.h
+++ b/libide/ide.h
@@ -113,6 +113,7 @@ G_BEGIN_DECLS
 #include "ide-workbench.h"
 #include "ide-workbench-addin.h"
 
+#include "editor/ide-editor-perspective.h"
 #include "editor/ide-editor-view.h"
 #include "editor/ide-editor-view-addin.h"
 


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