[nautilus/wip/antoniof/three-menus-no-more: 1/6] files-view: Stop setting actions on submenus
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/three-menus-no-more: 1/6] files-view: Stop setting actions on submenus
- Date: Mon, 1 Aug 2022 01:13:49 +0000 (UTC)
commit e88b7d5882c503910b1c3fa8b89d1bf49ddbcff3
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 | 43 ++++++++++++++--------
.../ui/nautilus-files-view-context-menus.ui | 6 +--
2 files changed, 29 insertions(+), 20 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 6df8e7a19..7be5722f7 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
@@ -8138,6 +8135,7 @@ update_background_menu (NautilusFilesView *view,
{
NautilusFilesViewPrivate *priv = nautilus_files_view_get_instance_private (view);
GObject *object;
+ gboolean remove_submenu = TRUE;
if (nautilus_files_view_supports_creating_files (view) &&
!showing_recent_directory (view) &&
@@ -8151,6 +8149,19 @@ update_background_menu (NautilusFilesView *view,
object = gtk_builder_get_object (builder, "templates-submenu");
nautilus_gmenu_set_from_model (G_MENU (object), priv->templates_menu);
+
+ if (priv->templates_menu != NULL)
+ {
+ remove_submenu = FALSE;
+ }
+ }
+
+ if (remove_submenu)
+ {
+ 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);
}
}
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]