[gnome-builder] git: start on some basic search functionality using git index
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] git: start on some basic search functionality using git index
- Date: Wed, 17 Dec 2014 10:45:50 +0000 (UTC)
commit 5832f285852b7275abd39a9365cad519a95a99fa
Author: Christian Hergert <christian hergert me>
Date: Sun Dec 14 16:39:55 2014 -0800
git: start on some basic search functionality using git index
src/git/gb-git-search-provider.c | 70 ++++++++++++++++++++++++++++++++++++-
src/search/gb-search-context.c | 17 +++++++--
src/search/gb-search-context.h | 19 +++++-----
3 files changed, 92 insertions(+), 14 deletions(-)
---
diff --git a/src/git/gb-git-search-provider.c b/src/git/gb-git-search-provider.c
index 1a0c6fe..fb4e2de 100644
--- a/src/git/gb-git-search-provider.c
+++ b/src/git/gb-git-search-provider.c
@@ -23,6 +23,10 @@
#include "fuzzy.h"
#include "gb-git-search-provider.h"
#include "gb-log.h"
+#include "gb-search-context.h"
+#include "gb-search-result.h"
+
+#define GB_GIT_SEARCH_PROVIDER_MAX_MATCHES 1000
struct _GbGitSearchProviderPrivate
{
@@ -30,8 +34,15 @@ struct _GbGitSearchProviderPrivate
Fuzzy *file_index;
};
-G_DEFINE_TYPE_WITH_PRIVATE (GbGitSearchProvider, gb_git_search_provider,
- G_TYPE_OBJECT)
+static void search_provider_init (GbSearchProviderInterface *iface);
+
+G_DEFINE_TYPE_EXTENDED (GbGitSearchProvider,
+ gb_git_search_provider,
+ G_TYPE_OBJECT,
+ 0,
+ G_ADD_PRIVATE (GbGitSearchProvider)
+ G_IMPLEMENT_INTERFACE (GB_TYPE_SEARCH_PROVIDER,
+ search_provider_init))
enum {
PROP_0,
@@ -122,6 +133,55 @@ cleanup:
EXIT;
}
+static void
+gb_git_search_provider_populate (GbSearchProvider *provider,
+ GbSearchContext *context,
+ GCancellable *cancellable)
+{
+ GbGitSearchProvider *self = (GbGitSearchProvider *)provider;
+ GList *list = NULL;
+
+ g_return_if_fail (GB_IS_GIT_SEARCH_PROVIDER (self));
+ g_return_if_fail (GB_IS_SEARCH_CONTEXT (context));
+ g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ if (self->priv->file_index)
+ {
+ const gchar *search_text;
+ GArray *matches;
+ guint i;
+
+ search_text = gb_search_context_get_search_text (context);
+ matches = fuzzy_match (self->priv->file_index, search_text,
+ GB_GIT_SEARCH_PROVIDER_MAX_MATCHES);
+
+ for (i = 0; i < matches->len; i++)
+ {
+ 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,
+ "visible", TRUE,
+ 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);
+ }
+
+ list = g_list_reverse (list);
+ gb_search_context_add_results (context, provider, list, TRUE);
+ g_array_unref (matches);
+ }
+}
+
GgitRepository *
gb_git_search_provider_get_repository (GbGitSearchProvider *provider)
{
@@ -230,3 +290,9 @@ gb_git_search_provider_init (GbGitSearchProvider *self)
{
self->priv = gb_git_search_provider_get_instance_private (self);
}
+
+static void
+search_provider_init (GbSearchProviderInterface *iface)
+{
+ iface->populate = gb_git_search_provider_populate;
+}
diff --git a/src/search/gb-search-context.c b/src/search/gb-search-context.c
index ad3712f..4027cbc 100644
--- a/src/search/gb-search-context.c
+++ b/src/search/gb-search-context.c
@@ -141,21 +141,32 @@ gb_search_context_results_added (GbSearchContext *context,
g_return_if_fail (GB_IS_SEARCH_CONTEXT (context));
g_return_if_fail (GB_IS_SEARCH_PROVIDER (provider));
+ /* TODO: how should we deal with priority? */
+
context->priv->results = g_list_concat (context->priv->results, results);
}
+/**
+ * gb_search_context_add_results:
+ * @results: (transfer full) (element-type GbSearchResult*): A #GList or %NULL
+ * @finished: if the provider is finished adding results.
+ *
+ * This function will add a list of results to the context. Ownership of
+ * @results and the contained elements will be transfered to @context.
+ */
void
gb_search_context_add_results (GbSearchContext *context,
GbSearchProvider *provider,
- GList *proposals,
+ GList *results,
gboolean finished)
{
g_return_if_fail (GB_IS_SEARCH_CONTEXT (context));
g_return_if_fail (GB_IS_SEARCH_PROVIDER (provider));
- g_signal_emit (context, gSignals [RESULTS_ADDED], 0,
- provider, proposals, finished);
+ g_list_foreach (results, (GFunc)g_object_ref_sink, NULL);
+ g_signal_emit (context, gSignals [RESULTS_ADDED], 0,
+ provider, results, finished);
}
const gchar *
diff --git a/src/search/gb-search-context.h b/src/search/gb-search-context.h
index 94bb03b..8b34f83 100644
--- a/src/search/gb-search-context.h
+++ b/src/search/gb-search-context.h
@@ -51,15 +51,16 @@ struct _GbSearchContextClass
gboolean finished);
};
-GType gb_search_context_get_type (void);
-GbSearchContext *gb_search_context_new (const GList *providers,
- const gchar *search_text);
-void gb_search_context_cancel (GbSearchContext *context);
-void gb_search_context_add_results (GbSearchContext *context,
- GbSearchProvider *provider,
- GList *results,
- gboolean finished);
-void gb_search_context_execute (GbSearchContext *context);
+GType gb_search_context_get_type (void);
+GbSearchContext *gb_search_context_new (const GList *providers,
+ const gchar *search_text);
+void gb_search_context_cancel (GbSearchContext *context);
+void gb_search_context_add_results (GbSearchContext *context,
+ GbSearchProvider *provider,
+ GList *results,
+ gboolean finished);
+void gb_search_context_execute (GbSearchContext *context);
+const gchar *gb_search_context_get_search_text (GbSearchContext *context);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]