diff options
author | António Fernandes <antoniof@gnome.org> | 2022-12-30 21:46:10 +0000 |
---|---|---|
committer | António Fernandes <antoniof@gnome.org> | 2023-01-07 20:26:01 -0500 |
commit | 049bfe9792e2ec6d0c435a8baa89bb81d2769ed4 (patch) | |
tree | da0b33b827c7952858a321cd5980e7b1120529d7 | |
parent | c0653d5376bac27dc80720218b56ede05d277236 (diff) | |
download | nautilus-049bfe9792e2ec6d0c435a8baa89bb81d2769ed4.tar.gz |
grid-cell, name-cell: Don't add missing emblems
In version 42, we relied on GTK 3's support for GEmblemedIcon to draw
emblems. It would implicitly skip any emblem name for which there was
no available icon:
gtk/gtkicontheme.c:
```
emblem_info = gtk_icon_theme_lookup_by_gicon_for_scale (icon_theme, emblem, size / 2, scale, flags | GTK_ICON_LOOKUP_FORCE_SIZE);
if (emblem_info)
info->emblem_infos = g_slist_prepend (info->emblem_infos, emblem_info);
```
But GTK 4 dropped support for GEmblemedIcon, so now we use one GtkImage
for each emblem. But we don't skip name for which no icon is installed.
Instead, GTK displays the missing image icon.
Let's check whether the emblem icon is available in the current theme
before creating a GtkImage.
(cherry picked from commit c1da92ba5f321fb45aab824368a51d1947fb3a80)
-rw-r--r-- | src/nautilus-grid-cell.c | 10 | ||||
-rw-r--r-- | src/nautilus-name-cell.c | 10 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/nautilus-grid-cell.c b/src/nautilus-grid-cell.c index e2d1724fe..9da7b783d 100644 --- a/src/nautilus-grid-cell.c +++ b/src/nautilus-grid-cell.c @@ -101,6 +101,7 @@ update_emblems (NautilusGridCell *self) g_autoptr (NautilusViewItem) item = NULL; NautilusFile *file; GtkWidget *child; + GtkIconTheme *theme; g_autolist (GIcon) emblems = NULL; item = nautilus_view_cell_get_item (NAUTILUS_VIEW_CELL (self)); @@ -113,9 +114,18 @@ update_emblems (NautilusGridCell *self) gtk_box_remove (GTK_BOX (self->emblems_box), child); } + theme = gtk_icon_theme_get_for_display (gdk_display_get_default ()); emblems = nautilus_file_get_emblem_icons (file); for (GList *l = emblems; l != NULL; l = l->next) { + if (!gtk_icon_theme_has_gicon (theme, l->data)) + { + g_autofree gchar *icon_string = g_icon_to_string (l->data); + g_warning ("Failed to add emblem. “%s” not found in the icon theme", + icon_string); + continue; + } + gtk_box_append (GTK_BOX (self->emblems_box), gtk_image_new_from_gicon (l->data)); } diff --git a/src/nautilus-name-cell.c b/src/nautilus-name-cell.c index 23e57ed22..f7e0a27de 100644 --- a/src/nautilus-name-cell.c +++ b/src/nautilus-name-cell.c @@ -180,6 +180,7 @@ update_emblems (NautilusNameCell *self) g_autoptr (NautilusViewItem) item = NULL; NautilusFile *file; GtkWidget *child; + GtkIconTheme *theme; g_autolist (GIcon) emblems = NULL; item = nautilus_view_cell_get_item (NAUTILUS_VIEW_CELL (self)); @@ -192,9 +193,18 @@ update_emblems (NautilusNameCell *self) gtk_box_remove (GTK_BOX (self->emblems_box), child); } + theme = gtk_icon_theme_get_for_display (gdk_display_get_default ()); emblems = nautilus_file_get_emblem_icons (file); for (GList *l = emblems; l != NULL; l = l->next) { + if (!gtk_icon_theme_has_gicon (theme, l->data)) + { + g_autofree gchar *icon_string = g_icon_to_string (l->data); + g_warning ("Failed to add emblem. “%s” not found in the icon theme", + icon_string); + continue; + } + gtk_box_append (GTK_BOX (self->emblems_box), gtk_image_new_from_gicon (l->data)); } |