[nautilus/wip/antoniof/three-menus-no-more: 2/7] files-view: Stop setting actions on submenus




commit 58146e4f73594fc68787ad01d80f60559568cf86
Author: António Fernandes <antoniof gnome org>
Date:   Sun Jul 31 19:33:57 2022 +0100

    files-view: Stop setting actions on submenus
    
    We show Templates and Scripts submenus conditionally, using the
    hidden-when=action-disabled attribute, by assigning a dummy action
    which we can set as active or inactive as fit.
    
    However, this causes criticals when the popover menu is destroyed:
    
    (org.gnome.Nautilus:21502): GLib-CRITICAL **: 16:15:32.870: g_hash_table_iter_next: assertion 
'ri->version == ri->hash_table->version' failed
    
    Indeed, submenus are not supposed to have actions. There is a
    "submenu-action" but it's for a different purpose.
    
    So, instead of controlling the visibility, and taking advantage of
    the fact that our models are rebuilt each time they need an update,
    just remove the submenu if not desirable.

 src/nautilus-files-view.c                          | 36 ++++++++++++----------
 .../ui/nautilus-files-view-context-menus.ui        |  6 ++--
 2 files changed, 22 insertions(+), 20 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 6df8e7a19..7b82ee192 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -7043,9 +7043,7 @@ const GActionEntry view_entries[] =
     { "paste_accel", action_paste_files_accel },
     { "create-link", action_create_links },
     { "create-link-shortcut", action_create_links },
-    { "new-document" },
     /* Selection menu */
-    { "scripts" },
     { "new-folder-with-selection", action_new_folder_with_selection },
     { "open-scripts-folder", action_open_scripts_folder },
     { "open-item-location", action_open_item_location },
@@ -7748,11 +7746,6 @@ real_update_actions_state (NautilusFilesView *view)
     g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
                                  show_detect_media);
 
-    action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
-                                         "scripts");
-    g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
-                                 priv->scripts_menu != NULL);
-
     /* Background menu actions */
     action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
                                          "open-current-directory-with-other-application");
@@ -7783,13 +7776,6 @@ real_update_actions_state (NautilusFilesView *view)
                                          "current-directory-properties");
     g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
                                  !selection_contains_search);
-    action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
-                                         "new-document");
-    g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
-                                 can_create_files &&
-                                 !selection_contains_recent &&
-                                 !selection_contains_starred &&
-                                 priv->templates_menu != NULL);
 
     /* Actions that are related to the clipboard need request, request the data
      * and update them once we have the data */
@@ -8128,8 +8114,19 @@ update_selection_menu (NautilusFilesView *view,
         update_scripts_menu (view, builder);
         priv->scripts_menu_updated = TRUE;
     }
-    object = gtk_builder_get_object (builder, "scripts-submenu-section");
-    nautilus_gmenu_set_from_model (G_MENU (object), priv->scripts_menu);
+
+    if (priv->scripts_menu != NULL)
+    {
+        object = gtk_builder_get_object (builder, "scripts-submenu-section");
+        nautilus_gmenu_set_from_model (G_MENU (object), priv->scripts_menu);
+    }
+    else
+    {
+        gint i = nautilus_g_menu_model_find_by_string (G_MENU_MODEL (priv->selection_menu_model),
+                                                       "nautilus-menu-item",
+                                                       "scripts-submenu");
+        g_menu_remove (priv->selection_menu_model, i);
+    }
 }
 
 static void
@@ -8152,6 +8149,13 @@ update_background_menu (NautilusFilesView *view,
         object = gtk_builder_get_object (builder, "templates-submenu");
         nautilus_gmenu_set_from_model (G_MENU (object), priv->templates_menu);
     }
+    else
+    {
+        gint i = nautilus_g_menu_model_find_by_string (G_MENU_MODEL (priv->background_menu_model),
+                                                       "nautilus-menu-item",
+                                                       "templates-submenu");
+        g_menu_remove (priv->background_menu_model, i);
+    }
 }
 
 static void
diff --git a/src/resources/ui/nautilus-files-view-context-menus.ui 
b/src/resources/ui/nautilus-files-view-context-menus.ui
index a88e5c5a0..ebbe9f5d8 100644
--- a/src/resources/ui/nautilus-files-view-context-menus.ui
+++ b/src/resources/ui/nautilus-files-view-context-menus.ui
@@ -8,8 +8,7 @@
     </item>
     <submenu id="templates-submenu">
       <attribute name="label" translatable="yes">New _Document</attribute>
-      <attribute name="action">view.new-document</attribute>
-      <attribute name="hidden-when">action-disabled</attribute>
+      <attribute name="nautilus-menu-item">templates-submenu</attribute>
     </submenu>
     <item>
       <attribute name="label" translatable="yes">Add to _Bookmarks</attribute>
@@ -72,8 +71,7 @@
     </section>
     <submenu>
       <attribute name="label" translatable="yes">_Scripts</attribute>
-      <attribute name="action">view.scripts</attribute>
-      <attribute name="hidden-when">action-disabled</attribute>
+      <attribute name="nautilus-menu-item">scripts-submenu</attribute>
       <section id="scripts-submenu-section"/>
       <section>
         <item>


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