[Xfce4-commits] <design:master> Add tooltips and change cell renderer packing.
Nick Schermer
noreply at xfce.org
Sun Jun 5 19:46:03 CEST 2011
Updating branch refs/heads/master
to 913774cc61a90212aa7baddd2bdb1deb3d4affbc (commit)
from 01d0956788e9f757362ce7e4b79c5904efa724f6 (commit)
commit 913774cc61a90212aa7baddd2bdb1deb3d4affbc
Author: Nick Schermer <nick at xfce.org>
Date: Sun Jun 5 19:43:55 2011 +0200
Add tooltips and change cell renderer packing.
.../merge-with-xfrun/demo-code/c/appfinder-model.c | 53 ++++++++++++++++++--
.../merge-with-xfrun/demo-code/c/appfinder-model.h | 1 +
.../demo-code/c/appfinder-window.c | 17 +++++--
3 files changed, 62 insertions(+), 9 deletions(-)
diff --git a/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-model.c b/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-model.c
index 615735c..479c329 100644
--- a/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-model.c
+++ b/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-model.c
@@ -85,6 +85,7 @@ typedef struct
gchar *abstract;
GPtrArray *categories;
gchar *command;
+ gchar *tooltip;
guint visible : 1;
GdkPixbuf *icon_small;
@@ -226,6 +227,7 @@ xfce_appfinder_model_get_column_type (GtkTreeModel *tree_model,
case XFCE_APPFINDER_MODEL_COLUMN_ABSTRACT:
case XFCE_APPFINDER_MODEL_COLUMN_URI:
case XFCE_APPFINDER_MODEL_COLUMN_COMMAND:
+ case XFCE_APPFINDER_MODEL_COLUMN_TOOLTIP:
return G_TYPE_STRING;
case XFCE_APPFINDER_MODEL_COLUMN_ICON_SMALL:
@@ -287,11 +289,17 @@ xfce_appfinder_model_get_value (GtkTreeModel *tree_model,
gint column,
GValue *value)
{
- XfceAppfinderModel *model = XFCE_APPFINDER_MODEL (tree_model);
- ModelItem *item;
- const gchar *name;
- const gchar *comment;
- const gchar *command, *p;
+ XfceAppfinderModel *model = XFCE_APPFINDER_MODEL (tree_model);
+ ModelItem *item;
+ const gchar *name;
+ const gchar *comment;
+ const gchar *command, *p;
+ GFile *file;
+ gchar *parse_name;
+ GList *categories, *li;
+ gchar **cat_arr;
+ gchar *cat_str;
+ guint i;
g_return_if_fail (XFCE_IS_APPFINDER_MODEL (model));
g_return_if_fail (iter->stamp == model->stamp);
@@ -374,6 +382,40 @@ xfce_appfinder_model_get_value (GtkTreeModel *tree_model,
g_value_set_object (value, item->icon_large);
break;
+ case XFCE_APPFINDER_MODEL_COLUMN_TOOLTIP:
+ if (item->item != NULL
+ && item->tooltip == NULL)
+ {
+ file = garcon_menu_item_get_file (item->item);
+ parse_name = g_file_get_parse_name (file);
+ g_object_unref (G_OBJECT (file));
+
+ /* create nice category string */
+ categories = garcon_menu_item_get_categories (item->item);
+ i = g_list_length (categories);
+ cat_arr = g_new0 (gchar *, i + 1);
+ for (li = categories; li != NULL; li = li->next)
+ cat_arr[--i] = li->data;
+ cat_str = g_strjoinv ("; ", cat_arr);
+ g_free (cat_arr);
+
+ item->tooltip = g_markup_printf_escaped ("<b>%s:</b> %s\n"
+ "<b>%s:</b> %s\n"
+ "<b>%s:</b> %s\n"
+ "<b>%s:</b> %s",
+ _("Name"), garcon_menu_item_get_name (item->item),
+ _("Command"), garcon_menu_item_get_command (item->item),
+ _("Categories"), cat_str,
+ _("Filename"), parse_name);
+
+ g_free (parse_name);
+ g_free (cat_str);
+ }
+
+ g_value_init (value, G_TYPE_STRING);
+ g_value_set_string (value, item->tooltip);
+ break;
+
case XFCE_APPFINDER_MODEL_COLUMN_URI:
g_value_init (value, G_TYPE_STRING);
if (item->item != NULL)
@@ -592,6 +634,7 @@ xfce_appfinder_model_item_free (gpointer data)
g_free (item->abstract);
g_free (item->key);
g_free (item->command);
+ g_free (item->tooltip);
g_slice_free (ModelItem, item);
}
diff --git a/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-model.h b/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-model.h
index f041949..22c87dd 100644
--- a/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-model.h
+++ b/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-model.h
@@ -34,6 +34,7 @@ enum
XFCE_APPFINDER_MODEL_COLUMN_VISIBLE,
XFCE_APPFINDER_MODEL_COLUMN_COMMAND,
XFCE_APPFINDER_MODEL_COLUMN_URI,
+ XFCE_APPFINDER_MODEL_COLUMN_TOOLTIP,
XFCE_APPFINDER_MODEL_N_COLUMNS,
};
diff --git a/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-window.c b/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-window.c
index 2482e02..23c3797 100644
--- a/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-window.c
+++ b/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-window.c
@@ -213,6 +213,7 @@ xfce_appfinder_window_init (XfceAppfinderWindow *window)
G_CALLBACK (xfce_appfinder_window_category_changed), window);
column = gtk_tree_view_column_new ();
+ gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_append_column (GTK_TREE_VIEW (sidepane), GTK_TREE_VIEW_COLUMN (column));
renderer = gtk_cell_renderer_pixbuf_new ();
@@ -238,6 +239,8 @@ xfce_appfinder_window_init (XfceAppfinderWindow *window)
window->treeview = treeview = gtk_tree_view_new_with_model (filter_model);
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
gtk_tree_view_set_enable_search (GTK_TREE_VIEW (treeview), FALSE);
+ gtk_tree_view_set_fixed_height_mode (GTK_TREE_VIEW (treeview), TRUE);
+ gtk_tree_view_set_tooltip_column (GTK_TREE_VIEW (treeview), XFCE_APPFINDER_MODEL_COLUMN_TOOLTIP);
g_signal_connect_swapped (GTK_TREE_VIEW (treeview), "row-activated", G_CALLBACK (xfce_appfinder_window_row_activated), window);
g_signal_connect_swapped (GTK_TREE_VIEW (treeview), "start-interactive-search", G_CALLBACK (gtk_widget_grab_focus), entry);
gtk_drag_source_set (treeview, GDK_BUTTON1_MASK, target_list, G_N_ELEMENTS (target_list), GDK_ACTION_COPY);
@@ -252,14 +255,20 @@ xfce_appfinder_window_init (XfceAppfinderWindow *window)
g_signal_connect_swapped (G_OBJECT (selection), "changed",
G_CALLBACK (xfce_appfinder_window_item_changed), window);
- renderer = gtk_cell_renderer_pixbuf_new ();
- column = gtk_tree_view_column_new_with_attributes (NULL, renderer, "pixbuf", XFCE_APPFINDER_MODEL_COLUMN_ICON_SMALL, NULL);
+ column = gtk_tree_view_column_new ();
+ gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), GTK_TREE_VIEW_COLUMN (column));
+ renderer = gtk_cell_renderer_pixbuf_new ();
+ gtk_tree_view_column_pack_start (GTK_TREE_VIEW_COLUMN (column), renderer, FALSE);
+ gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), renderer,
+ "pixbuf", XFCE_APPFINDER_MODEL_COLUMN_ICON_SMALL, NULL);
+
renderer = gtk_cell_renderer_text_new ();
g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
- column = gtk_tree_view_column_new_with_attributes (NULL, renderer, "markup", XFCE_APPFINDER_MODEL_COLUMN_ABSTRACT, NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), GTK_TREE_VIEW_COLUMN (column));
+ gtk_tree_view_column_pack_start (GTK_TREE_VIEW_COLUMN (column), renderer, TRUE);
+ gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), renderer,
+ "markup", XFCE_APPFINDER_MODEL_COLUMN_ABSTRACT, NULL);
window->bin_expanded = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
gtk_box_pack_start (GTK_BOX (vbox), window->bin_expanded, FALSE, TRUE, 0);
More information about the Xfce4-commits
mailing list