[gtksourceview/wip/chergert/gsv-gtk4] completion: port most of test completion
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/gsv-gtk4] completion: port most of test completion
- Date: Sun, 30 Aug 2020 16:10:09 +0000 (UTC)
commit 4b268086428559b955d568bbde5adbe83df1cddf
Author: Christian Hergert <chergert redhat com>
Date: Sun Aug 30 09:10:04 2020 -0700
completion: port most of test completion
tests/test-completion.c | 72 ++++++++++++++++++++++++++++---------------------
1 file changed, 41 insertions(+), 31 deletions(-)
---
diff --git a/tests/test-completion.c b/tests/test-completion.c
index 2ab975cb3..04ea1ee6b 100644
--- a/tests/test-completion.c
+++ b/tests/test-completion.c
@@ -35,7 +35,7 @@ struct _TestProvider
GList *proposals;
gint priority;
- gchar *name;
+ gchar *title;
GtkIconPaintable *provider_icon;
@@ -62,13 +62,14 @@ G_DEFINE_TYPE_WITH_CODE (TestProvider,
test_provider_iface_init))
static gchar *
-test_provider_get_name (GtkSourceCompletionProvider *provider)
+test_provider_get_title (GtkSourceCompletionProvider *provider)
{
- return g_strdup (((TestProvider *)provider)->name);
+ return g_strdup (((TestProvider *)provider)->title);
}
static gint
-test_provider_get_priority (GtkSourceCompletionProvider *provider)
+test_provider_get_priority (GtkSourceCompletionProvider *provider,
+ GtkSourceCompletionContext *context)
{
return ((TestProvider *)provider)->priority;
}
@@ -91,11 +92,16 @@ select_random_proposals (GList *all_proposals)
}
static void
-test_provider_populate (GtkSourceCompletionProvider *completion_provider,
- GtkSourceCompletionContext *context)
+test_provider_populate_async (GtkSourceCompletionProvider *completion_provider,
+ GtkSourceCompletionContext *context,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
TestProvider *provider = (TestProvider *)completion_provider;
+ GListStore *results;
GList *proposals;
+ GTask *task;
if (provider->is_random)
{
@@ -106,27 +112,34 @@ test_provider_populate (GtkSourceCompletionProvider *completion_provider,
proposals = provider->proposals;
}
- gtk_source_completion_context_add_proposals (context,
- completion_provider,
- proposals,
- TRUE);
+ task = g_task_new (completion_provider, cancellable, callback, user_data);
+
+ results = g_list_store_new (GTK_SOURCE_TYPE_COMPLETION_PROPOSAL);
+
+ for (const GList *iter = proposals; iter; iter = iter->next)
+ {
+ g_list_store_append (results, iter->data);
+ }
+
+ g_list_free_full (proposals, g_object_unref);
+ g_task_return_pointer (task, results, g_object_unref);
}
-static GdkTexture *
-test_provider_get_icon (GtkSourceCompletionProvider *provider)
+static GListModel *
+test_provider_populate_finish (GtkSourceCompletionProvider *provider,
+ GAsyncResult *result,
+ GError **error)
{
- //TestProvider *tp = (TestProvider *)provider;
- //return tp->is_random ? NULL : GDK_TEXTURE (tp->provider_icon);
- return NULL;
+ return g_task_propagate_pointer (G_TASK (result), error);
}
static void
test_provider_iface_init (GtkSourceCompletionProviderInterface *iface)
{
- iface->get_name = test_provider_get_name;
- iface->populate = test_provider_populate;
+ iface->get_title = test_provider_get_title;
+ iface->populate_async = test_provider_populate_async;
+ iface->populate_finish = test_provider_populate_finish;
iface->get_priority = test_provider_get_priority;
- iface->get_icon = test_provider_get_icon;
}
static void
@@ -149,8 +162,8 @@ test_provider_finalize (GObject *gobject)
{
TestProvider *self = (TestProvider *)gobject;
- g_free (self->name);
- self->name = NULL;
+ g_free (self->title);
+ self->title = NULL;
G_OBJECT_CLASS (test_provider_parent_class)->finalize (gobject);
}
@@ -274,11 +287,11 @@ add_remove_provider (GtkToggleButton *button,
if (gtk_toggle_button_get_active (button))
{
- gtk_source_completion_add_provider (completion, provider, NULL);
+ gtk_source_completion_add_provider (completion, provider);
}
else
{
- gtk_source_completion_remove_provider (completion, provider, NULL);
+ gtk_source_completion_remove_provider (completion, provider);
}
}
@@ -330,14 +343,13 @@ create_completion (GtkSourceView *source_view,
GtkSourceCompletion *completion)
{
/* Words completion provider */
- word_provider = gtk_source_completion_words_new (NULL, NULL);
+ word_provider = gtk_source_completion_words_new (NULL);
gtk_source_completion_words_register (word_provider,
gtk_text_view_get_buffer (GTK_TEXT_VIEW (source_view)));
gtk_source_completion_add_provider (completion,
- GTK_SOURCE_COMPLETION_PROVIDER (word_provider),
- NULL);
+ GTK_SOURCE_COMPLETION_PROVIDER (word_provider));
g_object_set (word_provider, "priority", 10, NULL);
@@ -345,21 +357,19 @@ create_completion (GtkSourceView *source_view,
fixed_provider = g_object_new (test_provider_get_type (), NULL);
test_provider_set_fixed (fixed_provider, 3);
fixed_provider->priority = 5;
- fixed_provider->name = g_strdup ("Fixed Provider");
+ fixed_provider->title = g_strdup ("Fixed Provider");
gtk_source_completion_add_provider (completion,
- GTK_SOURCE_COMPLETION_PROVIDER (fixed_provider),
- NULL);
+ GTK_SOURCE_COMPLETION_PROVIDER (fixed_provider));
/* Random provider: the proposals vary on each populate */
random_provider = g_object_new (test_provider_get_type (), NULL);
test_provider_set_random (random_provider, 10);
random_provider->priority = 1;
- random_provider->name = g_strdup ("Random Provider");
+ random_provider->title = g_strdup ("Random Provider");
gtk_source_completion_add_provider (completion,
- GTK_SOURCE_COMPLETION_PROVIDER (random_provider),
- NULL);
+ GTK_SOURCE_COMPLETION_PROVIDER (random_provider));
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]