[nautilus/wip/antoniof/reimagine-emblems: 2/2] general: Reimplement emblems as a box of icons
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/reimagine-emblems: 2/2] general: Reimplement emblems as a box of icons
- Date: Sat, 2 Jul 2022 12:37:12 +0000 (UTC)
commit 93ecb6dc6c5dfcdcac7591fb59fa02df66b50093
Author: António Fernandes <antoniof gnome org>
Date: Fri Jul 1 14:54:00 2022 +0100
general: Reimplement emblems as a box of icons
We used to display emblems overlaid on icons. This had a few problems:
* Emblemed icons were not cached.
* If the icon was too small, some emblems could be omitted.
* Emblems would partially obstruct the visibility of thumbnails.
So, we are reintroducing them as a mere box of icons:
* vertically next to the file icon/thumbnail in grid view;
* horizontally next to the filename in list view.
This avoids all the problems of the old implementation.
Closes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/2017
src/nautilus-file.c | 10 +++-------
src/nautilus-file.h | 2 ++
src/nautilus-grid-cell.c | 30 +++++++++++++++++++++++++++++
src/nautilus-name-cell.c | 29 ++++++++++++++++++++++++++++
src/resources/ui/nautilus-grid-cell.ui | 12 ++++++++++--
src/resources/ui/nautilus-name-cell.ui | 35 ++++++++++++++++++++++++----------
6 files changed, 99 insertions(+), 19 deletions(-)
---
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index 35538c96c..a173f63d9 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -3390,7 +3390,6 @@ compare_by_directory_name (NautilusFile *file_1,
file_2->details->directory_name_collation_key);
}
-#if 0 && EMBLEMS_NEEDS_GTK4_REIMPLEMENTATION
static GList *
prepend_automatic_keywords (NautilusFile *file,
GList *names)
@@ -3428,7 +3427,6 @@ prepend_automatic_keywords (NautilusFile *file,
return names;
}
-#endif
static int
compare_by_type (NautilusFile *file_1,
@@ -4850,7 +4848,6 @@ nautilus_is_video_file (NautilusFile *file)
return FALSE;
}
-#if 0 && EMBLEMS_NEEDS_GTK4_REIMPLEMENTATION
static GList *
sort_keyword_list_and_remove_duplicates (GList *keywords)
{
@@ -4958,7 +4955,7 @@ nautilus_file_get_keywords (NautilusFile *file)
metadata_strv = nautilus_file_get_metadata_list (file, NAUTILUS_METADATA_KEY_EMBLEMS);
/* Convert array to list */
- for (gint i = 0; metadata_strv[i] != NULL; i++)
+ for (gint i = 0; metadata_strv != NULL && metadata_strv[i] != NULL; i++)
{
metadata_keywords = g_list_prepend (metadata_keywords, metadata_strv[i]);
}
@@ -4978,10 +4975,10 @@ nautilus_file_get_keywords (NautilusFile *file)
* in canonical order.
* @file: NautilusFile representing the file in question.
*
- * Returns: A list of emblem names.
+ * Returns: (transfer full) (element-type GIcon): A list of emblem names.
*
**/
-static GList *
+GList *
nautilus_file_get_emblem_icons (NautilusFile *file)
{
GList *keywords, *l;
@@ -5023,7 +5020,6 @@ nautilus_file_get_emblem_icons (NautilusFile *file)
return icons;
}
-#endif
static void
prepend_icon_name (const char *name,
diff --git a/src/nautilus-file.h b/src/nautilus-file.h
index 4d8b3aecd..088d57d4b 100644
--- a/src/nautilus-file.h
+++ b/src/nautilus-file.h
@@ -479,6 +479,8 @@ GdkPaintable * nautilus_file_get_icon_paintable (Nautilu
int
scale,
NautilusFileIconFlags
flags);
+GList * nautilus_file_get_emblem_icons (NautilusFile
*file);
+
/* Whether the file should open inside a view */
gboolean nautilus_file_opens_in_view (NautilusFile
*file);
/* Thumbnailing handling */
diff --git a/src/nautilus-grid-cell.c b/src/nautilus-grid-cell.c
index 41fb3d0fc..383d85b03 100644
--- a/src/nautilus-grid-cell.c
+++ b/src/nautilus-grid-cell.c
@@ -16,6 +16,7 @@ struct _NautilusGridCell
GtkWidget *fixed_height_box;
GtkWidget *icon;
+ GtkWidget *emblems_box;
GtkWidget *label;
GtkWidget *first_caption;
GtkWidget *second_caption;
@@ -100,6 +101,33 @@ update_captions (NautilusGridCell *self)
}
}
+static void
+update_emblems (NautilusGridCell *self)
+{
+ NautilusViewItem *item;
+ NautilusFile *file;
+ GtkWidget *child;
+ g_autolist (GIcon) emblems = NULL;
+
+ item = nautilus_view_cell_get_item (NAUTILUS_VIEW_CELL (self));
+ g_return_if_fail (item != NULL);
+ file = nautilus_view_item_get_file (item);
+
+ /* Remove old emblems. */
+ while ((child = gtk_widget_get_first_child (self->emblems_box)) != NULL)
+ {
+ gtk_box_remove (GTK_BOX (self->emblems_box), child);
+ }
+
+ emblems = nautilus_file_get_emblem_icons (file);
+ for (GList *l = emblems; l != NULL; l = l->next)
+ {
+ gtk_box_append (GTK_BOX (self->emblems_box),
+ gtk_image_new_from_gicon (l->data));
+ }
+}
+
+
static void
on_file_changed (NautilusGridCell *self)
{
@@ -111,6 +139,7 @@ on_file_changed (NautilusGridCell *self)
file = nautilus_view_item_get_file (item);
update_icon (self);
+ update_emblems (self);
gtk_label_set_text (GTK_LABEL (self->label),
nautilus_file_get_display_name (file));
@@ -169,6 +198,7 @@ nautilus_grid_cell_class_init (NautilusGridCellClass *klass)
gtk_widget_class_bind_template_child (widget_class, NautilusGridCell, fixed_height_box);
gtk_widget_class_bind_template_child (widget_class, NautilusGridCell, icon);
+ gtk_widget_class_bind_template_child (widget_class, NautilusGridCell, emblems_box);
gtk_widget_class_bind_template_child (widget_class, NautilusGridCell, label);
gtk_widget_class_bind_template_child (widget_class, NautilusGridCell, first_caption);
gtk_widget_class_bind_template_child (widget_class, NautilusGridCell, second_caption);
diff --git a/src/nautilus-name-cell.c b/src/nautilus-name-cell.c
index 397693cdb..1a0720ea6 100644
--- a/src/nautilus-name-cell.c
+++ b/src/nautilus-name-cell.c
@@ -19,6 +19,7 @@ struct _NautilusNameCell
GtkWidget *fixed_height_box;
GtkWidget *icon;
GtkWidget *label;
+ GtkWidget *emblems_box;
GtkWidget *snippet;
GtkWidget *path;
@@ -190,11 +191,38 @@ update_icon (NautilusNameCell *self)
}
}
+static void
+update_emblems (NautilusNameCell *self)
+{
+ NautilusViewItem *item;
+ NautilusFile *file;
+ GtkWidget *child;
+ g_autolist (GIcon) emblems = NULL;
+
+ item = nautilus_view_cell_get_item (NAUTILUS_VIEW_CELL (self));
+ g_return_if_fail (item != NULL);
+ file = nautilus_view_item_get_file (item);
+
+ /* Remove old emblems. */
+ while ((child = gtk_widget_get_first_child (self->emblems_box)) != NULL)
+ {
+ gtk_box_remove (GTK_BOX (self->emblems_box), child);
+ }
+
+ emblems = nautilus_file_get_emblem_icons (file);
+ for (GList *l = emblems; l != NULL; l = l->next)
+ {
+ gtk_box_append (GTK_BOX (self->emblems_box),
+ gtk_image_new_from_gicon (l->data));
+ }
+}
+
static void
on_file_changed (NautilusNameCell *self)
{
update_icon (self);
update_labels (self);
+ update_emblems (self);
}
static void
@@ -289,6 +317,7 @@ nautilus_name_cell_class_init (NautilusNameCellClass *klass)
gtk_widget_class_bind_template_child (widget_class, NautilusNameCell, fixed_height_box);
gtk_widget_class_bind_template_child (widget_class, NautilusNameCell, icon);
gtk_widget_class_bind_template_child (widget_class, NautilusNameCell, label);
+ gtk_widget_class_bind_template_child (widget_class, NautilusNameCell, emblems_box);
gtk_widget_class_bind_template_child (widget_class, NautilusNameCell, snippet);
gtk_widget_class_bind_template_child (widget_class, NautilusNameCell, path);
}
diff --git a/src/resources/ui/nautilus-grid-cell.ui b/src/resources/ui/nautilus-grid-cell.ui
index 1b98d2201..63ec651c2 100644
--- a/src/resources/ui/nautilus-grid-cell.ui
+++ b/src/resources/ui/nautilus-grid-cell.ui
@@ -11,10 +11,9 @@
<property name="spacing">6</property>
<child>
<object class="GtkBox" id="fixed_height_box">
- <property name="orientation">vertical</property>
+ <property name="orientation">horizontal</property>
<property name="halign">center</property>
<property name="margin-start">18</property>
- <property name="margin-end">18</property>
<child>
<object class="AdwClamp">
<property name="maximum-size">0</property>
@@ -29,6 +28,15 @@
</property>
</object>
</child>
+ <child>
+ <object class="GtkBox" id="emblems_box">
+ <property name="orientation">vertical</property>
+ <property name="halign">end</property>
+ <property name="spacing">6</property>
+ <property name="margin-start">2</property>
+ <property name="width-request">16</property>
+ </object>
+ </child>
</object>
</child>
<child>
diff --git a/src/resources/ui/nautilus-name-cell.ui b/src/resources/ui/nautilus-name-cell.ui
index 366e6e370..4313b92d6 100644
--- a/src/resources/ui/nautilus-name-cell.ui
+++ b/src/resources/ui/nautilus-name-cell.ui
@@ -52,16 +52,31 @@
</object>
</child>
<child>
- <object class="GtkLabel" id="label">
- <property name="ellipsize">middle</property>
- <property name="lines">1</property>
- <property name="max-width-chars">-1</property>
- <property name="wrap">False</property>
- <property name="wrap-mode">word-char</property>
- <property name="halign">start</property>
- <attributes>
- <attribute name="insert-hyphens" value="false"></attribute>
- </attributes>
+ <object class="GtkBox">
+ <property name="orientation">horizontal</property>
+ <property name="halign">fill</property>
+ <property name="hexpand">True</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="label">
+ <property name="ellipsize">middle</property>
+ <property name="lines">1</property>
+ <property name="max-width-chars">-1</property>
+ <property name="wrap">False</property>
+ <property name="wrap-mode">word-char</property>
+ <property name="halign">start</property>
+ <attributes>
+ <attribute name="insert-hyphens" value="false"></attribute>
+ </attributes>
+ </object>
+ </child>
+ <child>
+ <object class="GtkBox" id="emblems_box">
+ <property name="orientation">horizontal</property>
+ <property name="halign">start</property>
+ <property name="spacing">6</property>
+ </object>
+ </child>
</object>
</child>
<child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]