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-08 01:19:17 +0000 |
commit | c1da92ba5f321fb45aab824368a51d1947fb3a80 (patch) | |
tree | d8322ff535cd6efc1857a6ba1c913a712e246c8e | |
parent | beeb2da98f4213a1e225291ae6b6c379f85398d4 (diff) | |
download | nautilus-c1da92ba5f321fb45aab824368a51d1947fb3a80.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.
-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 d95985e9f..fb0276d6e 100644 --- a/src/nautilus-grid-cell.c +++ b/src/nautilus-grid-cell.c @@ -99,6 +99,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)); @@ -111,9 +112,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 8dccb7d1b..7c525869c 100644 --- a/src/nautilus-name-cell.c +++ b/src/nautilus-name-cell.c @@ -178,6 +178,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)); @@ -190,9 +191,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)); } |