diff options
author | Christopher Davis <christopherdavis@gnome.org> | 2022-07-18 17:24:02 -0400 |
---|---|---|
committer | António Fernandes <antoniof@gnome.org> | 2022-07-30 23:46:09 +0100 |
commit | d10d61c0d3fa3aeff142e8229e7bbc3f507aaaa3 (patch) | |
tree | d8578adfb5100050961a6ba2af9a4ad08d60d015 | |
parent | 1bce7457c24a4c39e8be440d5140b7a42a5280bf (diff) | |
download | nautilus-d10d61c0d3fa3aeff142e8229e7bbc3f507aaaa3.tar.gz |
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.
Use an empty string as a fallback value while the slot has
no content view. This avoids trying to set NULL as icon-name.
-rw-r--r-- | src/nautilus-toolbar.c | 32 | ||||
-rw-r--r-- | src/nautilus-view.c | 20 | ||||
-rw-r--r-- | src/nautilus-view.h | 2 | ||||
-rw-r--r-- | src/nautilus-window-slot.c | 26 | ||||
-rw-r--r-- | src/nautilus-window-slot.h | 2 | ||||
-rw-r--r-- | src/resources/ui/nautilus-toolbar.ui | 5 |
6 files changed, 26 insertions, 61 deletions
diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c index 6ea4c7cdc..04efd9df7 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); @@ -1306,26 +1304,6 @@ disconnect_toolbar_menu_sections_change_handler (NautilusToolbar *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, GValue *to_value, @@ -1363,13 +1341,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 40fd5260f..976429e27 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, @@ -819,9 +819,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; @@ -2863,7 +2863,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]); @@ -3037,11 +3037,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] = @@ -3280,15 +3280,15 @@ 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); if (self->content_view == NULL) { - return NULL; + return ""; } current_view_id = nautilus_view_get_view_id (NAUTILUS_VIEW (self->content_view)); @@ -3296,19 +3296,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"> |