Hi all, I am coming with a new patch for displaying path-based icons in contextual menus and in the toolbar.
As seen with Alex last week, it doesn't modify the nautilus_icon_info_lookup_from_name() function, but introduces a new and very similar nautilus_icon_info_lookup_from_path(). Then, this new function is called from - [fm-directory-view.c] add_extension_action_for_files() - [nautilus-ui-utilities.c] nautilus_action_from_menu_item() - [nautilus-ui-utilities.c] nautilus_toolbar_action_from_menu_item(). Patch is attached to this mail, and is also available online at http://gist.github.com/242181. Hope that these will be better than the previous ;) Regards Pierre
diff --git a/libnautilus-private/nautilus-icon-info.c b/libnautilus-private/nautilus-icon-info.c index f1ddd7c..467378a 100644 --- a/libnautilus-private/nautilus-icon-info.c +++ b/libnautilus-private/nautilus-icon-info.c @@ -435,13 +435,28 @@ nautilus_icon_info_lookup_from_name (const char *name, { GIcon *icon; NautilusIconInfo *info; - + icon = g_themed_icon_new (name); info = nautilus_icon_info_lookup (icon, size); g_object_unref (icon); return info; } +NautilusIconInfo * +nautilus_icon_info_lookup_from_path (const char *path, + int size) +{ + GFile *icon_file; + GIcon *icon; + NautilusIconInfo *info; + + icon_file = g_file_new_for_path (path); + icon = g_file_icon_new (icon_file); + info = nautilus_icon_info_lookup (icon, size); + g_object_unref (icon); + g_object_unref (icon_file); + return info; +} GdkPixbuf * nautilus_icon_info_get_pixbuf_nodefault (NautilusIconInfo *icon) diff --git a/libnautilus-private/nautilus-icon-info.h b/libnautilus-private/nautilus-icon-info.h index d6f5b2f..5ef6cd2 100644 --- a/libnautilus-private/nautilus-icon-info.h +++ b/libnautilus-private/nautilus-icon-info.h @@ -58,6 +58,8 @@ NautilusIconInfo * nautilus_icon_info_lookup (GIcon int size); NautilusIconInfo * nautilus_icon_info_lookup_from_name (const char *name, int size); +NautilusIconInfo * nautilus_icon_info_lookup_from_path (const char *path, + int size); gboolean nautilus_icon_info_is_fallback (NautilusIconInfo *icon); GdkPixbuf * nautilus_icon_info_get_pixbuf (NautilusIconInfo *icon); GdkPixbuf * nautilus_icon_info_get_pixbuf_nodefault (NautilusIconInfo *icon); diff --git a/src/file-manager/fm-directory-view.c b/src/file-manager/fm-directory-view.c index abecc08..7ef7e60 100644 --- a/src/file-manager/fm-directory-view.c +++ b/src/file-manager/fm-directory-view.c @@ -4653,11 +4653,15 @@ get_menu_icon (const char *icon_name) int size; size = nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU); - - info = nautilus_icon_info_lookup_from_name (icon_name, size); + + if (g_path_is_absolute (icon_name)) { + info = nautilus_icon_info_lookup_from_path (icon_name, size); + } else { + info = nautilus_icon_info_lookup_from_name (icon_name, size); + } pixbuf = nautilus_icon_info_get_pixbuf_nodefault_at_size (info, size); g_object_unref (info); - + return pixbuf; } @@ -4700,8 +4704,6 @@ add_extension_action_for_files (FMDirectoryView *view, tip, icon); - /* TODO: This should really use themed icons, but that - doesn't work here yet */ if (icon != NULL) { pixbuf = get_menu_icon (icon); if (pixbuf != NULL) { diff --git a/libnautilus-private/nautilus-ui-utilities.c b/libnautilus-private/nautilus-ui-utilities.c index 5b7bccb..eb6cb98 100644 --- a/libnautilus-private/nautilus-ui-utilities.c +++ b/libnautilus-private/nautilus-ui-utilities.c @@ -128,6 +128,23 @@ extension_action_sensitive_callback (NautilusMenuItem *item, gtk_action_set_sensitive (GTK_ACTION (user_data), value); } +static GdkPixbuf * +get_action_icon (const char *icon_name, int size) +{ + NautilusIconInfo *info; + GdkPixbuf *pixbuf; + + if (g_path_is_absolute (icon_name)) { + info = nautilus_icon_info_lookup_from_path (icon_name, size); + } else { + info = nautilus_icon_info_lookup_from_name (icon_name, size); + } + pixbuf = nautilus_icon_info_get_pixbuf_nodefault_at_size (info, size); + g_object_unref (info); + + return pixbuf; +} + GtkAction * nautilus_action_from_menu_item (NautilusMenuItem *item) { @@ -135,47 +152,42 @@ nautilus_action_from_menu_item (NautilusMenuItem *item) gboolean sensitive, priority; GtkAction *action; GdkPixbuf *pixbuf; - NautilusIconInfo *info; - - g_object_get (G_OBJECT (item), - "name", &name, "label", &label, + + g_object_get (G_OBJECT (item), + "name", &name, "label", &label, "tip", &tip, "icon", &icon_name, "sensitive", &sensitive, "priority", &priority, NULL); - + action = gtk_action_new (name, label, tip, icon_name); - - if (icon_name != NULL) { - info = nautilus_icon_info_lookup_from_name (icon_name, - nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU)); - pixbuf = nautilus_icon_info_get_pixbuf_nodefault_at_size (info, - nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU)); + if (icon_name != NULL) { + pixbuf = get_action_icon (icon_name, + nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU)); if (pixbuf != NULL) { g_object_set_data_full (G_OBJECT (action), "menu-icon", pixbuf, g_object_unref); } - g_object_unref (info); } - + gtk_action_set_sensitive (action, sensitive); g_object_set (action, "is-important", priority, NULL); - + g_signal_connect_data (action, "activate", G_CALLBACK (extension_action_callback), - g_object_ref (item), + g_object_ref (item), (GClosureNotify)g_object_unref, 0); - + g_free (name); g_free (label); g_free (tip); g_free (icon_name); - + return action; } @@ -186,40 +198,35 @@ nautilus_toolbar_action_from_menu_item (NautilusMenuItem *item) gboolean sensitive, priority; GtkAction *action; GdkPixbuf *pixbuf; - NautilusIconInfo *info; - int icon_size; - - g_object_get (G_OBJECT (item), - "name", &name, "label", &label, + + g_object_get (G_OBJECT (item), + "name", &name, "label", &label, "tip", &tip, "icon", &icon_name, "sensitive", &sensitive, "priority", &priority, NULL); - + action = gtk_action_new (name, label, tip, icon_name); - - if (icon_name != NULL) { - icon_size = nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_LARGE_TOOLBAR); - info = nautilus_icon_info_lookup_from_name (icon_name, icon_size); - pixbuf = nautilus_icon_info_get_pixbuf_nodefault_at_size (info, icon_size); + if (icon_name != NULL) { + pixbuf = get_action_icon (icon_name, + nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_LARGE_TOOLBAR)); if (pixbuf != NULL) { g_object_set_data_full (G_OBJECT (action), "toolbar-icon", pixbuf, g_object_unref); } - g_object_unref (info); } - + gtk_action_set_sensitive (action, sensitive); g_object_set (action, "is-important", priority, NULL); - + g_signal_connect_data (action, "activate", G_CALLBACK (extension_action_callback), - g_object_ref (item), + g_object_ref (item), (GClosureNotify)g_object_unref, 0); g_signal_connect_object (item, "notify::sensitive",
-- nautilus-list mailing list nautilus-list@gnome.org http://mail.gnome.org/mailman/listinfo/nautilus-list