[gnome-builder] git-search: add result widget
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] git-search: add result widget
- Date: Wed, 17 Dec 2014 10:47:22 +0000 (UTC)
commit 711a3917312b4bf66dca599f224ec7879ebf7da1
Author: Christian Hergert <christian hergert me>
Date: Mon Dec 15 01:52:47 2014 -0800
git-search: add result widget
src/git/gb-git-search-provider.c | 11 +--
src/git/gb-git-search-result.c | 114 +++++++++++++++++++++++++++++
src/git/gb-git-search-result.h | 56 ++++++++++++++
src/gnome-builder.mk | 2 +
src/resources/gnome-builder.gresource.xml | 1 +
src/resources/ui/gb-git-search-result.ui | 15 ++++
6 files changed, 191 insertions(+), 8 deletions(-)
---
diff --git a/src/git/gb-git-search-provider.c b/src/git/gb-git-search-provider.c
index a105f2b..e66b5b2 100644
--- a/src/git/gb-git-search-provider.c
+++ b/src/git/gb-git-search-provider.c
@@ -22,6 +22,7 @@
#include "fuzzy.h"
#include "gb-git-search-provider.h"
+#include "gb-git-search-result.h"
#include "gb-log.h"
#include "gb-search-context.h"
#include "gb-search-result.h"
@@ -196,20 +197,14 @@ gb_git_search_provider_populate (GbSearchProvider *provider,
{
FuzzyMatch *match;
GtkWidget *widget;
- GtkWidget *child;
match = &g_array_index (matches, FuzzyMatch, i);
/* TODO: Make a git file search result */
- widget = g_object_new (GB_TYPE_SEARCH_RESULT,
+ widget = g_object_new (GB_TYPE_GIT_SEARCH_RESULT,
"visible", TRUE,
+ "path", match->key,
NULL);
- child = g_object_new (GTK_TYPE_LABEL,
- "label", match->key,
- "xalign", 0.0f,
- "visible", TRUE,
- NULL);
- gtk_container_add (GTK_CONTAINER (widget), child);
list = g_list_prepend (list, widget);
}
diff --git a/src/git/gb-git-search-result.c b/src/git/gb-git-search-result.c
new file mode 100644
index 0000000..6298a28
--- /dev/null
+++ b/src/git/gb-git-search-result.c
@@ -0,0 +1,114 @@
+/* gb-git-search-result.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-git-search-result.h"
+#include "gb-widget.h"
+
+struct _GbGitSearchResultPrivate
+{
+ gchar *path;
+
+ GtkLabel *label;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GbGitSearchResult, gb_git_search_result,
+ GB_TYPE_SEARCH_RESULT)
+
+enum {
+ PROP_0,
+ PROP_PATH,
+ LAST_PROP
+};
+
+static GParamSpec *gParamSpecs [LAST_PROP];
+
+GtkWidget *
+gb_git_search_result_new (const gchar *path)
+{
+ return g_object_new (GB_TYPE_GIT_SEARCH_RESULT, "path", path, NULL);
+}
+
+static void
+gb_git_search_result_set_path (GbGitSearchResult *result,
+ const gchar *path)
+{
+ g_return_if_fail (GB_IS_GIT_SEARCH_RESULT (result));
+
+ gtk_label_set_label (result->priv->label, path);
+}
+
+static void
+gb_git_search_result_finalize (GObject *object)
+{
+ GbGitSearchResultPrivate *priv = GB_GIT_SEARCH_RESULT (object)->priv;
+
+ g_clear_pointer (&priv->path, g_free);
+
+ G_OBJECT_CLASS (gb_git_search_result_parent_class)->finalize (object);
+}
+
+static void
+gb_git_search_result_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GbGitSearchResult *self = GB_GIT_SEARCH_RESULT (object);
+
+ switch (prop_id)
+ {
+ case PROP_PATH:
+ gb_git_search_result_set_path (self, g_value_get_string (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gb_git_search_result_class_init (GbGitSearchResultClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = gb_git_search_result_finalize;
+ object_class->set_property = gb_git_search_result_set_property;
+
+ gParamSpecs [PROP_PATH] =
+ g_param_spec_string ("path",
+ _("Path"),
+ _("The path to the resulting file."),
+ NULL,
+ (G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_PATH,
+ gParamSpecs [PROP_PATH]);
+
+ GB_WIDGET_CLASS_TEMPLATE (klass, "gb-git-search-result.ui");
+ GB_WIDGET_CLASS_BIND (klass, GbGitSearchResult, label);
+}
+
+static void
+gb_git_search_result_init (GbGitSearchResult *self)
+{
+ self->priv = gb_git_search_result_get_instance_private (self);
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
diff --git a/src/git/gb-git-search-result.h b/src/git/gb-git-search-result.h
new file mode 100644
index 0000000..52f2fba
--- /dev/null
+++ b/src/git/gb-git-search-result.h
@@ -0,0 +1,56 @@
+/* gb-git-search-result.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_GIT_SEARCH_RESULT_H
+#define GB_GIT_SEARCH_RESULT_H
+
+#include "gb-search-result.h"
+
+G_BEGIN_DECLS
+
+#define GB_TYPE_GIT_SEARCH_RESULT (gb_git_search_result_get_type())
+#define GB_GIT_SEARCH_RESULT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GB_TYPE_GIT_SEARCH_RESULT,
GbGitSearchResult))
+#define GB_GIT_SEARCH_RESULT_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GB_TYPE_GIT_SEARCH_RESULT,
GbGitSearchResult const))
+#define GB_GIT_SEARCH_RESULT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GB_TYPE_GIT_SEARCH_RESULT,
GbGitSearchResultClass))
+#define GB_IS_GIT_SEARCH_RESULT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GB_TYPE_GIT_SEARCH_RESULT))
+#define GB_IS_GIT_SEARCH_RESULT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GB_TYPE_GIT_SEARCH_RESULT))
+#define GB_GIT_SEARCH_RESULT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GB_TYPE_GIT_SEARCH_RESULT,
GbGitSearchResultClass))
+
+typedef struct _GbGitSearchResult GbGitSearchResult;
+typedef struct _GbGitSearchResultClass GbGitSearchResultClass;
+typedef struct _GbGitSearchResultPrivate GbGitSearchResultPrivate;
+
+struct _GbGitSearchResult
+{
+ GbSearchResult parent;
+
+ /*< private >*/
+ GbGitSearchResultPrivate *priv;
+};
+
+struct _GbGitSearchResultClass
+{
+ GbSearchResultClass parent;
+};
+
+GType gb_git_search_result_get_type (void);
+GtkWidget *gb_git_search_result_new (const gchar *path);
+
+G_END_DECLS
+
+#endif /* GB_GIT_SEARCH_RESULT_H */
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index 9ff8f1e..78f2443 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -106,6 +106,8 @@ libgnome_builder_la_SOURCES = \
src/gca/gca-structs.h \
src/git/gb-git-search-provider.c \
src/git/gb-git-search-provider.h \
+ src/git/gb-git-search-result.c \
+ src/git/gb-git-search-result.h \
src/html/gb-html-document.c \
src/html/gb-html-document.h \
src/html/gb-html-view.c \
diff --git a/src/resources/gnome-builder.gresource.xml b/src/resources/gnome-builder.gresource.xml
index 66bf705..7b943f7 100644
--- a/src/resources/gnome-builder.gresource.xml
+++ b/src/resources/gnome-builder.gresource.xml
@@ -28,6 +28,7 @@
<file>ui/gb-editor-frame.ui</file>
<file>ui/gb-editor-view.ui</file>
<file>ui/gb-editor-workspace.ui</file>
+ <file>ui/gb-git-search-result.ui</file>
<file>ui/gb-html-view.ui</file>
<file>ui/gb-preferences-window.ui</file>
<file>ui/gb-preferences-page-editor.ui</file>
diff --git a/src/resources/ui/gb-git-search-result.ui b/src/resources/ui/gb-git-search-result.ui
new file mode 100644
index 0000000..b448086
--- /dev/null
+++ b/src/resources/ui/gb-git-search-result.ui
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.14 -->
+ <template class="GbGitSearchResult" parent="GbSearchResult">
+ <child>
+ <object class="GtkLabel" id="label">
+ <property name="visible">true</property>
+ <property name="xalign">0.0</property>
+ <property name="margin-top">12</property>
+ <property name="margin-bottom">12</property>
+ <property name="margin-left">12</property>
+ </object>
+ </child>
+ </template>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]