[gnome-builder/wip/libide-merge] make devhelp search work again



commit 8da2db6312cdd168c4af1afbd22674aab079a25e
Author: Christian Hergert <christian hergert me>
Date:   Sat Mar 21 19:20:15 2015 -0700

    make devhelp search work again

 {src/resources => data}/ui/gb-devhelp-view.ui |    2 +-
 libide/Makefile.am                            |    2 +
 libide/devhelp/ide-devhelp-search-provider.c  |   11 ++-
 libide/devhelp/ide-devhelp-search-result.c    |  109 +++++++++++++++++++++++++
 libide/devhelp/ide-devhelp-search-result.h    |   33 ++++++++
 libide/git/ide-git-search-result.c            |    4 +-
 libide/ide.h                                  |    1 +
 src/devhelp/gb-devhelp-document.c             |   13 ++--
 src/devhelp/gb-devhelp-document.h             |    2 +
 src/devhelp/gb-devhelp-view.c                 |   19 ++---
 src/devhelp/gb-devhelp-view.h                 |   10 +-
 src/editor/gb-editor-workspace.c              |   43 ++++++++++
 src/editor/gb-editor-workspace.h              |    3 +
 src/gnome-builder.mk                          |    8 +-
 src/resources/gnome-builder.gresource.xml     |    2 +-
 src/search/gb-search-box.c                    |   10 +++
 src/views/gb-view-grid.c                      |   37 +++++++++
 src/views/gb-view-grid.h                      |   19 +++--
 src/views/gb-view-stack.c                     |   22 +++++
 src/views/gb-view-stack.h                     |   26 +++---
 src/workbench/gb-workbench.c                  |   20 +++++
 src/workbench/gb-workbench.h                  |    2 +
 22 files changed, 344 insertions(+), 54 deletions(-)
---
diff --git a/src/resources/ui/gb-devhelp-view.ui b/data/ui/gb-devhelp-view.ui
similarity index 89%
rename from src/resources/ui/gb-devhelp-view.ui
rename to data/ui/gb-devhelp-view.ui
index 75c0628..f5f2f1e 100644
--- a/src/resources/ui/gb-devhelp-view.ui
+++ b/data/ui/gb-devhelp-view.ui
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.14 -->
-  <template class="GbDevhelpView" parent="GbDocumentView">
+  <template class="GbDevhelpView" parent="GbView">
     <child internal-child="controls">
       <object class="GtkBox">
         <property name="visible">true</property>
diff --git a/libide/Makefile.am b/libide/Makefile.am
index 772e139..20894d2 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -26,6 +26,8 @@ libide_1_0_la_public_sources = \
        libide/clang/ide-clang-translation-unit.h \
        libide/devhelp/ide-devhelp-search-provider.c \
        libide/devhelp/ide-devhelp-search-provider.h \
+       libide/devhelp/ide-devhelp-search-result.c \
+       libide/devhelp/ide-devhelp-search-result.h \
        libide/directory/ide-directory-build-system.c \
        libide/directory/ide-directory-build-system.h \
        libide/directory/ide-directory-vcs.c \
diff --git a/libide/devhelp/ide-devhelp-search-provider.c b/libide/devhelp/ide-devhelp-search-provider.c
index af9ec9d..3a0b466 100644
--- a/libide/devhelp/ide-devhelp-search-provider.c
+++ b/libide/devhelp/ide-devhelp-search-provider.c
@@ -24,6 +24,7 @@
 #include <glib/gi18n.h>
 #include <devhelp/devhelp.h>
 
+#include "ide-devhelp-search-result.h"
 #include "ide-search-reducer.h"
 #include "ide-search-result.h"
 #include "ide-search-context.h"
@@ -102,10 +103,14 @@ ide_devhelp_search_provider_populate (IdeSearchProvider *provider,
           name = italic_name;
         }
 
-      result = ide_search_result_new (idecontext, name, dh_link_get_book_name (link), score);
-      g_object_set_qdata_full (G_OBJECT (result), gQuarkLink, dh_link_get_uri (link), g_free);
+      result = g_object_new (IDE_TYPE_DEVHELP_SEARCH_RESULT,
+                             "context", idecontext,
+                             "title", name,
+                             "subtitle", dh_link_get_book_name (link),
+                             "score", score,
+                             "uri", dh_link_get_uri (link),
+                             NULL);
 
-      /* push the result through the search reducer */
       ide_search_reducer_push (&reducer, result);
     }
 
diff --git a/libide/devhelp/ide-devhelp-search-result.c b/libide/devhelp/ide-devhelp-search-result.c
new file mode 100644
index 0000000..63ec1c3
--- /dev/null
+++ b/libide/devhelp/ide-devhelp-search-result.c
@@ -0,0 +1,109 @@
+/* ide-git-search-result.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This file is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n.h>
+
+#include "ide-devhelp-search-result.h"
+
+struct _IdeDevhelpSearchResult
+{
+  IdeSearchResult  parent_instance;
+  gchar           *uri;
+};
+
+enum
+{
+  PROP_0,
+  PROP_URI,
+  LAST_PROP
+};
+
+G_DEFINE_TYPE (IdeDevhelpSearchResult, ide_devhelp_search_result, IDE_TYPE_SEARCH_RESULT)
+
+static GParamSpec *gParamSpecs [LAST_PROP];
+
+static void
+ide_devhelp_search_result_finalize (GObject *object)
+{
+  IdeDevhelpSearchResult *self = (IdeDevhelpSearchResult *)object;
+
+  g_clear_pointer (&self->uri, g_free);
+
+  G_OBJECT_CLASS (ide_devhelp_search_result_parent_class)->finalize (object);
+}
+
+static void
+ide_devhelp_search_result_get_property (GObject    *object,
+                                        guint       prop_id,
+                                        GValue     *value,
+                                        GParamSpec *pspec)
+{
+  IdeDevhelpSearchResult *self = IDE_DEVHELP_SEARCH_RESULT (object);
+
+  switch (prop_id)
+    {
+    case PROP_URI:
+      g_value_set_string (value, self->uri);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_devhelp_search_result_set_property (GObject      *object,
+                                        guint         prop_id,
+                                        const GValue *value,
+                                        GParamSpec   *pspec)
+{
+  IdeDevhelpSearchResult *self = IDE_DEVHELP_SEARCH_RESULT (object);
+
+  switch (prop_id)
+    {
+    case PROP_URI:
+      self->uri = g_value_dup_string (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_devhelp_search_result_class_init (IdeDevhelpSearchResultClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = ide_devhelp_search_result_finalize;
+  object_class->get_property = ide_devhelp_search_result_get_property;
+  object_class->set_property = ide_devhelp_search_result_set_property;
+
+  gParamSpecs [PROP_URI] =
+    g_param_spec_string ("uri",
+                         _("Uri"),
+                         _("The uri to the devhelp document."),
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+  g_object_class_install_property (object_class, PROP_URI, gParamSpecs [PROP_URI]);
+}
+
+static void
+ide_devhelp_search_result_init (IdeDevhelpSearchResult *result)
+{
+}
diff --git a/libide/devhelp/ide-devhelp-search-result.h b/libide/devhelp/ide-devhelp-search-result.h
new file mode 100644
index 0000000..39f385a
--- /dev/null
+++ b/libide/devhelp/ide-devhelp-search-result.h
@@ -0,0 +1,33 @@
+/* ide-devhelp-search-result.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This file is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_DEVHELP_SEARCH_RESULT_H
+#define IDE_DEVHELP_SEARCH_RESULT_H
+
+#include "ide-search-result.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_DEVHELP_SEARCH_RESULT (ide_devhelp_search_result_get_type())
+
+G_DECLARE_FINAL_TYPE (IdeDevhelpSearchResult, ide_devhelp_search_result,
+                      IDE, DEVHELP_SEARCH_RESULT, IdeSearchResult)
+
+G_END_DECLS
+
+#endif /* IDE_DEVHELP_SEARCH_RESULT_H */
diff --git a/libide/git/ide-git-search-result.c b/libide/git/ide-git-search-result.c
index aec8d27..e906054 100644
--- a/libide/git/ide-git-search-result.c
+++ b/libide/git/ide-git-search-result.c
@@ -88,9 +88,7 @@ ide_git_search_result_set_property (GObject      *object,
 static void
 ide_git_search_result_class_init (IdeGitSearchResultClass *klass)
 {
-  GObjectClass *object_class;
-
-  object_class = G_OBJECT_CLASS (klass);
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
   object_class->finalize = ide_git_search_result_finalize;
   object_class->get_property = ide_git_search_result_get_property;
   object_class->set_property = ide_git_search_result_set_property;
diff --git a/libide/ide.h b/libide/ide.h
index cbaafff..ab3c64f 100644
--- a/libide/ide.h
+++ b/libide/ide.h
@@ -87,6 +87,7 @@ G_BEGIN_DECLS
 #include "ide-vcs.h"
 
 #include "autotools/ide-autotools-build-system.h"
+#include "devhelp/ide-devhelp-search-result.h"
 #include "directory/ide-directory-build-system.h"
 #include "directory/ide-directory-vcs.h"
 #include "git/ide-git-search-result.h"
diff --git a/src/devhelp/gb-devhelp-document.c b/src/devhelp/gb-devhelp-document.c
index 34316f1..7be6539 100644
--- a/src/devhelp/gb-devhelp-document.c
+++ b/src/devhelp/gb-devhelp-document.c
@@ -81,7 +81,7 @@ gb_devhelp_document_get_uri (GbDevhelpDocument *document)
   return document->priv->uri;
 }
 
-static void
+void
 gb_devhelp_document_set_uri (GbDevhelpDocument *document,
                              const gchar       *uri)
 {
@@ -227,12 +227,14 @@ gb_devhelp_document_set_property (GObject      *object,
                                   const GValue *value,
                                   GParamSpec   *pspec)
 {
-#if 0
   GbDevhelpDocument *self = GB_DEVHELP_DOCUMENT (object);
-#endif
 
   switch (prop_id)
     {
+    case PROP_URI:
+      gb_devhelp_document_set_uri (self, g_value_get_string (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -257,9 +259,8 @@ gb_devhelp_document_class_init (GbDevhelpDocumentClass *klass)
                          _("URI"),
                          _("The uri to load."),
                          NULL,
-                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
-  g_object_class_install_property (object_class, PROP_URI,
-                                   gParamSpecs [PROP_URI]);
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+  g_object_class_install_property (object_class, PROP_URI, gParamSpecs [PROP_URI]);
 }
 
 static void
diff --git a/src/devhelp/gb-devhelp-document.h b/src/devhelp/gb-devhelp-document.h
index 8a6c87f..dc1868f 100644
--- a/src/devhelp/gb-devhelp-document.h
+++ b/src/devhelp/gb-devhelp-document.h
@@ -53,6 +53,8 @@ GbDevhelpDocument *gb_devhelp_document_new        (void);
 void               gb_devhelp_document_set_search (GbDevhelpDocument *document,
                                                    const gchar       *search);
 const gchar       *gb_devhelp_document_get_uri    (GbDevhelpDocument *document);
+void               gb_devhelp_document_set_uri    (GbDevhelpDocument *document,
+                                                   const gchar       *uri);
 
 G_END_DECLS
 
diff --git a/src/devhelp/gb-devhelp-view.c b/src/devhelp/gb-devhelp-view.c
index 55bbad8..0cf3ca9 100644
--- a/src/devhelp/gb-devhelp-view.c
+++ b/src/devhelp/gb-devhelp-view.c
@@ -22,6 +22,7 @@
 #include <webkit2/webkit2.h>
 
 #include "gb-devhelp-view.h"
+#include "gb-widget.h"
 
 struct _GbDevhelpViewPrivate
 {
@@ -32,8 +33,7 @@ struct _GbDevhelpViewPrivate
   WebKitWebView *web_view;
 };
 
-G_DEFINE_TYPE_WITH_PRIVATE (GbDevhelpView, gb_devhelp_view,
-                            GB_TYPE_DOCUMENT_VIEW)
+G_DEFINE_TYPE_WITH_PRIVATE (GbDevhelpView, gb_devhelp_view, GB_TYPE_VIEW)
 
 enum {
   PROP_0,
@@ -43,7 +43,7 @@ enum {
 
 static GParamSpec *gParamSpecs [LAST_PROP];
 
-GbDocumentView *
+GbView *
 gb_devhelp_view_new (GbDevhelpDocument *document)
 {
   return g_object_new (GB_TYPE_DEVHELP_VIEW,
@@ -52,7 +52,7 @@ gb_devhelp_view_new (GbDevhelpDocument *document)
 }
 
 static GbDocument *
-gb_devhelp_view_get_document (GbDocumentView *view)
+gb_devhelp_view_get_document (GbView *view)
 {
   g_return_val_if_fail (GB_IS_DEVHELP_VIEW (view), NULL);
 
@@ -161,8 +161,7 @@ static void
 gb_devhelp_view_class_init (GbDevhelpViewClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-  GbDocumentViewClass *view_class = GB_DOCUMENT_VIEW_CLASS (klass);
+  GbViewClass *view_class = GB_VIEW_CLASS (klass);
 
   object_class->finalize = gb_devhelp_view_finalize;
   object_class->get_property = gb_devhelp_view_get_property;
@@ -176,12 +175,10 @@ gb_devhelp_view_class_init (GbDevhelpViewClass *klass)
                          _("The document for the devhelp view."),
                          GB_TYPE_DEVHELP_DOCUMENT,
                          (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-  g_object_class_install_property (object_class, PROP_DOCUMENT,
-                                   gParamSpecs [PROP_DOCUMENT]);
+  g_object_class_install_property (object_class, PROP_DOCUMENT, gParamSpecs [PROP_DOCUMENT]);
 
-  gtk_widget_class_set_template_from_resource (widget_class,
-                                               "/org/gnome/builder/ui/gb-devhelp-view.ui");
-  gtk_widget_class_bind_template_child_private (widget_class, GbDevhelpView, web_view);
+  GB_WIDGET_CLASS_TEMPLATE (klass, "gb-devhelp-view.ui");
+  GB_WIDGET_CLASS_BIND_PRIVATE (klass, GbDevhelpView, web_view);
 
   g_type_ensure (WEBKIT_TYPE_WEB_VIEW);
 }
diff --git a/src/devhelp/gb-devhelp-view.h b/src/devhelp/gb-devhelp-view.h
index 4714ea2..5f09dc2 100644
--- a/src/devhelp/gb-devhelp-view.h
+++ b/src/devhelp/gb-devhelp-view.h
@@ -20,7 +20,7 @@
 #define GB_DEVHELP_VIEW_H
 
 #include "gb-devhelp-document.h"
-#include "gb-document-view.h"
+#include "gb-view.h"
 
 G_BEGIN_DECLS
 
@@ -38,7 +38,7 @@ typedef struct _GbDevhelpViewPrivate GbDevhelpViewPrivate;
 
 struct _GbDevhelpView
 {
-  GbDocumentView parent;
+  GbView parent;
 
   /*< private >*/
   GbDevhelpViewPrivate *priv;
@@ -46,11 +46,11 @@ struct _GbDevhelpView
 
 struct _GbDevhelpViewClass
 {
-  GbDocumentViewClass parent;
+  GbViewClass parent;
 };
 
-GType           gb_devhelp_view_get_type (void);
-GbDocumentView *gb_devhelp_view_new      (GbDevhelpDocument *document);
+GType   gb_devhelp_view_get_type (void);
+GbView *gb_devhelp_view_new      (GbDevhelpDocument *document);
 
 G_END_DECLS
 
diff --git a/src/editor/gb-editor-workspace.c b/src/editor/gb-editor-workspace.c
index 410de2a..0e4ec59 100644
--- a/src/editor/gb-editor-workspace.c
+++ b/src/editor/gb-editor-workspace.c
@@ -21,6 +21,7 @@
 #include <glib/gi18n.h>
 #include <ide.h>
 
+#include "gb-devhelp-document.h"
 #include "gb-editor-document.h"
 #include "gb-editor-workspace.h"
 #include "gb-editor-workspace-actions.h"
@@ -165,3 +166,45 @@ gb_editor_workspace_init (GbEditorWorkspace *self)
 
   gb_widget_set_context_handler (self, gb_editor_workspace_context_changed);
 }
+
+void
+gb_editor_workspace_show_help (GbEditorWorkspace *self,
+                               const gchar       *uri)
+{
+  GbDocument *document;
+  GtkWidget *last_focus;
+  GtkWidget *after;
+
+  g_return_if_fail (GB_IS_EDITOR_WORKSPACE (self));
+  g_return_if_fail (uri);
+
+  document = gb_view_grid_find_document_typed (self->view_grid, GB_TYPE_DEVHELP_DOCUMENT);
+
+  if (document != NULL)
+    {
+      g_object_set (document, "uri", uri, NULL);
+      gb_view_grid_focus_document (self->view_grid, document);
+      return;
+    }
+
+  document = g_object_new (GB_TYPE_DEVHELP_DOCUMENT,
+                           "uri", uri,
+                           NULL);
+
+  last_focus = gb_view_grid_get_last_focus (self->view_grid);
+
+  if (last_focus == NULL)
+    {
+      gb_view_grid_focus_document (self->view_grid, document);
+      return;
+    }
+
+  after = gb_view_grid_get_stack_after (self->view_grid, GB_VIEW_STACK (last_focus));
+
+  if (after == NULL)
+    after = gb_view_grid_add_stack_after (self->view_grid, GB_VIEW_STACK (last_focus));
+
+  gb_view_stack_focus_document (GB_VIEW_STACK (after), document);
+
+  g_clear_object (&document);
+}
diff --git a/src/editor/gb-editor-workspace.h b/src/editor/gb-editor-workspace.h
index 5783cdf..04657cd 100644
--- a/src/editor/gb-editor-workspace.h
+++ b/src/editor/gb-editor-workspace.h
@@ -27,6 +27,9 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GbEditorWorkspace, gb_editor_workspace, GB, EDITOR_WORKSPACE, GbWorkspace)
 
+void gb_editor_workspace_show_help (GbEditorWorkspace *self,
+                                    const gchar       *uri);
+
 G_END_DECLS
 
 #endif /* GB_EDITOR_WORKSPACE_H */
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index 2803774..72836a6 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -30,6 +30,10 @@ libgnome_builder_la_SOURCES = \
        src/commands/gb-command-vim.h \
        src/commands/gb-command.c \
        src/commands/gb-command.h \
+       src/devhelp/gb-devhelp-document.c \
+       src/devhelp/gb-devhelp-document.h \
+       src/devhelp/gb-devhelp-view.c \
+       src/devhelp/gb-devhelp-view.h \
        src/documents/gb-document.c \
        src/documents/gb-document.h \
        src/editor/gb-editor-document.c \
@@ -139,10 +143,6 @@ libgnome_builder_la_SOURCES = \
        $(NULL)
 
 disabled_files = \
-       src/devhelp/gb-devhelp-document.c \
-       src/devhelp/gb-devhelp-document.h \
-       src/devhelp/gb-devhelp-view.c \
-       src/devhelp/gb-devhelp-view.h \
        src/editor/gb-source-formatter.c \
        src/editor/gb-source-formatter.h \
        src/editor/gb-source-highlight-menu.c \
diff --git a/src/resources/gnome-builder.gresource.xml b/src/resources/gnome-builder.gresource.xml
index 0fddcda..9ab351f 100644
--- a/src/resources/gnome-builder.gresource.xml
+++ b/src/resources/gnome-builder.gresource.xml
@@ -24,6 +24,7 @@
     <file alias="keybindings/vim.css">../../data/keybindings/vim.css</file>
 
     <file alias="ui/gb-command-bar.ui">../../data/ui/gb-command-bar.ui</file>
+    <file alias="ui/gb-devhelp-view.ui">../../data/ui/gb-devhelp-view.ui</file>
     <file alias="ui/gb-editor-frame.ui">../../data/ui/gb-editor-frame.ui</file>
     <file alias="ui/gb-editor-settings-widget.ui">../../data/ui/gb-editor-settings-widget.ui</file>
     <file alias="ui/gb-editor-tweak-widget.ui">../../data/ui/gb-editor-tweak-widget.ui</file>
@@ -43,6 +44,5 @@
     <file alias="ui/gb-workbench.ui">../../data/ui/gb-workbench.ui</file>
 
     <file>ui/gb-command-bar-item.ui</file>
-    <file>ui/gb-devhelp-view.ui</file>
   </gresource>
 </gresources>
diff --git a/src/search/gb-search-box.c b/src/search/gb-search-box.c
index 3b551cd..ff5ea5b 100644
--- a/src/search/gb-search-box.c
+++ b/src/search/gb-search-box.c
@@ -20,6 +20,7 @@
 
 #include <glib/gi18n.h>
 
+#include "gb-editor-workspace.h"
 #include "gb-glib.h"
 #include "gb-scrolled-window.h"
 #include "gb-search-box.h"
@@ -252,6 +253,15 @@ gb_search_box_display_result_activated (GbSearchBox     *self,
       if (file)
         gb_workbench_open (workbench, file);
     }
+  else if (IDE_IS_DEVHELP_SEARCH_RESULT (result))
+    {
+      g_autofree gchar *uri = NULL;
+      GbEditorWorkspace *workspace;
+
+      g_object_get (result, "uri", &uri, NULL);
+      workspace = gb_workbench_get_workspace_typed (workbench, GB_TYPE_EDITOR_WORKSPACE);
+      gb_editor_workspace_show_help (workspace, uri);
+    }
   else
     {
       g_warning (_("Builder does not know how to load %s"),
diff --git a/src/views/gb-view-grid.c b/src/views/gb-view-grid.c
index 5416654..3656508 100644
--- a/src/views/gb-view-grid.c
+++ b/src/views/gb-view-grid.c
@@ -791,3 +791,40 @@ gb_view_grid_split_get_type (void)
 
   return type_id;
 }
+
+GbDocument *
+gb_view_grid_find_document_typed (GbViewGrid *self,
+                                  GType       document_type)
+{
+  GbDocument *ret = NULL;
+  GList *stacks;
+  GList *iter;
+
+  g_return_val_if_fail (GB_IS_VIEW_GRID (self), NULL);
+  g_return_val_if_fail (g_type_is_a (document_type, GB_TYPE_DOCUMENT), NULL);
+
+  stacks = gb_view_grid_get_stacks (self);
+
+  for (iter = stacks; !ret && iter; iter = iter->next)
+    ret = gb_view_stack_find_document_typed (iter->data, document_type);
+
+  g_list_free (stacks);
+
+  return ret;
+}
+
+/**
+ * gb_view_grid_get_last_focus:
+ * @self: A #GbViewGrid.
+ *
+ * Gets the last focused #GbViewStack.
+ *
+ * Returns: (transfer none) (nullable): A #GbViewStack or %NULL.
+ */
+GtkWidget *
+gb_view_grid_get_last_focus (GbViewGrid *self)
+{
+  g_return_val_if_fail (GB_IS_VIEW_GRID (self), NULL);
+
+  return GTK_WIDGET (self->last_focus);
+}
diff --git a/src/views/gb-view-grid.h b/src/views/gb-view-grid.h
index 0873e11..49007f1 100644
--- a/src/views/gb-view-grid.h
+++ b/src/views/gb-view-grid.h
@@ -39,19 +39,22 @@ typedef enum
   GB_VIEW_GRID_MOVE_RIGHT,
 } GbViewGridSplit;
 
-GType      gb_view_grid_split_get_type       (void);
-GtkWidget *gb_view_grid_new                  (void);
-GtkWidget *gb_view_grid_add_stack_after      (GbViewGrid  *grid,
+GType       gb_view_grid_split_get_type      (void);
+GtkWidget  *gb_view_grid_new                 (void);
+GtkWidget  *gb_view_grid_add_stack_after     (GbViewGrid  *grid,
                                               GbViewStack *stack);
-GtkWidget *gb_view_grid_add_stack_before     (GbViewGrid  *grid,
+GtkWidget  *gb_view_grid_add_stack_before    (GbViewGrid  *grid,
                                               GbViewStack *stack);
-GtkWidget *gb_view_grid_get_stack_after      (GbViewGrid  *grid,
+GtkWidget  *gb_view_grid_get_stack_after     (GbViewGrid  *grid,
                                               GbViewStack *stack);
-GtkWidget *gb_view_grid_get_stack_before     (GbViewGrid  *grid,
+GtkWidget  *gb_view_grid_get_stack_before    (GbViewGrid  *grid,
                                               GbViewStack *stack);
-GList     *gb_view_grid_get_stacks           (GbViewGrid  *grid);
-void       gb_view_grid_focus_document       (GbViewGrid  *grid,
+GList      *gb_view_grid_get_stacks          (GbViewGrid  *grid);
+void        gb_view_grid_focus_document      (GbViewGrid  *grid,
                                               GbDocument  *document);
+GtkWidget  *gb_view_grid_get_last_focus      (GbViewGrid  *self);
+GbDocument *gb_view_grid_find_document_typed (GbViewGrid  *self,
+                                              GType        document_type);
 
 G_END_DECLS
 
diff --git a/src/views/gb-view-stack.c b/src/views/gb-view-stack.c
index 58dff71..ee97c60 100644
--- a/src/views/gb-view-stack.c
+++ b/src/views/gb-view-stack.c
@@ -19,6 +19,7 @@
 #include <glib/gi18n.h>
 #include <ide.h>
 
+#include "gb-document.h"
 #include "gb-view.h"
 #include "gb-view-grid.h"
 #include "gb-view-stack.h"
@@ -629,3 +630,24 @@ gb_view_stack_focus_location (GbViewStack       *self,
                                           g_object_ref (task));
     }
 }
+
+GbDocument *
+gb_view_stack_find_document_typed (GbViewStack *self,
+                                   GType        document_type)
+{
+  GList *iter;
+
+  g_return_val_if_fail (GB_IS_VIEW_STACK (self), NULL);
+  g_return_val_if_fail (g_type_is_a (document_type, GB_TYPE_DOCUMENT), NULL);
+
+  for (iter = self->focus_history; iter; iter = iter->next)
+    {
+      GbDocument *document;
+
+      document = gb_view_get_document (iter->data);
+      if (g_type_is_a (G_TYPE_FROM_INSTANCE (document), document_type))
+        return document;
+    }
+
+  return NULL;
+}
diff --git a/src/views/gb-view-stack.h b/src/views/gb-view-stack.h
index c641f96..0139b6b 100644
--- a/src/views/gb-view-stack.h
+++ b/src/views/gb-view-stack.h
@@ -31,18 +31,20 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GbViewStack, gb_view_stack, GB, VIEW_STACK, GtkBin)
 
-GtkWidget *gb_view_stack_new                (void);
-void       gb_view_stack_remove             (GbViewStack       *self,
-                                             GbView            *view);
-GtkWidget *gb_view_stack_get_active_view    (GbViewStack       *self);
-void       gb_view_stack_set_active_view    (GbViewStack       *self,
-                                             GtkWidget         *active_view);
-GtkWidget *gb_view_stack_find_with_document (GbViewStack       *self,
-                                             GbDocument        *document);
-void       gb_view_stack_focus_document     (GbViewStack       *self,
-                                             GbDocument        *document);
-void      gb_view_stack_focus_location      (GbViewStack       *self,
-                                             IdeSourceLocation *location);
+GtkWidget  *gb_view_stack_new                 (void);
+void        gb_view_stack_remove              (GbViewStack       *self,
+                                               GbView            *view);
+GtkWidget  *gb_view_stack_get_active_view     (GbViewStack       *self);
+void        gb_view_stack_set_active_view     (GbViewStack       *self,
+                                               GtkWidget         *active_view);
+GtkWidget  *gb_view_stack_find_with_document  (GbViewStack       *self,
+                                               GbDocument        *document);
+GbDocument *gb_view_stack_find_document_typed (GbViewStack       *self,
+                                               GType              document_type);
+void        gb_view_stack_focus_document      (GbViewStack       *self,
+                                               GbDocument        *document);
+void        gb_view_stack_focus_location      (GbViewStack       *self,
+                                               IdeSourceLocation *location);
 
 G_END_DECLS
 
diff --git a/src/workbench/gb-workbench.c b/src/workbench/gb-workbench.c
index 3d2fadb..9187261 100644
--- a/src/workbench/gb-workbench.c
+++ b/src/workbench/gb-workbench.c
@@ -589,3 +589,23 @@ gb_workbench_open_uri_list (GbWorkbench         *self,
       gb_workbench_open (self, file);
     }
 }
+
+/**
+ * gb_workbench_get_workspace_typed:
+ * @self: A #GbWorkbench.
+ *
+ * Gets the workspace matching @workspace_type
+ *
+ * Returns: (transfer none): A #GbWorkspace.
+ */
+gpointer
+gb_workbench_get_workspace_typed (GbWorkbench *self,
+                                  GType        workspace_type)
+{
+  g_return_val_if_fail (GB_IS_WORKBENCH (self), NULL);
+
+  if (workspace_type == GB_TYPE_EDITOR_WORKSPACE)
+    return self->editor_workspace;
+
+  return NULL;
+}
diff --git a/src/workbench/gb-workbench.h b/src/workbench/gb-workbench.h
index 4cd2412..17e6182 100644
--- a/src/workbench/gb-workbench.h
+++ b/src/workbench/gb-workbench.h
@@ -40,6 +40,8 @@ void              gb_workbench_open                 (GbWorkbench         *self,
 void              gb_workbench_open_uri_list        (GbWorkbench         *self,
                                                      const gchar * const *uri_list);
 GbCommandManager *gb_workbench_get_command_manager  (GbWorkbench         *self);
+gpointer          gb_workbench_get_workspace_typed  (GbWorkbench         *self,
+                                                     GType                workspace_type);
 
 G_END_DECLS
 


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