[gnome-builder] libide: make IdeCompletionItem work with bindings
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide: make IdeCompletionItem work with bindings
- Date: Thu, 1 Oct 2015 23:57:03 +0000 (UTC)
commit 20022b03b81384664714ead47238df74fd3efcab
Author: Christian Hergert <christian hergert me>
Date: Thu Oct 1 16:55:57 2015 -0700
libide: make IdeCompletionItem work with bindings
This requires that we don't implement GtkSourceCompletionProposal in the
paret class, but require the subclasses do it. Was causing weird text
issues with Vala overridding IdeCompletionItem.
Also, we can drop the "head" structure and just imherit the GObject the
old fashioned way.
libide/ide-completion-item.c | 41 ++++----------
libide/ide-completion-item.h | 86 +++++++++++------------------
libide/ide-completion-results.c | 8 +-
plugins/ctags/ide-ctags-completion-item.c | 3 +-
4 files changed, 49 insertions(+), 89 deletions(-)
---
diff --git a/libide/ide-completion-item.c b/libide/ide-completion-item.c
index b350cf4..2a28600 100644
--- a/libide/ide-completion-item.c
+++ b/libide/ide-completion-item.c
@@ -22,38 +22,29 @@
#include "ide-completion-item.h"
-G_DEFINE_ABSTRACT_TYPE_WITH_CODE (IdeCompletionItem, ide_completion_item, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_COMPLETION_PROPOSAL, NULL))
+G_DEFINE_ABSTRACT_TYPE (IdeCompletionItem, ide_completion_item, G_TYPE_OBJECT)
static gboolean
ide_completion_item_real_match (IdeCompletionItem *self,
const gchar *query,
const gchar *casefold)
{
- gchar *text;
- gboolean ret;
+ gboolean ret = FALSE;
g_assert (IDE_IS_COMPLETION_ITEM (self));
g_assert (query != NULL);
g_assert (casefold != NULL);
- text = ide_completion_item_get_column_markup (self, IDE_COMPLETION_COLUMN_PRIMARY);
- ret = !!strstr (text ?: "", query);
- g_free (text);
-
- return ret;
-}
-
-static gchar *
-ide_completion_item_real_get_column_markup (IdeCompletionItem *self,
- IdeCompletionColumn column)
-{
- g_return_val_if_fail (IDE_IS_COMPLETION_ITEM (self), NULL);
+ if (GTK_SOURCE_IS_COMPLETION_PROPOSAL (self))
+ {
+ gchar *text;
- if (column == IDE_COMPLETION_COLUMN_PRIMARY)
- return gtk_source_completion_proposal_get_markup (GTK_SOURCE_COMPLETION_PROPOSAL (self));
+ text = gtk_source_completion_proposal_get_label (GTK_SOURCE_COMPLETION_PROPOSAL (self));
+ ret = !!strstr (text ?: "", query);
+ g_free (text);
+ }
- return NULL;
+ return ret;
}
gboolean
@@ -66,26 +57,16 @@ ide_completion_item_match (IdeCompletionItem *self,
return IDE_COMPLETION_ITEM_GET_CLASS (self)->match (self, query, casefold);
}
-gchar *
-ide_completion_item_get_column_markup (IdeCompletionItem *self,
- IdeCompletionColumn column)
-{
- g_return_val_if_fail (IDE_IS_COMPLETION_ITEM (self), FALSE);
-
- return IDE_COMPLETION_ITEM_GET_CLASS (self)->get_column_markup (self, column);
-}
-
static void
ide_completion_item_class_init (IdeCompletionItemClass *klass)
{
- klass->get_column_markup = ide_completion_item_real_get_column_markup;
klass->match = ide_completion_item_real_match;
}
static void
ide_completion_item_init (IdeCompletionItem *self)
{
- self->parent_instance.link.data = self;
+ self->link.data = self;
}
/**
diff --git a/libide/ide-completion-item.h b/libide/ide-completion-item.h
index 444f8d7..65ed549 100644
--- a/libide/ide-completion-item.h
+++ b/libide/ide-completion-item.h
@@ -23,44 +23,29 @@
G_BEGIN_DECLS
-#define IDE_TYPE_COMPLETION_ITEM (ide_completion_item_get_type())
+#define IDE_TYPE_COMPLETION_ITEM (ide_completion_item_get_type())
+#define IDE_COMPLETION_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDE_TYPE_COMPLETION_ITEM,
IdeCompletionItem))
+#define IDE_COMPLETION_ITEM_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDE_TYPE_COMPLETION_ITEM,
IdeCompletionItem const))
+#define IDE_COMPLETION_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IDE_TYPE_COMPLETION_ITEM,
IdeCompletionItemClass))
+#define IDE_IS_COMPLETION_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDE_TYPE_COMPLETION_ITEM))
+#define IDE_IS_COMPLETION_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IDE_TYPE_COMPLETION_ITEM))
+#define IDE_COMPLETION_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IDE_TYPE_COMPLETION_ITEM,
IdeCompletionItemClass))
-/*
- * We provide this private, but defined in the header API for IdeCompletionItemHead
- * so that we have a location to store a GList node without allocating one. This is
- * used for sorting of result structures by IdeCompletionResults without allocating
- * GList items for GtkSourceCompletionContext.
- */
-typedef struct
+typedef struct _IdeCompletionItem IdeCompletionItem;
+typedef struct _IdeCompletionItemClass IdeCompletionItemClass;
+
+struct _IdeCompletionItem
{
- GObject parent;
- /*< semi-public >*/
+ GObject parent_instance;
+
+ /*< private >*/
GList link;
guint priority;
-} IdeCompletionItemHead;
-
-/*
- * We require the following cleanup function so that G_DECLARE_DERIVABLE_TYPE() can
- * work with our semi-public IdeCompletionItemHead node.
- */
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (IdeCompletionItemHead, g_object_unref)
-
-G_DECLARE_DERIVABLE_TYPE (IdeCompletionItem,
- ide_completion_item,
- IDE, COMPLETION_ITEM,
- IdeCompletionItemHead)
-
-typedef enum
-{
- IDE_COMPLETION_COLUMN_PRIMARY = 0,
- IDE_COMPLETION_COLUMN_PREFIX = 1,
- IDE_COMPLETION_COLUMN_SUFFIX = 2,
- IDE_COMPLETION_COLUMN_INFO = 3,
-} IdeCompletionColumn;
+};
struct _IdeCompletionItemClass
{
- GObjectClass parent;
+ GObjectClass parent_class;
/**
* IdeCompletionItem::match:
@@ -78,30 +63,25 @@ struct _IdeCompletionItemClass
gboolean (*match) (IdeCompletionItem *self,
const gchar *query,
const gchar *casefold);
-
- /**
- * IdeCompletionItem::get_column_markup:
- * @self: An #IdeCompletionItem.
- * @column: The #IdeCompletionItemColumn to retrieve.
- *
- * This function returns the text for a particular column.
- * This allows for Builder to organize results with aligned
- * columns in GtkSourceView. NOTE: This is not yet performed
- * today, but will in the future.
- */
- gchar *(*get_column_markup) (IdeCompletionItem *self,
- IdeCompletionColumn column);
};
-IdeCompletionItem *ide_completion_item_new (void);
-gboolean ide_completion_item_match (IdeCompletionItem *self,
- const gchar *query,
- const gchar *casefold);
-gchar *ide_completion_item_get_column_markup (IdeCompletionItem *self,
- IdeCompletionColumn column);
-gboolean ide_completion_item_fuzzy_match (const gchar *haystack,
- const gchar *casefold_needle,
- guint *priority);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (IdeCompletionItem, g_object_unref)
+
+static inline void
+ide_completion_item_set_priority (IdeCompletionItem *self,
+ guint priority)
+{
+ self->priority = priority;
+}
+
+GType ide_completion_item_get_type (void);
+IdeCompletionItem *ide_completion_item_new (void);
+gboolean ide_completion_item_match (IdeCompletionItem *self,
+ const gchar *query,
+ const gchar *casefold);
+gboolean ide_completion_item_fuzzy_match (const gchar *haystack,
+ const gchar *casefold_needle,
+ guint *priority);
G_END_DECLS
diff --git a/libide/ide-completion-results.c b/libide/ide-completion-results.c
index 09c3cef..3abbcd4 100644
--- a/libide/ide-completion-results.c
+++ b/libide/ide-completion-results.c
@@ -78,8 +78,8 @@ G_DEFINE_TYPE_WITH_PRIVATE (IdeCompletionResults, ide_completion_results, G_TYPE
EGG_DEFINE_COUNTER (instances, "IdeCompletionResults", "Instances", "Number of IdeCompletionResults")
-#define GET_ITEM(i) ((IdeCompletionItem*)(g_ptr_array_index((priv)->results, (i))))
-#define GET_ITEM_LINK(item) (&((IdeCompletionItemHead *)(item))->link)
+#define GET_ITEM(i) ((IdeCompletionItem *)(g_ptr_array_index((priv)->results, (i))))
+#define GET_ITEM_LINK(item) (&((IdeCompletionItem *)(item))->link)
enum {
PROP_0,
@@ -337,9 +337,9 @@ ide_completion_results_compare (IdeCompletionResults *self,
IdeCompletionItem *left,
IdeCompletionItem *right)
{
- if (left->parent_instance.priority < right->parent_instance.priority)
+ if (left->priority < right->priority)
return -1;
- else if (left->parent_instance.priority > right->parent_instance.priority)
+ else if (left->priority > right->priority)
return 1;
else
return 0;
diff --git a/plugins/ctags/ide-ctags-completion-item.c b/plugins/ctags/ide-ctags-completion-item.c
index 896741c..6a226ab 100644
--- a/plugins/ctags/ide-ctags-completion-item.c
+++ b/plugins/ctags/ide-ctags-completion-item.c
@@ -74,9 +74,8 @@ ide_ctags_completion_item_match (IdeCompletionItem *item,
const gchar *casefold)
{
IdeCtagsCompletionItem *self = (IdeCtagsCompletionItem *)item;
- IdeCompletionItemHead *head = (IdeCompletionItemHead *)item;
- return ide_completion_item_fuzzy_match (self->entry->name, casefold, &head->priority);
+ return ide_completion_item_fuzzy_match (self->entry->name, casefold, &item->priority);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]