[nautilus/wip/antoniof/new-list-view-continuation: 27/27] toolbar-view-menu: Add icon size options to view menu
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/new-list-view-continuation: 27/27] toolbar-view-menu: Add icon size options to view menu
- Date: Fri, 10 Jun 2022 21:50:58 +0000 (UTC)
commit b5131cb4b8407035bbf7d526095e73ee065d5a87
Author: António Fernandes <antoniof gnome org>
Date: Thu Jun 2 17:29:39 2022 +0100
toolbar-view-menu: Add icon size options to view menu
And remove control from primary menu.
Closes https://gitlab.gnome.org/GNOME/nautilus/-/issues/2222
src/nautilus-files-view.c | 8 ++++++
src/nautilus-grid-view.c | 2 +-
src/nautilus-list-view.c | 2 +-
src/nautilus-toolbar-menu-sections.h | 1 +
src/nautilus-toolbar.c | 15 ++++++----
src/resources/ui/nautilus-toolbar-view-menu.ui | 31 ++++++++++++++++++++
src/resources/ui/nautilus-toolbar.ui | 39 ++++++--------------------
7 files changed, 61 insertions(+), 37 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 26263bbe0..bd005833f 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -3319,6 +3319,7 @@ nautilus_files_view_finalize (GObject *object)
g_clear_object (&priv->view_action_group);
g_clear_object (&priv->background_menu_model);
g_clear_object (&priv->selection_menu_model);
+ g_clear_object (&priv->toolbar_menu_sections->icon_size_section);
g_clear_object (&priv->toolbar_menu_sections->sort_section);
g_clear_object (&priv->extensions_background_menu);
g_clear_object (&priv->templates_menu);
@@ -8061,12 +8062,18 @@ nautilus_files_view_reset_view_menu (NautilusFilesView *view)
{
NautilusFilesViewPrivate *priv = nautilus_files_view_get_instance_private (view);
NautilusFile *file;
+ GMenuModel *icon_size_section = priv->toolbar_menu_sections->icon_size_section;
GMenuModel *sort_section = priv->toolbar_menu_sections->sort_section;
const gchar *action;
gint i;
file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (view));
+ /* Extra large icons option is available for grid view only. */
+ action = NAUTILUS_IS_GRID_VIEW (view) ? "view.zoom-to-level" : "doesnt-exist";
+ i = nautilus_g_menu_model_find_by_string (icon_size_section, "nautilus-menu-item", "extra-large");
+ nautilus_g_menu_replace_string_in_item (G_MENU (icon_size_section), i, "action", action);
+
/* When not in the special location, set an inexistant action to hide the
* menu item. This works under the assumptiont that the menu item has its
* "hidden-when" attribute set to "action-disabled", and that an inexistant
@@ -9416,6 +9423,7 @@ nautilus_files_view_init (NautilusFilesView *view)
/* Toolbar menu */
builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-toolbar-view-menu.ui");
priv->toolbar_menu_sections = g_new0 (NautilusToolbarMenuSections, 1);
+ priv->toolbar_menu_sections->icon_size_section = G_MENU_MODEL (g_object_ref (gtk_builder_get_object
(builder, "icon_size_section")));
priv->toolbar_menu_sections->sort_section = G_MENU_MODEL (g_object_ref (gtk_builder_get_object (builder,
"sort_section")));
g_signal_connect (view,
diff --git a/src/nautilus-grid-view.c b/src/nautilus-grid-view.c
index 6c44bcc90..878fd8788 100644
--- a/src/nautilus-grid-view.c
+++ b/src/nautilus-grid-view.c
@@ -414,7 +414,7 @@ create_view_ui (NautilusGridView *self)
const GActionEntry view_icon_actions[] =
{
{ "sort", NULL, "(sb)", "('invalid',false)", action_sort_order_changed },
- { "zoom-to-level", NULL, NULL, "100", action_zoom_to_level }
+ { "zoom-to-level", NULL, "i", "100", action_zoom_to_level }
};
static void
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 4506422d3..dbbeb3e34 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -699,7 +699,7 @@ const GActionEntry list_view_entries[] =
{
{ "visible-columns", action_visible_columns },
{ "sort", NULL, "(sb)", "('invalid',false)", action_sort_order_changed },
- { "zoom-to-level", NULL, NULL, "1", action_zoom_to_level }
+ { "zoom-to-level", NULL, "i", "1", action_zoom_to_level }
};
static void
diff --git a/src/nautilus-toolbar-menu-sections.h b/src/nautilus-toolbar-menu-sections.h
index 8f5a98667..fc907226c 100644
--- a/src/nautilus-toolbar-menu-sections.h
+++ b/src/nautilus-toolbar-menu-sections.h
@@ -25,6 +25,7 @@ typedef struct _NautilusToolbarMenuSections NautilusToolbarMenuSections;
struct _NautilusToolbarMenuSections {
GMenuModel *sort_section;
+ GMenuModel *icon_size_section;
};
G_END_DECLS
diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c
index 57fe64dc3..1e9d44aae 100644
--- a/src/nautilus-toolbar.c
+++ b/src/nautilus-toolbar.c
@@ -1219,7 +1219,7 @@ on_slot_toolbar_menu_sections_changed (NautilusToolbar *self,
NautilusWindowSlot *slot)
{
NautilusToolbarMenuSections *new_sections;
- g_autoptr (GMenuItem) zoom_item = NULL;
+ g_autoptr (GMenuItem) icon_size_item = NULL;
g_autoptr (GMenuItem) sort_item = NULL;
new_sections = nautilus_window_slot_get_toolbar_menu_sections (slot);
@@ -1230,13 +1230,18 @@ on_slot_toolbar_menu_sections_changed (NautilusToolbar *self,
return;
}
- /* Let's assume that sort section is the first item
- * in view_menu, as per nautilus-toolbar.ui. */
+ /* Let's assume that icon size and sort sections are the first and second
+ * items in view_menu, as per nautilus-toolbar.ui. */
- sort_item = g_menu_item_new_from_model (self->view_menu, 0);
+ icon_size_item = g_menu_item_new_from_model (self->view_menu, 0);
g_menu_remove (G_MENU (self->view_menu), 0);
+ g_menu_item_set_section (icon_size_item, new_sections->icon_size_section);
+ g_menu_insert_item (G_MENU (self->view_menu), 0, icon_size_item);
+
+ sort_item = g_menu_item_new_from_model (self->view_menu, 1);
+ g_menu_remove (G_MENU (self->view_menu), 1);
g_menu_item_set_section (sort_item, new_sections->sort_section);
- g_menu_insert_item (G_MENU (self->view_menu), 0, sort_item);
+ g_menu_insert_item (G_MENU (self->view_menu), 1, sort_item);
}
diff --git a/src/resources/ui/nautilus-toolbar-view-menu.ui b/src/resources/ui/nautilus-toolbar-view-menu.ui
index 03c6e8e8d..40b30e9fb 100644
--- a/src/resources/ui/nautilus-toolbar-view-menu.ui
+++ b/src/resources/ui/nautilus-toolbar-view-menu.ui
@@ -1,6 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
+ <menu id="icon_size_section">
+ <item>
+ <attribute name="action">view.zoom-to-level</attribute>
+ <attribute name="target" type="i">3</attribute>
+ <attribute name="label" translatable="yes" context="View menu"
+ comments="An icon size to choose for items in the view">Extra Large</attribute>
+ <attribute name="hidden-when">action-disabled</attribute>
+ <attribute name="nautilus-menu-item">extra-large</attribute>
+ </item>
+ <item>
+ <attribute name="action">view.zoom-to-level</attribute>
+ <attribute name="target" type="i">2</attribute>
+ <attribute name="label" translatable="yes" context="View menu"
+ comments="An icon size to choose for items in the view">Large</attribute>
+ <attribute name="hidden-when">action-disabled</attribute>
+ </item>
+ <item>
+ <attribute name="action">view.zoom-to-level</attribute>
+ <attribute name="target" type="i">1</attribute>
+ <attribute name="label" translatable="yes" context="View menu"
+ comments="An icon size to choose for items in the view">Medium</attribute>
+ <attribute name="hidden-when">action-disabled</attribute>
+ </item>
+ <item>
+ <attribute name="action">view.zoom-to-level</attribute>
+ <attribute name="target" type="i">0</attribute>
+ <attribute name="label" translatable="yes" context="View menu"
+ comments="An icon size to choose for items in the view">Small</attribute>
+ <attribute name="hidden-when">action-disabled</attribute>
+ </item>
+ </menu>
<menu id="sort_section">
<item>
<attribute name="action">view.sort</attribute>
diff --git a/src/resources/ui/nautilus-toolbar.ui b/src/resources/ui/nautilus-toolbar.ui
index 7103e4423..7344b6c1b 100644
--- a/src/resources/ui/nautilus-toolbar.ui
+++ b/src/resources/ui/nautilus-toolbar.ui
@@ -4,6 +4,15 @@
<object class="GtkPopoverMenu" id="back_menu"/>
<object class="GtkPopoverMenu" id="forward_menu"/>
<menu id="view_menu">
+ <section>
+ <attribute name="label" translatable="yes" context="menu item" comments="Translators: a menu item in a
group of icon size options in a toolbar menu, with options such as "Small" or
"Large".">Icon Size</attribute>
+ <!--
+ Icon size section.
+
+ The toolbar code assumes this is the first item of this menu model.
+ Its contents is provided by the view.
+ -->
+ </section>
<section>
<attribute name="label" translatable="yes" context="menu item" comments="Translators: a menu item in a
group of sorting options in a toolbar menu, with criterions such as "A-Z" or "Last
Modified".">Sort</attribute>
<!--
@@ -34,16 +43,6 @@
<attribute name="verb-icon">tab-new-symbolic</attribute>
</item>
</section>
- <section>
- <attribute name="label" translatable="yes">Icon size</attribute>
- <attribute name="display-hint">inline-buttons</attribute>
- <item>
- <attribute name="custom">zoom-out</attribute>
- </item>
- <item>
- <attribute name="custom">zoom-in</attribute>
- </item>
- </section>
<section id="undo_redo_section">
<!-- Note: This section is often recreated by undo_manager_changed() to
change the labels of the actions. If you change anything here,
@@ -225,26 +224,6 @@
<property name="popover">
<object class="GtkPopoverMenu">
<property name="menu-model">app_menu</property>
- <child type="zoom-out">
- <object class="GtkButton">
- <property name="icon-name">zoom-out-symbolic</property>
- <property name="action-name">view.zoom-out</property>
- <property name="tooltip-text">Zoom out</property>
- <style>
- <class name="flat"/>
- </style>
- </object>
- </child>
- <child type="zoom-in">
- <object class="GtkButton">
- <property name="icon-name">zoom-in-symbolic</property>
- <property name="action-name">view.zoom-in</property>
- <property name="tooltip-text">Zoom in</property>
- <style>
- <class name="flat"/>
- </style>
- </object>
- </child>
</object>
</property>
<child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]