[gnome-builder/wip/chergert/docs: 11/12] fowrard/backward navigation



commit 9f23eed2512e76ab8bcd7e038e65474f42bd33cd
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jul 12 15:27:45 2019 -0700

    fowrard/backward navigation

 src/libide/docs/ide-docs-search-section.c |   8 +++
 src/libide/docs/ide-docs-search-section.h |  15 ++--
 src/libide/docs/ide-docs-search-view.c    | 116 +++++++++++++++++++++++++-----
 src/libide/docs/ide-docs-search-view.ui   |   2 +-
 4 files changed, 115 insertions(+), 26 deletions(-)
---
diff --git a/src/libide/docs/ide-docs-search-section.c b/src/libide/docs/ide-docs-search-section.c
index d681fd1ae..f6a700762 100644
--- a/src/libide/docs/ide-docs-search-section.c
+++ b/src/libide/docs/ide-docs-search-section.c
@@ -303,3 +303,11 @@ ide_docs_search_section_add_groups (IdeDocsSearchSection *self,
 
   gtk_widget_show (GTK_WIDGET (self->groups));
 }
+
+gboolean
+ide_docs_search_section_get_show_all_results (IdeDocsSearchSection *self)
+{
+  g_return_val_if_fail (IDE_IS_DOCS_SEARCH_SECTION (self), FALSE);
+
+  return self->show_all_results;
+}
diff --git a/src/libide/docs/ide-docs-search-section.h b/src/libide/docs/ide-docs-search-section.h
index 75b4ea710..b17b1c901 100644
--- a/src/libide/docs/ide-docs-search-section.h
+++ b/src/libide/docs/ide-docs-search-section.h
@@ -28,12 +28,13 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (IdeDocsSearchSection, ide_docs_search_section, IDE, DOCS_SEARCH_SECTION, GtkBin)
 
-GtkWidget   *ide_docs_search_section_new          (const gchar          *title);
-const gchar *ide_docs_search_section_get_title    (IdeDocsSearchSection *self);
-gint         ide_docs_search_section_get_priority (IdeDocsSearchSection *self);
-void         ide_docs_search_section_set_priority (IdeDocsSearchSection *self,
-                                                   gint                  priority);
-void         ide_docs_search_section_add_groups   (IdeDocsSearchSection *self,
-                                                   IdeDocsItem          *parent);
+GtkWidget   *ide_docs_search_section_new                  (const gchar          *title);
+const gchar *ide_docs_search_section_get_title            (IdeDocsSearchSection *self);
+gint         ide_docs_search_section_get_priority         (IdeDocsSearchSection *self);
+void         ide_docs_search_section_set_priority         (IdeDocsSearchSection *self,
+                                                           gint                  priority);
+gboolean     ide_docs_search_section_get_show_all_results (IdeDocsSearchSection *self);
+void         ide_docs_search_section_add_groups           (IdeDocsSearchSection *self,
+                                                           IdeDocsItem          *parent);
 
 G_END_DECLS
diff --git a/src/libide/docs/ide-docs-search-view.c b/src/libide/docs/ide-docs-search-view.c
index be27ba432..ecd051dd3 100644
--- a/src/libide/docs/ide-docs-search-view.c
+++ b/src/libide/docs/ide-docs-search-view.c
@@ -33,14 +33,31 @@
 
 struct _IdeDocsSearchView
 {
-  GtkBin          parent_instance;
+  GtkBin             parent_instance;
 
-  DzlPriorityBox *sections;
-  DzlPriorityBox *titles;
+  /* The most recent full result set, so that we can go back after
+   * viewing a specific set and going backwards.
+   */
+  IdeDocsItem       *full_set;
+
+  GtkScrolledWindow *scroller;
+  DzlPriorityBox    *sections;
+  DzlPriorityBox    *titles;
 };
 
 G_DEFINE_TYPE (IdeDocsSearchView, ide_docs_search_view, GTK_TYPE_BIN)
 
+static void
+on_go_previous_clicked_cb (IdeDocsSearchView *self,
+                           GtkButton         *button)
+{
+  g_assert (IDE_IS_DOCS_SEARCH_VIEW (self));
+  g_assert (GTK_IS_BUTTON (button));
+
+  if (self->full_set != NULL)
+    ide_docs_search_view_add_sections (self, self->full_set);
+}
+
 static void
 ide_docs_search_view_add (GtkContainer *container,
                           GtkWidget    *child)
@@ -56,38 +73,103 @@ ide_docs_search_view_add (GtkContainer *container,
       gint priority = ide_docs_search_section_get_priority (IDE_DOCS_SEARCH_SECTION (child));
       GtkSizeGroup *group;
       GtkLabel *label;
+      GtkBox *box;
+      GtkBox *vbox;
+
+      gtk_container_add_with_properties (GTK_CONTAINER (self->sections), child,
+                                         "priority", priority,
+                                         NULL);
+
+      vbox = g_object_new (GTK_TYPE_BOX,
+                           "orientation", GTK_ORIENTATION_VERTICAL,
+                           "visible", TRUE,
+                           NULL);
+      gtk_container_add (GTK_CONTAINER (self->titles), GTK_WIDGET (vbox));
+
+      box = g_object_new (GTK_TYPE_BOX,
+                          "orientation", GTK_ORIENTATION_HORIZONTAL,
+                          "spacing", 6,
+                          "visible", TRUE,
+                          NULL);
+
+      if (ide_docs_search_section_get_show_all_results (IDE_DOCS_SEARCH_SECTION (child)))
+        {
+          GtkImage *image;
+          GtkButton *button;
+
+          button = g_object_new (GTK_TYPE_BUTTON,
+                                 "focus-on-click", FALSE,
+                                 "halign", GTK_ALIGN_END,
+                                 "valign", GTK_ALIGN_START,
+                                 "visible", TRUE,
+                                 NULL);
+          g_signal_connect_object (button,
+                                   "clicked",
+                                   G_CALLBACK (on_go_previous_clicked_cb),
+                                   self,
+                                   G_CONNECT_SWAPPED);
+          dzl_gtk_widget_add_style_class (GTK_WIDGET (button), "image-button");
+          dzl_gtk_widget_add_style_class (GTK_WIDGET (button), "flat");
+          gtk_container_add (GTK_CONTAINER (vbox), GTK_WIDGET (button));
+          gtk_container_add (GTK_CONTAINER (button), GTK_WIDGET (box));
+
+          image = g_object_new (GTK_TYPE_IMAGE,
+                                "icon-name", "go-previous-symbolic",
+                                "pixel-size", 16,
+                                "visible", TRUE,
+                                NULL);
+          gtk_container_add (GTK_CONTAINER (box), GTK_WIDGET (image));
+        }
+      else
+        {
+          gtk_container_add (GTK_CONTAINER (vbox), GTK_WIDGET (box));
+        }
 
       label = g_object_new (GTK_TYPE_LABEL,
                             "label", title,
-                            "xalign", 1.0f,
-                            "yalign", 0.0f,
                             "visible", TRUE,
                             NULL);
-      dzl_gtk_widget_add_style_class (GTK_WIDGET (label), "section-title");
-      gtk_container_add (GTK_CONTAINER (self->titles), GTK_WIDGET (label));
-      gtk_container_add_with_properties (GTK_CONTAINER (self->sections), child,
-                                         "priority", priority,
-                                         NULL);
+      gtk_container_add (GTK_CONTAINER (box), GTK_WIDGET (label));
+
       group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
-      gtk_size_group_add_widget (group, GTK_WIDGET (label));
+      gtk_size_group_add_widget (group, GTK_WIDGET (vbox));
       gtk_size_group_add_widget (group, GTK_WIDGET (child));
       g_object_unref (group);
+
+      gtk_adjustment_set_value (gtk_scrolled_window_get_vadjustment (self->scroller), 0);
+
       return;
     }
 
   GTK_CONTAINER_CLASS (ide_docs_search_view_parent_class)->add (container, child);
 }
 
+static void
+ide_docs_search_view_finalize (GObject *object)
+{
+  IdeDocsSearchView *self = (IdeDocsSearchView *)object;
+
+  g_assert (IDE_IS_DOCS_SEARCH_VIEW (self));
+
+  g_clear_object (&self->full_set);
+
+  G_OBJECT_CLASS (ide_docs_search_view_parent_class)->finalize (object);
+}
+
 static void
 ide_docs_search_view_class_init (IdeDocsSearchViewClass *klass)
 {
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
   GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
 
+  object_class->finalize = ide_docs_search_view_finalize;
+
   container_class->add = ide_docs_search_view_add;
 
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/libide-docs/ui/ide-docs-search-view.ui");
   gtk_widget_class_set_css_name (widget_class, "IdeDocsSearchView");
+  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);
 }
@@ -120,17 +202,12 @@ on_item_activated_cb (IdeDocsSearchView    *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"),
@@ -146,8 +223,7 @@ on_item_activated_cb (IdeDocsSearchView    *self,
     }
   else
     {
-      g_print ("  Jump to documentation: %s\n",
-               ide_docs_item_get_url (item));
+      g_print ("Display docs for %s\n", ide_docs_item_get_title (item));
     }
 }
 
@@ -160,6 +236,8 @@ ide_docs_search_view_add_sections (IdeDocsSearchView *self,
 
   ide_docs_search_view_clear (self);
 
+  g_set_object (&self->full_set, item);
+
   if (item == NULL)
     return;
 
@@ -203,6 +281,8 @@ ide_docs_search_view_add_sections (IdeDocsSearchView *self,
       gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (section));
       gtk_widget_show (GTK_WIDGET (section));
     }
+
+  gtk_adjustment_set_value (gtk_scrolled_window_get_vadjustment (self->scroller), 0);
 }
 
 GtkWidget *
diff --git a/src/libide/docs/ide-docs-search-view.ui b/src/libide/docs/ide-docs-search-view.ui
index dd7c75c00..442716f76 100644
--- a/src/libide/docs/ide-docs-search-view.ui
+++ b/src/libide/docs/ide-docs-search-view.ui
@@ -2,7 +2,7 @@
 <interface>
   <template class="IdeDocsSearchView" parent="GtkBin">
     <child>
-      <object class="GtkScrolledWindow">
+      <object class="GtkScrolledWindow" id="scroller">
         <property name="hscrollbar-policy">never</property>
         <property name="visible">true</property>
         <child>


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