From 11d1ab85d10b22b96dc3664e0f2b67275cf539f5 Mon Sep 17 00:00:00 2001
From: hishitetsu <66369541+hishitetsu@users.noreply.github.com>
Date: Sat, 4 Feb 2023 17:22:13 +0900
Subject: [PATCH 1/4] Added groups direction preferences
---
src/Files.App/BaseLayout.cs | 14 ++++++++++++
.../ItemListDisplayHelpers/GroupingHelper.cs | 6 ++---
.../LayoutPreferences/LayoutPreferences.cs | 4 ++++
.../AbstractDateTimeFormatter.cs | 16 +++++++-------
.../Settings/LayoutSettingsService.cs | 6 +++++
.../UserControls/InnerNavigationToolbar.xaml | 15 ++++++++++---
.../ViewModels/FolderSettingsViewModel.cs | 19 +++++++++++++++-
src/Files.App/ViewModels/ItemViewModel.cs | 17 +++++++++++++-
src/Files.App/ViewModels/ToolbarViewModel.cs | 22 +++++++++++++++++++
.../Settings/ILayoutSettingsService.cs | 2 ++
10 files changed, 105 insertions(+), 16 deletions(-)
diff --git a/src/Files.App/BaseLayout.cs b/src/Files.App/BaseLayout.cs
index bd3c05cbf3f4..1c102d3741cb 100644
--- a/src/Files.App/BaseLayout.cs
+++ b/src/Files.App/BaseLayout.cs
@@ -38,6 +38,7 @@
using Windows.System;
using static Files.App.Helpers.PathNormalization;
using DispatcherQueueTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer;
+using SortDirection = Files.Shared.Enums.SortDirection;
namespace Files.App
{
@@ -377,6 +378,7 @@ protected override async void OnNavigatedTo(NavigationEventArgs eventArgs)
IsItemSelected = false;
FolderSettings!.LayoutModeChangeRequested += BaseFolderSettings_LayoutModeChangeRequested;
FolderSettings.GroupOptionPreferenceUpdated += FolderSettings_GroupOptionPreferenceUpdated;
+ FolderSettings.GroupDirectionPreferenceUpdated += FolderSettings_GroupDirectionPreferenceUpdated;
ParentShellPageInstance.FilesystemViewModel.EmptyTextType = EmptyTextType.None;
ParentShellPageInstance.ToolbarViewModel.UpdateSortAndGroupOptions();
ParentShellPageInstance.ToolbarViewModel.CanRefresh = true;
@@ -485,6 +487,17 @@ private async void FolderSettings_GroupOptionPreferenceUpdated(object? sender, G
await ParentShellPageInstance.FilesystemViewModel.ReloadItemGroupHeaderImagesAsync();
}
+ private async void FolderSettings_GroupDirectionPreferenceUpdated(object? sender, SortDirection e)
+ {
+ // Two or more of these running at the same time will cause a crash, so cancel the previous one before beginning
+ groupingCancellationToken?.Cancel();
+ groupingCancellationToken = new CancellationTokenSource();
+ var token = groupingCancellationToken.Token;
+ await ParentShellPageInstance!.FilesystemViewModel.GroupOptionsUpdated(token);
+ UpdateCollectionViewSource();
+ await ParentShellPageInstance.FilesystemViewModel.ReloadItemGroupHeaderImagesAsync();
+ }
+
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
base.OnNavigatingFrom(e);
@@ -492,6 +505,7 @@ protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
CharacterReceived -= Page_CharacterReceived;
FolderSettings!.LayoutModeChangeRequested -= BaseFolderSettings_LayoutModeChangeRequested;
FolderSettings.GroupOptionPreferenceUpdated -= FolderSettings_GroupOptionPreferenceUpdated;
+ FolderSettings.GroupDirectionPreferenceUpdated -= FolderSettings_GroupDirectionPreferenceUpdated;
ItemContextMenuFlyout.Opening -= ItemContextFlyout_Opening;
BaseContextMenuFlyout.Opening -= BaseContextFlyout_Opening;
diff --git a/src/Files.App/Helpers/ItemListDisplayHelpers/GroupingHelper.cs b/src/Files.App/Helpers/ItemListDisplayHelpers/GroupingHelper.cs
index 0d64ee54e2e5..7f2fa5e614d0 100644
--- a/src/Files.App/Helpers/ItemListDisplayHelpers/GroupingHelper.cs
+++ b/src/Files.App/Helpers/ItemListDisplayHelpers/GroupingHelper.cs
@@ -140,12 +140,12 @@ public static (string key, string text, string range, int index) GetGroupSizeInf
if (size > sizeGp.size)
{
var rangeStr = i > 0 ? $"{sizeGp.sizeText} - {sizeGroups[i - 1].sizeText}" : $"{sizeGp.sizeText} +";
- return (sizeGp.size.ToString(), sizeGp.text, rangeStr, i + 1); //i +1 is so that other groups always show below "unspecified"
+ return (sizeGp.size.ToString(), sizeGp.text, rangeStr, sizeGroups.Length - i);
}
lastSizeStr = sizeGp.sizeText;
}
- return ("0", "ItemSizeText_Tiny".GetLocalizedResource(), $"{"0 B".ConvertSizeAbbreviation()} - {lastSizeStr}", sizeGroups.Length + 1);
+ return ("0", "ItemSizeText_Tiny".GetLocalizedResource(), $"{"0 B".ConvertSizeAbbreviation()} - {lastSizeStr}", 0);
}
public static string GetGroupSizeKey(long size)
@@ -175,4 +175,4 @@ public interface IGroupableItem
{
public string Key { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/Files.App/Helpers/LayoutPreferences/LayoutPreferences.cs b/src/Files.App/Helpers/LayoutPreferences/LayoutPreferences.cs
index 50361dd51903..b0845a1410a2 100644
--- a/src/Files.App/Helpers/LayoutPreferences/LayoutPreferences.cs
+++ b/src/Files.App/Helpers/LayoutPreferences/LayoutPreferences.cs
@@ -13,6 +13,7 @@ public class LayoutPreferences
public SortDirection DirectorySortDirection;
public bool SortDirectoriesAlongsideFiles;
public GroupOption DirectoryGroupOption;
+ public SortDirection DirectoryGroupDirection;
public FolderLayoutModes LayoutMode;
public int GridViewSize;
public bool IsAdaptiveLayoutOverridden;
@@ -31,6 +32,7 @@ public LayoutPreferences()
DirectorySortOption = UserSettingsService.FoldersSettingsService.DefaultSortOption;
DirectoryGroupOption = UserSettingsService.FoldersSettingsService.DefaultGroupOption;
DirectorySortDirection = UserSettingsService.LayoutSettingsService.DefaultDirectorySortDirection;
+ DirectoryGroupDirection = UserSettingsService.LayoutSettingsService.DefaultDirectoryGroupDirection;
SortDirectoriesAlongsideFiles = UserSettingsService.LayoutSettingsService.DefaultSortDirectoriesAlongsideFiles;
IsAdaptiveLayoutOverridden = defaultLayout is not FolderLayoutModes.Adaptive;
@@ -71,6 +73,7 @@ public override bool Equals(object? obj)
prefs.DirectoryGroupOption == DirectoryGroupOption &&
prefs.DirectorySortOption == DirectorySortOption &&
prefs.DirectorySortDirection == DirectorySortDirection &&
+ prefs.DirectoryGroupDirection == DirectoryGroupDirection &&
prefs.SortDirectoriesAlongsideFiles == SortDirectoriesAlongsideFiles &&
prefs.IsAdaptiveLayoutOverridden == IsAdaptiveLayoutOverridden &&
prefs.ColumnsViewModel.Equals(ColumnsViewModel));
@@ -85,6 +88,7 @@ public override int GetHashCode()
hashCode = (hashCode * 397) ^ DirectoryGroupOption.GetHashCode();
hashCode = (hashCode * 397) ^ DirectorySortOption.GetHashCode();
hashCode = (hashCode * 397) ^ DirectorySortDirection.GetHashCode();
+ hashCode = (hashCode * 397) ^ DirectoryGroupDirection.GetHashCode();
hashCode = (hashCode * 397) ^ SortDirectoriesAlongsideFiles.GetHashCode();
hashCode = (hashCode * 397) ^ IsAdaptiveLayoutOverridden.GetHashCode();
hashCode = (hashCode * 397) ^ ColumnsViewModel.GetHashCode();
diff --git a/src/Files.App/ServicesImplementation/DateTimeFormatter/AbstractDateTimeFormatter.cs b/src/Files.App/ServicesImplementation/DateTimeFormatter/AbstractDateTimeFormatter.cs
index 4fd98f4a4328..a3529092f90a 100644
--- a/src/Files.App/ServicesImplementation/DateTimeFormatter/AbstractDateTimeFormatter.cs
+++ b/src/Files.App/ServicesImplementation/DateTimeFormatter/AbstractDateTimeFormatter.cs
@@ -26,14 +26,14 @@ public ITimeSpanLabel ToTimeSpanLabel(DateTimeOffset offset)
return 0 switch
{
- _ when now.Date == time.Date => new Label("Today", "\ue184", 0),
- _ when y.Date == time.Date => new Label("ItemTimeText_Yesterday", "\ue161", 1),
- _ when diff.Days < 7 && w.Year == time.Year && GetWeekOfYear(w) == GetWeekOfYear(time) => new Label("ItemTimeText_ThisWeek", "\uE162", 2),
- _ when diff.Days < 14 && w.Year == time.Year && GetWeekOfYear(w) == GetWeekOfYear(time) => new Label("ItemTimeText_LastWeek", "\uE162", 3),
- _ when now.Year == time.Year && now.Month == time.Month => new Label("ItemTimeText_ThisMonth", "\ue163", 4),
- _ when now.AddMonths(-1).Year == time.Year && now.AddMonths(-1).Month == time.Month => new Label("ItemTimeText_LastMonth", "\ue163", 5),
- _ when now.Year == time.Year => new Label("ItemTimeText_ThisYear", "\ue163", 5),
- _ => new Label("ItemTimeText_Older", "\uEC92", 6),
+ _ when now.Date == time.Date => new Label("Today", "\ue184", 7),
+ _ when y.Date == time.Date => new Label("ItemTimeText_Yesterday", "\ue161", 6),
+ _ when diff.Days < 7 && w.Year == time.Year && GetWeekOfYear(w) == GetWeekOfYear(time) => new Label("ItemTimeText_ThisWeek", "\uE162", 5),
+ _ when diff.Days < 14 && w.Year == time.Year && GetWeekOfYear(w) == GetWeekOfYear(time) => new Label("ItemTimeText_LastWeek", "\uE162", 4),
+ _ when now.Year == time.Year && now.Month == time.Month => new Label("ItemTimeText_ThisMonth", "\ue163", 3),
+ _ when now.AddMonths(-1).Year == time.Year && now.AddMonths(-1).Month == time.Month => new Label("ItemTimeText_LastMonth", "\ue163", 2),
+ _ when now.Year == time.Year => new Label("ItemTimeText_ThisYear", "\ue163", 1),
+ _ => new Label("ItemTimeText_Older", "\uEC92", 0),
};
}
diff --git a/src/Files.App/ServicesImplementation/Settings/LayoutSettingsService.cs b/src/Files.App/ServicesImplementation/Settings/LayoutSettingsService.cs
index ba6bb06914e0..0635302783fa 100644
--- a/src/Files.App/ServicesImplementation/Settings/LayoutSettingsService.cs
+++ b/src/Files.App/ServicesImplementation/Settings/LayoutSettingsService.cs
@@ -24,6 +24,12 @@ public SortDirection DefaultDirectorySortDirection
set => Set((long)value);
}
+ public SortDirection DefaultDirectoryGroupDirection
+ {
+ get => (SortDirection)Get((long)SortDirection.Ascending);
+ set => Set((long)value);
+ }
+
public bool DefaultSortDirectoriesAlongsideFiles
{
get => Get(false);
diff --git a/src/Files.App/UserControls/InnerNavigationToolbar.xaml b/src/Files.App/UserControls/InnerNavigationToolbar.xaml
index 7348f6b64867..ce4745542d1c 100644
--- a/src/Files.App/UserControls/InnerNavigationToolbar.xaml
+++ b/src/Files.App/UserControls/InnerNavigationToolbar.xaml
@@ -493,6 +493,9 @@
IsChecked="{x:Bind ViewModel.IsSortedByDateDeleted, Mode=TwoWay}"
IsEnabled="{x:Bind ViewModel.InstanceViewModel.IsPageTypeRecycleBin, Mode=OneWay}"
Text="{helpers:ResourceString Name=DateDeleted}" />
+
+
+
@@ -518,11 +521,17 @@
IsChecked="{x:Bind ViewModel.IsGroupedByFolderPath, Mode=TwoWay}"
IsEnabled="{x:Bind ViewModel.InstanceViewModel.IsPageTypeLibrary, Mode=OneWay}"
Text="{helpers:ResourceString Name=NavToolbarArrangementOptionFolderPath/Text}" />
+
+
+
-
-
-
diff --git a/src/Files.App/ViewModels/FolderSettingsViewModel.cs b/src/Files.App/ViewModels/FolderSettingsViewModel.cs
index ba84c4e56939..07baa3cda482 100644
--- a/src/Files.App/ViewModels/FolderSettingsViewModel.cs
+++ b/src/Files.App/ViewModels/FolderSettingsViewModel.cs
@@ -215,6 +215,8 @@ public int GridViewSize
public event EventHandler? SortDirectionPreferenceUpdated;
+ public event EventHandler? GroupDirectionPreferenceUpdated;
+
public event EventHandler? SortDirectoriesAlongsideFilesPreferenceUpdated;
public SortOption DirectorySortOption
@@ -258,6 +260,19 @@ public SortDirection DirectorySortDirection
}
}
+ public SortDirection DirectoryGroupDirection
+ {
+ get => LayoutPreference.DirectoryGroupDirection;
+ set
+ {
+ if (SetProperty(ref LayoutPreference.DirectoryGroupDirection, value, nameof(DirectoryGroupDirection)))
+ {
+ LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference));
+ GroupDirectionPreferenceUpdated?.Invoke(this, DirectoryGroupDirection);
+ }
+ }
+ }
+
public bool SortDirectoriesAlongsideFiles
{
get
@@ -327,6 +342,7 @@ public static void SetLayoutPreferencesForPath(string folderPath, LayoutPreferen
userSettingsService.FoldersSettingsService.DefaultGroupOption = prefs.DirectoryGroupOption;
}
userSettingsService.LayoutSettingsService.DefaultDirectorySortDirection = prefs.DirectorySortDirection;
+ userSettingsService.LayoutSettingsService.DefaultDirectoryGroupDirection = prefs.DirectoryGroupDirection;
userSettingsService.LayoutSettingsService.DefaultSortDirectoriesAlongsideFiles = prefs.SortDirectoriesAlongsideFiles;
userSettingsService.FoldersSettingsService.ShowDateColumn = !prefs.ColumnsViewModel.DateModifiedColumn.UserCollapsed;
@@ -376,7 +392,7 @@ private static LayoutPreferences GetDefaultLayoutPreferences(string folderPath)
if (folderPath == CommonPaths.DownloadsPath)
// Default for downloads folder is to group by date created
- return new LayoutPreferences() { DirectoryGroupOption = GroupOption.DateCreated };
+ return new LayoutPreferences() { DirectoryGroupOption = GroupOption.DateCreated, DirectoryGroupDirection = SortDirection.Descending };
else if (LibraryManager.IsLibraryPath(folderPath))
// Default for libraries is to group by folder path
return new LayoutPreferences() { DirectoryGroupOption = GroupOption.FolderPath };
@@ -414,6 +430,7 @@ private set
OnPropertyChanged(nameof(DirectoryGroupOption));
OnPropertyChanged(nameof(DirectorySortOption));
OnPropertyChanged(nameof(DirectorySortDirection));
+ OnPropertyChanged(nameof(DirectoryGroupDirection));
OnPropertyChanged(nameof(SortDirectoriesAlongsideFiles));
OnPropertyChanged(nameof(ColumnsViewModel));
}
diff --git a/src/Files.App/ViewModels/ItemViewModel.cs b/src/Files.App/ViewModels/ItemViewModel.cs
index b8e9e68f6dc5..c601ace5d81e 100644
--- a/src/Files.App/ViewModels/ItemViewModel.cs
+++ b/src/Files.App/ViewModels/ItemViewModel.cs
@@ -706,7 +706,22 @@ private void OrderGroups(CancellationToken token = default)
if (FilesAndFolders.GroupedCollection is null || FilesAndFolders.GroupedCollection.IsSorted)
return;
- FilesAndFolders.GroupedCollection.Order(x => x.OrderBy(y => y.Model.SortIndexOverride).ThenBy(y => y.Model.Text));
+ if (folderSettings.DirectoryGroupDirection == SortDirection.Ascending)
+ {
+ if (folderSettings.DirectoryGroupOption == GroupOption.Size)
+ // Always show file sections below folders
+ FilesAndFolders.GroupedCollection.Order(x => x.OrderBy(y => y.First().PrimaryItemAttribute != StorageItemTypes.Folder).ThenBy(y => y.Model.SortIndexOverride).ThenBy(y => y.Model.Text));
+ else
+ FilesAndFolders.GroupedCollection.Order(x => x.OrderBy(y => y.Model.SortIndexOverride).ThenBy(y => y.Model.Text));
+ }
+ else
+ {
+ if (folderSettings.DirectoryGroupOption == GroupOption.Size)
+ // Always show file sections below folders
+ FilesAndFolders.GroupedCollection.Order(x => x.OrderBy(y => y.First().PrimaryItemAttribute != StorageItemTypes.Folder).ThenByDescending(y => y.Model.SortIndexOverride).ThenByDescending(y => y.Model.Text));
+ else
+ FilesAndFolders.GroupedCollection.Order(x => x.OrderByDescending(y => y.Model.SortIndexOverride).ThenByDescending(y => y.Model.Text));
+ }
FilesAndFolders.GroupedCollection.IsSorted = true;
}
diff --git a/src/Files.App/ViewModels/ToolbarViewModel.cs b/src/Files.App/ViewModels/ToolbarViewModel.cs
index 10ac1109e857..909d3eabe494 100644
--- a/src/Files.App/ViewModels/ToolbarViewModel.cs
+++ b/src/Files.App/ViewModels/ToolbarViewModel.cs
@@ -94,6 +94,18 @@ public bool IsSortedDescending
set { if (value) InstanceViewModel.FolderSettings.DirectorySortDirection = SortDirection.Descending; }
}
+ public bool IsGroupedAscending
+ {
+ get => InstanceViewModel?.FolderSettings.DirectoryGroupDirection == SortDirection.Ascending;
+ set { if (value) InstanceViewModel.FolderSettings.DirectoryGroupDirection = SortDirection.Ascending; }
+ }
+
+ public bool IsGroupedDescending
+ {
+ get => InstanceViewModel?.FolderSettings.DirectoryGroupDirection == SortDirection.Descending;
+ set { if (value) InstanceViewModel.FolderSettings.DirectoryGroupDirection = SortDirection.Descending; }
+ }
+
public bool AreDirectoriesSortedAlongsideFiles
{
get => InstanceViewModel.FolderSettings.SortDirectoriesAlongsideFiles;
@@ -375,6 +387,7 @@ public CurrentInstanceViewModel InstanceViewModel
InstanceViewModel.FolderSettings.SortDirectionPreferenceUpdated -= FolderSettings_SortDirectionPreferenceUpdated;
InstanceViewModel.FolderSettings.SortOptionPreferenceUpdated -= FolderSettings_SortOptionPreferenceUpdated;
InstanceViewModel.FolderSettings.SortDirectoriesAlongsideFilesPreferenceUpdated -= FolderSettings_SortDirectoriesAlongsideFilesPreferenceUpdated;
+ InstanceViewModel.FolderSettings.GroupDirectionPreferenceUpdated -= FolderSettings_GroupDirectionPreferenceUpdated;
InstanceViewModel.FolderSettings.GroupOptionPreferenceUpdated -= FolderSettings_GroupOptionPreferenceUpdated;
InstanceViewModel.FolderSettings.LayoutPreferencesUpdateRequired -= FolderSettings_LayoutPreferencesUpdateRequired;
}
@@ -386,6 +399,7 @@ public CurrentInstanceViewModel InstanceViewModel
InstanceViewModel.FolderSettings.SortDirectionPreferenceUpdated += FolderSettings_SortDirectionPreferenceUpdated;
InstanceViewModel.FolderSettings.SortOptionPreferenceUpdated += FolderSettings_SortOptionPreferenceUpdated;
InstanceViewModel.FolderSettings.SortDirectoriesAlongsideFilesPreferenceUpdated += FolderSettings_SortDirectoriesAlongsideFilesPreferenceUpdated;
+ InstanceViewModel.FolderSettings.GroupDirectionPreferenceUpdated += FolderSettings_GroupDirectionPreferenceUpdated;
InstanceViewModel.FolderSettings.GroupOptionPreferenceUpdated += FolderSettings_GroupOptionPreferenceUpdated;
InstanceViewModel.FolderSettings.LayoutPreferencesUpdateRequired += FolderSettings_LayoutPreferencesUpdateRequired;
}
@@ -476,6 +490,7 @@ public void UpdateSortAndGroupOptions()
FolderSettings_SortDirectionPreferenceUpdated(null, 0);
FolderSettings_SortOptionPreferenceUpdated(null, 0);
FolderSettings_SortDirectoriesAlongsideFilesPreferenceUpdated(null, true);
+ FolderSettings_GroupDirectionPreferenceUpdated(null, 0);
FolderSettings_GroupOptionPreferenceUpdated(null, 0);
FolderSettings_LayoutPreferencesUpdateRequired(null, 0);
}
@@ -504,6 +519,12 @@ private void FolderSettings_SortDirectoriesAlongsideFilesPreferenceUpdated(objec
OnPropertyChanged(nameof(AreDirectoriesSortedAlongsideFiles));
}
+ private void FolderSettings_GroupDirectionPreferenceUpdated(object? sender, SortDirection e)
+ {
+ OnPropertyChanged(nameof(IsGroupedAscending));
+ OnPropertyChanged(nameof(IsGroupedDescending));
+ }
+
private void FolderSettings_GroupOptionPreferenceUpdated(object? sender, GroupOption e)
{
OnPropertyChanged(nameof(IsGroupedByNone));
@@ -1196,6 +1217,7 @@ public void Dispose()
InstanceViewModel.FolderSettings.SortDirectionPreferenceUpdated -= FolderSettings_SortDirectionPreferenceUpdated;
InstanceViewModel.FolderSettings.SortOptionPreferenceUpdated -= FolderSettings_SortOptionPreferenceUpdated;
InstanceViewModel.FolderSettings.SortDirectoriesAlongsideFilesPreferenceUpdated -= FolderSettings_SortDirectoriesAlongsideFilesPreferenceUpdated;
+ InstanceViewModel.FolderSettings.GroupDirectionPreferenceUpdated -= FolderSettings_GroupDirectionPreferenceUpdated;
InstanceViewModel.FolderSettings.GroupOptionPreferenceUpdated -= FolderSettings_GroupOptionPreferenceUpdated;
InstanceViewModel.FolderSettings.LayoutPreferencesUpdateRequired -= FolderSettings_LayoutPreferencesUpdateRequired;
}
diff --git a/src/Files.Backend/Services/Settings/ILayoutSettingsService.cs b/src/Files.Backend/Services/Settings/ILayoutSettingsService.cs
index ae6b2b27d10a..30e2e2c7b5ea 100644
--- a/src/Files.Backend/Services/Settings/ILayoutSettingsService.cs
+++ b/src/Files.Backend/Services/Settings/ILayoutSettingsService.cs
@@ -9,6 +9,8 @@ public interface ILayoutSettingsService : IBaseSettingsService, INotifyPropertyC
SortDirection DefaultDirectorySortDirection { get; set; }
+ SortDirection DefaultDirectoryGroupDirection { get; set; }
+
bool DefaultSortDirectoriesAlongsideFiles { get; set; }
}
}
From 3c02ffc2e2aa372a012d9c474d9fd698ce7b0cdd Mon Sep 17 00:00:00 2001
From: hishitetsu <66369541+hishitetsu@users.noreply.github.com>
Date: Sat, 4 Feb 2023 20:56:35 +0900
Subject: [PATCH 2/4] Refactor BaseLayout.cs
---
src/Files.App/BaseLayout.cs | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/src/Files.App/BaseLayout.cs b/src/Files.App/BaseLayout.cs
index 1c102d3741cb..604fda9b7f1e 100644
--- a/src/Files.App/BaseLayout.cs
+++ b/src/Files.App/BaseLayout.cs
@@ -476,18 +476,13 @@ public void SetSelectedItemsOnNavigation()
private CancellationTokenSource? groupingCancellationToken;
- private async void FolderSettings_GroupOptionPreferenceUpdated(object? sender, GroupOption e)
- {
- // Two or more of these running at the same time will cause a crash, so cancel the previous one before beginning
- groupingCancellationToken?.Cancel();
- groupingCancellationToken = new CancellationTokenSource();
- var token = groupingCancellationToken.Token;
- await ParentShellPageInstance!.FilesystemViewModel.GroupOptionsUpdated(token);
- UpdateCollectionViewSource();
- await ParentShellPageInstance.FilesystemViewModel.ReloadItemGroupHeaderImagesAsync();
- }
+ private void FolderSettings_GroupOptionPreferenceUpdated(object? sender, GroupOption e)
+ => GroupPreferenceUpdated();
+
+ private void FolderSettings_GroupDirectionPreferenceUpdated(object? sender, SortDirection e)
+ => GroupPreferenceUpdated();
- private async void FolderSettings_GroupDirectionPreferenceUpdated(object? sender, SortDirection e)
+ private async void GroupPreferenceUpdated()
{
// Two or more of these running at the same time will cause a crash, so cancel the previous one before beginning
groupingCancellationToken?.Cancel();
From 9905258d87b185154f6b63b59aa004d5d63a43ba Mon Sep 17 00:00:00 2001
From: hishitetsu <66369541+hishitetsu@users.noreply.github.com>
Date: Thu, 9 Feb 2023 07:28:40 +0900
Subject: [PATCH 3/4] Update FolderSettingsViewModel.cs
---
src/Files.App/ViewModels/FolderSettingsViewModel.cs | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/Files.App/ViewModels/FolderSettingsViewModel.cs b/src/Files.App/ViewModels/FolderSettingsViewModel.cs
index 07baa3cda482..af286bf2695f 100644
--- a/src/Files.App/ViewModels/FolderSettingsViewModel.cs
+++ b/src/Files.App/ViewModels/FolderSettingsViewModel.cs
@@ -392,7 +392,10 @@ private static LayoutPreferences GetDefaultLayoutPreferences(string folderPath)
if (folderPath == CommonPaths.DownloadsPath)
// Default for downloads folder is to group by date created
- return new LayoutPreferences() { DirectoryGroupOption = GroupOption.DateCreated, DirectoryGroupDirection = SortDirection.Descending };
+ return new LayoutPreferences() {
+ DirectoryGroupOption = GroupOption.DateCreated,
+ DirectoryGroupDirection = SortDirection.Descending
+ };
else if (LibraryManager.IsLibraryPath(folderPath))
// Default for libraries is to group by folder path
return new LayoutPreferences() { DirectoryGroupOption = GroupOption.FolderPath };
From a77bcea304da1b4afa1e621e6897667f9260e219 Mon Sep 17 00:00:00 2001
From: hishitetsu <66369541+hishitetsu@users.noreply.github.com>
Date: Thu, 9 Feb 2023 09:05:11 +0900
Subject: [PATCH 4/4] The right click menu support
---
.../Helpers/ContextFlyoutItemHelper.cs | 34 +++++++++++++++++++
.../ViewModels/FolderSettingsViewModel.cs | 5 +++
2 files changed, 39 insertions(+)
diff --git a/src/Files.App/Helpers/ContextFlyoutItemHelper.cs b/src/Files.App/Helpers/ContextFlyoutItemHelper.cs
index 17cc9d8089c0..ba471000d242 100644
--- a/src/Files.App/Helpers/ContextFlyoutItemHelper.cs
+++ b/src/Files.App/Helpers/ContextFlyoutItemHelper.cs
@@ -469,6 +469,40 @@ public static List GetBaseLayoutMenuItems(Curren
ItemType = ItemType.Toggle,
ShowItem = currentInstanceViewModel.IsPageTypeLibrary,
},
+ new ContextMenuFlyoutItemViewModel()
+ {
+ ItemType = ItemType.Separator,
+ ShowInRecycleBin = true,
+ ShowInSearchPage = true,
+ ShowInFtpPage = true,
+ ShowInZipPage = true,
+ },
+ new ContextMenuFlyoutItemViewModel()
+ {
+ Text = "Ascending".GetLocalizedResource(),
+ IsChecked = currentInstanceViewModel.FolderSettings.DirectoryGroupDirection == SortDirection.Ascending,
+ IsEnabled = currentInstanceViewModel.FolderSettings.DirectoryGroupOption != GroupOption.None,
+ ShowInRecycleBin = true,
+ ShowInSearchPage = true,
+ ShowInFtpPage = true,
+ ShowInZipPage = true,
+ Command = currentInstanceViewModel.FolderSettings.ChangeGroupDirectionCommand,
+ CommandParameter = SortDirection.Ascending,
+ ItemType = ItemType.Toggle,
+ },
+ new ContextMenuFlyoutItemViewModel()
+ {
+ Text = "Descending".GetLocalizedResource(),
+ IsChecked = currentInstanceViewModel.FolderSettings.DirectoryGroupDirection == SortDirection.Descending,
+ IsEnabled = currentInstanceViewModel.FolderSettings.DirectoryGroupOption != GroupOption.None,
+ ShowInRecycleBin = true,
+ ShowInSearchPage = true,
+ ShowInFtpPage = true,
+ ShowInZipPage = true,
+ Command = currentInstanceViewModel.FolderSettings.ChangeGroupDirectionCommand,
+ CommandParameter = SortDirection.Descending,
+ ItemType = ItemType.Toggle,
+ },
}
},
new ContextMenuFlyoutItemViewModel()
diff --git a/src/Files.App/ViewModels/FolderSettingsViewModel.cs b/src/Files.App/ViewModels/FolderSettingsViewModel.cs
index af286bf2695f..1b0ff06940d7 100644
--- a/src/Files.App/ViewModels/FolderSettingsViewModel.cs
+++ b/src/Files.App/ViewModels/FolderSettingsViewModel.cs
@@ -43,6 +43,7 @@ public FolderSettingsViewModel()
ToggleLayoutModeAdaptiveCommand = new RelayCommand(ToggleLayoutModeAdaptive);
ChangeGroupOptionCommand = new RelayCommand(ChangeGroupOption);
+ ChangeGroupDirectionCommand = new RelayCommand(ChangeGroupDirection);
}
public FolderSettingsViewModel(FolderLayoutModes modeOverride) : this()
=> (rootLayoutMode, LayoutPreference.IsAdaptiveLayoutOverridden) = (modeOverride, true);
@@ -260,6 +261,8 @@ public SortDirection DirectorySortDirection
}
}
+ public ICommand ChangeGroupDirectionCommand { get; }
+
public SortDirection DirectoryGroupDirection
{
get => LayoutPreference.DirectoryGroupDirection;
@@ -518,6 +521,8 @@ public void ToggleLayoutModeAdaptive()
private void ChangeGroupOption(GroupOption option) => DirectoryGroupOption = option;
+ private void ChangeGroupDirection(SortDirection option) => DirectoryGroupDirection = option;
+
public void OnDefaultPreferencesChanged(string folderPath, string settingsName)
{
var prefs = GetLayoutPreferencesForPath(folderPath);