[nautilus/wip/cdavis/toolbar-refactor: 35/41] general: Refactor view icon from a GIcon to an icon name
- From: Christopher Davis <christopherdavis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/cdavis/toolbar-refactor: 35/41] general: Refactor view icon from a GIcon to an icon name
- Date: Sat, 23 Jul 2022 04:39:40 +0000 (UTC)
commit 62b6c4ab665bdee1eb2652b6bb5b9a7a8f5c4357
Author: Christopher Davis <christopherdavis gnome org>
Date: Mon Jul 18 17:24:02 2022 -0400
general: Refactor view icon from a GIcon to an icon name
Most APIs these days receive icons in the form of `icon-name`,
and we need to manually set up widgets like `GtkImage` if
we must use a GIcon. In the case of the view icon, we use
it for a button, which takes `icon-name`. So, this commit
reworks the API to use an icon name instead of GIcon.
src/nautilus-toolbar.c | 32 +++-----------------------------
src/nautilus-view.c | 20 ++++++++------------
src/nautilus-view.h | 2 +-
src/nautilus-window-slot.c | 24 ++++++++++++------------
src/nautilus-window-slot.h | 2 +-
src/resources/ui/nautilus-toolbar.ui | 5 -----
6 files changed, 25 insertions(+), 60 deletions(-)
---
diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c
index 0437f25a6..b893e3909 100644
--- a/src/nautilus-toolbar.c
+++ b/src/nautilus-toolbar.c
@@ -72,7 +72,6 @@ struct _NautilusToolbar
GtkWidget *operations_icon;
GtkWidget *view_split_button;
- GtkWidget *view_toggle_icon;
GMenuModel *view_menu;
GtkWidget *app_button;
@@ -1180,7 +1179,6 @@ nautilus_toolbar_class_init (NautilusToolbarClass *klass)
gtk_widget_class_bind_template_child (widget_class, NautilusToolbar, operations_revealer);
gtk_widget_class_bind_template_child (widget_class, NautilusToolbar, view_menu);
gtk_widget_class_bind_template_child (widget_class, NautilusToolbar, view_split_button);
- gtk_widget_class_bind_template_child (widget_class, NautilusToolbar, view_toggle_icon);
gtk_widget_class_bind_template_child (widget_class, NautilusToolbar, app_button);
gtk_widget_class_bind_template_child (widget_class, NautilusToolbar, undo_redo_section);
gtk_widget_class_bind_template_child (widget_class, NautilusToolbar, back_button);
@@ -1303,26 +1301,6 @@ disconnect_toolbar_menu_sections_change_handler (NautilusToolbar *self)
self);
}
-static gboolean
-nautilus_toolbar_view_toggle_icon_transform_to (GBinding *binding,
- const GValue *from_value,
- GValue *to_value,
- gpointer user_data)
-{
- GIcon *icon;
-
- icon = g_value_get_object (from_value);
-
- /* As per design decision, we let the previous used icon if no
- * view menu is available */
- if (icon)
- {
- g_value_set_object (to_value, icon);
- }
-
- return TRUE;
-}
-
static gboolean
nautilus_toolbar_view_toggle_tooltip_transform_to (GBinding *binding,
const GValue *from_value,
@@ -1361,13 +1339,9 @@ nautilus_toolbar_set_window_slot_real (NautilusToolbar *self,
on_window_slot_destroyed,
self);
- self->icon_binding = g_object_bind_property_full (self->window_slot, "icon",
- self->view_toggle_icon, "gicon",
- G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE,
- (GBindingTransformFunc)
nautilus_toolbar_view_toggle_icon_transform_to,
- NULL,
- self,
- NULL);
+ self->icon_binding = g_object_bind_property (self->window_slot, "icon-name",
+ self->view_split_button, "icon-name",
+ G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
/* HACK. We shouldn't be poking at internal children. But alas, no other option. */
toggle_button = gtk_widget_get_parent (adw_split_button_get_child (ADW_SPLIT_BUTTON
(self->view_split_button)));
diff --git a/src/nautilus-view.c b/src/nautilus-view.c
index 3efeeca05..2463ba632 100644
--- a/src/nautilus-view.c
+++ b/src/nautilus-view.c
@@ -110,27 +110,23 @@ nautilus_view_default_init (NautilusViewInterface *iface)
}
/**
- * nautilus_view_get_icon:
+ * nautilus_view_get_icon_name:
* @view: a #NautilusView
*
- * Retrieves the #GIcon that represents @view.
+ * Retrieves the icon name that represents @view.
*
- * Returns: (transfer full): a #GIcon
+ * Returns: (transfer none): an icon name
*/
-GIcon *
-nautilus_view_get_icon (guint view_id)
+const gchar *
+nautilus_view_get_icon_name (guint view_id)
{
if (view_id == NAUTILUS_VIEW_GRID_ID)
{
- return g_themed_icon_new ("view-grid-symbolic");
+ return "view-grid-symbolic";
}
- else if (view_id == NAUTILUS_VIEW_LIST_ID)
- {
- return g_themed_icon_new ("view-list-symbolic");
- }
- else if (view_id == NAUTILUS_VIEW_OTHER_LOCATIONS_ID)
+ else if (view_id == NAUTILUS_VIEW_LIST_ID || view_id == NAUTILUS_VIEW_OTHER_LOCATIONS_ID)
{
- return g_themed_icon_new_with_default_fallbacks ("view-list-symbolic");
+ return "view-list-symbolic";
}
else
{
diff --git a/src/nautilus-view.h b/src/nautilus-view.h
index 8a17b35de..9a8911e28 100644
--- a/src/nautilus-view.h
+++ b/src/nautilus-view.h
@@ -84,7 +84,7 @@ struct _NautilusViewInterface
gboolean (*is_searching) (NautilusView *view);
};
-GIcon * nautilus_view_get_icon (guint view_id);
+const gchar * nautilus_view_get_icon_name (guint view_id);
const gchar * nautilus_view_get_tooltip (guint view_id);
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index 3b0a83baf..cb4e45455 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -53,7 +53,7 @@ enum
{
PROP_ACTIVE = 1,
PROP_WINDOW,
- PROP_ICON,
+ PROP_ICON_NAME,
PROP_TOOLBAR_MENU_SECTIONS,
PROP_EXTENSIONS_BACKGROUND_MENU,
PROP_TEMPLATES_MENU,
@@ -817,9 +817,9 @@ nautilus_window_slot_get_property (GObject *object,
}
break;
- case PROP_ICON:
+ case PROP_ICON_NAME:
{
- g_value_take_object (value, nautilus_window_slot_get_icon (self));
+ g_value_set_static_string (value, nautilus_window_slot_get_icon_name (self));
}
break;
@@ -2848,7 +2848,7 @@ nautilus_window_slot_switch_new_content_view (NautilusWindowSlot *self)
self->templates_menu_binding = g_object_bind_property (self->content_view, "templates-menu",
self, "templates-menu",
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ICON]);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ICON_NAME]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TOOLBAR_MENU_SECTIONS]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_EXTENSIONS_BACKGROUND_MENU]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TEMPLATES_MENU]);
@@ -3022,11 +3022,11 @@ nautilus_window_slot_class_init (NautilusWindowSlotClass *klass)
NAUTILUS_TYPE_WINDOW,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
- properties[PROP_ICON] =
- g_param_spec_object ("icon",
+ properties[PROP_ICON_NAME] =
+ g_param_spec_string ("icon-name",
"Icon that represents the slot",
"The icon that represents the slot",
- G_TYPE_ICON,
+ NULL,
G_PARAM_READABLE);
properties[PROP_TOOLBAR_MENU_SECTIONS] =
@@ -3268,8 +3268,8 @@ nautilus_window_slot_new (NautilusWindow *window)
NULL);
}
-GIcon *
-nautilus_window_slot_get_icon (NautilusWindowSlot *self)
+const gchar *
+nautilus_window_slot_get_icon_name (NautilusWindowSlot *self)
{
guint current_view_id;
g_return_val_if_fail (NAUTILUS_IS_WINDOW_SLOT (self), NULL);
@@ -3284,19 +3284,19 @@ nautilus_window_slot_get_icon (NautilusWindowSlot *self)
{
case NAUTILUS_VIEW_LIST_ID:
{
- return nautilus_view_get_icon (NAUTILUS_VIEW_GRID_ID);
+ return nautilus_view_get_icon_name (NAUTILUS_VIEW_GRID_ID);
}
break;
case NAUTILUS_VIEW_GRID_ID:
{
- return nautilus_view_get_icon (NAUTILUS_VIEW_LIST_ID);
+ return nautilus_view_get_icon_name (NAUTILUS_VIEW_LIST_ID);
}
break;
case NAUTILUS_VIEW_OTHER_LOCATIONS_ID:
{
- return nautilus_view_get_icon (NAUTILUS_VIEW_OTHER_LOCATIONS_ID);
+ return nautilus_view_get_icon_name (NAUTILUS_VIEW_OTHER_LOCATIONS_ID);
}
break;
diff --git a/src/nautilus-window-slot.h b/src/nautilus-window-slot.h
index 3746e8fcd..364c63728 100644
--- a/src/nautilus-window-slot.h
+++ b/src/nautilus-window-slot.h
@@ -80,7 +80,7 @@ gboolean nautilus_window_slot_handle_event (NautilusWindowSlot *slo
void nautilus_window_slot_queue_reload (NautilusWindowSlot *slot);
-GIcon* nautilus_window_slot_get_icon (NautilusWindowSlot *slot);
+const gchar* nautilus_window_slot_get_icon_name (NautilusWindowSlot *slot);
const gchar* nautilus_window_slot_get_tooltip (NautilusWindowSlot *slot);
diff --git a/src/resources/ui/nautilus-toolbar.ui b/src/resources/ui/nautilus-toolbar.ui
index 2ad5d49b1..b482f7da3 100644
--- a/src/resources/ui/nautilus-toolbar.ui
+++ b/src/resources/ui/nautilus-toolbar.ui
@@ -232,11 +232,6 @@
<property name="tooltip_text" translatable="yes" comments="Translators: This is a noun, meaning
the options pertaining to the view.">View options</property>
<property name="action_name">slot.files-view-mode-toggle</property>
<property name="menu-model">view_menu</property>
- <child>
- <object class="GtkImage" id="view_toggle_icon">
- <property name="icon_size">1</property>
- </object>
- </child>
</object>
</child>
<child type="end">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]