Added support to --imagelist on tree. Thanks to Joshua Nathaniel Pritikin <jpritikin@pobox.com> now the first column can have an image.

This commit is contained in:
Arx Cruz 2012-07-19 14:22:25 -03:00
parent 9a2a2d8367
commit c17eff5863
3 changed files with 64 additions and 6 deletions

View File

@ -78,6 +78,7 @@ static gboolean zenity_list_radiolist;
static gchar *zenity_list_print_column; static gchar *zenity_list_print_column;
static gchar *zenity_list_hide_column; static gchar *zenity_list_hide_column;
static gboolean zenity_list_hide_header; static gboolean zenity_list_hide_header;
static gboolean zenity_list_imagelist;
#ifdef HAVE_LIBNOTIFY #ifdef HAVE_LIBNOTIFY
/* Notification Dialog Options */ /* Notification Dialog Options */
@ -524,6 +525,15 @@ static GOptionEntry list_options[] = {
N_("Use radio buttons for first column"), N_("Use radio buttons for first column"),
NULL NULL
}, },
{
"imagelist",
'\0',
0,
G_OPTION_ARG_NONE,
&zenity_list_imagelist,
N_("Use an image for first column"),
NULL
},
{ {
"separator", "separator",
'\0', '\0',
@ -1356,6 +1366,7 @@ zenity_list_pre_callback (GOptionContext *context,
zenity_list_columns = NULL; zenity_list_columns = NULL;
zenity_list_checklist = FALSE; zenity_list_checklist = FALSE;
zenity_list_radiolist = FALSE; zenity_list_radiolist = FALSE;
zenity_list_imagelist = FALSE;
zenity_list_hide_header = FALSE; zenity_list_hide_header = FALSE;
zenity_list_print_column = NULL; zenity_list_print_column = NULL;
zenity_list_hide_column = NULL; zenity_list_hide_column = NULL;
@ -1687,6 +1698,7 @@ zenity_list_post_callback (GOptionContext *context,
results->tree_data->checkbox = zenity_list_checklist; results->tree_data->checkbox = zenity_list_checklist;
results->tree_data->radiobox = zenity_list_radiolist; results->tree_data->radiobox = zenity_list_radiolist;
results->tree_data->imagebox = zenity_list_imagelist;
results->tree_data->multi = zenity_general_multiple; results->tree_data->multi = zenity_general_multiple;
results->tree_data->editable = zenity_general_editable; results->tree_data->editable = zenity_general_editable;
results->tree_data->print_column = zenity_list_print_column; results->tree_data->print_column = zenity_list_print_column;
@ -1706,6 +1718,10 @@ zenity_list_post_callback (GOptionContext *context,
zenity_option_error (zenity_option_get_name (list_options, &zenity_list_radiolist), zenity_option_error (zenity_option_get_name (list_options, &zenity_list_radiolist),
ERROR_SUPPORT); ERROR_SUPPORT);
if (zenity_list_imagelist)
zenity_option_error (zenity_option_get_name (list_options, &zenity_list_imagelist),
ERROR_SUPPORT);
if (zenity_list_print_column) if (zenity_list_print_column)
zenity_option_error (zenity_option_get_name (list_options, &zenity_list_print_column), zenity_option_error (zenity_option_get_name (list_options, &zenity_list_print_column),
ERROR_SUPPORT); ERROR_SUPPORT);

View File

@ -87,6 +87,44 @@ zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, g
gtk_tree_path_free (path); gtk_tree_path_free (path);
} }
static void
zenity_load_pixbuf (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
gpointer data)
{
static GHashTable *pixbuf_cache = NULL;
GError *error = NULL;
GdkPixbuf *pixbuf;
gchar *str;
gtk_tree_model_get (tree_model, iter, 0, &str, -1);
if (!str)
return;
if (!pixbuf_cache) {
pixbuf_cache = g_hash_table_new (g_str_hash, g_str_equal);
g_assert(pixbuf_cache);
}
pixbuf = g_hash_table_lookup (pixbuf_cache, str);
if (!pixbuf) {
pixbuf = gdk_pixbuf_new_from_file (str, &error);
if (!pixbuf)
g_warning ("Failed to load '%s'", str);
g_hash_table_insert (pixbuf_cache, g_strdup (str), pixbuf);
}
if (pixbuf)
g_object_set (cell, "pixbuf", pixbuf, NULL);
g_free (str);
}
static gboolean static gboolean
zenity_tree_handle_stdin (GIOChannel *channel, zenity_tree_handle_stdin (GIOChannel *channel,
GIOCondition condition, GIOCondition condition,
@ -249,7 +287,7 @@ zenity_tree_fill_entries (GtkTreeView *tree_view,
GtkWidget *scrolled_window; GtkWidget *scrolled_window;
GtkRequisition rectangle; GtkRequisition rectangle;
gtk_widget_size_request (GTK_WIDGET (tree_view), &rectangle); gtk_widget_get_preferred_size (GTK_WIDGET (tree_view), &rectangle, NULL);
scrolled_window = GTK_WIDGET (gtk_builder_get_object (builder, scrolled_window = GTK_WIDGET (gtk_builder_get_object (builder,
"zenity_tree_window")); "zenity_tree_window"));
gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); gtk_widget_set_size_request (scrolled_window, -1, rectangle.height);
@ -329,7 +367,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
return; return;
} }
if (tree_data->checkbox && tree_data->radiobox) { if (tree_data->checkbox + tree_data->radiobox + tree_data->imagebox > 1) {
g_printerr (_("You should use only one List dialog type.\n")); g_printerr (_("You should use only one List dialog type.\n"));
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
return; return;
@ -433,6 +471,12 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
column = gtk_tree_view_column_new_with_attributes (tmp->data, column = gtk_tree_view_column_new_with_attributes (tmp->data,
cell_renderer, cell_renderer,
"active", column_index, NULL); "active", column_index, NULL);
} else if (tree_data->imagebox) {
GtkCellRenderer *cell_renderer = gtk_cell_renderer_pixbuf_new ();
column = gtk_tree_view_column_new_with_attributes (tmp->data,
cell_renderer, NULL);
gtk_tree_view_column_set_cell_data_func (column, cell_renderer,
zenity_load_pixbuf, NULL, NULL);
} }
else { else {
if (tree_data->editable) { if (tree_data->editable) {
@ -657,10 +701,7 @@ zenity_tree_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path,
{ {
ZenityData *zen_data = data; ZenityData *zen_data = data;
GtkTreeSelection *selection; GtkTreeSelection *selection;
GtkTreeModel *model;
model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
gtk_tree_selection_selected_foreach (selection, gtk_tree_selection_selected_foreach (selection,
(GtkTreeSelectionForeachFunc) zenity_tree_dialog_get_selected, (GtkTreeSelectionForeachFunc) zenity_tree_dialog_get_selected,

View File

@ -121,6 +121,7 @@ typedef struct {
gboolean checkbox; gboolean checkbox;
gboolean radiobox; gboolean radiobox;
gboolean hide_header; gboolean hide_header;
gboolean imagebox;
gchar *separator; gchar *separator;
gboolean multi; gboolean multi;
gboolean editable; gboolean editable;