[nautilus/wip/corey/fix-sort] list-base: Add boolean to "sort" action to force re-sort
- From: Corey Berla <coreyberla src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/corey/fix-sort] list-base: Add boolean to "sort" action to force re-sort
- Date: Thu, 13 Oct 2022 20:43:32 +0000 (UTC)
commit 8e7ec297acf3d71a74b9ef52fdef8bb8063f67cd
Author: Corey Berla <corey berla me>
Date: Thu Oct 13 13:35:58 2022 -0700
list-base: Add boolean to "sort" action to force re-sort
The sort action re-sorts in the columns in list-view whether the
action was initiated by the toolbar or the column header. We really
only want to re-sort when it was initiated by the toolbar.
Clicking on the column already sorts the column, so sorting again
can cause problems.
src/nautilus-grid-view.c | 4 ++--
src/nautilus-list-base.c | 5 +++--
src/nautilus-list-view.c | 23 +++++++++++++----------
src/resources/ui/nautilus-toolbar-view-menu.ui | 18 +++++++++---------
4 files changed, 27 insertions(+), 23 deletions(-)
---
diff --git a/src/nautilus-grid-view.c b/src/nautilus-grid-view.c
index 5c6da40b4..a32128173 100644
--- a/src/nautilus-grid-view.c
+++ b/src/nautilus-grid-view.c
@@ -289,7 +289,7 @@ action_sort_order_changed (GSimpleAction *action,
return;
}
- g_variant_get (value, "(&sb)", &target_name, &self->reversed);
+ g_variant_get (value, "(&sbb)", &target_name, &self->reversed);
self->sort_type = get_sorts_type_from_metadata_text (target_name);
sorter = gtk_custom_sorter_new (nautilus_grid_view_sort, self, NULL);
@@ -448,7 +448,7 @@ create_view_ui (NautilusGridView *self)
const GActionEntry view_icon_actions[] =
{
- { "sort", NULL, "(sb)", "('invalid',false)", action_sort_order_changed },
+ { "sort", NULL, "(sbb)", "('invalid',false,true)", action_sort_order_changed },
{ "zoom-to-level", NULL, NULL, "100", action_zoom_to_level }
};
diff --git a/src/nautilus-list-base.c b/src/nautilus-list-base.c
index 174105fcb..e0df43892 100644
--- a/src/nautilus-list-base.c
+++ b/src/nautilus-list-base.c
@@ -223,9 +223,10 @@ update_sort_order_from_metadata_and_preferences (NautilusListBase *self)
view_action_group = nautilus_files_view_get_action_group (NAUTILUS_FILES_VIEW (self));
g_action_group_change_action_state (view_action_group,
"sort",
- g_variant_new ("(sb)",
+ g_variant_new ("(sbb)",
default_directory_sort->metadata_name,
- reversed));
+ reversed,
+ TRUE));
}
void
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 282be684c..237169812 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -640,7 +640,7 @@ action_sort_order_changed (GSimpleAction *action,
gpointer user_data)
{
const gchar *target_name;
- gboolean reversed;
+ gboolean reversed, resort;
NautilusFileSortType sort_type;
NautilusListView *self;
GListModel *view_columns;
@@ -673,7 +673,7 @@ action_sort_order_changed (GSimpleAction *action,
}
self = NAUTILUS_LIST_VIEW (user_data);
- g_variant_get (value, "(&sb)", &target_name, &reversed);
+ g_variant_get (value, "(&sbb)", &target_name, &reversed, &resort);
if (g_strcmp0 (target_name, "unknown") == 0)
{
@@ -710,12 +710,15 @@ action_sort_order_changed (GSimpleAction *action,
model = nautilus_list_base_get_model (NAUTILUS_LIST_BASE (self));
sorter = nautilus_view_model_get_sorter (model);
- g_signal_handlers_block_by_func (sorter, on_sorter_changed, self);
- /* FIXME: Set NULL to stop drawing the arrow on previous sort column
- * to workaround https://gitlab.gnome.org/GNOME/gtk/-/issues/4696 */
- gtk_column_view_sort_by_column (self->view_ui, NULL, FALSE);
- gtk_column_view_sort_by_column (self->view_ui, sort_column, reversed);
- g_signal_handlers_unblock_by_func (sorter, on_sorter_changed, self);
+ if (resort)
+ {
+ g_signal_handlers_block_by_func (sorter, on_sorter_changed, self);
+ /* FIXME: Set NULL to stop drawing the arrow on previous sort column
+ * to workaround https://gitlab.gnome.org/GNOME/gtk/-/issues/4696 */
+ gtk_column_view_sort_by_column (self->view_ui, NULL, FALSE);
+ gtk_column_view_sort_by_column (self->view_ui, sort_column, reversed);
+ g_signal_handlers_unblock_by_func (sorter, on_sorter_changed, self);
+ }
set_directory_sort_metadata (nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (self)),
target_name,
@@ -769,7 +772,7 @@ action_zoom_to_level (GSimpleAction *action,
const GActionEntry list_view_entries[] =
{
{ "visible-columns", action_visible_columns },
- { "sort", NULL, "(sb)", "('invalid',false)", action_sort_order_changed },
+ { "sort", NULL, "(sbb)", "('invalid',false,true)", action_sort_order_changed },
{ "zoom-to-level", NULL, NULL, "1", action_zoom_to_level }
};
@@ -897,7 +900,7 @@ on_sorter_changed (GtkSorter *sorter,
* new sort order is. Make sure the sort menu doesn't indicate a outdated
* action state. */
g_action_group_change_action_state (nautilus_files_view_get_action_group (NAUTILUS_FILES_VIEW (self)),
- "sort", g_variant_new ("(sb)", "unknown", FALSE));
+ "sort", g_variant_new ("(sbb)", new_sort_text, reversed, FALSE));
}
static guint
diff --git a/src/resources/ui/nautilus-toolbar-view-menu.ui b/src/resources/ui/nautilus-toolbar-view-menu.ui
index de675f365..7547183f6 100644
--- a/src/resources/ui/nautilus-toolbar-view-menu.ui
+++ b/src/resources/ui/nautilus-toolbar-view-menu.ui
@@ -4,57 +4,57 @@
<menu id="sort_section">
<item>
<attribute name="action">view.sort</attribute>
- <attribute name="target" type="(sb)">('name',false)</attribute>
+ <attribute name="target" type="(sbb)">('name',false,true)</attribute>
<attribute name="label" translatable="yes" context="Sort Criterion" comments="This is used to sort by
name in the toolbar view menu">_A-Z</attribute>
<attribute name="hidden-when">action-disabled</attribute>
</item>
<item>
<attribute name="action">view.sort</attribute>
- <attribute name="target" type="(sb)">('name',true)</attribute>
+ <attribute name="target" type="(sbb)">('name',true,true)</attribute>
<attribute name="label" translatable="yes" context="Sort Criterion" comments="This is used to sort by
name, in descending order in the toolbar view menu">_Z-A</attribute>
<attribute name="hidden-when">action-disabled</attribute>
</item>
<item>
<attribute name="action">view.sort</attribute>
- <attribute name="target" type="(sbb)">('date_modified',true)</attribute>
+ <attribute name="target" type="(sbb)">('date_modified',true,true)</attribute>
<attribute name="label" translatable="yes">Last _Modified</attribute>
<attribute name="hidden-when">action-disabled</attribute>
</item>
<item>
<attribute name="action">view.sort</attribute>
- <attribute name="target" type="(sbb)">('date_modified',false)</attribute>
+ <attribute name="target" type="(sbb)">('date_modified',false,true)</attribute>
<attribute name="label" translatable="yes">_First Modified</attribute>
<attribute name="hidden-when">action-disabled</attribute>
</item>
<item>
<attribute name="action">view.sort</attribute>
- <attribute name="target" type="(sb)">('size',true)</attribute>
+ <attribute name="target" type="(sbb)">('size',true,true)</attribute>
<attribute name="label" translatable="yes">_Size</attribute>
<attribute name="hidden-when">action-disabled</attribute>
</item>
<item>
<attribute name="action">view.sort</attribute>
- <attribute name="target" type="(sb)">('type',false)</attribute>
+ <attribute name="target" type="(sbb)">('type',false,true)</attribute>
<attribute name="label" translatable="yes">_Type</attribute>
<attribute name="hidden-when">action-disabled</attribute>
</item>
<item>
<attribute name="action">view.sort</attribute>
- <attribute name="target" type="(sbb)">('trashed_on',true)</attribute>
+ <attribute name="target" type="(sbb)">('trashed_on',true,true)</attribute>
<attribute name="label" translatable="yes">Last _Trashed</attribute>
<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="target" type="(sbb)">('recency',true,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="target" type="(sbb)">('search_relevance',true,true)</attribute>
<attribute name="label" translatable="yes">Relevance</attribute>
<attribute name="hidden-when">action-disabled</attribute>
<attribute name="nautilus-menu-item">relevance</attribute>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]