[gnome-builder/global-search] search: add GbSearchDisplay widget



commit a9cde6f33c1d63811153fe792cb1715b2f972cef
Author: Christian Hergert <christian hergert me>
Date:   Sat Dec 13 03:53:50 2014 -0800

    search: add GbSearchDisplay widget
    
    Stub out container widget for search results.

 src/gnome-builder.mk                      |    3 +
 src/resources/gnome-builder.gresource.xml |    1 +
 src/resources/ui/gb-search-display.ui     |   19 +++
 src/search/gb-search-display.c            |  187 +++++++++++++++++++++++++++++
 src/search/gb-search-display.h            |   61 ++++++++++
 5 files changed, 271 insertions(+), 0 deletions(-)
---
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index 54673eb..6cf8838 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -125,6 +125,8 @@ libgnome_builder_la_SOURCES = \
        src/preferences/gb-preferences-page-language.h \
        src/search/gb-search-context.c \
        src/search/gb-search-context.h \
+       src/search/gb-search-display.c \
+       src/search/gb-search-display.h \
        src/search/gb-search-manager.c \
        src/search/gb-search-manager.h \
        src/search/gb-search-provider.c \
@@ -234,6 +236,7 @@ libgnome_builder_la_CFLAGS = \
        -I$(top_srcdir)/src/preferences \
        -I$(top_srcdir)/src/resources \
        -I$(top_builddir)/src/resources \
+       -I$(top_srcdir)/src/search \
        -I$(top_srcdir)/src/snippets \
        -I$(top_srcdir)/src/tabs \
        -I$(top_srcdir)/src/tree \
diff --git a/src/resources/gnome-builder.gresource.xml b/src/resources/gnome-builder.gresource.xml
index 59723b9..66bf705 100644
--- a/src/resources/gnome-builder.gresource.xml
+++ b/src/resources/gnome-builder.gresource.xml
@@ -33,6 +33,7 @@
     <file>ui/gb-preferences-page-editor.ui</file>
     <file>ui/gb-preferences-page-git.ui</file>
     <file>ui/gb-preferences-page-language.ui</file>
+    <file>ui/gb-search-display.ui</file>
     <file>ui/gb-workbench.ui</file>
   </gresource>
 </gresources>
diff --git a/src/resources/ui/gb-search-display.ui b/src/resources/ui/gb-search-display.ui
new file mode 100644
index 0000000..a109773
--- /dev/null
+++ b/src/resources/ui/gb-search-display.ui
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.14 -->
+  <template class="GbSearchDisplay" parent="GtkBin">
+    <property name="border_width">10</property>
+    <property name="width_request">800</property>
+    <property name="height_request">600</property>
+    <child>
+      <object class="GtkScrolledWindow" id="scroller">
+        <property name="visible">true</property>
+        <child>
+          <object class="GtkListBox" id="list_box">
+            <property name="visible">true</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/search/gb-search-display.c b/src/search/gb-search-display.c
new file mode 100644
index 0000000..535f39a
--- /dev/null
+++ b/src/search/gb-search-display.c
@@ -0,0 +1,187 @@
+/* gb-search-display.c
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 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 "gb-search-display.h"
+#include "gb-search-provider.h"
+
+struct _GbSearchDisplayPrivate
+{
+  /* References owned by widget */
+  GbSearchContext *context;
+
+  /* References owned by Gtk template */
+  GtkListBox      *list_box;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GbSearchDisplay, gb_search_display, GTK_TYPE_BIN)
+
+enum {
+  PROP_0,
+  PROP_CONTEXT,
+  LAST_PROP
+};
+
+static GParamSpec *gParamSpecs [LAST_PROP];
+
+GtkWidget *
+gb_search_display_new (void)
+{
+  return g_object_new (GB_TYPE_SEARCH_DISPLAY, NULL);
+}
+
+static void
+gb_search_display_results_added (GbSearchDisplay  *display,
+                                 GbSearchProvider *provider,
+                                 GList            *results,
+                                 gboolean          finished)
+{
+  GList *iter;
+
+  g_return_if_fail (GB_IS_SEARCH_DISPLAY (display));
+  g_return_if_fail (GB_IS_SEARCH_PROVIDER (provider));
+
+  for (iter = results; iter; iter = iter->next)
+    gtk_list_box_insert (display->priv->list_box, iter->data, -1);
+
+  gtk_list_box_invalidate_sort (display->priv->list_box);
+}
+
+static void
+gb_search_display_connect (GbSearchDisplay *display,
+                           GbSearchContext *context)
+{
+  g_return_if_fail (GB_IS_SEARCH_DISPLAY (display));
+  g_return_if_fail (GB_IS_SEARCH_CONTEXT (context));
+
+  g_signal_connect_object (context,
+                           "results-added",
+                           G_CALLBACK (gb_search_display_results_added),
+                           display,
+                           G_CONNECT_SWAPPED);
+}
+
+static void
+gb_search_display_disconnect (GbSearchDisplay *display,
+                              GbSearchContext *context)
+{
+  g_return_if_fail (GB_IS_SEARCH_DISPLAY (display));
+  g_return_if_fail (GB_IS_SEARCH_CONTEXT (context));
+
+  g_signal_handlers_disconnect_by_func (context,
+                                        G_CALLBACK (gb_search_display_results_added),
+                                        display);
+}
+
+void
+gb_search_display_set_context (GbSearchDisplay *display,
+                               GbSearchContext *context)
+{
+  g_return_if_fail (GB_IS_SEARCH_DISPLAY (display));
+  g_return_if_fail (!context || GB_IS_SEARCH_CONTEXT (context));
+
+  if (display->priv->context != context)
+    {
+      if (display->priv->context)
+        {
+          gb_search_display_disconnect (display, context);
+          g_clear_object (&display->priv->context);
+        }
+
+      if (context)
+        {
+          display->priv->context = g_object_ref (context);
+          gb_search_display_connect (display, context);
+        }
+
+      g_object_notify_by_pspec (G_OBJECT (display),
+                                gParamSpecs [PROP_CONTEXT]);
+    }
+}
+
+static void
+gb_search_display_finalize (GObject *object)
+{
+  GbSearchDisplayPrivate *priv = GB_SEARCH_DISPLAY (object)->priv;
+
+  g_clear_object (&priv->context);
+
+  G_OBJECT_CLASS (gb_search_display_parent_class)->finalize (object);
+}
+
+static void
+gb_search_display_get_property (GObject    *object,
+                                guint       prop_id,
+                                GValue     *value,
+                                GParamSpec *pspec)
+{
+  GbSearchDisplay *self = GB_SEARCH_DISPLAY (object);
+
+  switch (prop_id)
+    {
+    case PROP_CONTEXT:
+      g_value_set_object (value, self->priv->context);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gb_search_display_set_property (GObject      *object,
+                                guint         prop_id,
+                                const GValue *value,
+                                GParamSpec   *pspec)
+{
+  GbSearchDisplay *self = GB_SEARCH_DISPLAY (object);
+
+  switch (prop_id)
+    {
+    case PROP_CONTEXT:
+      gb_search_display_set_context (self, g_value_get_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gb_search_display_class_init (GbSearchDisplayClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->finalize = gb_search_display_finalize;
+  object_class->get_property = gb_search_display_get_property;
+  object_class->set_property = gb_search_display_set_property;
+
+  gtk_widget_class_set_template_from_resource (widget_class,
+                                               "/org/gnome/builder/ui/gb-search-display.ui");
+  gtk_widget_class_bind_template_child_private (widget_class, GbSearchDisplay, list_box);
+}
+
+static void
+gb_search_display_init (GbSearchDisplay *self)
+{
+  self->priv = gb_search_display_get_instance_private (self);
+
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
diff --git a/src/search/gb-search-display.h b/src/search/gb-search-display.h
new file mode 100644
index 0000000..7bd9675
--- /dev/null
+++ b/src/search/gb-search-display.h
@@ -0,0 +1,61 @@
+/* gb-search-display.h
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 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 GB_SEARCH_DISPLAY_H
+#define GB_SEARCH_DISPLAY_H
+
+#include <gtk/gtk.h>
+
+#include "gb-search-types.h"
+#include "gb-search-context.h"
+
+G_BEGIN_DECLS
+
+#define GB_TYPE_SEARCH_DISPLAY            (gb_search_display_get_type())
+#define GB_SEARCH_DISPLAY(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GB_TYPE_SEARCH_DISPLAY, 
GbSearchDisplay))
+#define GB_SEARCH_DISPLAY_CONST(obj)      (G_TYPE_CHECK_INSTANCE_CAST ((obj), GB_TYPE_SEARCH_DISPLAY, 
GbSearchDisplay const))
+#define GB_SEARCH_DISPLAY_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  GB_TYPE_SEARCH_DISPLAY, 
GbSearchDisplayClass))
+#define GB_IS_SEARCH_DISPLAY(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GB_TYPE_SEARCH_DISPLAY))
+#define GB_IS_SEARCH_DISPLAY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  GB_TYPE_SEARCH_DISPLAY))
+#define GB_SEARCH_DISPLAY_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  GB_TYPE_SEARCH_DISPLAY, 
GbSearchDisplayClass))
+
+typedef struct _GbSearchDisplay        GbSearchDisplay;
+typedef struct _GbSearchDisplayClass   GbSearchDisplayClass;
+typedef struct _GbSearchDisplayPrivate GbSearchDisplayPrivate;
+
+struct _GbSearchDisplay
+{
+  GtkBin parent;
+
+  /*< private >*/
+  GbSearchDisplayPrivate *priv;
+};
+
+struct _GbSearchDisplayClass
+{
+  GtkBinClass parent;
+};
+
+GType      gb_search_display_get_type    (void);
+GtkWidget *gb_search_display_new         (void);
+void       gb_search_display_set_context (GbSearchDisplay *display,
+                                          GbSearchContext *context);
+
+G_END_DECLS
+
+#endif /* GB_SEARCH_DISPLAY_H */


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