[gnome-builder] search: plumb support for setting max search results
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] search: plumb support for setting max search results
- Date: Thu, 8 Jun 2017 23:24:28 +0000 (UTC)
commit 476946865d63a3fb93c95b69f241bb79563c088d
Author: Christian Hergert <chergert redhat com>
Date: Thu Jun 8 16:22:11 2017 -0700
search: plumb support for setting max search results
We can use this with a GSetting later on to make it configurable how many
search results to display. Larger settings have more overhead, so I'd like
to keep it relatively small by default, and allow for more later on.
libide/search/ide-search-engine.c | 7 +++-
libide/search/ide-search-engine.h | 1 +
libide/search/ide-search-entry.c | 67 +++++++++++++++++++++++++++++++++++++
3 files changed, 74 insertions(+), 1 deletions(-)
---
diff --git a/libide/search/ide-search-engine.c b/libide/search/ide-search-engine.c
index 8c35476..ba0fd85 100644
--- a/libide/search/ide-search-engine.c
+++ b/libide/search/ide-search-engine.c
@@ -24,6 +24,8 @@
#include "ide-search-provider.h"
#include "ide-search-result.h"
+#define DEFAULT_MAX_RESULTS 50
+
struct _IdeSearchEngine
{
IdeObject parent_instance;
@@ -244,6 +246,7 @@ ide_search_engine_search_foreach (PeasExtensionSet *set,
void
ide_search_engine_search_async (IdeSearchEngine *self,
const gchar *query,
+ guint max_results,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -256,13 +259,15 @@ ide_search_engine_search_async (IdeSearchEngine *self,
g_return_if_fail (query != NULL);
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+ max_results = max_results ? max_results : DEFAULT_MAX_RESULTS;
+
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, ide_search_engine_search_async);
g_task_set_priority (task, G_PRIORITY_LOW);
r = request_new ();
r->query = g_strdup (query);
- r->max_results = 25;
+ r->max_results = max_results;
r->task = task;
r->store = g_list_store_new (IDE_TYPE_SEARCH_RESULT);
r->outstanding = 0;
diff --git a/libide/search/ide-search-engine.h b/libide/search/ide-search-engine.h
index 2f14b1a..cfabea4 100644
--- a/libide/search/ide-search-engine.h
+++ b/libide/search/ide-search-engine.h
@@ -31,6 +31,7 @@ IdeSearchEngine *ide_search_engine_new (void);
gboolean ide_search_engine_get_busy (IdeSearchEngine *self);
void ide_search_engine_search_async (IdeSearchEngine *self,
const gchar *query,
+ guint max_results,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
diff --git a/libide/search/ide-search-entry.c b/libide/search/ide-search-entry.c
index 1d623b8..47b2a33 100644
--- a/libide/search/ide-search-entry.c
+++ b/libide/search/ide-search-entry.c
@@ -28,13 +28,24 @@
#include "util/ide-gtk.h"
#include "workbench/ide-workbench.h"
+#define DEFAULT_SEARCH_MAX 25
+
struct _IdeSearchEntry
{
DzlSuggestionEntry parent_instance;
+ guint max_results;
};
G_DEFINE_TYPE (IdeSearchEntry, ide_search_entry, DZL_TYPE_SUGGESTION_ENTRY)
+enum {
+ PROP_0,
+ PROP_MAX_RESULTS,
+ N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
static void
ide_search_entry_search_cb (GObject *object,
GAsyncResult *result,
@@ -88,6 +99,7 @@ ide_search_entry_changed (IdeSearchEntry *self)
ide_search_engine_search_async (engine,
typed_text,
+ self->max_results,
NULL,
ide_search_entry_search_cb,
g_object_ref (self));
@@ -114,15 +126,70 @@ suggestion_activated (DzlSuggestionEntry *entry,
}
static void
+ide_search_entry_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ IdeSearchEntry *self = IDE_SEARCH_ENTRY (object);
+
+ switch (prop_id)
+ {
+ case PROP_MAX_RESULTS:
+ g_value_set_uint (value, self->max_results);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ide_search_entry_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ IdeSearchEntry *self = IDE_SEARCH_ENTRY (object);
+
+ switch (prop_id)
+ {
+ case PROP_MAX_RESULTS:
+ self->max_results = g_value_get_uint (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
ide_search_entry_class_init (IdeSearchEntryClass *klass)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
DzlSuggestionEntryClass *suggestion_entry_class = DZL_SUGGESTION_ENTRY_CLASS (klass);
+ object_class->get_property = ide_search_entry_get_property;
+ object_class->set_property = ide_search_entry_set_property;
+
suggestion_entry_class->suggestion_activated = suggestion_activated;
+
+ properties [PROP_MAX_RESULTS] =
+ g_param_spec_uint ("max-results",
+ "Max Results",
+ "Maximum number of search results to display",
+ 1,
+ 1000,
+ DEFAULT_SEARCH_MAX,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
ide_search_entry_init (IdeSearchEntry *self)
{
+ self->max_results = DEFAULT_SEARCH_MAX;
+
g_signal_connect (self, "changed", G_CALLBACK (ide_search_entry_changed), NULL);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]