[nautilus/wip/antoniof/menu-reorganization: 28/29] files-view: Reorganize context menus




commit 8354ab72574200fc8398c6469998a9cdd6a4fa1b
Author: António Fernandes <antoniof gnome org>
Date:   Tue Aug 2 20:21:46 2022 +0100

    files-view: Reorganize context menus
    
    Resolves https://gitlab.gnome.org/GNOME/nautilus/-/issues/2207

 src/nautilus-files-view.c                          |  34 +++-
 .../ui/nautilus-files-view-context-menus.ui        | 205 +++++++++------------
 2 files changed, 115 insertions(+), 124 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index dde7e746f..a32b63ea1 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -8044,17 +8044,39 @@ update_selection_menu (NautilusFilesView *view,
         item_label = g_strdup (_("Open"));
     }
 
-    menu_item = g_menu_item_new (item_label, "view.open-with-default-application");
-    if (app_icon != NULL)
+    /* The action already exists in the submenu if item opens in view */
+    if (!item_opens_in_view)
     {
-        g_menu_item_set_icon (menu_item, app_icon);
+        menu_item = g_menu_item_new (item_label, "view.open-with-default-application");
+        if (app_icon != NULL)
+        {
+            g_menu_item_set_icon (menu_item, app_icon);
+        }
+
+        object = gtk_builder_get_object (builder, "open-with-application-section");
+        g_menu_prepend_item (G_MENU (object), menu_item);
+
+        g_object_unref (menu_item);
     }
+    else
+    {
+        object = gtk_builder_get_object (builder, "open-with-application-section");
+        i = nautilus_g_menu_model_find_by_string (G_MENU_MODEL (object),
+                                                  "nautilus-menu-item",
+                                                  "open_with_in_main_menu");
 
-    object = gtk_builder_get_object (builder, "open-with-application-section");
-    g_menu_prepend_item (G_MENU (object), menu_item);
+        g_menu_remove (G_MENU (object), i);
+    }
+
+    /* The "Open" submenu should be hidden if the item doesn't open in the view. */
+    i = nautilus_g_menu_model_find_by_string (G_MENU_MODEL (priv->selection_menu_model),
+                                              "nautilus-menu-item",
+                                              "open_in_view_submenu");
+    nautilus_g_menu_replace_string_in_item (priv->selection_menu_model, i,
+                                            "hidden-when",
+                                            (!item_opens_in_view) ? "action-missing" : NULL);
 
     g_free (item_label);
-    g_object_unref (menu_item);
 
     /* Drives */
     for (l = selection; l != NULL && (show_mount || show_unmount
diff --git a/src/resources/ui/nautilus-files-view-context-menus.ui 
b/src/resources/ui/nautilus-files-view-context-menus.ui
index ca011272e..24d06ad30 100644
--- a/src/resources/ui/nautilus-files-view-context-menus.ui
+++ b/src/resources/ui/nautilus-files-view-context-menus.ui
@@ -3,7 +3,7 @@
   <requires lib="gtk" version="4.0"/>
   <menu id="background-menu">
     <item>
-      <attribute name="label" translatable="yes">New _Folder</attribute>
+      <attribute name="label" translatable="yes">New _Folder…</attribute>
       <attribute name="action">view.new-folder</attribute>
     </item>
     <item>
@@ -11,42 +11,16 @@
       <attribute name="nautilus-menu-item">templates-submenu</attribute>
       <link name="submenu" id="templates-submenu"/>
     </item>
-    <item>
-      <attribute name="label" translatable="yes">Add to _Bookmarks</attribute>
-      <attribute name="action">win.bookmark-current-location</attribute>
-    </item>
-    <item>
-      <attribute name="label" translatable="yes">R_eload</attribute>
-      <attribute name="action">win.reload</attribute>
-      <attribute name="hidden-when">action-disabled</attribute>
-    </item>
-    <item>
-      <attribute name="label" translatable="yes">St_op</attribute>
-      <attribute name="action">win.stop</attribute>
-      <attribute name="hidden-when">action-disabled</attribute>
-    </item>
     <section>
       <item>
-        <attribute name="label" translatable="yes">_Open With Other Application</attribute>
-        <attribute name="action">view.open-current-directory-with-other-application</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">_Copy Location</attribute>
-        <attribute name="action">view.copy-current-location</attribute>
+        <attribute name="label" translatable="yes">_Paste</attribute>
+        <attribute name="action">view.paste</attribute>
       </item>
-    </section>
-    <section>
       <item>
-        <attribute name="label" translatable="yes">Create _Link</attribute>
+        <attribute name="label" translatable="yes">Paste as _Link</attribute>
         <attribute name="action">view.create-link</attribute>
         <attribute name="hidden-when">action-disabled</attribute>
       </item>
-    </section>
-    <section>
-      <item>
-        <attribute name="label" translatable="yes">_Paste</attribute>
-        <attribute name="action">view.paste</attribute>
-      </item>
       <item>
         <attribute name="label" translatable="yes">Select _All</attribute>
         <attribute name="action">view.select-all</attribute>
@@ -55,8 +29,13 @@
     <section id="background-extensions-section"/>
     <section>
       <item>
-        <attribute name="label" translatable="yes">Open in Consol_e</attribute>
-        <attribute name="action">view.current-directory-console</attribute>
+        <attribute name="label" translatable="yes">R_eload</attribute>
+        <attribute name="action">win.reload</attribute>
+        <attribute name="hidden-when">action-disabled</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">St_op</attribute>
+        <attribute name="action">win.stop</attribute>
         <attribute name="hidden-when">action-disabled</attribute>
       </item>
     </section>
@@ -72,9 +51,57 @@
     <section id="new-folder-with-selection-section"/>
     <section id="open-with-application-section">
       <item>
-        <attribute name="label" translatable="yes">Open With Other _Application</attribute>
+        <attribute name="label" translatable="yes">Open _With…</attribute>
         <attribute name="action">view.open-with-other-application</attribute>
         <attribute name="hidden-when">action-disabled</attribute>
+        <attribute name="nautilus-menu-item">open_with_in_main_menu</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Run as a Program</attribute>
+        <attribute name="action">view.run-in-terminal</attribute>
+        <attribute name="hidden-when">action-disabled</attribute>
+      </item>
+    </section>
+    <item>
+      <attribute name="label" translatable="yes">_Open</attribute>
+      <attribute name="nautilus-menu-item">open_in_view_submenu</attribute>
+      <link name="submenu">
+        <section>
+          <item>
+            <attribute name="label" translatable="yes">Open</attribute>
+            <attribute name="action">view.open-with-default-application</attribute>
+            <attribute name="hidden-when">action-disabled</attribute>
+          </item>
+          <item>
+            <attribute name="label" translatable="yes">Open In New _Tab</attribute>
+            <attribute name="action">view.open-item-new-tab</attribute>
+            <attribute name="hidden-when">action-disabled</attribute>
+          </item>
+          <item>
+            <attribute name="label" translatable="yes">Open In New _Window</attribute>
+            <attribute name="action">view.open-item-new-window</attribute>
+            <attribute name="hidden-when">action-disabled</attribute>
+          </item>
+        </section>
+        <section>
+          <item>
+            <attribute name="label" translatable="yes">Open _With…</attribute>
+            <attribute name="action">view.open-with-other-application</attribute>
+            <attribute name="hidden-when">action-disabled</attribute>
+          </item>
+          <item>
+            <attribute name="label" translatable="yes">Open in Consol_e</attribute>
+            <attribute name="action">view.console</attribute>
+            <attribute name="hidden-when">action-disabled</attribute>
+          </item>
+        </section>
+      </link>
+    </item>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Open Item Location</attribute>
+        <attribute name="action">view.open-item-location</attribute>
+        <attribute name="hidden-when">action-disabled</attribute>
       </item>
     </section>
     <submenu>
@@ -89,30 +116,6 @@
         </item>
       </section>
     </submenu>
-    <section>
-      <item>
-        <attribute name="label" translatable="yes">_Open Item Location</attribute>
-        <attribute name="action">view.open-item-location</attribute>
-        <attribute name="hidden-when">action-disabled</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">Open In New _Tab</attribute>
-        <attribute name="action">view.open-item-new-tab</attribute>
-        <attribute name="hidden-when">action-disabled</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">Open In New _Window</attribute>
-        <attribute name="action">view.open-item-new-window</attribute>
-        <attribute name="hidden-when">action-disabled</attribute>
-      </item>
-    </section>
-    <section>
-      <item>
-        <attribute name="label" translatable="yes">_Run as a Program</attribute>
-        <attribute name="action">view.run-in-terminal</attribute>
-        <attribute name="hidden-when">action-disabled</attribute>
-      </item>
-    </section>
     <section id="drive-section">
       <item>
         <attribute name="label" translatable="yes">_Mount</attribute>
@@ -154,18 +157,6 @@
         <attribute name="label" translatable="yes">_Copy</attribute>
         <attribute name="action">view.copy</attribute>
       </item>
-      <item>
-        <attribute name="label" translatable="yes">Create _Link</attribute>
-        <attribute name="action">view.create-link-in-place</attribute>
-        <attribute name="hidden-when">action-disabled</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">_Paste Into Folder</attribute>
-        <attribute name="action">view.paste-into</attribute>
-        <attribute name="hidden-when">action-disabled</attribute>
-      </item>
-    </section>
-    <section>
       <item>
         <attribute name="label" translatable="yes">Move to…</attribute>
         <attribute name="action">view.move-to</attribute>
@@ -177,28 +168,18 @@
     </section>
     <section>
       <item>
-        <attribute name="label" translatable="yes">Mo_ve to Trash</attribute>
-        <attribute name="action">view.move-to-trash</attribute>
-        <attribute name="hidden-when">action-disabled</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">_Delete from Trash</attribute>
-        <attribute name="action">view.delete-from-trash</attribute>
-        <attribute name="hidden-when">action-disabled</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">_Delete Permanently…</attribute>
-        <attribute name="action">view.delete-permanently-menu-item</attribute>
+        <attribute name="label" translatable="yes">_Extract Here</attribute>
+        <attribute name="action">view.extract-here</attribute>
         <attribute name="hidden-when">action-disabled</attribute>
       </item>
       <item>
-        <attribute name="label" translatable="yes">_Delete Permanently…</attribute>
-        <attribute name="action">view.permanent-delete-permanently-menu-item</attribute>
+        <attribute name="label" translatable="yes">E_xtract to…</attribute>
+        <attribute name="action">view.extract-to</attribute>
         <attribute name="hidden-when">action-disabled</attribute>
       </item>
       <item>
-        <attribute name="label" translatable="yes">_Restore From Trash</attribute>
-        <attribute name="action">view.restore-from-trash</attribute>
+        <attribute name="label" translatable="yes">_Paste Into Folder</attribute>
+        <attribute name="action">view.paste-into</attribute>
         <attribute name="hidden-when">action-disabled</attribute>
       </item>
     </section>
@@ -207,70 +188,58 @@
         <attribute name="label" translatable="yes">Rena_me…</attribute>
         <attribute name="action">view.rename</attribute>
       </item>
-    </section>
-    <section>
       <item>
-        <attribute name="label" translatable="yes">Set As Wallpaper</attribute>
-        <attribute name="action">view.set-as-wallpaper</attribute>
+        <attribute name="label" translatable="yes">Create _Link</attribute>
+        <attribute name="action">view.create-link-in-place</attribute>
         <attribute name="hidden-when">action-disabled</attribute>
       </item>
-    </section>
-    <section>
       <item>
-        <attribute name="label" translatable="yes">_Remove from Recent</attribute>
-        <attribute name="action">view.remove-from-recent</attribute>
+        <attribute name="label" translatable="yes">C_ompress…</attribute>
+        <attribute name="action">view.compress</attribute>
         <attribute name="hidden-when">action-disabled</attribute>
       </item>
-    </section>
-    <section>
       <item>
-        <attribute name="label" translatable="yes">_Extract Here</attribute>
-        <attribute name="action">view.extract-here</attribute>
+        <attribute name="label" translatable="yes">Set as Background…</attribute>
+        <attribute name="action">view.set-as-wallpaper</attribute>
         <attribute name="hidden-when">action-disabled</attribute>
       </item>
       <item>
-        <attribute name="label" translatable="yes">E_xtract to…</attribute>
-        <attribute name="action">view.extract-to</attribute>
+        <attribute name="label" translatable="yes" comments="Translators: This is the transitive verb 
meaning 'to send via email' (e.g. 'email this document to Angela).">Email…</attribute>
+        <attribute name="action">view.send-email</attribute>
         <attribute name="hidden-when">action-disabled</attribute>
       </item>
       <item>
-        <attribute name="label" translatable="yes">C_ompress…</attribute>
-        <attribute name="action">view.compress</attribute>
+        <attribute name="label" translatable="yes">Mo_ve to Trash</attribute>
+        <attribute name="action">view.move-to-trash</attribute>
         <attribute name="hidden-when">action-disabled</attribute>
       </item>
-    </section>
-    <section>
       <item>
-        <attribute name="label" translatable="yes" comments="Translators: This is the transitive verb 
meaning 'to send via email' (e.g. 'email this document to Angela).">Email…</attribute>
-        <attribute name="action">view.send-email</attribute>
+        <attribute name="label" translatable="yes">_Delete from Trash</attribute>
+        <attribute name="action">view.delete-from-trash</attribute>
         <attribute name="hidden-when">action-disabled</attribute>
       </item>
-    </section>
-    <section id="selection-extensions-section"/>
-    <section>
       <item>
-        <attribute name="label" translatable="yes">Tags</attribute>
-        <attribute name="action">view.edit-tags</attribute>
+        <attribute name="label" translatable="yes">_Delete Permanently…</attribute>
+        <attribute name="action">view.delete-permanently-menu-item</attribute>
         <attribute name="hidden-when">action-disabled</attribute>
       </item>
       <item>
-        <attribute name="label" translatable="yes" context="menu item" comments="Marks a file as starred 
(starred)">Star</attribute>
-        <attribute name="action">view.star</attribute>
+        <attribute name="label" translatable="yes">_Delete Permanently…</attribute>
+        <attribute name="action">view.permanent-delete-permanently-menu-item</attribute>
         <attribute name="hidden-when">action-disabled</attribute>
       </item>
       <item>
-        <attribute name="label" translatable="yes" context="menu item" comments="Unmarks a file as starred 
(starred)">Unstar</attribute>
-        <attribute name="action">view.unstar</attribute>
+        <attribute name="label" translatable="yes">_Restore From Trash</attribute>
+        <attribute name="action">view.restore-from-trash</attribute>
         <attribute name="hidden-when">action-disabled</attribute>
       </item>
-    </section>
-    <section>
       <item>
-        <attribute name="label" translatable="yes">Open in Consol_e</attribute>
-        <attribute name="action">view.console</attribute>
+        <attribute name="label" translatable="yes">_Remove from Recent</attribute>
+        <attribute name="action">view.remove-from-recent</attribute>
         <attribute name="hidden-when">action-disabled</attribute>
       </item>
     </section>
+    <section id="selection-extensions-section"/>
     <section>
       <item>
         <attribute name="label" translatable="yes">P_roperties</attribute>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]