[gtksourceview/wip/chergert/gsv-gtk4: 221/259] words: implement filtering with GtkFilterListModel
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/gsv-gtk4: 221/259] words: implement filtering with GtkFilterListModel
- Date: Mon, 21 Sep 2020 23:27:48 +0000 (UTC)
commit d1cf4cea60a483b720b87222daed19331d0cff1f
Author: Christian Hergert <chergert redhat com>
Date: Tue Sep 1 16:10:38 2020 -0700
words: implement filtering with GtkFilterListModel
.../words/gtksourcecompletionwords.c | 40 ++++++++++++++++++++++
.../words/gtksourcecompletionwordsproposal.c | 37 ++++++++++++++++++++
2 files changed, 77 insertions(+)
---
diff --git a/gtksourceview/completion-providers/words/gtksourcecompletionwords.c
b/gtksourceview/completion-providers/words/gtksourcecompletionwords.c
index 21e91c71..017fcbf9 100644
--- a/gtksourceview/completion-providers/words/gtksourcecompletionwords.c
+++ b/gtksourceview/completion-providers/words/gtksourcecompletionwords.c
@@ -498,6 +498,45 @@ gtk_source_completion_words_activate (GtkSourceCompletionProvider *provider,
}
}
+static void
+gtk_source_completion_words_refilter (GtkSourceCompletionProvider *provider,
+ GtkSourceCompletionContext *context,
+ GListModel *model)
+{
+ GtkFilterListModel *filter_model;
+ GtkExpression *expression;
+ GtkFilter *filter;
+ gchar *word;
+
+ g_assert (GTK_SOURCE_IS_COMPLETION_PROVIDER (provider));
+ g_assert (GTK_SOURCE_IS_COMPLETION_CONTEXT (context));
+ g_assert (G_IS_LIST_MODEL (model));
+
+ word = gtk_source_completion_context_get_word (context);
+
+ if (GTK_IS_FILTER_LIST_MODEL (model))
+ {
+ model = gtk_filter_list_model_get_model (GTK_FILTER_LIST_MODEL (model));
+ }
+
+ if (!word || !word[0])
+ {
+ gtk_source_completion_context_set_proposals_for_provider (context, provider, model);
+ g_free (word);
+ return;
+ }
+
+ expression = gtk_property_expression_new (GTK_SOURCE_TYPE_COMPLETION_WORDS_PROPOSAL, NULL, "word");
+ filter = gtk_string_filter_new (g_steal_pointer (&expression));
+ gtk_string_filter_set_search (GTK_STRING_FILTER (filter), word);
+ filter_model = gtk_filter_list_model_new (g_object_ref (model), g_steal_pointer (&filter));
+ gtk_filter_list_model_set_incremental (filter_model, TRUE);
+ gtk_source_completion_context_set_proposals_for_provider (context, provider, G_LIST_MODEL
(filter_model));
+
+ g_clear_object (&filter_model);
+ g_free (word);
+}
+
static void
gtk_source_completion_words_iface_init (GtkSourceCompletionProviderInterface *iface)
{
@@ -507,6 +546,7 @@ gtk_source_completion_words_iface_init (GtkSourceCompletionProviderInterface *if
iface->get_priority = gtk_source_completion_words_get_priority;
iface->display = gtk_source_completion_words_display;
iface->activate = gtk_source_completion_words_activate;
+ iface->refilter = gtk_source_completion_words_refilter;
}
static void
diff --git a/gtksourceview/completion-providers/words/gtksourcecompletionwordsproposal.c
b/gtksourceview/completion-providers/words/gtksourcecompletionwordsproposal.c
index 5f88571f..bb394e18 100644
--- a/gtksourceview/completion-providers/words/gtksourcecompletionwordsproposal.c
+++ b/gtksourceview/completion-providers/words/gtksourcecompletionwordsproposal.c
@@ -35,6 +35,14 @@ enum
N_SIGNALS
};
+enum
+{
+ PROP_0,
+ PROP_WORD,
+ N_PROPS
+};
+
+static GParamSpec *properties[N_PROPS];
static guint signals[N_SIGNALS];
G_DEFINE_TYPE_WITH_CODE (GtkSourceCompletionWordsProposal,
@@ -53,12 +61,41 @@ gtk_source_completion_words_proposal_finalize (GObject *object)
G_OBJECT_CLASS (gtk_source_completion_words_proposal_parent_class)->finalize (object);
}
+static void
+gtk_source_completion_words_proposal_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkSourceCompletionWordsProposal *self = GTK_SOURCE_COMPLETION_WORDS_PROPOSAL (object);
+
+ switch (prop_id)
+ {
+ case PROP_WORD:
+ g_value_set_string (value, self->word);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
static void
gtk_source_completion_words_proposal_class_init (GtkSourceCompletionWordsProposalClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gtk_source_completion_words_proposal_finalize;
+ object_class->get_property = gtk_source_completion_words_proposal_get_property;
+
+ properties [PROP_WORD] =
+ g_param_spec_string ("word",
+ "Word",
+ "The word for the proposal",
+ NULL,
+ (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
signals[UNUSED] =
g_signal_new ("unused",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]