[gtksourceview] Completion: simplify render_proposal_{icon, text}_func()
- From: SÃbastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] Completion: simplify render_proposal_{icon, text}_func()
- Date: Thu, 14 Feb 2013 23:07:38 +0000 (UTC)
commit 51cb792d30826485c5834e6b8cc5e5e6b0e069d3
Author: SÃbastien Wilmet <swilmet gnome org>
Date: Thu Feb 14 20:22:14 2013 +0100
Completion: simplify render_proposal_{icon,text}_func()
The 'markup' column of a header row is now handled directly in the
CompletionModel.
gtksourceview/gtksourcecompletion.c | 82 +++++++++---------------------
gtksourceview/gtksourcecompletionmodel.c | 32 +++++++++---
2 files changed, 48 insertions(+), 66 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 7fce2f2..e308ca2 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -2672,13 +2672,9 @@ render_proposal_icon_func (GtkTreeViewColumn *column,
GtkTreeIter *iter,
GtkSourceCompletion *completion)
{
- gboolean isheader;
- GdkPixbuf *icon;
-
- isheader = gtk_source_completion_model_iter_is_header (completion->priv->model_proposals,
- iter);
+ GdkPixbuf *icon = NULL;
- if (isheader)
+ if (gtk_source_completion_model_iter_is_header (completion->priv->model_proposals, iter))
{
GtkStyleContext *context;
GdkRGBA color;
@@ -2699,15 +2695,13 @@ render_proposal_icon_func (GtkTreeViewColumn *column,
NULL);
}
- gtk_tree_model_get (model,
- iter,
- GTK_SOURCE_COMPLETION_MODEL_COLUMN_ICON,
- &icon,
+ gtk_tree_model_get (model, iter,
+ GTK_SOURCE_COMPLETION_MODEL_COLUMN_ICON, &icon,
-1);
g_object_set (cell, "pixbuf", icon, NULL);
- if (icon)
+ if (icon != NULL)
{
g_object_unref (icon);
}
@@ -2722,38 +2716,31 @@ render_proposal_text_func (GtkTreeViewColumn *column,
{
gchar *label;
gchar *markup;
- GtkSourceCompletionProvider *provider;
- gboolean isheader;
- isheader = gtk_source_completion_model_iter_is_header (completion->priv->model_proposals,
- iter);
+ /* Set text */
- if (isheader)
+ gtk_tree_model_get (model, iter,
+ GTK_SOURCE_COMPLETION_MODEL_COLUMN_LABEL, &label,
+ GTK_SOURCE_COMPLETION_MODEL_COLUMN_MARKUP, &markup,
+ -1);
+
+ if (markup == NULL)
{
- gchar *name;
- GtkStyleContext *context;
- GdkRGBA color;
- GdkRGBA bgcolor;
+ markup = g_markup_escape_text (label != NULL ? label : "", -1);
+ }
- gtk_tree_model_get (model,
- iter,
- GTK_SOURCE_COMPLETION_MODEL_COLUMN_PROVIDER,
- &provider,
- -1);
+ g_object_set (cell, "markup", markup, NULL);
- name = gtk_source_completion_provider_get_name (provider);
+ g_free (label);
+ g_free (markup);
- if (name != NULL)
- {
- gchar *escaped = g_markup_escape_text (name, -1);
- label = g_strdup_printf ("<b>%s</b>", escaped);
- g_free (escaped);
- g_free (name);
- }
- else
- {
- label = g_strdup_printf ("<b>%s</b>", _("Provider"));
- }
+ /* Set colors */
+
+ if (gtk_source_completion_model_iter_is_header (completion->priv->model_proposals, iter))
+ {
+ GtkStyleContext *context;
+ GdkRGBA color;
+ GdkRGBA bgcolor;
context = gtk_widget_get_style_context (completion->priv->tree_view_proposals);
gtk_style_context_get_color (context,
@@ -2763,37 +2750,16 @@ render_proposal_text_func (GtkTreeViewColumn *column,
GTK_STATE_FLAG_INSENSITIVE,
&bgcolor);
g_object_set (cell,
- "markup", label,
"foreground-rgba", &color,
"cell-background-rgba", &bgcolor,
NULL);
-
- g_free (label);
- g_object_unref (provider);
}
else
{
- gtk_tree_model_get (model,
- iter,
- GTK_SOURCE_COMPLETION_MODEL_COLUMN_LABEL,
- &label,
- GTK_SOURCE_COMPLETION_MODEL_COLUMN_MARKUP,
- &markup,
- -1);
-
- if (!markup)
- {
- markup = g_markup_escape_text (label ? label : "", -1);
- }
-
g_object_set (cell,
- "markup", markup,
"cell-background-set", FALSE,
"foreground-set", FALSE,
NULL);
-
- g_free (label);
- g_free (markup);
}
}
diff --git a/gtksourceview/gtksourcecompletionmodel.c b/gtksourceview/gtksourcecompletionmodel.c
index 6f6dbfa..27c30ed 100644
--- a/gtksourceview/gtksourcecompletionmodel.c
+++ b/gtksourceview/gtksourcecompletionmodel.c
@@ -23,6 +23,7 @@
#include "gtksourcecompletionmodel.h"
#include "gtksourcecompletionprovider.h"
#include "gtksourcecompletionproposal.h"
+#include "gtksourceview-i18n.h"
#define GTK_SOURCE_COMPLETION_MODEL_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object),
GTK_SOURCE_TYPE_COMPLETION_MODEL, GtkSourceCompletionModelPrivate))
@@ -447,26 +448,41 @@ tree_model_get_value (GtkTreeModel *tree_model,
break;
case GTK_SOURCE_COMPLETION_MODEL_COLUMN_LABEL:
- if (completion_proposal != NULL)
+ if (is_header (proposal_info))
{
- gchar *label = gtk_source_completion_proposal_get_label (completion_proposal);
- g_value_take_string (value, label);
+ g_value_take_string (value, NULL);
}
else
{
- g_value_take_string (value, NULL);
+ gchar *label = gtk_source_completion_proposal_get_label (completion_proposal);
+ g_value_take_string (value, label);
}
break;
case GTK_SOURCE_COMPLETION_MODEL_COLUMN_MARKUP:
- if (completion_proposal != NULL)
+ if (is_header (proposal_info))
{
- gchar *markup = gtk_source_completion_proposal_get_markup
(completion_proposal);
- g_value_take_string (value, markup);
+ gchar *name = gtk_source_completion_provider_get_name (completion_provider);
+
+ if (name != NULL)
+ {
+ gchar *escaped = g_markup_escape_text (name, -1);
+ gchar *markup = g_strdup_printf ("<b>%s</b>", escaped);
+ g_value_take_string (value, markup);
+
+ g_free (name);
+ g_free (escaped);
+ }
+ else
+ {
+ gchar *markup = g_strdup_printf ("<b>%s</b>", _("Provider"));
+ g_value_take_string (value, markup);
+ }
}
else
{
- g_value_take_string (value, NULL);
+ gchar *markup = gtk_source_completion_proposal_get_markup
(completion_proposal);
+ g_value_take_string (value, markup);
}
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]