[gtksourceview] Added show-icons property to GtkSourceCompletion
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gtksourceview] Added show-icons property to GtkSourceCompletion
- Date: Sun, 3 Jan 2010 13:02:49 +0000 (UTC)
commit 3f923ae50b7609df46f4036775952d83630c4ebd
Author: Jesse van den Kieboom <jesse vandenkieboom epfl ch>
Date: Sun Jan 3 14:02:42 2010 +0100
Added show-icons property to GtkSourceCompletion
This property will allow the user to set whether or not to show
the provider/proposal icons in the completion popup.
gtksourceview/gtksourcecompletion.c | 70 ++++++++++++++++++++++++++---------
tests/test-completion.c | 46 +++++++++++++++++++++--
2 files changed, 94 insertions(+), 22 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 4cb27a5..f9c3fd0 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -79,6 +79,7 @@ enum
PROP_REMEMBER_INFO_VISIBILITY,
PROP_SELECT_ON_SHOW,
PROP_SHOW_HEADERS,
+ PROP_SHOW_ICONS,
PROP_ACCELERATORS,
PROP_AUTO_COMPLETE_DELAY,
@@ -154,6 +155,7 @@ struct _GtkSourceCompletionPrivate
gulong signals_ids[LAST_EXTERNAL_SIGNAL];
gboolean select_first;
+ gboolean show_icons;
gint min_auto_complete_delay;
GList *auto_completion_selection;
@@ -1179,28 +1181,41 @@ update_column_sizes (GtkSourceCompletion *completion)
gint icon_height;
/* Resize tree view columns accordingly */
- g_object_get (completion->priv->cell_renderer_accelerator,
- "xpad", &xpad,
- NULL);
+ if (completion->priv->num_accelerators > 0)
+ {
+ g_object_get (completion->priv->cell_renderer_accelerator,
+ "xpad", &xpad,
+ NULL);
- style = gtk_widget_get_style (completion->priv->tree_view_proposals);
- gtk_style_get (style,
- GTK_TYPE_TREE_VIEW,
- "horizontal-separator", &separator,
- NULL);
+ style = gtk_widget_get_style (completion->priv->tree_view_proposals);
+ gtk_style_get (style,
+ GTK_TYPE_TREE_VIEW,
+ "horizontal-separator", &separator,
+ NULL);
- cwidth = measure_accelerator_width (completion->priv->tree_view_proposals);
- cwidth += (xpad + separator) * 2;
+ cwidth = measure_accelerator_width (completion->priv->tree_view_proposals);
+ cwidth += (xpad + separator) * 2;
+ }
+ else
+ {
+ cwidth = 0;
+ }
tv = GTK_TREE_VIEW (completion->priv->tree_view_proposals);
set_column_width (tv, 0, completion->priv->tree_view_proposals->allocation.width - cwidth);
set_column_width (tv, 1, cwidth);
+ gtk_tree_view_column_set_visible (completion->priv->tree_view_column_accelerator,
+ completion->priv->num_accelerators > 0);
+
+ gtk_cell_renderer_set_visible (completion->priv->cell_renderer_icon,
+ completion->priv->show_icons);
+
gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &icon_width, &icon_height);
gtk_cell_renderer_set_fixed_size (completion->priv->cell_renderer_icon,
- icon_width,
- icon_height);
+ icon_width,
+ icon_height);
}
static void
@@ -1984,6 +1999,9 @@ gtk_source_completion_get_property (GObject *object,
case PROP_SHOW_HEADERS:
g_value_set_boolean (value, completion->priv->show_headers);
break;
+ case PROP_SHOW_ICONS:
+ g_value_set_boolean (value, completion->priv->show_icons);
+ break;
case PROP_ACCELERATORS:
g_value_set_uint (value, completion->priv->num_accelerators);
break;
@@ -2036,14 +2054,15 @@ gtk_source_completion_set_property (GObject *object,
completion->priv->show_headers);
}
break;
+ case PROP_SHOW_ICONS:
+ completion->priv->show_icons = g_value_get_boolean (value);
+
+ update_column_sizes (completion);
+ break;
case PROP_ACCELERATORS:
completion->priv->num_accelerators = g_value_get_uint (value);
-
- if (completion->priv->tree_view_column_accelerator != NULL)
- {
- gtk_tree_view_column_set_visible (completion->priv->tree_view_column_accelerator,
- completion->priv->num_accelerators > 0);
- }
+
+ update_column_sizes (completion);
break;
case PROP_AUTO_COMPLETE_DELAY:
completion->priv->auto_complete_delay = g_value_get_uint (value);
@@ -2265,6 +2284,21 @@ gtk_source_completion_class_init (GtkSourceCompletionClass *klass)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
/**
+ * GtkSourceCompletion:show-icons:
+ *
+ * Determines whether provider and proposal icons should be shown in
+ * the completion popup.
+ *
+ */
+ g_object_class_install_property (object_class,
+ PROP_SHOW_ICONS,
+ g_param_spec_boolean ("show-icons",
+ _("Show Icons"),
+ _("Show provider and proposal icons in the completion popup"),
+ TRUE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+ /**
* GtkSourceCompletion:accelerators:
*
* Number of accelerators to show for the first proposals.
diff --git a/tests/test-completion.c b/tests/test-completion.c
index 17efcee..7195fe2 100644
--- a/tests/test-completion.c
+++ b/tests/test-completion.c
@@ -47,6 +47,8 @@ struct _TestProvider
GList *proposals;
gint priority;
gchar *name;
+
+ GdkPixbuf *icon;
};
struct _TestProviderClass
@@ -92,6 +94,20 @@ test_provider_populate (GtkSourceCompletionProvider *provider,
TRUE);
}
+static GdkPixbuf *
+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, GTK_STOCK_DIALOG_INFO, 16, 0, NULL);
+ }
+
+ return tp->icon;
+}
+
static void
test_provider_iface_init (GtkSourceCompletionProviderIface *iface)
{
@@ -100,6 +116,8 @@ test_provider_iface_init (GtkSourceCompletionProviderIface *iface)
iface->populate = test_provider_populate;
iface->match = test_provider_match;
iface->get_priority = test_provider_get_priority;
+
+ //iface->get_icon = test_provider_get_icon;
}
static void
@@ -111,15 +129,16 @@ static void
test_provider_init (TestProvider *self)
{
GList *proposals = NULL;
+ GdkPixbuf *icon = test_provider_get_icon (GTK_SOURCE_COMPLETION_PROVIDER (self));
proposals = g_list_prepend (proposals,
- gtk_source_completion_item_new ("Proposal 3", "Proposal 3", NULL, NULL));
+ gtk_source_completion_item_new ("Proposal 3", "Proposal 3", icon, NULL));
proposals = g_list_prepend (proposals,
- gtk_source_completion_item_new ("Proposal 2", "Proposal 2", NULL, NULL));
+ gtk_source_completion_item_new ("Proposal 2", "Proposal 2", icon, NULL));
proposals = g_list_prepend (proposals,
- gtk_source_completion_item_new ("Proposal 1", "Proposal 1", NULL, NULL));
+ gtk_source_completion_item_new ("Proposal 1", "Proposal 1", icon, NULL));
self->proposals = proposals;
}
@@ -151,7 +170,7 @@ select_on_show_toggled_cb (GtkToggleButton *button,
static void
show_headers_toggled_cb (GtkToggleButton *button,
- gpointer user_data)
+ gpointer user_data)
{
g_object_set (comp, "show-headers",
gtk_toggle_button_get_active (button),
@@ -169,6 +188,16 @@ toggle_active_property (gpointer source,
g_object_set (dest, "active", value, NULL);
}
+static void
+show_icons_toggled_cb (GtkToggleButton *button,
+ gpointer user_data)
+{
+ g_object_set (comp, "show-icons",
+ gtk_toggle_button_get_active (button),
+ NULL);
+}
+
+
static GtkWidget*
create_window (void)
{
@@ -178,6 +207,7 @@ create_window (void)
GtkWidget *remember;
GtkWidget *select_on_show;
GtkWidget *show_headers;
+ GtkWidget *show_icons;
GtkSourceCompletion *completion;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
@@ -193,16 +223,19 @@ create_window (void)
remember = gtk_check_button_new_with_label ("Remember info visibility");
select_on_show = gtk_check_button_new_with_label ("Select first on show");
show_headers = gtk_check_button_new_with_label ("Show headers");
+ show_icons = gtk_check_button_new_with_label ("Show icons");
completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (view));
toggle_active_property (completion, remember, "remember-info-visibility");
toggle_active_property (completion, select_on_show, "select-on-show");
toggle_active_property (completion, show_headers, "show-headers");
+ toggle_active_property (completion, show_icons, "show-icons");
gtk_box_pack_start (GTK_BOX (hbox), remember, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), select_on_show, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), show_headers, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), show_icons, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), scroll, TRUE, TRUE, 0);
gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
@@ -221,6 +254,9 @@ create_window (void)
g_signal_connect (show_headers, "toggled",
G_CALLBACK (show_headers_toggled_cb),
NULL);
+ g_signal_connect (show_icons, "toggled",
+ G_CALLBACK (show_icons_toggled_cb),
+ NULL);
return window;
}
@@ -240,6 +276,8 @@ create_completion(void)
GTK_SOURCE_COMPLETION_PROVIDER (prov_words),
NULL);
+ g_object_set (prov_words, "priority", 10, NULL);
+
TestProvider *tp = g_object_new (test_provider_get_type (), NULL);
tp->priority = 1;
tp->name = "Test Provider 1";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]