[gnome-builder/wip/chergert/docs] add plumbing for item activation



commit b92d1c434f37ce4e167566f34c4b2f4b883d4f30
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jul 15 10:31:21 2019 -0700

    add plumbing for item activation

 src/libide/docs/ide-docs-search-view.c          | 28 ++++++++++++++++++++++++-
 src/libide/docs/ide-docs-workspace.c            | 20 ++++++++++++++++++
 src/plugins/devhelp/gbp-devhelp-docs-provider.c |  1 +
 3 files changed, 48 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/docs/ide-docs-search-view.c b/src/libide/docs/ide-docs-search-view.c
index ecd051dd3..4949823a6 100644
--- a/src/libide/docs/ide-docs-search-view.c
+++ b/src/libide/docs/ide-docs-search-view.c
@@ -47,6 +47,13 @@ struct _IdeDocsSearchView
 
 G_DEFINE_TYPE (IdeDocsSearchView, ide_docs_search_view, GTK_TYPE_BIN)
 
+enum {
+  ITEM_ACTIVATED,
+  N_SIGNALS
+};
+
+static guint signals [N_SIGNALS];
+
 static void
 on_go_previous_clicked_cb (IdeDocsSearchView *self,
                            GtkButton         *button)
@@ -172,6 +179,25 @@ ide_docs_search_view_class_init (IdeDocsSearchViewClass *klass)
   gtk_widget_class_bind_template_child (widget_class, IdeDocsSearchView, scroller);
   gtk_widget_class_bind_template_child (widget_class, IdeDocsSearchView, sections);
   gtk_widget_class_bind_template_child (widget_class, IdeDocsSearchView, titles);
+
+  /**
+   * IdeDocsSearchView::item-activated:
+   * @self: an #IdeDocsSearchView
+   * @item: an #IdeDocsItem
+   *
+   * The "item-activated" signal is emitted when a documentation item
+   * has been activated and should be displayed to the user.
+   *
+   * Since: 3.34
+   */
+  signals [ITEM_ACTIVATED] =
+    g_signal_new ("item-activated",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL, NULL,
+                  NULL,
+                  G_TYPE_NONE, 1, IDE_TYPE_DOCS_ITEM);
 }
 
 static void
@@ -223,7 +249,7 @@ on_item_activated_cb (IdeDocsSearchView    *self,
     }
   else
     {
-      g_print ("Display docs for %s\n", ide_docs_item_get_title (item));
+      g_signal_emit (self, signals [ITEM_ACTIVATED], 0, item);
     }
 }
 
diff --git a/src/libide/docs/ide-docs-workspace.c b/src/libide/docs/ide-docs-workspace.c
index b0be737c7..a280900ff 100644
--- a/src/libide/docs/ide-docs-workspace.c
+++ b/src/libide/docs/ide-docs-workspace.c
@@ -86,6 +86,20 @@ on_search_entry_changed_cb (IdeDocsWorkspace *self,
                                      NULL);
 }
 
+static void
+on_search_view_item_activated_cb (IdeDocsWorkspace  *self,
+                                  IdeDocsItem       *item,
+                                  IdeDocsSearchView *view)
+{
+  g_assert (IDE_IS_DOCS_WORKSPACE (self));
+  g_assert (IDE_IS_DOCS_ITEM (item));
+  g_assert (IDE_IS_DOCS_SEARCH_VIEW (view));
+
+  g_print ("Activate view for %s at %s\n",
+           ide_docs_item_get_title (item),
+           ide_docs_item_get_url (item));
+}
+
 static void
 ide_docs_workspace_class_init (IdeDocsWorkspaceClass *klass)
 {
@@ -106,6 +120,12 @@ ide_docs_workspace_init (IdeDocsWorkspace *self)
 {
   gtk_widget_init_template (GTK_WIDGET (self));
 
+  g_signal_connect_object (self->search_view,
+                           "item-activated",
+                           G_CALLBACK (on_search_view_item_activated_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+
   g_signal_connect_object (self->entry,
                            "changed",
                            G_CALLBACK (on_search_entry_changed_cb),
diff --git a/src/plugins/devhelp/gbp-devhelp-docs-provider.c b/src/plugins/devhelp/gbp-devhelp-docs-provider.c
index 6d0616306..403231802 100644
--- a/src/plugins/devhelp/gbp-devhelp-docs-provider.c
+++ b/src/plugins/devhelp/gbp-devhelp-docs-provider.c
@@ -135,6 +135,7 @@ gbp_devhelp_docs_provider_search_async (IdeDocsProvider     *provider,
                   ide_docs_item_set_title (child, kw->name);
                   ide_docs_item_set_display_name (child, highlight);
                   ide_docs_item_set_kind (child, kw->kind);
+                  ide_docs_item_set_url (group, kw->link);
                   ide_docs_item_set_priority (group, prio);
                   ide_docs_item_append (group, child);
 


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