[gnome-builder/wip/chergert/perspective] libide: reintroduce gd/alt+. support on perspectives



commit 469983748237ffed26f6694fc7585af93cb0d5c2
Author: Christian Hergert <chergert redhat com>
Date:   Sat Dec 5 23:01:53 2015 -0800

    libide: reintroduce gd/alt+. support on perspectives

 libide/editor/ide-editor-frame.c       |   18 ++++------
 libide/editor/ide-editor-perspective.c |   62 ++++++++++++++++++++++++++++++--
 2 files changed, 66 insertions(+), 14 deletions(-)
---
diff --git a/libide/editor/ide-editor-frame.c b/libide/editor/ide-editor-frame.c
index 3e7013e..94a4886 100644
--- a/libide/editor/ide-editor-frame.c
+++ b/libide/editor/ide-editor-frame.c
@@ -25,6 +25,8 @@
 #include "ide-editor-map-bin.h"
 #include "ide-gtk.h"
 #include "ide-layout-stack.h"
+#include "ide-source-location.h"
+#include "ide-workbench.h"
 
 #define MINIMAP_HIDE_DURATION 1000
 #define MINIMAP_SHOW_DURATION 250
@@ -541,23 +543,17 @@ ide_editor_frame__source_view_focus_location (IdeEditorFrame    *self,
                                               IdeSourceLocation *location,
                                               IdeSourceView     *source_view)
 {
-  GtkWidget *toplevel;
+  IdeWorkbench *workbench;
+  IdePerspective *editor;
 
   g_assert (IDE_IS_EDITOR_FRAME (self));
   g_assert (location != NULL);
   g_assert (IDE_IS_SOURCE_VIEW (source_view));
 
-  toplevel = gtk_widget_get_ancestor (GTK_WIDGET (self), IDE_TYPE_WORKBENCH);
+  workbench = ide_widget_get_workbench (GTK_WIDGET (self));
+  editor = ide_workbench_get_perspective_by_name (workbench, "editor");
 
-  if (IDE_IS_WORKBENCH (toplevel))
-    {
-      /*
-       * Convert location to Uri and open.
-       */
-#if 0
-      ide_layout_stack_focus_location (IDE_LAYOUT_STACK (widget), location);
-#endif
-    }
+  ide_editor_perspective_focus_location (IDE_EDITOR_PERSPECTIVE (editor), location);
 }
 
 static void
diff --git a/libide/editor/ide-editor-perspective.c b/libide/editor/ide-editor-perspective.c
index 962c220..4b9d2b3 100644
--- a/libide/editor/ide-editor-perspective.c
+++ b/libide/editor/ide-editor-perspective.c
@@ -43,6 +43,12 @@ struct _IdeEditorPerspective
   EggSignalGroup        *buffer_manager_signals;
 };
 
+typedef struct
+{
+  IdeEditorPerspective *self;
+  IdeSourceLocation    *location;
+} FocusLocation;
+
 static void ide_perspective_iface_init (IdePerspectiveInterface *iface);
 
 G_DEFINE_TYPE_EXTENDED (IdeEditorPerspective, ide_editor_perspective, IDE_TYPE_LAYOUT, 0,
@@ -405,7 +411,7 @@ ide_editor_perspective_find_source_location (GtkWidget *widget,
                                              gpointer   user_data)
 {
   struct {
-    IdeFile       *file;
+    IdeFile *file;
     IdeEditorView *view;
   } *lookup = user_data;
   IdeBuffer *buffer;
@@ -426,12 +432,43 @@ ide_editor_perspective_find_source_location (GtkWidget *widget,
     lookup->view = IDE_EDITOR_VIEW (widget);
 }
 
+static void
+ide_editor_perspective_focus_location_cb (GObject      *object,
+                                          GAsyncResult *result,
+                                          gpointer      user_data)
+{
+  IdeBufferManager *bufmgr = (IdeBufferManager *)object;
+  FocusLocation *state = user_data;
+  GError *error = NULL;
+
+  g_assert (IDE_IS_BUFFER_MANAGER (bufmgr));
+  g_assert (state != NULL);
+  g_assert (IDE_IS_EDITOR_PERSPECTIVE (state->self));
+  g_assert (state->location != NULL);
+
+  if (!ide_buffer_manager_load_file_finish (bufmgr, result, &error))
+    {
+      /* TODO: display warning breifly to the user in the frame? */
+      g_warning ("%s", error->message);
+      g_clear_error (&error);
+      goto cleanup;
+    }
+
+  /* try again now that we have loaded */
+  ide_editor_perspective_focus_location (state->self, state->location);
+
+cleanup:
+  g_object_unref (state->self);
+  ide_source_location_unref (state->location);
+  g_slice_free (FocusLocation, state);
+}
+
 void
 ide_editor_perspective_focus_location (IdeEditorPerspective *self,
                                        IdeSourceLocation    *location)
 {
   struct {
-    IdeFile       *file;
+    IdeFile *file;
     IdeEditorView *view;
   } lookup = { 0 };
   GtkWidget *stack;
@@ -448,7 +485,26 @@ ide_editor_perspective_focus_location (IdeEditorPerspective *self,
 
   if (lookup.view == NULL)
     {
-      /* TODO: create view */
+      FocusLocation *state;
+      IdeBufferManager *bufmgr;
+      IdeWorkbench *workbench;
+      IdeContext *context;
+
+      workbench = ide_widget_get_workbench (GTK_WIDGET (self));
+      context = ide_workbench_get_context (workbench);
+      bufmgr = ide_context_get_buffer_manager (context);
+
+      state = g_slice_new0 (FocusLocation);
+      state->self = g_object_ref (self);
+      state->location = ide_source_location_ref (location);
+
+      ide_buffer_manager_load_file_async (bufmgr,
+                                          lookup.file,
+                                          FALSE,
+                                          NULL,
+                                          NULL,
+                                          ide_editor_perspective_focus_location_cb,
+                                          state);
       return;
     }
 


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