[nautilus/wip/antoniof/new-list-view-without-expanders: 9/10] files-view: Allow sorting in recent and search
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/new-list-view-without-expanders: 9/10] files-view: Allow sorting in recent and search
- Date: Tue, 14 Jun 2022 18:54:07 +0000 (UTC)
commit 9f070ec332978da4f453df1dd7e76e8da15c25e2
Author: António Fernandes <antoniof gnome org>
Date: Sat Apr 9 12:03:59 2022 +0100
files-view: Allow sorting in recent and search
Now that both list and grid view have a sort menu, we can finally
enable sorting the recent and search directories while providing
in the menu a way to restore their natural sort order (Recency
and Relevance, respectively).
Fixes https://gitlab.gnome.org/GNOME/nautilus/-/issues/374
src/nautilus-files-view.c | 24 ++++++++------
src/nautilus-list-base.c | 43 --------------------------
src/nautilus-ui-utilities.c | 2 ++
src/resources/ui/nautilus-toolbar-view-menu.ui | 14 +++++++++
4 files changed, 31 insertions(+), 52 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 8890c7a2c..5c8729c30 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -8052,20 +8052,26 @@ nautilus_files_view_reset_view_menu (NautilusFilesView *view)
NautilusFilesViewPrivate *priv = nautilus_files_view_get_instance_private (view);
NautilusFile *file;
GMenuModel *sort_section = priv->toolbar_menu_sections->sort_section;
- const gchar *trashed_action;
+ const gchar *action;
gint i;
file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (view));
- /* When not in Trash, 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 action is
- * treated as a disabled action. */
- trashed_action = nautilus_file_is_in_trash (file) ? "view.sort" : "doesnt-exist";
+ /* 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
+ * action is treated as a disabled action. */
+ action = nautilus_file_is_in_trash (file) ? "view.sort" : "doesnt-exist";
i = nautilus_g_menu_model_find_by_string (sort_section, "nautilus-menu-item", "last_trashed");
- g_return_if_fail (i != -1);
- nautilus_g_menu_replace_string_in_item (G_MENU (sort_section), i,
- "action", trashed_action);
+ nautilus_g_menu_replace_string_in_item (G_MENU (sort_section), i, "action", action);
+
+ action = nautilus_file_is_in_recent (file) ? "view.sort" : "doesnt-exist";
+ i = nautilus_g_menu_model_find_by_string (sort_section, "nautilus-menu-item", "recency");
+ nautilus_g_menu_replace_string_in_item (G_MENU (sort_section), i, "action", action);
+
+ action = nautilus_file_is_in_search (file) ? "view.sort" : "doesnt-exist";
+ i = nautilus_g_menu_model_find_by_string (sort_section, "nautilus-menu-item", "relevance");
+ nautilus_g_menu_replace_string_in_item (G_MENU (sort_section), i, "action", action);
}
/* Convenience function to reset the menus owned by the view but managed on
diff --git a/src/nautilus-list-base.c b/src/nautilus-list-base.c
index 2ced625b3..58315d0aa 100644
--- a/src/nautilus-list-base.c
+++ b/src/nautilus-list-base.c
@@ -738,48 +738,6 @@ real_reveal_selection (NautilusFilesView *files_view)
nautilus_list_base_scroll_to_item (self, get_first_selected_item (self));
}
-static gboolean
-showing_recent_directory (NautilusFilesView *view)
-{
- NautilusFile *file;
-
- file = nautilus_files_view_get_directory_as_file (view);
- if (file != NULL)
- {
- return nautilus_file_is_in_recent (file);
- }
- return FALSE;
-}
-
-static gboolean
-showing_search_directory (NautilusFilesView *view)
-{
- NautilusFile *file;
-
- file = nautilus_files_view_get_directory_as_file (view);
- if (file != NULL)
- {
- return nautilus_file_is_in_search (file);
- }
- return FALSE;
-}
-
-static void
-real_update_actions_state (NautilusFilesView *files_view)
-{
- GAction *action;
- GActionGroup *view_action_group;
-
- NAUTILUS_FILES_VIEW_CLASS (nautilus_list_base_parent_class)->update_actions_state (files_view);
-
- view_action_group = nautilus_files_view_get_action_group (files_view);
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "sort");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- !showing_recent_directory (files_view) &&
- !showing_search_directory (files_view));
-}
-
-
static int
real_compare_files (NautilusFilesView *files_view,
NautilusFile *file1,
@@ -1242,7 +1200,6 @@ nautilus_list_base_class_init (NautilusListBaseClass *klass)
files_view_class->end_loading = real_end_loading;
files_view_class->get_first_visible_file = real_get_first_visible_file;
files_view_class->reveal_selection = real_reveal_selection;
- files_view_class->update_actions_state = real_update_actions_state;
files_view_class->scroll_to_file = real_scroll_to_file;
files_view_class->select_first = real_select_first;
files_view_class->compute_rename_popover_pointing_to = real_compute_rename_popover_pointing_to;
diff --git a/src/nautilus-ui-utilities.c b/src/nautilus-ui-utilities.c
index 1498488df..8e5933ee8 100644
--- a/src/nautilus-ui-utilities.c
+++ b/src/nautilus-ui-utilities.c
@@ -127,7 +127,9 @@ nautilus_g_menu_replace_string_in_item (GMenu *menu,
{
g_autoptr (GMenuItem) item = NULL;
+ g_return_if_fail (i != -1);
item = g_menu_item_new_from_model (G_MENU_MODEL (menu), i);
+ g_return_if_fail (item != NULL);
g_menu_item_set_attribute (item, attribute, "s", string);
g_menu_remove (menu, i);
g_menu_insert_item (menu, i, item);
diff --git a/src/resources/ui/nautilus-toolbar-view-menu.ui b/src/resources/ui/nautilus-toolbar-view-menu.ui
index 32d0e95cf..03c6e8e8d 100644
--- a/src/resources/ui/nautilus-toolbar-view-menu.ui
+++ b/src/resources/ui/nautilus-toolbar-view-menu.ui
@@ -45,5 +45,19 @@
<attribute name="hidden-when">action-disabled</attribute>
<attribute name="nautilus-menu-item">last_trashed</attribute>
</item>
+ <item>
+ <attribute name="action">view.sort</attribute>
+ <attribute name="target" type="(sb)">('recency',true)</attribute>
+ <attribute name="label" translatable="yes">Recency</attribute>
+ <attribute name="hidden-when">action-disabled</attribute>
+ <attribute name="nautilus-menu-item">recency</attribute>
+ </item>
+ <item>
+ <attribute name="action">view.sort</attribute>
+ <attribute name="target" type="(sb)">('search_relevance',true)</attribute>
+ <attribute name="label" translatable="yes">Relevance</attribute>
+ <attribute name="hidden-when">action-disabled</attribute>
+ <attribute name="nautilus-menu-item">relevance</attribute>
+ </item>
</menu>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]