[gtksourceview] completion: add support for named-icons and GIcon
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] completion: add support for named-icons and GIcon
- Date: Sat, 15 Aug 2015 08:00:30 +0000 (UTC)
commit 5fabb88e1ea02abdbfc3a945e6b9367112b2b09e
Author: Paolo Borelli <pborelli gnome org>
Date: Tue Aug 11 15:32:11 2015 +0200
completion: add support for named-icons and GIcon
Support setting an icon-name or a GIcon on providers and proposals
as an alternative to setting the Pixbuf. This makes much easier
to use symbolic icons.
docs/reference/gtksourceview-3.0-sections.txt | 4 +
gtksourceview/gtksourcecompletion.c | 47 ++++++++++++++-
gtksourceview/gtksourcecompletionitem.c | 81 +++++++++++++++++++++++--
gtksourceview/gtksourcecompletionmodel.c | 28 +++++++++
gtksourceview/gtksourcecompletionmodel.h | 2 +
gtksourceview/gtksourcecompletionproposal.c | 55 ++++++++++++++++-
gtksourceview/gtksourcecompletionproposal.h | 28 ++++++---
gtksourceview/gtksourcecompletionprovider.c | 55 ++++++++++++++++-
gtksourceview/gtksourcecompletionprovider.h | 12 ++++
tests/test-completion.c | 70 +++++++++++++++------
10 files changed, 343 insertions(+), 39 deletions(-)
---
diff --git a/docs/reference/gtksourceview-3.0-sections.txt b/docs/reference/gtksourceview-3.0-sections.txt
index 01a6a46..5d88b23 100644
--- a/docs/reference/gtksourceview-3.0-sections.txt
+++ b/docs/reference/gtksourceview-3.0-sections.txt
@@ -159,6 +159,8 @@ gtk_source_completion_proposal_get_label
gtk_source_completion_proposal_get_markup
gtk_source_completion_proposal_get_text
gtk_source_completion_proposal_get_icon
+gtk_source_completion_proposal_get_icon_name
+gtk_source_completion_proposal_get_gicon
gtk_source_completion_proposal_get_info
gtk_source_completion_proposal_changed
gtk_source_completion_proposal_hash
@@ -178,6 +180,8 @@ GtkSourceCompletionProvider
GtkSourceCompletionProviderIface
gtk_source_completion_provider_get_name
gtk_source_completion_provider_get_icon
+gtk_source_completion_provider_get_icon_name
+gtk_source_completion_provider_get_gicon
gtk_source_completion_provider_populate
gtk_source_completion_provider_get_activation
gtk_source_completion_provider_match
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 7485157..65fd3e8 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -1950,6 +1950,42 @@ accelerators_notify_cb (GtkSourceCompletion *completion,
}
static void
+cell_icon_func (GtkTreeViewColumn *column,
+ GtkCellRenderer *cell,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ GdkPixbuf *pixbuf;
+ gchar *icon_name;
+ GIcon *gicon;
+
+ gtk_tree_model_get (model, iter,
+ GTK_SOURCE_COMPLETION_MODEL_COLUMN_ICON, &pixbuf,
+ GTK_SOURCE_COMPLETION_MODEL_COLUMN_ICON_NAME, &icon_name,
+ GTK_SOURCE_COMPLETION_MODEL_COLUMN_GICON, &gicon,
+ -1);
+
+ if (pixbuf != NULL)
+ {
+ g_object_set (cell, "pixbuf", pixbuf, NULL);
+ g_object_unref (pixbuf);
+ }
+
+ if (icon_name != NULL)
+ {
+ g_object_set (cell, "icon-name", icon_name, NULL);
+ g_free (icon_name);
+ }
+
+ if (gicon != NULL)
+ {
+ g_object_set (cell, "gicon", gicon, NULL);
+ g_object_unref (gicon);
+ }
+}
+
+static void
init_tree_view (GtkSourceCompletion *completion,
GtkBuilder *builder)
{
@@ -1992,8 +2028,17 @@ init_tree_view (GtkSourceCompletion *completion,
column = GTK_TREE_VIEW_COLUMN (gtk_builder_get_object (builder, "tree_view_column_icon"));
+ /* We use a cell function instead of plain attributes for the icon since
+ * the pixbuf renderer will not renderer any icon if pixbuf is set to NULL.
+ * See https://bugzilla.gnome.org/show_bug.cgi?id=753510
+ */
+ gtk_tree_view_column_set_cell_data_func (column,
+ cell_renderer,
+ cell_icon_func,
+ NULL,
+ NULL);
+
gtk_tree_view_column_set_attributes (column, cell_renderer,
- "pixbuf", GTK_SOURCE_COMPLETION_MODEL_COLUMN_ICON,
"cell-background-set",
GTK_SOURCE_COMPLETION_MODEL_COLUMN_IS_HEADER,
NULL);
diff --git a/gtksourceview/gtksourcecompletionitem.c b/gtksourceview/gtksourcecompletionitem.c
index 66df16d..b352fd8 100644
--- a/gtksourceview/gtksourcecompletionitem.c
+++ b/gtksourceview/gtksourcecompletionitem.c
@@ -39,6 +39,8 @@ struct _GtkSourceCompletionItemPrivate
gchar *text;
gchar *info;
GdkPixbuf *icon;
+ gchar *icon_name;
+ GIcon *gicon;
};
/* Properties */
@@ -49,6 +51,8 @@ enum
PROP_MARKUP,
PROP_TEXT,
PROP_ICON,
+ PROP_ICON_NAME,
+ PROP_GICON,
PROP_INFO
};
@@ -85,6 +89,18 @@ gtk_source_completion_proposal_get_icon_impl (GtkSourceCompletionProposal *self)
return GTK_SOURCE_COMPLETION_ITEM (self)->priv->icon;
}
+static const gchar *
+gtk_source_completion_proposal_get_icon_name_impl (GtkSourceCompletionProposal *self)
+{
+ return GTK_SOURCE_COMPLETION_ITEM (self)->priv->icon_name;
+}
+
+static GIcon *
+gtk_source_completion_proposal_get_gicon_impl (GtkSourceCompletionProposal *self)
+{
+ return GTK_SOURCE_COMPLETION_ITEM (self)->priv->gicon;
+}
+
static gchar *
gtk_source_completion_proposal_get_info_impl (GtkSourceCompletionProposal *self)
{
@@ -102,6 +118,8 @@ gtk_source_completion_proposal_iface_init (gpointer g_iface,
iface->get_markup = gtk_source_completion_proposal_get_markup_impl;
iface->get_text = gtk_source_completion_proposal_get_text_impl;
iface->get_icon = gtk_source_completion_proposal_get_icon_impl;
+ iface->get_icon_name = gtk_source_completion_proposal_get_icon_name_impl;
+ iface->get_gicon = gtk_source_completion_proposal_get_gicon_impl;
iface->get_info = gtk_source_completion_proposal_get_info_impl;
}
@@ -121,6 +139,13 @@ gtk_source_completion_item_finalize (GObject *object)
g_object_unref (self->priv->icon);
}
+ g_free (self->priv->icon_name);
+
+ if (self->priv->gicon != NULL)
+ {
+ g_object_unref (self->priv->gicon);
+ }
+
G_OBJECT_CLASS (gtk_source_completion_item_parent_class)->finalize (object);
}
@@ -153,6 +178,12 @@ gtk_source_completion_item_get_property (GObject *object,
case PROP_ICON:
g_value_set_object (value, self->priv->icon);
break;
+ case PROP_ICON_NAME:
+ g_value_set_string (value, self->priv->icon_name);
+ break;
+ case PROP_GICON:
+ g_value_set_object (value, self->priv->gicon);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -182,13 +213,11 @@ gtk_source_completion_item_set_property (GObject *object,
case PROP_LABEL:
g_free (self->priv->label);
self->priv->label = g_value_dup_string (value);
-
emit_changed (self);
break;
case PROP_MARKUP:
g_free (self->priv->markup);
self->priv->markup = g_value_dup_string (value);
-
emit_changed (self);
break;
case PROP_TEXT:
@@ -198,7 +227,6 @@ gtk_source_completion_item_set_property (GObject *object,
case PROP_INFO:
g_free (self->priv->info);
self->priv->info = g_value_dup_string (value);
-
emit_changed (self);
break;
case PROP_ICON:
@@ -210,6 +238,20 @@ gtk_source_completion_item_set_property (GObject *object,
self->priv->icon = GDK_PIXBUF (g_value_dup_object (value));
emit_changed (self);
break;
+ case PROP_ICON_NAME:
+ g_free (self->priv->icon_name);
+ self->priv->icon_name = g_value_dup_string (value);
+ emit_changed (self);
+ break;
+ case PROP_GICON:
+ if (self->priv->gicon != NULL)
+ {
+ g_object_unref (self->priv->gicon);
+ }
+
+ self->priv->gicon = G_ICON (g_value_dup_object (value));
+ emit_changed (self);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -267,17 +309,46 @@ gtk_source_completion_item_class_init (GtkSourceCompletionItemClass *klass)
/**
* GtkSourceCompletionItem:icon:
*
- * Icon to be shown for this proposal.
+ * The #GdkPixbuf for the icon to be shown for this proposal.
*/
g_object_class_install_property (object_class,
PROP_ICON,
g_param_spec_object ("icon",
"Icon",
- "Icon to be shown for this item",
+ "Pixbuf of the icon to be shown for this item",
GDK_TYPE_PIXBUF,
G_PARAM_READWRITE));
/**
+ * GtkSourceCompletionItem:icon-name:
+ *
+ * The icon name for the icon to be shown for this proposal.
+ *
+ * Since: 3.18
+ */
+ g_object_class_install_property (object_class,
+ PROP_ICON_NAME,
+ g_param_spec_string ("icon-name",
+ "Icon Name",
+ "Icon name of the icon to be shown for this
item",
+ NULL,
+ G_PARAM_READWRITE));
+
+ /**
+ * GtkSourceCompletionItem:gicon:
+ *
+ * The #GIcon for the icon to be shown for this proposal.
+ *
+ * Since: 3.18
+ */
+ g_object_class_install_property (object_class,
+ PROP_GICON,
+ g_param_spec_object ("gicon",
+ "GIcon",
+ "GIcon of the icon to be shown for this item",
+ G_TYPE_ICON,
+ G_PARAM_READWRITE));
+ /**
* GtkSourceCompletionItem:info:
*
* Optional extra information to be shown for this proposal.
diff --git a/gtksourceview/gtksourcecompletionmodel.c b/gtksourceview/gtksourcecompletionmodel.c
index 0430a2a..ca54de8 100644
--- a/gtksourceview/gtksourcecompletionmodel.c
+++ b/gtksourceview/gtksourcecompletionmodel.c
@@ -520,6 +520,32 @@ tree_model_get_value (GtkTreeModel *tree_model,
}
break;
+ case GTK_SOURCE_COMPLETION_MODEL_COLUMN_ICON_NAME:
+ if (is_header (proposal_info))
+ {
+ const gchar *icon_name = gtk_source_completion_provider_get_icon_name
(completion_provider);
+ g_value_set_string (value, (gpointer)icon_name);
+ }
+ else
+ {
+ const gchar *icon_name = gtk_source_completion_proposal_get_icon_name
(completion_proposal);
+ g_value_set_string (value, (gpointer)icon_name);
+ }
+ break;
+
+ case GTK_SOURCE_COMPLETION_MODEL_COLUMN_GICON:
+ if (is_header (proposal_info))
+ {
+ GIcon *icon = gtk_source_completion_provider_get_gicon (completion_provider);
+ g_value_set_object (value, (gpointer)icon);
+ }
+ else
+ {
+ GIcon *icon = gtk_source_completion_proposal_get_gicon (completion_proposal);
+ g_value_set_object (value, (gpointer)icon);
+ }
+ break;
+
case GTK_SOURCE_COMPLETION_MODEL_COLUMN_IS_HEADER:
g_value_set_boolean (value, is_header (proposal_info));
break;
@@ -724,6 +750,8 @@ gtk_source_completion_model_init (GtkSourceCompletionModel *self)
self->priv->column_types[GTK_SOURCE_COMPLETION_MODEL_COLUMN_MARKUP] = G_TYPE_STRING;
self->priv->column_types[GTK_SOURCE_COMPLETION_MODEL_COLUMN_ICON] = GDK_TYPE_PIXBUF;
+ self->priv->column_types[GTK_SOURCE_COMPLETION_MODEL_COLUMN_ICON_NAME] = G_TYPE_STRING;
+ self->priv->column_types[GTK_SOURCE_COMPLETION_MODEL_COLUMN_GICON] = G_TYPE_ICON;
self->priv->column_types[GTK_SOURCE_COMPLETION_MODEL_COLUMN_PROPOSAL] = G_TYPE_OBJECT;
self->priv->column_types[GTK_SOURCE_COMPLETION_MODEL_COLUMN_PROVIDER] = G_TYPE_OBJECT;
self->priv->column_types[GTK_SOURCE_COMPLETION_MODEL_COLUMN_IS_HEADER] = G_TYPE_BOOLEAN;
diff --git a/gtksourceview/gtksourcecompletionmodel.h b/gtksourceview/gtksourcecompletionmodel.h
index 927051d..8f7ee26 100644
--- a/gtksourceview/gtksourcecompletionmodel.h
+++ b/gtksourceview/gtksourcecompletionmodel.h
@@ -55,6 +55,8 @@ enum
{
GTK_SOURCE_COMPLETION_MODEL_COLUMN_MARKUP,
GTK_SOURCE_COMPLETION_MODEL_COLUMN_ICON,
+ GTK_SOURCE_COMPLETION_MODEL_COLUMN_ICON_NAME,
+ GTK_SOURCE_COMPLETION_MODEL_COLUMN_GICON,
GTK_SOURCE_COMPLETION_MODEL_COLUMN_PROPOSAL,
GTK_SOURCE_COMPLETION_MODEL_COLUMN_PROVIDER,
GTK_SOURCE_COMPLETION_MODEL_COLUMN_IS_HEADER,
diff --git a/gtksourceview/gtksourcecompletionproposal.c b/gtksourceview/gtksourcecompletionproposal.c
index 47bf925..8e063a3 100644
--- a/gtksourceview/gtksourcecompletionproposal.c
+++ b/gtksourceview/gtksourcecompletionproposal.c
@@ -69,6 +69,18 @@ gtk_source_completion_proposal_get_icon_default (GtkSourceCompletionProposal *pr
return NULL;
}
+static const gchar *
+gtk_source_completion_proposal_get_icon_name_default (GtkSourceCompletionProposal *proposal)
+{
+ return NULL;
+}
+
+static GIcon *
+gtk_source_completion_proposal_get_gicon_default (GtkSourceCompletionProposal *proposal)
+{
+ return NULL;
+}
+
static gchar *
gtk_source_completion_proposal_get_info_default (GtkSourceCompletionProposal *proposal)
{
@@ -96,8 +108,9 @@ gtk_source_completion_proposal_default_init (GtkSourceCompletionProposalIface *i
iface->get_label = gtk_source_completion_proposal_get_label_default;
iface->get_markup = gtk_source_completion_proposal_get_markup_default;
iface->get_text = gtk_source_completion_proposal_get_text_default;
-
iface->get_icon = gtk_source_completion_proposal_get_icon_default;
+ iface->get_icon_name = gtk_source_completion_proposal_get_icon_name_default;
+ iface->get_gicon = gtk_source_completion_proposal_get_gicon_default;
iface->get_info = gtk_source_completion_proposal_get_info_default;
iface->hash = gtk_source_completion_proposal_hash_default;
iface->equal = gtk_source_completion_proposal_equal_default;
@@ -187,9 +200,9 @@ gtk_source_completion_proposal_get_text (GtkSourceCompletionProposal *proposal)
* gtk_source_completion_proposal_get_icon:
* @proposal: a #GtkSourceCompletionProposal.
*
- * Gets the icon of @proposal.
+ * Gets the #GdkPixbuf for the icon of @proposal.
*
- * Returns: (transfer none): The icon of @proposal.
+ * Returns: (nullable) (transfer none): A #GdkPixbuf with the icon of @proposal.
*/
GdkPixbuf *
gtk_source_completion_proposal_get_icon (GtkSourceCompletionProposal *proposal)
@@ -200,6 +213,42 @@ gtk_source_completion_proposal_get_icon (GtkSourceCompletionProposal *proposal)
}
/**
+ * gtk_source_completion_proposal_get_icon_name:
+ * @proposal: a #GtkSourceCompletionProposal.
+ *
+ * Gets the icon name of @proposal.
+ *
+ * Returns: (nullable) (transfer none): The icon name of @proposal.
+ *
+ * Since: 3.18
+ */
+const gchar *
+gtk_source_completion_proposal_get_icon_name (GtkSourceCompletionProposal *proposal)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_COMPLETION_PROPOSAL (proposal), NULL);
+
+ return GTK_SOURCE_COMPLETION_PROPOSAL_GET_INTERFACE (proposal)->get_icon_name (proposal);
+}
+
+/**
+ * gtk_source_completion_proposal_get_gicon:
+ * @proposal: a #GtkSourceCompletionProposal.
+ *
+ * Gets the #GIcon for the icon of @proposal.
+ *
+ * Returns: (nullable) (transfer none): A #GIcon with the icon of @proposal.
+ *
+ * Since: 3.18
+ */
+GIcon *
+gtk_source_completion_proposal_get_gicon (GtkSourceCompletionProposal *proposal)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_COMPLETION_PROPOSAL (proposal), NULL);
+
+ return GTK_SOURCE_COMPLETION_PROPOSAL_GET_INTERFACE (proposal)->get_gicon (proposal);
+}
+
+/**
* gtk_source_completion_proposal_get_info:
* @proposal: a #GtkSourceCompletionProposal.
*
diff --git a/gtksourceview/gtksourcecompletionproposal.h b/gtksourceview/gtksourcecompletionproposal.h
index 05d0969..0b59012 100644
--- a/gtksourceview/gtksourcecompletionproposal.h
+++ b/gtksourceview/gtksourcecompletionproposal.h
@@ -47,6 +47,10 @@ typedef struct _GtkSourceCompletionProposalIface GtkSourceCompletionProposalIfac
* By default, %NULL is returned.
* @get_icon: The virtual function pointer for gtk_source_completion_proposal_get_icon().
* By default, %NULL is returned.
+ * @get_icon_name: The virtual function pointer for gtk_source_completion_proposal_get_icon_name().
+ * By default, %NULL is returned.
+ * @get_gicon: The virtual function pointer for gtk_source_completion_proposal_get_gicon().
+ * By default, %NULL is returned.
* @get_info: The virtual function pointer for gtk_source_completion_proposal_get_info().
* By default, %NULL is returned.
* @hash: The virtual function pointer for gtk_source_completion_proposal_hash().
@@ -62,19 +66,22 @@ struct _GtkSourceCompletionProposalIface
GTypeInterface parent;
/* Interface functions */
- gchar *(*get_label) (GtkSourceCompletionProposal *proposal);
- gchar *(*get_markup) (GtkSourceCompletionProposal *proposal);
- gchar *(*get_text) (GtkSourceCompletionProposal *proposal);
+ gchar *(*get_label) (GtkSourceCompletionProposal *proposal);
+ gchar *(*get_markup) (GtkSourceCompletionProposal *proposal);
+ gchar *(*get_text) (GtkSourceCompletionProposal *proposal);
- GdkPixbuf *(*get_icon) (GtkSourceCompletionProposal *proposal);
- gchar *(*get_info) (GtkSourceCompletionProposal *proposal);
+ GdkPixbuf *(*get_icon) (GtkSourceCompletionProposal *proposal);
+ const gchar *(*get_icon_name) (GtkSourceCompletionProposal *proposal);
+ GIcon *(*get_gicon) (GtkSourceCompletionProposal *proposal);
- guint (*hash) (GtkSourceCompletionProposal *proposal);
- gboolean (*equal) (GtkSourceCompletionProposal *proposal,
- GtkSourceCompletionProposal *other);
+ gchar *(*get_info) (GtkSourceCompletionProposal *proposal);
+
+ guint (*hash) (GtkSourceCompletionProposal *proposal);
+ gboolean (*equal) (GtkSourceCompletionProposal *proposal,
+ GtkSourceCompletionProposal *other);
/* Signals */
- void (*changed) (GtkSourceCompletionProposal *proposal);
+ void (*changed) (GtkSourceCompletionProposal *proposal);
};
GType gtk_source_completion_proposal_get_type (void) G_GNUC_CONST;
@@ -84,6 +91,9 @@ gchar *gtk_source_completion_proposal_get_markup
(GtkSourceCompletionProposal
gchar *gtk_source_completion_proposal_get_text (GtkSourceCompletionProposal
*proposal);
GdkPixbuf *gtk_source_completion_proposal_get_icon (GtkSourceCompletionProposal
*proposal);
+const gchar *gtk_source_completion_proposal_get_icon_name (GtkSourceCompletionProposal
*proposal);
+GIcon *gtk_source_completion_proposal_get_gicon (GtkSourceCompletionProposal
*proposal);
+
gchar *gtk_source_completion_proposal_get_info (GtkSourceCompletionProposal
*proposal);
void gtk_source_completion_proposal_changed (GtkSourceCompletionProposal
*proposal);
diff --git a/gtksourceview/gtksourcecompletionprovider.c b/gtksourceview/gtksourcecompletionprovider.c
index 3f1f4f7..1b3ad81 100644
--- a/gtksourceview/gtksourcecompletionprovider.c
+++ b/gtksourceview/gtksourcecompletionprovider.c
@@ -50,6 +50,18 @@ gtk_source_completion_provider_get_icon_default (GtkSourceCompletionProvider *pr
return NULL;
}
+static const gchar *
+gtk_source_completion_provider_get_icon_name_default (GtkSourceCompletionProvider *provider)
+{
+ return NULL;
+}
+
+static GIcon *
+gtk_source_completion_provider_get_gicon_default (GtkSourceCompletionProvider *provider)
+{
+ return NULL;
+}
+
static void
gtk_source_completion_provider_populate_default (GtkSourceCompletionProvider *provider,
GtkSourceCompletionContext *context)
@@ -119,7 +131,10 @@ static void
gtk_source_completion_provider_default_init (GtkSourceCompletionProviderIface *iface)
{
iface->get_name = gtk_source_completion_provider_get_name_default;
+
iface->get_icon = gtk_source_completion_provider_get_icon_default;
+ iface->get_icon_name = gtk_source_completion_provider_get_icon_name_default;
+ iface->get_gicon = gtk_source_completion_provider_get_gicon_default;
iface->populate = gtk_source_completion_provider_populate_default;
@@ -158,7 +173,7 @@ gtk_source_completion_provider_get_name (GtkSourceCompletionProvider *provider)
* gtk_source_completion_provider_get_icon:
* @provider: The #GtkSourceCompletionProvider
*
- * Get the icon of the provider.
+ * Get the #GdkPixbuf for the icon of the @provider.
*
* Returns: (nullable) (transfer none): The icon to be used for the provider,
* or %NULL if the provider does not have a special icon.
@@ -172,6 +187,44 @@ gtk_source_completion_provider_get_icon (GtkSourceCompletionProvider *provider)
}
/**
+ * gtk_source_completion_provider_get_icon_name:
+ * @provider: The #GtkSourceCompletionProvider
+ *
+ * Gets the icon name of @provider.
+ *
+ * Returns: (nullable) (transfer none): The icon name to be used for the provider,
+ * or %NULL if the provider does not have a special icon.
+ *
+ * Since: 3.18
+ */
+const gchar *
+gtk_source_completion_provider_get_icon_name (GtkSourceCompletionProvider *provider)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_COMPLETION_PROVIDER (provider), NULL);
+
+ return GTK_SOURCE_COMPLETION_PROVIDER_GET_INTERFACE (provider)->get_icon_name (provider);
+}
+
+/**
+ * gtk_source_completion_provider_get_gicon:
+ * @provider: The #GtkSourceCompletionProvider
+ *
+ * Gets the #GIcon for the icon of @provider.
+ *
+ * Returns: (nullable) (transfer none): The icon to be used for the provider,
+ * or %NULL if the provider does not have a special icon.
+ *
+ * Since: 3.18
+ */
+GIcon *
+gtk_source_completion_provider_get_gicon (GtkSourceCompletionProvider *provider)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_COMPLETION_PROVIDER (provider), NULL);
+
+ return GTK_SOURCE_COMPLETION_PROVIDER_GET_INTERFACE (provider)->get_gicon (provider);
+}
+
+/**
* gtk_source_completion_provider_populate:
* @provider: a #GtkSourceCompletionProvider.
* @context: a #GtkSourceCompletionContext.
diff --git a/gtksourceview/gtksourcecompletionprovider.h b/gtksourceview/gtksourcecompletionprovider.h
index e6a1e70..f1aa173 100644
--- a/gtksourceview/gtksourcecompletionprovider.h
+++ b/gtksourceview/gtksourcecompletionprovider.h
@@ -43,6 +43,10 @@ typedef struct _GtkSourceCompletionProviderIface GtkSourceCompletionProviderIfac
* Must be implemented.
* @get_icon: The virtual function pointer for gtk_source_completion_provider_get_icon().
* By default, %NULL is returned.
+ * @get_icon_name: The virtual function pointer for gtk_source_completion_provider_get_icon_name().
+ * By default, %NULL is returned.
+ * @get_gicon: The virtual function pointer for gtk_source_completion_provider_get_gicon().
+ * By default, %NULL is returned.
* @populate: The virtual function pointer for gtk_source_completion_provider_populate().
* Add no proposals by default.
* @match: The virtual function pointer for gtk_source_completion_provider_match().
@@ -69,7 +73,11 @@ struct _GtkSourceCompletionProviderIface
GTypeInterface g_iface;
gchar *(*get_name) (GtkSourceCompletionProvider *provider);
+
GdkPixbuf *(*get_icon) (GtkSourceCompletionProvider *provider);
+ const gchar *(*get_icon_name) (GtkSourceCompletionProvider *provider);
+ GIcon *(*get_gicon) (GtkSourceCompletionProvider *provider);
+
void (*populate) (GtkSourceCompletionProvider *provider,
GtkSourceCompletionContext *context);
@@ -104,6 +112,10 @@ gchar *gtk_source_completion_provider_get_name
(GtkSourceCompletionProvider *pr
GdkPixbuf *gtk_source_completion_provider_get_icon (GtkSourceCompletionProvider *provider);
+const gchar *gtk_source_completion_provider_get_icon_name (GtkSourceCompletionProvider *provider);
+
+GIcon *gtk_source_completion_provider_get_gicon (GtkSourceCompletionProvider *provider);
+
void gtk_source_completion_provider_populate (GtkSourceCompletionProvider *provider,
GtkSourceCompletionContext *context);
diff --git a/tests/test-completion.c b/tests/test-completion.c
index ad40140..60d38b0 100644
--- a/tests/test-completion.c
+++ b/tests/test-completion.c
@@ -39,7 +39,10 @@ struct _TestProvider
gint priority;
gchar *name;
- GdkPixbuf *icon;
+ GdkPixbuf *provider_icon;
+
+ GdkPixbuf *item_icon;
+ GIcon *item_gicon;
/* If it's a random provider, a subset of 'proposals' are choosen on
* each populate. Otherwise, all the proposals are shown. */
@@ -116,13 +119,7 @@ test_provider_get_icon (GtkSourceCompletionProvider *provider)
{
TestProvider *tp = (TestProvider *)provider;
- if (tp->icon == NULL)
- {
- GtkIconTheme *theme = gtk_icon_theme_get_default ();
- tp->icon = gtk_icon_theme_load_icon (theme, "dialog-information", 16, 0, NULL);
- }
-
- return tp->icon;
+ return tp->is_random ? NULL : tp->provider_icon;
}
static void
@@ -131,7 +128,7 @@ test_provider_iface_init (GtkSourceCompletionProviderIface *iface)
iface->get_name = test_provider_get_name;
iface->populate = test_provider_populate;
iface->get_priority = test_provider_get_priority;
- /* iface->get_icon = test_provider_get_icon; */
+ iface->get_icon = test_provider_get_icon;
}
static void
@@ -142,7 +139,9 @@ test_provider_dispose (GObject *gobject)
g_list_free_full (self->proposals, g_object_unref);
self->proposals = NULL;
- g_clear_object (&self->icon);
+ g_clear_object (&self->provider_icon);
+ g_clear_object (&self->item_icon);
+ g_clear_object (&self->item_gicon);
G_OBJECT_CLASS (test_provider_parent_class)->dispose (gobject);
}
@@ -170,18 +169,56 @@ test_provider_class_init (TestProviderClass *klass)
static void
test_provider_init (TestProvider *self)
{
+ GtkIconTheme *theme;
+ GIcon *icon;
+ GIcon *emblem_icon;
+ GEmblem *emblem;
+
+ theme = gtk_icon_theme_get_default ();
+ self->provider_icon = gtk_icon_theme_load_icon (theme, "dialog-information", 16, 0, NULL);
+
+ self->item_icon = gtk_icon_theme_load_icon (theme, "trophy-gold", 16, 0, NULL);
+
+ icon = g_themed_icon_new ("trophy-silver");
+ emblem_icon = g_themed_icon_new ("emblem-urgent");
+ emblem = g_emblem_new (emblem_icon);
+ self->item_gicon = g_emblemed_icon_new (icon, emblem);
+ g_object_unref (icon);
+ g_object_unref (emblem_icon);
+ g_object_unref (emblem);
}
static void
test_provider_set_fixed (TestProvider *provider,
gint nb_proposals)
{
- GdkPixbuf *icon = test_provider_get_icon (GTK_SOURCE_COMPLETION_PROVIDER (provider));
GList *proposals = NULL;
gint i;
g_list_free_full (provider->proposals, g_object_unref);
+ proposals = g_list_prepend (proposals,
+ gtk_source_completion_item_new_with_markup ("A very <b>long</b> proposal.
I <i>repeat</i>, a very long proposal!",
+ "A very long proposal. I
repeat, a very long proposal!",
+ provider->item_icon,
+ "To test the horizontal
scrollbar and the markup."));
+
+
+
+ proposals = g_list_prepend (proposals,
+ g_object_new (GTK_SOURCE_TYPE_COMPLETION_ITEM,
+ "markup", "A proposal with a <b>symbolic</b> icon",
+ "text", "Test setting the icon-name property",
+ "icon-name", "face-cool-symbolic",
+ NULL));
+
+ proposals = g_list_prepend (proposals,
+ g_object_new (GTK_SOURCE_TYPE_COMPLETION_ITEM,
+ "markup", "A proposal with an emblem <b>GIcon</b>",
+ "text", "Test setting the GIcon property",
+ "gicon", provider->item_gicon,
+ NULL));
+
for (i = nb_proposals - 1; i > 0; i--)
{
gchar *name = g_strdup_printf ("Proposal %d", i);
@@ -189,19 +226,13 @@ test_provider_set_fixed (TestProvider *provider,
proposals = g_list_prepend (proposals,
gtk_source_completion_item_new (name,
name,
- icon,
+ provider->item_icon,
"The extra info of the
proposal.\n"
"A second line."));
g_free (name);
}
- proposals = g_list_prepend (proposals,
- gtk_source_completion_item_new_with_markup ("A very <b>long</b> proposal.
I <i>repeat</i>, a very long proposal!",
- "A very long proposal. I
repeat, a very long proposal!",
- icon,
- "To test the horizontal
scrollbar and the markup."));
-
provider->proposals = proposals;
provider->is_random = 0;
}
@@ -210,7 +241,6 @@ static void
test_provider_set_random (TestProvider *provider,
gint nb_proposals)
{
- GdkPixbuf *icon = test_provider_get_icon (GTK_SOURCE_COMPLETION_PROVIDER (provider));
GList *proposals = NULL;
gint i;
@@ -224,7 +254,7 @@ test_provider_set_random (TestProvider *provider,
proposals = g_list_prepend (proposals,
gtk_source_completion_item_new (name,
name,
- icon,
+ provider->item_icon,
NULL));
g_free (padding);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]