[gtksourceview/gtksourcecompletion] Implemented gsc_proposal_get_markup and gsc_proposal_get_action
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: svn-commits-list gnome org
- Subject: [gtksourceview/gtksourcecompletion] Implemented gsc_proposal_get_markup and gsc_proposal_get_action
- Date: Sun, 26 Apr 2009 13:36:19 -0400 (EDT)
commit 8d13e6e229882a594c61b33661e0809eed736b59
Author: Jesse van den Kieboom <jesse icecrew nl>
Date: Sun Apr 26 19:36:09 2009 +0200
Implemented gsc_proposal_get_markup and gsc_proposal_get_action
---
gtksourceview/gtksourcecompletion.c | 27 +++++--
gtksourceview/gtksourcecompletionitem.c | 97 ++++++++++++++++++++++++++-
gtksourceview/gtksourcecompletionitem.h | 7 ++
gtksourceview/gtksourcecompletionmodel.c | 4 +
gtksourceview/gtksourcecompletionmodel.h | 1 +
gtksourceview/gtksourcecompletionproposal.c | 56 +++++++++++++++-
gtksourceview/gtksourcecompletionproposal.h | 6 ++
tests/gsc-provider-devhelp.c | 1 +
tests/gsc-provider-test.c | 2 +-
9 files changed, 188 insertions(+), 13 deletions(-)
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index d0c2e23..0ddf501 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -176,6 +176,7 @@ activate_current_proposal (GtkSourceCompletion *completion)
GtkSourceCompletionProposal *proposal = NULL;
GtkSourceCompletionProvider *provider = NULL;
GtkTextBuffer *buffer;
+ const gchar *action;
if (!get_selected_proposal (completion, &iter, &proposal))
{
@@ -196,8 +197,9 @@ activate_current_proposal (GtkSourceCompletion *completion)
if (!activated)
{
+ action = gtk_source_completion_proposal_get_action (proposal);
gtk_source_completion_utils_replace_current_word (GTK_SOURCE_BUFFER (buffer),
- gtk_source_completion_proposal_get_label (proposal),
+ action ? action : NULL,
-1);
}
@@ -1638,7 +1640,8 @@ render_proposal_text_func (GtkTreeViewColumn *column,
GtkTreeIter *iter,
GtkSourceCompletion *completion)
{
- gchar *name;
+ gchar *label;
+ gchar *markup;
GtkSourceCompletionProvider *provider;
gboolean isheader;
GtkStyle *style;
@@ -1654,18 +1657,18 @@ render_proposal_text_func (GtkTreeViewColumn *column,
&provider,
-1);
- name = g_strdup_printf ("<b>%s</b>",
+ label = g_strdup_printf ("<b>%s</b>",
g_markup_escape_text (gtk_source_completion_provider_get_name (provider),
-1));
style = gtk_widget_get_style (GTK_WIDGET (completion->priv->tree_view_proposals));
g_object_set (cell,
- "markup", name,
+ "markup", label,
"background-gdk", &(style->bg[GTK_STATE_INSENSITIVE]),
"foreground-gdk", &(style->fg[GTK_STATE_INSENSITIVE]),
NULL);
- g_free (name);
+ g_free (label);
g_object_unref (provider);
}
@@ -1674,16 +1677,24 @@ render_proposal_text_func (GtkTreeViewColumn *column,
gtk_tree_model_get (model,
iter,
GTK_SOURCE_COMPLETION_MODEL_COLUMN_LABEL,
- &name,
+ &label,
+ GTK_SOURCE_COMPLETION_MODEL_COLUMN_MARKUP,
+ &markup,
-1);
+ if (!markup)
+ {
+ markup = g_markup_escape_text (label ? label : "", -1);
+ }
+
g_object_set (cell,
- "markup", name,
+ "markup", markup,
"background-set", FALSE,
"foreground-set", FALSE,
NULL);
- g_free (name);
+ g_free (label);
+ g_free (markup);
}
}
diff --git a/gtksourceview/gtksourcecompletionitem.c b/gtksourceview/gtksourcecompletionitem.c
index a8b5dc7..c249311 100644
--- a/gtksourceview/gtksourcecompletionitem.c
+++ b/gtksourceview/gtksourcecompletionitem.c
@@ -8,6 +8,8 @@
struct _GtkSourceCompletionItemPrivate
{
gchar *label;
+ gchar *markup;
+ gchar *action;
gchar *info;
GdkPixbuf *icon;
};
@@ -17,6 +19,8 @@ enum
{
PROP_0,
PROP_LABEL,
+ PROP_MARKUP,
+ PROP_ACTION,
PROP_ICON,
PROP_INFO
};
@@ -35,6 +39,18 @@ gtk_source_completion_proposal_get_label_impl (GtkSourceCompletionProposal *self
return GTK_SOURCE_COMPLETION_ITEM (self)->priv->label;
}
+static const gchar *
+gtk_source_completion_proposal_get_markup_impl (GtkSourceCompletionProposal *self)
+{
+ return GTK_SOURCE_COMPLETION_ITEM (self)->priv->markup;
+}
+
+static const gchar *
+gtk_source_completion_proposal_get_action_impl (GtkSourceCompletionProposal *self)
+{
+ return GTK_SOURCE_COMPLETION_ITEM (self)->priv->action;
+}
+
static GdkPixbuf *
gtk_source_completion_proposal_get_icon_impl (GtkSourceCompletionProposal *self)
{
@@ -55,6 +71,8 @@ gtk_source_completion_proposal_iface_init (gpointer g_iface,
/* Interface data getter implementations */
iface->get_label = gtk_source_completion_proposal_get_label_impl;
+ iface->get_markup = gtk_source_completion_proposal_get_markup_impl;
+ iface->get_action = gtk_source_completion_proposal_get_action_impl;
iface->get_icon = gtk_source_completion_proposal_get_icon_impl;
iface->get_info = gtk_source_completion_proposal_get_info_impl;
}
@@ -65,6 +83,9 @@ gtk_source_completion_item_finalize (GObject *object)
GtkSourceCompletionItem *self = GTK_SOURCE_COMPLETION_ITEM(object);
g_free (self->priv->label);
+ g_free (self->priv->markup);
+ g_free (self->priv->action);
+
g_free (self->priv->info);
if (self->priv->icon != NULL)
@@ -92,6 +113,12 @@ gtk_source_completion_item_get_property (GObject *object,
case PROP_LABEL:
g_value_set_string (value, self->priv->label);
break;
+ case PROP_MARKUP:
+ g_value_set_string (value, self->priv->markup);
+ break;
+ case PROP_ACTION:
+ g_value_set_string (value, self->priv->action);
+ break;
case PROP_INFO:
g_value_set_string (value, self->priv->info);
break;
@@ -130,6 +157,16 @@ gtk_source_completion_item_set_property (GObject *object,
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_ACTION:
+ g_free (self->priv->action);
+ self->priv->action = g_value_dup_string (value);
+ break;
case PROP_INFO:
g_free (self->priv->info);
self->priv->info = g_value_dup_string (value);
@@ -174,6 +211,32 @@ gtk_source_completion_item_class_init (GtkSourceCompletionItemClass *klass)
G_PARAM_READWRITE));
/**
+ * GtkSourceCompletionItem:markup:
+ *
+ * Label with markup to be shown for this proposal.
+ */
+ g_object_class_install_property (object_class,
+ PROP_MARKUP,
+ g_param_spec_string ("markup",
+ _("Markup"),
+ _("Markup to be shown for this item"),
+ NULL,
+ G_PARAM_READWRITE));
+
+ /**
+ * GtkSourceCompletionItem:action:
+ *
+ * Proposal action.
+ */
+ g_object_class_install_property (object_class,
+ PROP_ACTION,
+ g_param_spec_string ("action",
+ _("Action"),
+ _("Item action"),
+ NULL,
+ G_PARAM_READWRITE));
+
+ /**
* GtkSourceCompletionItem:icon:
*
* Icon to be shown for this proposal.
@@ -211,6 +274,7 @@ gtk_source_completion_item_init (GtkSourceCompletionItem *self)
/**
* gtk_source_completion_item_new:
* @label: The item label
+ * @action: The item action
* @icon: The item icon
* @info: The item extra information
*
@@ -223,11 +287,41 @@ gtk_source_completion_item_init (GtkSourceCompletionItem *self)
*/
GtkSourceCompletionItem *
gtk_source_completion_item_new (const gchar *label,
+ const gchar *action,
GdkPixbuf *icon,
const gchar *info)
{
return g_object_new (GTK_TYPE_SOURCE_COMPLETION_ITEM,
"label", label,
+ "action", action,
+ "icon", icon,
+ "info", info,
+ NULL);
+}
+
+/**
+ * gtk_source_completion_item_new_with_markup:
+ * @markup: The item markup label
+ * @action: The item action
+ * @icon: The item icon
+ * @info: The item extra information
+ *
+ * Create a new #GtkSourceCompletionItem with markup label @markup, icon
+ * @icon and extra information @info. Both @icon and @info can be %NULL in
+ * which case there will be no icon shown and no extra information available.
+ *
+ * Returns: The new #GtkSourceCompletionItem.
+ *
+ */
+GtkSourceCompletionItem *
+gtk_source_completion_item_new_with_markup (const gchar *markup,
+ const gchar *action,
+ GdkPixbuf *icon,
+ const gchar *info)
+{
+ return g_object_new (GTK_TYPE_SOURCE_COMPLETION_ITEM,
+ "markup", markup,
+ "action", action,
"icon", icon,
"info", info,
NULL);
@@ -247,6 +341,7 @@ gtk_source_completion_item_new (const gchar *label,
*/
GtkSourceCompletionItem *
gtk_source_completion_item_new_from_stock (const gchar *label,
+ const gchar *action,
const gchar *stock,
const gchar *info)
{
@@ -279,7 +374,7 @@ gtk_source_completion_item_new_from_stock (const gchar *label,
icon = NULL;
}
- item = gtk_source_completion_item_new (label, icon, info);
+ item = gtk_source_completion_item_new (label, action, icon, info);
if (icon != NULL)
{
diff --git a/gtksourceview/gtksourcecompletionitem.h b/gtksourceview/gtksourcecompletionitem.h
index dad80e9..3b760f7 100644
--- a/gtksourceview/gtksourcecompletionitem.h
+++ b/gtksourceview/gtksourcecompletionitem.h
@@ -31,10 +31,17 @@ struct _GtkSourceCompletionItemClass {
GType gtk_source_completion_item_get_type (void) G_GNUC_CONST;
GtkSourceCompletionItem *gtk_source_completion_item_new (const gchar *label,
+ const gchar *action,
+ GdkPixbuf *icon,
+ const gchar *info);
+
+GtkSourceCompletionItem *gtk_source_completion_item_new_with_markup (const gchar *markup,
+ const gchar *action,
GdkPixbuf *icon,
const gchar *info);
GtkSourceCompletionItem *gtk_source_completion_item_new_from_stock (const gchar *label,
+ const gchar *action,
const gchar *stock,
const gchar *info);
diff --git a/gtksourceview/gtksourcecompletionmodel.c b/gtksourceview/gtksourcecompletionmodel.c
index 98b6341..4c90768 100644
--- a/gtksourceview/gtksourcecompletionmodel.c
+++ b/gtksourceview/gtksourcecompletionmodel.c
@@ -252,6 +252,9 @@ tree_model_get_value (GtkTreeModel *tree_model,
case GTK_SOURCE_COMPLETION_MODEL_COLUMN_LABEL:
g_value_set_string (value, gtk_source_completion_proposal_get_label (node->proposal));
break;
+ case GTK_SOURCE_COMPLETION_MODEL_COLUMN_MARKUP:
+ g_value_set_string (value, gtk_source_completion_proposal_get_markup (node->proposal));
+ break;
case GTK_SOURCE_COMPLETION_MODEL_COLUMN_ICON:
if (node->proposal == NULL)
{
@@ -563,6 +566,7 @@ gtk_source_completion_model_init (GtkSourceCompletionModel *self)
self->priv->column_types[GTK_SOURCE_COMPLETION_MODEL_COLUMN_PROVIDER] = G_TYPE_OBJECT;
self->priv->column_types[GTK_SOURCE_COMPLETION_MODEL_COLUMN_PROPOSAL] = G_TYPE_OBJECT;
self->priv->column_types[GTK_SOURCE_COMPLETION_MODEL_COLUMN_LABEL] = G_TYPE_STRING;
+ 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->num_per_provider = g_hash_table_new_full (g_direct_hash,
diff --git a/gtksourceview/gtksourcecompletionmodel.h b/gtksourceview/gtksourcecompletionmodel.h
index b62b3f0..bb112ae 100644
--- a/gtksourceview/gtksourcecompletionmodel.h
+++ b/gtksourceview/gtksourcecompletionmodel.h
@@ -64,6 +64,7 @@ typedef enum
enum
{
GTK_SOURCE_COMPLETION_MODEL_COLUMN_LABEL,
+ GTK_SOURCE_COMPLETION_MODEL_COLUMN_MARKUP,
GTK_SOURCE_COMPLETION_MODEL_COLUMN_ICON,
GTK_SOURCE_COMPLETION_MODEL_COLUMN_PROPOSAL,
GTK_SOURCE_COMPLETION_MODEL_COLUMN_PROVIDER,
diff --git a/gtksourceview/gtksourcecompletionproposal.c b/gtksourceview/gtksourcecompletionproposal.c
index 32a007c..65edd0c 100644
--- a/gtksourceview/gtksourcecompletionproposal.c
+++ b/gtksourceview/gtksourcecompletionproposal.c
@@ -50,6 +50,18 @@ gtk_source_completion_proposal_get_label_default (GtkSourceCompletionProposal *p
g_return_val_if_reached (NULL);
}
+static const gchar *
+gtk_source_completion_proposal_get_markup_default (GtkSourceCompletionProposal *proposal)
+{
+ return NULL;
+}
+
+static const gchar *
+gtk_source_completion_proposal_get_action_default (GtkSourceCompletionProposal *proposal)
+{
+ return NULL;
+}
+
static GdkPixbuf *
gtk_source_completion_proposal_get_icon_default (GtkSourceCompletionProposal *proposal)
{
@@ -68,6 +80,9 @@ gtk_source_completion_proposal_init (GtkSourceCompletionProposalIface *iface)
static gboolean initialized = FALSE;
iface->get_label = gtk_source_completion_proposal_get_label_default;
+ iface->get_markup = gtk_source_completion_proposal_get_markup_default;
+ iface->get_action = gtk_source_completion_proposal_get_action_default;
+
iface->get_icon = gtk_source_completion_proposal_get_icon_default;
iface->get_info = gtk_source_completion_proposal_get_info_default;
@@ -130,9 +145,9 @@ gtk_source_completion_proposal_get_type ()
* gtk_source_completion_proposal_get_label:
* @proposal: A #GtkSourceCompletionProposal
*
- * Gets the label of @proposal. The label is shown in the list of proposals and
- * may contain markup. It should be a valid UTF-8 string ready for display to
- * the user.
+ * Gets the label of @proposal. The label is shown in the list of proposals as
+ * plain text. If you need any markup (such as bold or italic text), you have
+ * to implement #gtk_source_completion_proposal_get_markup.
*
* Returns: The label of @proposal.
*/
@@ -144,6 +159,41 @@ gtk_source_completion_proposal_get_label (GtkSourceCompletionProposal *proposal)
}
/**
+ * gtk_source_completion_proposal_get_markup:
+ * @proposal: A #GtkSourceCompletionProposal
+ *
+ * Gets the label of @proposal with markup. The label is shown in the list of
+ * proposals and may contain markup. This will be used instead of
+ * #gtk_source_completion_proposal_get_label if implemented.
+ *
+ * Returns: The label of @proposal with markup.
+ */
+const gchar *
+gtk_source_completion_proposal_get_markup (GtkSourceCompletionProposal *proposal)
+{
+ g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (proposal), NULL);
+ return GTK_SOURCE_COMPLETION_PROPOSAL_GET_INTERFACE (proposal)->get_markup (proposal);
+}
+
+/**
+ * gtk_source_completion_proposal_get_action:
+ * @proposal: A #GtkSourceCompletionProposal
+ *
+ * Gets the action of @proposal. The action is the text that is inserted into
+ * the text buffer when the proposal is activated by the default activation.
+ * You are free to implement a custom activation handler in the provider and
+ * not implement this function.
+ *
+ * Returns: The action of @proposal.
+ */
+const gchar *
+gtk_source_completion_proposal_get_action (GtkSourceCompletionProposal *proposal)
+{
+ g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (proposal), NULL);
+ return GTK_SOURCE_COMPLETION_PROPOSAL_GET_INTERFACE (proposal)->get_action (proposal);
+}
+
+/**
* gtk_source_completion_proposal_get_icon:
* @proposal: A #GtkSourceCompletionProposal
*
diff --git a/gtksourceview/gtksourcecompletionproposal.h b/gtksourceview/gtksourcecompletionproposal.h
index aa50686..e2fd6b9 100644
--- a/gtksourceview/gtksourcecompletionproposal.h
+++ b/gtksourceview/gtksourcecompletionproposal.h
@@ -43,6 +43,9 @@ struct _GtkSourceCompletionProposalIface
/* Interface functions */
const gchar *(*get_label) (GtkSourceCompletionProposal *proposal);
+ const gchar *(*get_markup) (GtkSourceCompletionProposal *proposal);
+ const gchar *(*get_action) (GtkSourceCompletionProposal *proposal);
+
GdkPixbuf *(*get_icon) (GtkSourceCompletionProposal *proposal);
const gchar *(*get_info) (GtkSourceCompletionProposal *proposal);
@@ -53,6 +56,9 @@ struct _GtkSourceCompletionProposalIface
GType gtk_source_completion_proposal_get_type (void) G_GNUC_CONST;
const gchar *gtk_source_completion_proposal_get_label (GtkSourceCompletionProposal *proposal);
+const gchar *gtk_source_completion_proposal_get_markup (GtkSourceCompletionProposal *proposal);
+const gchar *gtk_source_completion_proposal_get_action (GtkSourceCompletionProposal *proposal);
+
GdkPixbuf *gtk_source_completion_proposal_get_icon (GtkSourceCompletionProposal *proposal);
const gchar *gtk_source_completion_proposal_get_info (GtkSourceCompletionProposal *proposal);
diff --git a/tests/gsc-provider-devhelp.c b/tests/gsc-provider-devhelp.c
index 00a9b83..707b449 100644
--- a/tests/gsc-provider-devhelp.c
+++ b/tests/gsc-provider-devhelp.c
@@ -128,6 +128,7 @@ gsc_provider_devhelp_init (GscProviderDevhelp *self)
DhLink *link = (DhLink *)item->data;
ret = g_list_prepend (ret, gtk_source_completion_item_new (dh_link_get_name (link),
+ dh_link_get_name (link),
NULL,
dh_link_get_uri (link)));
}
diff --git a/tests/gsc-provider-test.c b/tests/gsc-provider-test.c
index 55c8224..d782a37 100644
--- a/tests/gsc-provider-test.c
+++ b/tests/gsc-provider-test.c
@@ -56,7 +56,7 @@ append_item (GList *list, const gchar *name, GdkPixbuf *icon, const gchar *info)
{
GtkSourceCompletionItem *prop;
- prop = gtk_source_completion_item_new (name, icon, info);
+ prop = gtk_source_completion_item_new (name, name, icon, info);
return g_list_append (list, prop);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]