[gnome-builder/wip/gtk4-port: 577/1774] plugins/c-pack: port c-pack plugin
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 577/1774] plugins/c-pack: port c-pack plugin
- Date: Mon, 11 Jul 2022 22:31:16 +0000 (UTC)
commit 614e0eea3536fecca9c2a6dd988dc58827c8363d
Author: Christian Hergert <chergert redhat com>
Date: Sat Apr 16 10:46:13 2022 -0700
plugins/c-pack: port c-pack plugin
This still needs work for the indenter, but that needs to go upstream in
GtkSourceView anyway.
src/plugins/c-pack/c-pack-plugin.c | 9 +-
src/plugins/c-pack/cpack-completion-item.c | 42 ++++++++-
src/plugins/c-pack/cpack-completion-item.h | 5 +-
src/plugins/c-pack/cpack-completion-provider.c | 114 +++++++++++++++----------
src/plugins/c-pack/cpack-completion-results.c | 2 +-
src/plugins/c-pack/meson.build | 4 +-
src/plugins/ctags/gbp-ctags-workbench-addin.c | 3 +-
src/plugins/meson.build | 2 +-
8 files changed, 125 insertions(+), 56 deletions(-)
---
diff --git a/src/plugins/c-pack/c-pack-plugin.c b/src/plugins/c-pack/c-pack-plugin.c
index 82bd8b2d2..a0e03e4b2 100644
--- a/src/plugins/c-pack/c-pack-plugin.c
+++ b/src/plugins/c-pack/c-pack-plugin.c
@@ -20,24 +20,29 @@
#define G_LOG_DOMAIN "c-pack-plugin"
+#include <libpeas/peas.h>
+
#include <libide-editor.h>
#include <libide-sourceview.h>
-#include <libpeas/peas.h>
+#if 0
#include "ide-c-indenter.h"
+#endif
#include "cpack-completion-provider.h"
#include "cpack-editor-page-addin.h"
_IDE_EXTERN void
_ide_c_pack_register_types (PeasObjectModule *module)
{
+#if 0
peas_object_module_register_extension_type (module,
IDE_TYPE_INDENTER,
IDE_TYPE_C_INDENTER);
+#endif
peas_object_module_register_extension_type (module,
IDE_TYPE_EDITOR_PAGE_ADDIN,
CPACK_TYPE_EDITOR_PAGE_ADDIN);
peas_object_module_register_extension_type (module,
- IDE_TYPE_COMPLETION_PROVIDER,
+ GTK_SOURCE_TYPE_COMPLETION_PROVIDER,
CPACK_TYPE_COMPLETION_PROVIDER);
}
diff --git a/src/plugins/c-pack/cpack-completion-item.c b/src/plugins/c-pack/cpack-completion-item.c
index 177050110..f354b3b0b 100644
--- a/src/plugins/c-pack/cpack-completion-item.c
+++ b/src/plugins/c-pack/cpack-completion-item.c
@@ -27,7 +27,7 @@
#include "cpack-completion-item.h"
G_DEFINE_FINAL_TYPE_WITH_CODE (CpackCompletionItem, cpack_completion_item, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (IDE_TYPE_COMPLETION_PROPOSAL, NULL))
+ G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_COMPLETION_PROPOSAL, NULL))
static void
cpack_completion_item_finalize (GObject *object)
@@ -62,3 +62,43 @@ cpack_completion_item_new (const gchar *word)
return self;
}
+
+void
+cpack_completion_item_display (CpackCompletionItem *self,
+ GtkSourceCompletionCell *cell,
+ const char *typed_text)
+{
+ GtkSourceCompletionColumn column;
+
+ g_return_if_fail (CPACK_IS_COMPLETION_ITEM (self));
+ g_return_if_fail (GTK_SOURCE_IS_COMPLETION_CELL (cell));
+
+ column = gtk_source_completion_cell_get_column (cell);
+
+ switch (column)
+ {
+ case GTK_SOURCE_COMPLETION_COLUMN_ICON:
+ gtk_source_completion_cell_set_icon_name (cell, "lang-include-symbolic");
+ break;
+
+ case GTK_SOURCE_COMPLETION_COLUMN_TYPED_TEXT:
+ {
+ PangoAttrList *attrs;
+
+ attrs = gtk_source_completion_fuzzy_highlight (self->name, typed_text);
+ gtk_source_completion_cell_set_text_with_attributes (cell, self->name, attrs);
+ pango_attr_list_unref (attrs);
+
+ break;
+ }
+
+ case GTK_SOURCE_COMPLETION_COLUMN_COMMENT:
+ case GTK_SOURCE_COMPLETION_COLUMN_DETAILS:
+ case GTK_SOURCE_COMPLETION_COLUMN_BEFORE:
+ case GTK_SOURCE_COMPLETION_COLUMN_AFTER:
+ default:
+ gtk_source_completion_cell_set_text (cell, NULL);
+ break;
+ }
+
+}
diff --git a/src/plugins/c-pack/cpack-completion-item.h b/src/plugins/c-pack/cpack-completion-item.h
index 6252b9558..bd649f696 100644
--- a/src/plugins/c-pack/cpack-completion-item.h
+++ b/src/plugins/c-pack/cpack-completion-item.h
@@ -34,6 +34,9 @@ struct _CpackCompletionItem
gchar *name;
};
-CpackCompletionItem *cpack_completion_item_new (const gchar *word);
+CpackCompletionItem *cpack_completion_item_new (const gchar *word);
+void cpack_completion_item_display (CpackCompletionItem *self,
+ GtkSourceCompletionCell *cell,
+ const char *typed_text);
G_END_DECLS
diff --git a/src/plugins/c-pack/cpack-completion-provider.c b/src/plugins/c-pack/cpack-completion-provider.c
index d0d29adb3..e53f1238b 100644
--- a/src/plugins/c-pack/cpack-completion-provider.c
+++ b/src/plugins/c-pack/cpack-completion-provider.c
@@ -32,16 +32,32 @@
struct _CpackCompletionProvider
{
IdeObject parent_instance;
+ char *word;
+ char *refilter_word;
};
-static void provider_iface_init (IdeCompletionProviderInterface *iface);
+static void provider_iface_init (GtkSourceCompletionProviderInterface *iface);
G_DEFINE_FINAL_TYPE_WITH_CODE (CpackCompletionProvider, cpack_completion_provider, IDE_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (IDE_TYPE_COMPLETION_PROVIDER, provider_iface_init))
+ G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_COMPLETION_PROVIDER,
provider_iface_init))
+
+static void
+cpack_completion_provider_dispose (GObject *object)
+{
+ CpackCompletionProvider *self = (CpackCompletionProvider *)object;
+
+ g_clear_pointer (&self->word, g_free);
+ g_clear_pointer (&self->refilter_word, g_free);
+
+ G_OBJECT_CLASS (cpack_completion_provider_parent_class)->dispose (object);
+}
static void
cpack_completion_provider_class_init (CpackCompletionProviderClass *klass)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = cpack_completion_provider_dispose;
}
static void
@@ -108,12 +124,13 @@ cpack_completion_provider_get_build_flags_cb (GObject *object,
}
static void
-cpack_completion_provider_populate_async (IdeCompletionProvider *provider,
- IdeCompletionContext *context,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+cpack_completion_provider_populate_async (GtkSourceCompletionProvider *provider,
+ GtkSourceCompletionContext *context,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
+ CpackCompletionProvider *self = (CpackCompletionProvider *)provider;
g_autoptr(IdeTask) task = NULL;
g_autofree gchar *prefix = NULL;
GtkTextIter begin, end;
@@ -123,15 +140,17 @@ cpack_completion_provider_populate_async (IdeCompletionProvider *provider,
GFile *file = NULL;
g_assert (CPACK_IS_COMPLETION_PROVIDER (provider));
- 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 (provider, cancellable, callback, user_data);
ide_task_set_source_tag (task, cpack_completion_provider_populate_async);
- ide_completion_context_get_bounds (context, &begin, &end);
+ g_clear_pointer (&self->word, g_free);
- buffer = ide_completion_context_get_buffer (context);
+ gtk_source_completion_context_get_bounds (context, &begin, &end);
+
+ buffer = GTK_TEXT_BUFFER (gtk_source_completion_context_get_buffer (context));
if (gtk_source_buffer_iter_has_context_class (GTK_SOURCE_BUFFER (buffer), &begin, "path"))
{
@@ -163,6 +182,8 @@ query_filesystem:
g_assert (IDE_IS_BUFFER (buffer));
+ self->word = g_strdup (prefix);
+
/*
* First step is to get our list of include paths from the CFLAGS for the
* file. After that, we can start looking for matches on the file-system
@@ -182,7 +203,7 @@ query_filesystem:
}
static GListModel *
-cpack_completion_provider_populate_finish (IdeCompletionProvider *self,
+cpack_completion_provider_populate_finish (GtkSourceCompletionProvider *self,
GAsyncResult *result,
GError **error)
{
@@ -193,32 +214,31 @@ cpack_completion_provider_populate_finish (IdeCompletionProvider *self,
}
static void
-cpack_completion_provider_display_proposal (IdeCompletionProvider *provider,
- IdeCompletionListBoxRow *row,
- IdeCompletionContext *context,
- const gchar *typed_text,
- IdeCompletionProposal *proposal)
+cpack_completion_provider_display (GtkSourceCompletionProvider *provider,
+ GtkSourceCompletionContext *context,
+ GtkSourceCompletionProposal *proposal,
+ GtkSourceCompletionCell *cell)
{
- g_autofree gchar *markup = NULL;
+ CpackCompletionProvider *self = (CpackCompletionProvider *)provider;
+ const char *typed_text;
- g_assert (CPACK_IS_COMPLETION_PROVIDER (provider));
- g_assert (IDE_IS_COMPLETION_LIST_BOX_ROW (row));
- g_assert (IDE_IS_COMPLETION_CONTEXT (context));
+ g_assert (CPACK_IS_COMPLETION_PROVIDER (self));
+ g_assert (GTK_SOURCE_IS_COMPLETION_CONTEXT (context));
g_assert (CPACK_IS_COMPLETION_ITEM (proposal));
+ g_assert (GTK_SOURCE_IS_COMPLETION_CELL (cell));
- markup = ide_completion_fuzzy_highlight (CPACK_COMPLETION_ITEM (proposal)->name, typed_text);
+ if (self->refilter_word)
+ typed_text = self->refilter_word;
+ else
+ typed_text = self->word;
- ide_completion_list_box_row_set_icon_name (row, "lang-include-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);
+ cpack_completion_item_display (CPACK_COMPLETION_ITEM (proposal), cell, typed_text);
}
static void
-cpack_completion_provider_activate_proposal (IdeCompletionProvider *provider,
- IdeCompletionContext *context,
- IdeCompletionProposal *proposal,
- const GdkEventKey *key)
+cpack_completion_provider_activate (GtkSourceCompletionProvider *provider,
+ GtkSourceCompletionContext *context,
+ GtkSourceCompletionProposal *proposal)
{
CpackCompletionItem *item = (CpackCompletionItem *)proposal;
GtkTextBuffer *buffer;
@@ -226,16 +246,16 @@ cpack_completion_provider_activate_proposal (IdeCompletionProvider *provider,
gsize len;
g_assert (CPACK_IS_COMPLETION_PROVIDER (provider));
- g_assert (IDE_IS_COMPLETION_CONTEXT (context));
+ g_assert (GTK_SOURCE_IS_COMPLETION_CONTEXT (context));
g_assert (CPACK_IS_COMPLETION_ITEM (item));
- buffer = ide_completion_context_get_buffer (context);
+ buffer = GTK_TEXT_BUFFER (gtk_source_completion_context_get_buffer (context));
len = strlen (item->name);
gtk_text_buffer_begin_user_action (buffer);
- if (ide_completion_context_get_bounds (context, &begin, &end))
+ if (gtk_source_completion_context_get_bounds (context, &begin, &end))
gtk_text_buffer_delete (buffer, &begin, &end);
/* don't insert trailing / so user does that to trigger next popup */
@@ -247,33 +267,33 @@ cpack_completion_provider_activate_proposal (IdeCompletionProvider *provider,
gtk_text_buffer_end_user_action (buffer);
}
-static gboolean
-cpack_completion_provider_refilter (IdeCompletionProvider *provider,
- IdeCompletionContext *context,
- GListModel *model)
+static void
+cpack_completion_provider_refilter (GtkSourceCompletionProvider *provider,
+ GtkSourceCompletionContext *context,
+ GListModel *model)
{
- g_autofree gchar *word = NULL;
+ CpackCompletionProvider *self = (CpackCompletionProvider *)provider;
g_assert (CPACK_IS_COMPLETION_PROVIDER (provider));
- g_assert (IDE_IS_COMPLETION_CONTEXT (context));
+ g_assert (GTK_SOURCE_IS_COMPLETION_CONTEXT (context));
g_assert (CPACK_IS_COMPLETION_RESULTS (model));
- word = ide_completion_context_get_word (context);
- cpack_completion_results_refilter (CPACK_COMPLETION_RESULTS (model), word);
+ g_clear_pointer (&self->refilter_word, g_free);
+ self->refilter_word = gtk_source_completion_context_get_word (context);
- return TRUE;
+ cpack_completion_results_refilter (CPACK_COMPLETION_RESULTS (model), self->refilter_word);
}
static gint
-cpack_completion_provider_get_priority (IdeCompletionProvider *provider,
- IdeCompletionContext *context)
+cpack_completion_provider_get_priority (GtkSourceCompletionProvider *provider,
+ GtkSourceCompletionContext *context)
{
/* we only activate when applicable, so high priority */
return -100;
}
static gboolean
-cpack_completion_provider_is_trigger (IdeCompletionProvider *provider,
+cpack_completion_provider_is_trigger (GtkSourceCompletionProvider *provider,
const GtkTextIter *iter,
gunichar ch)
{
@@ -289,13 +309,13 @@ cpack_completion_provider_is_trigger (IdeCompletionProvider *provider,
}
static void
-provider_iface_init (IdeCompletionProviderInterface *iface)
+provider_iface_init (GtkSourceCompletionProviderInterface *iface)
{
iface->populate_async = cpack_completion_provider_populate_async;
iface->populate_finish = cpack_completion_provider_populate_finish;
iface->refilter = cpack_completion_provider_refilter;
- iface->display_proposal = cpack_completion_provider_display_proposal;
- iface->activate_proposal = cpack_completion_provider_activate_proposal;
+ iface->display = cpack_completion_provider_display;
+ iface->activate = cpack_completion_provider_activate;
iface->get_priority = cpack_completion_provider_get_priority;
iface->is_trigger = cpack_completion_provider_is_trigger;
}
diff --git a/src/plugins/c-pack/cpack-completion-results.c b/src/plugins/c-pack/cpack-completion-results.c
index b4c06d872..50cdd5e8d 100644
--- a/src/plugins/c-pack/cpack-completion-results.c
+++ b/src/plugins/c-pack/cpack-completion-results.c
@@ -176,7 +176,7 @@ cpack_completion_results_refilter (CpackCompletionResults *self,
const gchar *ele = g_ptr_array_index (self->unfiltered, i);
guint priority;
- if (ide_completion_fuzzy_match (ele, casefold, &priority))
+ if (gtk_source_completion_fuzzy_match (ele, casefold, &priority))
{
Item item = { .word = ele, .priority = priority };
diff --git a/src/plugins/c-pack/meson.build b/src/plugins/c-pack/meson.build
index 0fffd5f9f..676dd1e98 100644
--- a/src/plugins/c-pack/meson.build
+++ b/src/plugins/c-pack/meson.build
@@ -8,9 +8,11 @@ plugins_sources += files([
'cpack-completion-results.c',
'cpack-editor-page-addin.c',
'hdr-format.c',
- 'ide-c-indenter.c',
])
+# needs to be ported to GtkSourceView 5 and moved there
+# 'ide-c-indenter.c',
+
plugin_c_pack_resources = gnome.compile_resources(
'c-pack-resources',
'c-pack.gresource.xml',
diff --git a/src/plugins/ctags/gbp-ctags-workbench-addin.c b/src/plugins/ctags/gbp-ctags-workbench-addin.c
index aa3ea4fb4..0db41808f 100644
--- a/src/plugins/ctags/gbp-ctags-workbench-addin.c
+++ b/src/plugins/ctags/gbp-ctags-workbench-addin.c
@@ -167,8 +167,7 @@ workbench_addin_iface_init (IdeWorkbenchAddinInterface *iface)
}
G_DEFINE_FINAL_TYPE_WITH_CODE (GbpCtagsWorkbenchAddin, gbp_ctags_workbench_addin, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (IDE_TYPE_WORKBENCH_ADDIN,
- workbench_addin_iface_init))
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_WORKBENCH_ADDIN, workbench_addin_iface_init))
static void
gbp_ctags_workbench_addin_class_init (GbpCtagsWorkbenchAddinClass *klass)
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index 4032819db..f68ec0e9a 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -55,7 +55,7 @@ subdir('codespell')
#subdir('command-bar')
subdir('comment-code')
subdir('copyright')
-#subdir('c-pack')
+subdir('c-pack')
#subdir('create-project')
#subdir('ctags')
#subdir('debuggerui')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]