[gnome-builder/wip/chergert/docs] start on all results by-group view
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/docs] start on all results by-group view
- Date: Fri, 12 Jul 2019 18:54:03 +0000 (UTC)
commit b101b30b675e69b5a942aef033351cd730758975
Author: Christian Hergert <chergert redhat com>
Date: Fri Jul 12 11:53:48 2019 -0700
start on all results by-group view
src/libide/docs/ide-docs-search-row.c | 4 +-
src/libide/docs/ide-docs-search-section.c | 109 +++++++++++++++++++++---
src/libide/docs/ide-docs-search-view.c | 46 ++++++++++
src/libide/themes/themes/shared/shared-docs.css | 2 +-
4 files changed, 145 insertions(+), 16 deletions(-)
---
diff --git a/src/libide/docs/ide-docs-search-row.c b/src/libide/docs/ide-docs-search-row.c
index bd4db79fd..e90d0ebf3 100644
--- a/src/libide/docs/ide-docs-search-row.c
+++ b/src/libide/docs/ide-docs-search-row.c
@@ -126,14 +126,14 @@ ide_docs_search_row_set_item (IdeDocsSearchRow *self,
style_context = gtk_widget_get_style_context (GTK_WIDGET (self));
- if (kind == IDE_DOCS_ITEM_KIND_BOOK && ide_docs_item_has_child (item))
+ if (kind == IDE_DOCS_ITEM_KIND_BOOK || ide_docs_item_has_child (item))
{
guint n_children = ide_docs_item_get_n_children (item);
gtk_style_context_add_class (style_context, "header");
if (n_children > DEFAULT_MAX_CHILDREN)
- title = with_size = g_strdup_printf ("%s +%u", title, n_children - DEFAULT_MAX_CHILDREN);
+ title = with_size = g_strdup_printf ("%s +%u", title, n_children - DEFAULT_MAX_CHILDREN);
}
else
{
diff --git a/src/libide/docs/ide-docs-search-section.c b/src/libide/docs/ide-docs-search-section.c
index b5eab76e5..d681fd1ae 100644
--- a/src/libide/docs/ide-docs-search-section.c
+++ b/src/libide/docs/ide-docs-search-section.c
@@ -39,6 +39,8 @@ struct _IdeDocsSearchSection
gchar *title;
gint priority;
+
+ guint show_all_results : 1;
};
G_DEFINE_TYPE (IdeDocsSearchSection, ide_docs_search_section, GTK_TYPE_BIN)
@@ -46,11 +48,34 @@ G_DEFINE_TYPE (IdeDocsSearchSection, ide_docs_search_section, GTK_TYPE_BIN)
enum {
PROP_0,
PROP_PRIORITY,
+ PROP_SHOW_ALL_RESULTS,
PROP_TITLE,
N_PROPS
};
+enum {
+ ITEM_ACTIVATED,
+ N_SIGNALS
+};
+
static GParamSpec *properties [N_PROPS];
+static guint signals [N_SIGNALS];
+
+static void
+on_row_activated_cb (IdeDocsSearchSection *self,
+ IdeDocsSearchRow *row,
+ DzlListBox *list_box)
+{
+ IdeDocsItem *item;
+
+ g_assert (IDE_IS_DOCS_SEARCH_SECTION (self));
+ g_assert (IDE_IS_DOCS_SEARCH_ROW (row));
+ g_assert (DZL_IS_LIST_BOX (list_box));
+
+ item = ide_docs_search_row_get_item (row);
+
+ g_signal_emit (self, signals [ITEM_ACTIVATED], 0, item);
+}
static void
ide_docs_search_section_finalize (GObject *object)
@@ -76,6 +101,10 @@ ide_docs_search_section_get_property (GObject *object,
g_value_set_int (value, ide_docs_search_section_get_priority (self));
break;
+ case PROP_SHOW_ALL_RESULTS:
+ g_value_set_boolean (value, self->show_all_results);
+ break;
+
case PROP_TITLE:
g_value_set_string (value, self->title);
break;
@@ -99,6 +128,10 @@ ide_docs_search_section_set_property (GObject *object,
ide_docs_search_section_set_priority (self, g_value_get_int (value));
break;
+ case PROP_SHOW_ALL_RESULTS:
+ self->show_all_results = g_value_get_boolean (value);
+ break;
+
case PROP_TITLE:
self->title = g_value_dup_string (value);
break;
@@ -125,6 +158,13 @@ ide_docs_search_section_class_init (IdeDocsSearchSectionClass *klass)
G_MININT, G_MAXINT, 0,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ properties [PROP_SHOW_ALL_RESULTS] =
+ g_param_spec_boolean ("show-all-results",
+ "Show All Results",
+ "Show all of the results from groups",
+ FALSE,
+ (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
properties [PROP_TITLE] =
g_param_spec_string ("title",
"Title",
@@ -135,6 +175,15 @@ ide_docs_search_section_class_init (IdeDocsSearchSectionClass *klass)
g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_css_name (widget_class, "IdeDocsSearchSection");
+
+ 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
@@ -147,6 +196,11 @@ ide_docs_search_section_init (IdeDocsSearchSection *self)
"visible", TRUE,
NULL);
dzl_list_box_set_recycle_max (self->groups, 100);
+ g_signal_connect_object (self->groups,
+ "row-activated",
+ G_CALLBACK (on_row_activated_cb),
+ self,
+ G_CONNECT_SWAPPED);
gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (self->groups));
}
@@ -191,32 +245,61 @@ void
ide_docs_search_section_add_groups (IdeDocsSearchSection *self,
IdeDocsItem *parent)
{
- g_autoptr(IdeDocsSearchModel) model = NULL;
-
g_return_if_fail (IDE_IS_DOCS_SEARCH_SECTION (self));
g_return_if_fail (IDE_IS_DOCS_ITEM (parent));
+ /* Clear state before we add new stuff, so we get a chance to
+ * re-use cached listbox rows.
+ */
dzl_list_box_set_model (self->groups, NULL);
-
- model = ide_docs_search_model_new ();
-
gtk_widget_hide (GTK_WIDGET (self->groups));
- for (const GList *iter = ide_docs_item_get_children (parent);
- iter != NULL;
- iter = iter->next)
+ if (self->show_all_results)
{
- IdeDocsItem *child = iter->data;
+ g_autoptr(GListStore) model = g_list_store_new (IDE_TYPE_DOCS_ITEM);
+ g_autoptr(IdeDocsItem) copy = NULL;
+
+ /* Make a fake title with no children so we don't get
+ * the +123 items in the header.
+ */
+ copy = ide_docs_item_new ();
+ ide_docs_item_set_title (copy, ide_docs_item_get_title (parent));
+ ide_docs_item_set_kind (copy, IDE_DOCS_ITEM_KIND_BOOK);
+ g_list_store_append (model, copy);
- g_assert (IDE_IS_DOCS_ITEM (child));
+ for (const GList *iter = ide_docs_item_get_children (parent);
+ iter != NULL;
+ iter = iter->next)
+ {
+ IdeDocsItem *child = iter->data;
- /* Truncate to a reasonable number to avoid very large lists */
- ide_docs_item_truncate (child, MAX_ALLOWED_BY_GROUP);
+ g_assert (IDE_IS_DOCS_ITEM (child));
- ide_docs_search_model_add_group (model, child);
+ g_list_store_append (model, child);
+ }
dzl_list_box_set_model (self->groups, G_LIST_MODEL (model));
}
+ else
+ {
+ g_autoptr(IdeDocsSearchModel) model = ide_docs_search_model_new ();
+
+ for (const GList *iter = ide_docs_item_get_children (parent);
+ iter != NULL;
+ iter = iter->next)
+ {
+ IdeDocsItem *child = iter->data;
+
+ g_assert (IDE_IS_DOCS_ITEM (child));
+
+ /* Truncate to a reasonable number to avoid very large lists */
+ ide_docs_item_truncate (child, MAX_ALLOWED_BY_GROUP);
+
+ ide_docs_search_model_add_group (model, child);
+
+ dzl_list_box_set_model (self->groups, G_LIST_MODEL (model));
+ }
+ }
gtk_widget_show (GTK_WIDGET (self->groups));
}
diff --git a/src/libide/docs/ide-docs-search-view.c b/src/libide/docs/ide-docs-search-view.c
index cb885e8d3..f537f1614 100644
--- a/src/libide/docs/ide-docs-search-view.c
+++ b/src/libide/docs/ide-docs-search-view.c
@@ -23,6 +23,7 @@
#include "config.h"
#include <dazzle.h>
+#include <glib/gi18n.h>
#include <libide-gui.h>
#include <libide-threading.h>
@@ -109,6 +110,46 @@ ide_docs_search_view_clear (IdeDocsSearchView *self)
NULL);
}
+static void
+on_item_activated_cb (IdeDocsSearchView *self,
+ IdeDocsItem *item,
+ IdeDocsSearchSection *old_section)
+{
+ g_assert (IDE_IS_DOCS_SEARCH_VIEW (self));
+ g_assert (IDE_IS_DOCS_ITEM (item));
+ g_assert (IDE_IS_DOCS_SEARCH_SECTION (old_section));
+
+ g_print ("Activate item: %s\n", ide_docs_item_get_title (item));
+
+ if (ide_docs_item_has_child (item))
+ {
+ IdeDocsSearchSection *section;
+
+ ide_docs_search_view_clear (self);
+
+ g_print ("Adding %d children\n",
+ ide_docs_item_get_n_children (item));
+
+ section = g_object_new (IDE_TYPE_DOCS_SEARCH_SECTION,
+ "show-all-results", TRUE,
+ "title", _("All Search Results"),
+ NULL);
+ ide_docs_search_section_add_groups (section, item);
+ g_signal_connect_object (section,
+ "item-activated",
+ G_CALLBACK (on_item_activated_cb),
+ self,
+ G_CONNECT_SWAPPED);
+ gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (section));
+ gtk_widget_show (GTK_WIDGET (section));
+ }
+ else
+ {
+ g_print (" Jump to documentation: %s\n",
+ ide_docs_item_get_url (item));
+ }
+}
+
void
ide_docs_search_view_add_sections (IdeDocsSearchView *self,
IdeDocsItem *item)
@@ -153,6 +194,11 @@ ide_docs_search_view_add_sections (IdeDocsSearchView *self,
"priority", priority,
NULL);
ide_docs_search_section_add_groups (section, child);
+ g_signal_connect_object (section,
+ "item-activated",
+ G_CALLBACK (on_item_activated_cb),
+ self,
+ G_CONNECT_SWAPPED);
gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (section));
gtk_widget_show (GTK_WIDGET (section));
}
diff --git a/src/libide/themes/themes/shared/shared-docs.css b/src/libide/themes/themes/shared/shared-docs.css
index d3fc226bc..5b024c609 100644
--- a/src/libide/themes/themes/shared/shared-docs.css
+++ b/src/libide/themes/themes/shared/shared-docs.css
@@ -2,7 +2,7 @@ IdeDocsSearchSection list {
background-color: transparent;
}
IdeDocsSearchSection list row.header:not(:first-child) {
- margin-top: 24px;
+ margin-top: 16px;
}
IdeDocsSearchSection list row.header box {
padding: 7px;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]