[gtksourceview] completion: add GtkSourceCompletionProposal.get_typed_text
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] completion: add GtkSourceCompletionProposal.get_typed_text
- Date: Sat, 3 Sep 2022 06:29:41 +0000 (UTC)
commit 3a13f101428c1360d42a2c23be9e3eafd309b7dd
Author: Christian Hergert <chergert redhat com>
Date: Fri Sep 2 23:23:54 2022 -0700
completion: add GtkSourceCompletionProposal.get_typed_text
This optional vfunc can be used by consumers to get what the typed text
should be for a proposal. This can be useful when creating specialized
models that filter existing items such as high-priority filtering.
.../snippets/gtksourcecompletionsnippetsproposal.c | 13 ++++++++++-
.../words/gtksourcecompletionwordsproposal.c | 14 +++++++++++-
gtksourceview/gtksourcecompletionproposal.c | 25 ++++++++++++++++++++++
gtksourceview/gtksourcecompletionproposal.h | 9 ++++++++
4 files changed, 59 insertions(+), 2 deletions(-)
---
diff --git a/gtksourceview/completion-providers/snippets/gtksourcecompletionsnippetsproposal.c
b/gtksourceview/completion-providers/snippets/gtksourcecompletionsnippetsproposal.c
index 389364df..8d176332 100644
--- a/gtksourceview/completion-providers/snippets/gtksourcecompletionsnippetsproposal.c
+++ b/gtksourceview/completion-providers/snippets/gtksourcecompletionsnippetsproposal.c
@@ -23,11 +23,22 @@
#include "gtksourcecompletionsnippetsproposal-private.h"
+static char *
+gtk_source_completion_snippets_proposal_get_typed_text (GtkSourceCompletionProposal *proposal)
+{
+ return g_strdup (GTK_SOURCE_COMPLETION_SNIPPETS_PROPOSAL (proposal)->info.trigger);
+}
+
+static void
+proposal_iface_init (GtkSourceCompletionProposalInterface *iface)
+{
+ iface->get_typed_text = gtk_source_completion_snippets_proposal_get_typed_text;
+}
G_DEFINE_TYPE_WITH_CODE (GtkSourceCompletionSnippetsProposal,
gtk_source_completion_snippets_proposal,
G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_COMPLETION_PROPOSAL, NULL))
+ G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_COMPLETION_PROPOSAL, proposal_iface_init))
enum {
PROP_0,
diff --git a/gtksourceview/completion-providers/words/gtksourcecompletionwordsproposal.c
b/gtksourceview/completion-providers/words/gtksourcecompletionwordsproposal.c
index bb394e18..98cb7965 100644
--- a/gtksourceview/completion-providers/words/gtksourcecompletionwordsproposal.c
+++ b/gtksourceview/completion-providers/words/gtksourcecompletionwordsproposal.c
@@ -45,10 +45,22 @@ enum
static GParamSpec *properties[N_PROPS];
static guint signals[N_SIGNALS];
+static char *
+gtk_source_completion_words_proposal_get_typed_text (GtkSourceCompletionProposal *proposal)
+{
+ return g_strdup (GTK_SOURCE_COMPLETION_WORDS_PROPOSAL (proposal)->word);
+}
+
+static void
+proposal_iface_init (GtkSourceCompletionProposalInterface *iface)
+{
+ iface->get_typed_text = gtk_source_completion_words_proposal_get_typed_text;
+}
+
G_DEFINE_TYPE_WITH_CODE (GtkSourceCompletionWordsProposal,
gtk_source_completion_words_proposal,
G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_COMPLETION_PROPOSAL, NULL))
+ G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_COMPLETION_PROPOSAL, proposal_iface_init))
static void
gtk_source_completion_words_proposal_finalize (GObject *object)
diff --git a/gtksourceview/gtksourcecompletionproposal.c b/gtksourceview/gtksourcecompletionproposal.c
index 63be5065..e630c627 100644
--- a/gtksourceview/gtksourcecompletionproposal.c
+++ b/gtksourceview/gtksourcecompletionproposal.c
@@ -43,3 +43,28 @@ static void
gtk_source_completion_proposal_default_init (GtkSourceCompletionProposalInterface *iface)
{
}
+
+/**
+ * gtk_source_completion_proposal_get_typed_text:
+ * @proposal: a #GtkSourceCompletionProposal
+ *
+ * Gets the typed-text for the proposal, if supported by the implementation.
+ *
+ * Implementing this virtual-function is optional, but can be useful to allow
+ * external tooling to compare results.
+ *
+ * Returns: (transfer full) (nullable): a newly allocated string, or %NULL
+ *
+ * Since: 5.6
+ */
+char *
+gtk_source_completion_proposal_get_typed_text (GtkSourceCompletionProposal *proposal)
+{
+ GtkSourceCompletionProposalInterface *iface;
+
+ g_return_val_if_fail (GTK_SOURCE_IS_COMPLETION_PROPOSAL (proposal), NULL);
+
+ iface = GTK_SOURCE_COMPLETION_PROPOSAL_GET_IFACE (proposal);
+
+ return iface->get_typed_text ? iface->get_typed_text (proposal) : NULL;
+}
diff --git a/gtksourceview/gtksourcecompletionproposal.h b/gtksourceview/gtksourcecompletionproposal.h
index f3b38e82..52007f14 100644
--- a/gtksourceview/gtksourcecompletionproposal.h
+++ b/gtksourceview/gtksourcecompletionproposal.h
@@ -21,6 +21,10 @@
#pragma once
+#if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
+#error "Only <gtksourceview/gtksource.h> can be included directly."
+#endif
+
#include <glib-object.h>
#include "gtksourcetypes.h"
@@ -35,6 +39,11 @@ G_DECLARE_INTERFACE (GtkSourceCompletionProposal, gtk_source_completion_proposal
struct _GtkSourceCompletionProposalInterface
{
GTypeInterface parent_iface;
+
+ char *(*get_typed_text) (GtkSourceCompletionProposal *proposal);
};
+GTK_SOURCE_AVAILABLE_IN_5_6
+char *gtk_source_completion_proposal_get_typed_text (GtkSourceCompletionProposal *proposal);
+
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]