[gnome-builder/wip/gtk4-port: 610/1774] plugins/words: port to GTK 4
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 610/1774] plugins/words: port to GTK 4
- Date: Mon, 11 Jul 2022 22:31:17 +0000 (UTC)
commit 76db4542f0451fdf415fbf5b144e0f024f648072
Author: Christian Hergert <chergert redhat com>
Date: Mon Apr 18 20:33:09 2022 -0700
plugins/words: port to GTK 4
src/plugins/meson.build | 2 +-
src/plugins/words/gbp-word-completion-provider.c | 130 +++++++++++++----------
src/plugins/words/gbp-word-proposal.c | 2 +-
src/plugins/words/gbp-word-proposals.c | 30 +++---
src/plugins/words/gbp-word-proposals.h | 22 ++--
src/plugins/words/words-plugin.c | 5 +-
6 files changed, 102 insertions(+), 89 deletions(-)
---
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index 5894e10b6..8bee5b7c0 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -140,7 +140,7 @@ subdir('vcsui')
subdir('vim')
subdir('vls')
subdir('waf')
-#subdir('words')
+subdir('words')
#subdir('xml-pack')
plugins = static_library('plugins', plugins_sources,
diff --git a/src/plugins/words/gbp-word-completion-provider.c
b/src/plugins/words/gbp-word-completion-provider.c
index 947f3e78c..bd9034717 100644
--- a/src/plugins/words/gbp-word-completion-provider.c
+++ b/src/plugins/words/gbp-word-completion-provider.c
@@ -30,14 +30,14 @@
struct _GbpWordCompletionProvider
{
- GObject parent_instance;
+ GObject parent_instance;
GbpWordProposals *proposals;
};
-static void completion_provider_iface_init (IdeCompletionProviderInterface *iface);
+static void completion_provider_iface_init (GtkSourceCompletionProviderInterface *iface);
G_DEFINE_FINAL_TYPE_WITH_CODE (GbpWordCompletionProvider, gbp_word_completion_provider, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (IDE_TYPE_COMPLETION_PROVIDER,
completion_provider_iface_init))
+ G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_COMPLETION_PROVIDER,
completion_provider_iface_init))
static void
gbp_word_completion_provider_finalize (GObject *object)
@@ -62,24 +62,22 @@ gbp_word_completion_provider_init (GbpWordCompletionProvider *self)
{
}
-static gboolean
-gbp_word_completion_provider_refilter (IdeCompletionProvider *provider,
- IdeCompletionContext *context,
- GListModel *model)
+static void
+gbp_word_completion_provider_refilter (GtkSourceCompletionProvider *provider,
+ GtkSourceCompletionContext *context,
+ GListModel *model)
{
g_autofree gchar *casefold = NULL;
g_autofree gchar *word = NULL;
g_assert (GBP_IS_WORD_COMPLETION_PROVIDER (provider));
- g_assert (IDE_IS_COMPLETION_CONTEXT (context));
+ g_assert (GTK_SOURCE_IS_COMPLETION_CONTEXT (context));
g_assert (GBP_IS_WORD_PROPOSALS (model));
- if ((word = ide_completion_context_get_word (context)))
+ if ((word = gtk_source_completion_context_get_word (context)))
casefold = g_utf8_casefold (word, -1);
gbp_word_proposals_refilter (GBP_WORD_PROPOSALS (model), casefold);
-
- return TRUE;
}
static void
@@ -102,18 +100,18 @@ gbp_word_completion_provider_populate_cb (GObject *object,
}
static void
-gbp_word_completion_provider_populate_async (IdeCompletionProvider *provider,
- IdeCompletionContext *context,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+gbp_word_completion_provider_populate_async (GtkSourceCompletionProvider *provider,
+ GtkSourceCompletionContext *context,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
GbpWordCompletionProvider *self = (GbpWordCompletionProvider *)provider;
- IdeCompletionActivation activation;
+ GtkSourceCompletionActivation activation;
g_autoptr(IdeTask) task = NULL;
g_assert (GBP_IS_WORD_COMPLETION_PROVIDER (self));
- g_assert (IDE_IS_COMPLETION_CONTEXT (context));
+ g_assert (GTK_SOURCE_IS_COMPLETION_CONTEXT (context));
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
task = ide_task_new (self, cancellable, callback, user_data);
@@ -126,17 +124,17 @@ gbp_word_completion_provider_populate_async (IdeCompletionProvider *provider,
* Avoid extra processing unless the user requested completion, since
* scanning the buffer is rather expensive.
*/
- activation = ide_completion_context_get_activation (context);
- if (activation != IDE_COMPLETION_USER_REQUESTED)
+ activation = gtk_source_completion_context_get_activation (context);
+ if (activation != GTK_SOURCE_COMPLETION_ACTIVATION_USER_REQUESTED)
{
gbp_word_proposals_clear (self->proposals);
ide_task_return_boolean (task, TRUE);
return;
}
- ide_completion_context_set_proposals_for_provider (context,
- provider,
- G_LIST_MODEL (self->proposals));
+ gtk_source_completion_context_set_proposals_for_provider (context,
+ provider,
+ G_LIST_MODEL (self->proposals));
gbp_word_proposals_populate_async (self->proposals,
context,
@@ -146,7 +144,7 @@ gbp_word_completion_provider_populate_async (IdeCompletionProvider *provider,
}
static GListModel *
-gbp_word_completion_provider_populate_finish (IdeCompletionProvider *provider,
+gbp_word_completion_provider_populate_finish (GtkSourceCompletionProvider *provider,
GAsyncResult *result,
GError **error)
{
@@ -157,68 +155,82 @@ gbp_word_completion_provider_populate_finish (IdeCompletionProvider *provider,
}
static void
-gbp_word_completion_provider_display_proposal (IdeCompletionProvider *provider,
- IdeCompletionListBoxRow *row,
- IdeCompletionContext *context,
- const gchar *typed_text,
- IdeCompletionProposal *proposal)
+gbp_word_completion_provider_display (GtkSourceCompletionProvider *provider,
+ GtkSourceCompletionContext *context,
+ GtkSourceCompletionProposal *proposal,
+ GtkSourceCompletionCell *cell)
{
- g_autofree gchar *markup = NULL;
- const gchar *word;
+ GtkSourceCompletionColumn column;
g_assert (GBP_IS_WORD_COMPLETION_PROVIDER (provider));
- g_assert (IDE_IS_COMPLETION_LIST_BOX_ROW (row));
- g_assert (IDE_IS_COMPLETION_CONTEXT (context));
- g_assert (IDE_IS_COMPLETION_PROPOSAL (proposal));
+ g_assert (GTK_SOURCE_IS_COMPLETION_CONTEXT (context));
+ g_assert (GTK_SOURCE_IS_COMPLETION_PROPOSAL (proposal));
+ g_assert (GTK_SOURCE_IS_COMPLETION_CELL (cell));
- word = gbp_word_proposal_get_word (GBP_WORD_PROPOSAL (proposal));
- markup = ide_completion_fuzzy_highlight (word, typed_text);
+ column = gtk_source_completion_cell_get_column (cell);
- ide_completion_list_box_row_set_icon_name (row, "completion-word-symbolic");
- ide_completion_list_box_row_set_left (row, NULL);
- ide_completion_list_box_row_set_center_markup (row, markup);
- ide_completion_list_box_row_set_right (row, NULL);
+ switch (column)
+ {
+ case GTK_SOURCE_COMPLETION_COLUMN_ICON:
+ gtk_source_completion_cell_set_icon_name (cell, "completion-word-symbolic");
+ break;
+
+ case GTK_SOURCE_COMPLETION_COLUMN_TYPED_TEXT:
+ {
+ const char *word = gbp_word_proposal_get_word (GBP_WORD_PROPOSAL (proposal));
+ g_autofree char *typed_text = gtk_source_completion_context_get_word (context);
+ g_autoptr(PangoAttrList) attrs = gtk_source_completion_fuzzy_highlight (word, typed_text);
+ gtk_source_completion_cell_set_text_with_attributes (cell, word, attrs);
+ break;
+ }
+
+ case GTK_SOURCE_COMPLETION_COLUMN_BEFORE:
+ case GTK_SOURCE_COMPLETION_COLUMN_AFTER:
+ case GTK_SOURCE_COMPLETION_COLUMN_COMMENT:
+ case GTK_SOURCE_COMPLETION_COLUMN_DETAILS:
+ default:
+ gtk_source_completion_cell_set_text (cell, NULL);
+ break;
+ }
}
static void
-gbp_word_completion_provider_activate_proposal (IdeCompletionProvider *provider,
- IdeCompletionContext *context,
- IdeCompletionProposal *proposal,
- const GdkEventKey *key)
+gbp_word_completion_provider_activate (GtkSourceCompletionProvider *provider,
+ GtkSourceCompletionContext *context,
+ GtkSourceCompletionProposal *proposal)
{
- GtkTextIter begin, end;
- GtkTextBuffer *buffer;
+ GtkSourceBuffer *buffer;
const gchar *word;
+ GtkTextIter begin, end;
g_assert (GBP_IS_WORD_COMPLETION_PROVIDER (provider));
- g_assert (IDE_IS_COMPLETION_CONTEXT (context));
+ g_assert (GTK_SOURCE_IS_COMPLETION_CONTEXT (context));
g_assert (GBP_IS_WORD_PROPOSAL (proposal));
- g_assert (key != NULL);
- buffer = ide_completion_context_get_buffer (context);
+ buffer = gtk_source_completion_context_get_buffer (context);
word = gbp_word_proposal_get_word (GBP_WORD_PROPOSAL (proposal));
- gtk_text_buffer_begin_user_action (buffer);
- if (ide_completion_context_get_bounds (context, &begin, &end))
- gtk_text_buffer_delete (buffer, &begin, &end);
- gtk_text_buffer_insert (buffer, &begin, word, -1);
- gtk_text_buffer_end_user_action (buffer);
+ gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (buffer));
+ if (gtk_source_completion_context_get_bounds (context, &begin, &end))
+ gtk_text_buffer_delete (GTK_TEXT_BUFFER (buffer), &begin, &end);
+ gtk_text_buffer_insert (GTK_TEXT_BUFFER (buffer), &begin, word, -1);
+ gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
}
static gint
-gbp_word_completion_provider_get_priority (IdeCompletionProvider *provider,
- IdeCompletionContext *context)
+gbp_word_completion_provider_get_priority (GtkSourceCompletionProvider *provider,
+ GtkSourceCompletionContext *context)
{
return 1000;
}
static void
-completion_provider_iface_init (IdeCompletionProviderInterface *iface)
+completion_provider_iface_init (GtkSourceCompletionProviderInterface *iface)
{
iface->populate_async = gbp_word_completion_provider_populate_async;
iface->populate_finish = gbp_word_completion_provider_populate_finish;
- iface->display_proposal = gbp_word_completion_provider_display_proposal;
- iface->activate_proposal = gbp_word_completion_provider_activate_proposal;
+ iface->display = gbp_word_completion_provider_display;
+ iface->activate = gbp_word_completion_provider_activate;
iface->refilter = gbp_word_completion_provider_refilter;
iface->get_priority = gbp_word_completion_provider_get_priority;
}
diff --git a/src/plugins/words/gbp-word-proposal.c b/src/plugins/words/gbp-word-proposal.c
index f23195829..a716674d2 100644
--- a/src/plugins/words/gbp-word-proposal.c
+++ b/src/plugins/words/gbp-word-proposal.c
@@ -33,7 +33,7 @@ struct _GbpWordProposal
};
G_DEFINE_FINAL_TYPE_WITH_CODE (GbpWordProposal, gbp_word_proposal, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (IDE_TYPE_COMPLETION_PROPOSAL, NULL))
+ G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_COMPLETION_PROPOSAL, NULL))
static void
gbp_word_proposal_finalize (GObject *object)
diff --git a/src/plugins/words/gbp-word-proposals.c b/src/plugins/words/gbp-word-proposals.c
index e927e43c9..0fffa4970 100644
--- a/src/plugins/words/gbp-word-proposals.c
+++ b/src/plugins/words/gbp-word-proposals.c
@@ -169,7 +169,7 @@ gbp_word_proposals_backward_cb (GObject *object,
buffer = GTK_TEXT_BUFFER (gtk_source_search_context_get_buffer (search));
- if (ide_source_search_context_backward_finish2 (search, result, &begin, &end, &wrapped, &error))
+ if (gtk_source_search_context_backward_finish (search, result, &begin, &end, &wrapped, &error))
{
guint line;
guint line_offset;
@@ -217,7 +217,7 @@ gbp_word_proposals_backward_cb (GObject *object,
gbp_word_proposals_add (self, word);
- ide_source_search_context_backward_async (search,
+ gtk_source_search_context_backward_async (search,
&begin,
cancellable,
gbp_word_proposals_backward_cb,
@@ -225,11 +225,11 @@ gbp_word_proposals_backward_cb (GObject *object,
}
void
-gbp_word_proposals_populate_async (GbpWordProposals *self,
- IdeCompletionContext *context,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+gbp_word_proposals_populate_async (GbpWordProposals *self,
+ GtkSourceCompletionContext *context,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
g_autoptr(IdeTask) task = NULL;
g_autoptr(GtkSourceSearchContext) search = NULL;
@@ -241,7 +241,7 @@ gbp_word_proposals_populate_async (GbpWordProposals *self,
guint old_len;
g_assert (GBP_IS_WORD_PROPOSALS (self));
- g_assert (IDE_IS_COMPLETION_CONTEXT (context));
+ g_assert (GTK_SOURCE_IS_COMPLETION_CONTEXT (context));
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
task = ide_task_new (self, cancellable, callback, user_data);
@@ -266,7 +266,7 @@ gbp_word_proposals_populate_async (GbpWordProposals *self,
* we'd just create a list of every word in the file. While that might
* be interesting, it's more work than we want to do currently.
*/
- if (!ide_completion_context_get_bounds (context, &begin, &end))
+ if (!gtk_source_completion_context_get_bounds (context, &begin, &end))
{
ide_task_return_boolean (task, TRUE);
return;
@@ -281,7 +281,7 @@ gbp_word_proposals_populate_async (GbpWordProposals *self,
gtk_source_search_settings_set_search_text (settings, search_text);
gtk_source_search_settings_set_wrap_around (settings, TRUE);
- buffer = ide_completion_context_get_buffer (context);
+ buffer = GTK_TEXT_BUFFER (gtk_source_completion_context_get_buffer (context));
search = gtk_source_search_context_new (GTK_SOURCE_BUFFER (buffer), settings);
gtk_source_search_context_set_highlight (search, FALSE);
@@ -290,7 +290,7 @@ gbp_word_proposals_populate_async (GbpWordProposals *self,
g_object_ref (state->mark);
ide_task_set_task_data (task, state, state_free);
- ide_source_search_context_backward_async (search,
+ gtk_source_search_context_backward_async (search,
&begin,
NULL,
gbp_word_proposals_backward_cb,
@@ -318,7 +318,7 @@ gbp_word_proposals_populate_finish (GbpWordProposals *self,
const gchar *element = g_ptr_array_index (self->unfiltered, i);
guint priority;
- if (ide_completion_fuzzy_match (element, word, &priority))
+ if (gtk_source_completion_fuzzy_match (element, word, &priority))
{
Item item = { element, priority };
g_array_append_val (self->items, item);
@@ -363,7 +363,7 @@ gbp_word_proposals_refilter (GbpWordProposals *self,
{
Item *item = &g_array_index (self->items, Item, i - 1);
- if (!ide_completion_fuzzy_match (item->word, word, &item->priority))
+ if (!gtk_source_completion_fuzzy_match (item->word, word, &item->priority))
g_array_remove_index_fast (self->items, i - 1);
}
}
@@ -377,7 +377,7 @@ gbp_word_proposals_refilter (GbpWordProposals *self,
const gchar *element = g_ptr_array_index (self->unfiltered, i);
guint priority;
- if (ide_completion_fuzzy_match (element, word, &priority))
+ if (gtk_source_completion_fuzzy_match (element, word, &priority))
{
Item item = { element, priority };
g_array_append_val (self->items, item);
@@ -416,7 +416,7 @@ gbp_word_proposals_clear (GbpWordProposals *self)
static GType
gbp_word_proposals_get_item_type (GListModel *model)
{
- return IDE_TYPE_COMPLETION_PROPOSAL;
+ return GTK_SOURCE_TYPE_COMPLETION_PROPOSAL;
}
static guint
diff --git a/src/plugins/words/gbp-word-proposals.h b/src/plugins/words/gbp-word-proposals.h
index f1786e7ca..f3246f960 100644
--- a/src/plugins/words/gbp-word-proposals.h
+++ b/src/plugins/words/gbp-word-proposals.h
@@ -29,16 +29,16 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GbpWordProposals, gbp_word_proposals, GBP, WORD_PROPOSALS, GObject)
GbpWordProposals *gbp_word_proposals_new (void);
-void gbp_word_proposals_populate_async (GbpWordProposals *self,
- IdeCompletionContext *context,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-gboolean gbp_word_proposals_populate_finish (GbpWordProposals *self,
- GAsyncResult *result,
- GError **error);
-void gbp_word_proposals_refilter (GbpWordProposals *self,
- const gchar *word);
-void gbp_word_proposals_clear (GbpWordProposals *self);
+void gbp_word_proposals_populate_async (GbpWordProposals *self,
+ GtkSourceCompletionContext *context,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean gbp_word_proposals_populate_finish (GbpWordProposals *self,
+ GAsyncResult *result,
+ GError **error);
+void gbp_word_proposals_refilter (GbpWordProposals *self,
+ const gchar *word);
+void gbp_word_proposals_clear (GbpWordProposals *self);
G_END_DECLS
diff --git a/src/plugins/words/words-plugin.c b/src/plugins/words/words-plugin.c
index 69220f01d..b6dad7a1e 100644
--- a/src/plugins/words/words-plugin.c
+++ b/src/plugins/words/words-plugin.c
@@ -20,15 +20,16 @@
#include "config.h"
-#include <libide-sourceview.h>
#include <libpeas/peas.h>
+#include <libide-sourceview.h>
+
#include "gbp-word-completion-provider.h"
_IDE_EXTERN void
_gbp_words_register_types (PeasObjectModule *module)
{
peas_object_module_register_extension_type (module,
- IDE_TYPE_COMPLETION_PROVIDER,
+ GTK_SOURCE_TYPE_COMPLETION_PROVIDER,
GBP_TYPE_WORD_COMPLETION_PROVIDER);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]