Skip to content

Commit 5dd38f1

Browse files
authored
Feature: Add support for choosing the default sorting and grouping options (#10596)
1 parent 21f19ec commit 5dd38f1

File tree

12 files changed

+113
-31
lines changed

12 files changed

+113
-31
lines changed

src/Files.App/Helpers/LayoutPreferences/LayoutPreferences.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public LayoutPreferences()
2828

2929
this.LayoutMode = defaultLayout is FolderLayoutModes.Adaptive ? FolderLayoutModes.DetailsView : defaultLayout;
3030
this.GridViewSize = UserSettingsService.LayoutSettingsService.DefaultGridViewSize;
31-
this.DirectorySortOption = UserSettingsService.LayoutSettingsService.DefaultDirectorySortOption;
32-
this.DirectoryGroupOption = UserSettingsService.LayoutSettingsService.DefaultDirectoryGroupOption;
31+
this.DirectorySortOption = UserSettingsService.FoldersSettingsService.DefaultSortOption;
32+
this.DirectoryGroupOption = UserSettingsService.FoldersSettingsService.DefaultGroupOption;
3333
this.DirectorySortDirection = UserSettingsService.LayoutSettingsService.DefaultDirectorySortDirection;
3434
this.SortDirectoriesAlongsideFiles = UserSettingsService.LayoutSettingsService.DefaultSortDirectoriesAlongsideFiles;
3535
this.IsAdaptiveLayoutOverridden = defaultLayout is not FolderLayoutModes.Adaptive;

src/Files.App/ServicesImplementation/Settings/FoldersSettingsService.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,19 @@ public bool CalculateFolderSizes
207207
get => Get(false);
208208
set => Set(value);
209209
}
210+
211+
public SortOption DefaultSortOption
212+
{
213+
get => (SortOption)Get((long)SortOption.Name);
214+
set => Set((long)value);
215+
}
216+
217+
public GroupOption DefaultGroupOption
218+
{
219+
get => (GroupOption)Get((long)GroupOption.None);
220+
set => Set((long)value);
221+
}
222+
210223
protected override void RaiseOnSettingChangedEvent(object sender, SettingChangedEventArgs e)
211224
{
212225
switch (e.SettingName)

src/Files.App/ServicesImplementation/Settings/LayoutSettingsService.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,10 @@ public SortDirection DefaultDirectorySortDirection
2424
set => Set((long)value);
2525
}
2626

27-
public SortOption DefaultDirectorySortOption
28-
{
29-
get => (SortOption)Get((long)SortOption.Name);
30-
set => Set((long)value);
31-
}
32-
3327
public bool DefaultSortDirectoriesAlongsideFiles
3428
{
3529
get => Get(false);
3630
set => Set(value);
3731
}
38-
39-
public GroupOption DefaultDirectoryGroupOption
40-
{
41-
get => (GroupOption)Get((long)GroupOption.None);
42-
set => Set((long)value);
43-
}
4432
}
4533
}

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
that is mostly human readable. The generation and parsing of the
1010
various data types are done through the TypeConverter classes
1111
associated with the data types.
12-
1312
Example:
14-
1513
... ado.net/XML headers & schema ...
1614
<resheader name="resmimetype">text/microsoft-resx</resheader>
1715
<resheader name="version">2.0</resheader>
@@ -26,7 +24,6 @@
2624
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
2725
<comment>This is a comment</comment>
2826
</data>
29-
3027
There are any number of "resheader" rows that contain simple
3128
name/value pairs.
3229
@@ -43,12 +40,10 @@
4340
Note - application/x-microsoft.net.object.binary.base64 is the format
4441
that the ResXResourceWriter will generate, however the reader can
4542
read any of the formats listed below.
46-
4743
mimetype: application/x-microsoft.net.object.binary.base64
4844
value : The object must be serialized with
4945
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
5046
: and then encoded with base64 encoding.
51-
5247
mimetype: application/x-microsoft.net.object.soap.base64
5348
value : The object must be serialized with
5449
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
@@ -2862,6 +2857,9 @@
28622857
<data name="ExtractToPath" xml:space="preserve">
28632858
<value>Path</value>
28642859
</data>
2860+
<data name="SortingAndGrouping" xml:space="preserve">
2861+
<value>Sorting and grouping</value>
2862+
</data>
28652863
<data name="Archive" xml:space="preserve">
28662864
<value>Archive</value>
28672865
</data>
@@ -2931,4 +2929,10 @@
29312929
<data name="DetailsViewHeaderFlyout_ShowSyncStatus.Text" xml:space="preserve">
29322930
<value>Sync status column</value>
29332931
</data>
2932+
<data name="GroupBy" xml:space="preserve">
2933+
<value>Group by</value>
2934+
</data>
2935+
<data name="SortBy" xml:space="preserve">
2936+
<value>Sort by</value>
2937+
</data>
29342938
</root>

src/Files.App/ViewModels/FolderSettingsViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,19 +312,19 @@ public static void SetLayoutPreferencesForPath(string folderPath, LayoutPreferen
312312
{
313313
userSettingsService.FoldersSettingsService.DefaultLayoutMode = prefs.LayoutMode;
314314
userSettingsService.LayoutSettingsService.DefaultGridViewSize = prefs.GridViewSize;
315-
// Do not save OriginalPath as global sort option (only works in recycle bin)
315+
// Do not save options which only work in recycle bin or cloud folders as global
316316
if (prefs.DirectorySortOption != SortOption.OriginalFolder &&
317317
prefs.DirectorySortOption != SortOption.DateDeleted &&
318318
prefs.DirectorySortOption != SortOption.SyncStatus)
319319
{
320-
userSettingsService.LayoutSettingsService.DefaultDirectorySortOption = prefs.DirectorySortOption;
320+
userSettingsService.FoldersSettingsService.DefaultSortOption = prefs.DirectorySortOption;
321321
}
322322
if (prefs.DirectoryGroupOption != GroupOption.OriginalFolder &&
323323
prefs.DirectoryGroupOption != GroupOption.DateDeleted &&
324324
prefs.DirectoryGroupOption != GroupOption.FolderPath &&
325325
prefs.DirectoryGroupOption != GroupOption.SyncStatus)
326326
{
327-
userSettingsService.LayoutSettingsService.DefaultDirectoryGroupOption = prefs.DirectoryGroupOption;
327+
userSettingsService.FoldersSettingsService.DefaultGroupOption = prefs.DirectoryGroupOption;
328328
}
329329
userSettingsService.LayoutSettingsService.DefaultDirectorySortDirection = prefs.DirectorySortDirection;
330330
userSettingsService.LayoutSettingsService.DefaultSortDirectoriesAlongsideFiles = prefs.SortDirectoriesAlongsideFiles;

src/Files.App/ViewModels/ItemViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,8 @@ await dispatcherQueue.EnqueueAsync(() =>
497497
RefreshItems(null);
498498
});
499499
break;
500+
case nameof(UserSettingsService.FoldersSettingsService.DefaultSortOption):
501+
case nameof(UserSettingsService.FoldersSettingsService.DefaultGroupOption):
500502
case nameof(UserSettingsService.LayoutSettingsService.DefaultSortDirectoriesAlongsideFiles):
501503
case nameof(UserSettingsService.FoldersSettingsService.EnableOverridingFolderPreferences):
502504
await dispatcherQueue.EnqueueAsync(() =>

src/Files.App/ViewModels/SettingsViewModels/FoldersViewModel.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ public class FoldersViewModel : ObservableObject
1010
{
1111
private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService<IUserSettingsService>();
1212

13+
14+
//FileTag combobox indexes (required to hide SyncStatus)
15+
private readonly int FileTagSortingIndex = 5;
16+
private readonly int FileTagGroupingIndex = 6;
17+
1318
// Commands
1419
public RelayCommand ResetLayoutPreferencesCommand { get; }
1520
public RelayCommand ShowResetLayoutPreferencesTipCommand { get; }
@@ -20,6 +25,8 @@ public FoldersViewModel()
2025
ShowResetLayoutPreferencesTipCommand = new RelayCommand(() => IsResetLayoutPreferencesTipOpen = true);
2126

2227
SelectedDefaultLayoutModeIndex = (int)DefaultLayoutMode;
28+
SelectedDefaultSortingIndex = UserSettingsService.FoldersSettingsService.DefaultSortOption == SortOption.FileTag ? FileTagSortingIndex : (int)UserSettingsService.FoldersSettingsService.DefaultSortOption;
29+
SelectedDefaultGroupingIndex = UserSettingsService.FoldersSettingsService.DefaultGroupOption == GroupOption.FileTag ? FileTagGroupingIndex : (int)UserSettingsService.FoldersSettingsService.DefaultGroupOption;
2330
}
2431

2532
// Properties
@@ -239,6 +246,34 @@ public bool CalculateFolderSizes
239246
}
240247
}
241248

249+
private int selectedDefaultSortingIndex;
250+
public int SelectedDefaultSortingIndex
251+
{
252+
get => selectedDefaultSortingIndex;
253+
set
254+
{
255+
if (SetProperty(ref selectedDefaultSortingIndex, value))
256+
{
257+
OnPropertyChanged(nameof(SelectedDefaultSortingIndex));
258+
UserSettingsService.FoldersSettingsService.DefaultSortOption = value == FileTagSortingIndex ? SortOption.FileTag : (SortOption)value;
259+
}
260+
}
261+
}
262+
263+
private int selectedDefaultGroupingIndex;
264+
public int SelectedDefaultGroupingIndex
265+
{
266+
get => selectedDefaultGroupingIndex;
267+
set
268+
{
269+
if (SetProperty(ref selectedDefaultGroupingIndex, value))
270+
{
271+
OnPropertyChanged(nameof(SelectedDefaultGroupingIndex));
272+
UserSettingsService.FoldersSettingsService.DefaultGroupOption = value == FileTagGroupingIndex ? GroupOption.FileTag : (GroupOption)value;
273+
}
274+
}
275+
}
276+
242277
// Local methods
243278

244279
public void ResetLayoutPreferences()

src/Files.App/ViewModels/SettingsViewModels/PreferencesViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ public string Text
511511
{
512512
if (Path == "Home".GetLocalizedResource())
513513
return "Home".GetLocalizedResource();
514-
return (Path == CommonPaths.RecycleBinPath)
514+
return (Path == CommonPaths.RecycleBinPath)
515515
? ApplicationData.Current.LocalSettings.Values.Get("RecycleBin_Title", "Recycle Bin")
516516
: Path;
517517
}

src/Files.App/Views/SettingsPages/Folders.xaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,41 @@
120120
</local:SettingsBlockControl.ExpandableContent>
121121
</local:SettingsBlockControl>
122122

123+
<!-- Default sorting and grouping options -->
124+
<local:SettingsBlockControl Title="{helpers:ResourceString Name=SortingAndGrouping}" HorizontalAlignment="Stretch">
125+
<local:SettingsBlockControl.Icon>
126+
<FontIcon Glyph="&#xE8CB;" />
127+
</local:SettingsBlockControl.Icon>
128+
<local:SettingsBlockControl.ExpandableContent>
129+
<StackPanel>
130+
<!-- Sorting Options -->
131+
<local:SettingsBlockControl Title="{helpers:ResourceString Name=SortBy}" HorizontalAlignment="Stretch">
132+
<ComboBox AutomationProperties.Name="{helpers:ResourceString Name=SortBy}" SelectedIndex="{x:Bind ViewModel.SelectedDefaultSortingIndex, Mode=TwoWay}">
133+
<ComboBoxItem Content="{helpers:ResourceString Name=Name}" />
134+
<ComboBoxItem Content="{helpers:ResourceString Name=DateModifiedLowerCase}" />
135+
<ComboBoxItem Content="{helpers:ResourceString Name=DateCreated}" />
136+
<ComboBoxItem Content="{helpers:ResourceString Name=Size}" />
137+
<ComboBoxItem Content="{helpers:ResourceString Name=BaseLayoutContextFlyoutSortByType/Text}" />
138+
<ComboBoxItem Content="{helpers:ResourceString Name=Tag}" />
139+
</ComboBox>
140+
</local:SettingsBlockControl>
141+
142+
<!-- Grouping Options -->
143+
<local:SettingsBlockControl Title="{helpers:ResourceString Name=GroupBy}" HorizontalAlignment="Stretch">
144+
<ComboBox AutomationProperties.Name="{helpers:ResourceString Name=GroupBy}" SelectedIndex="{x:Bind ViewModel.SelectedDefaultGroupingIndex, Mode=TwoWay}">
145+
<ComboBoxItem Content="{helpers:ResourceString Name=None}" />
146+
<ComboBoxItem Content="{helpers:ResourceString Name=Name}" />
147+
<ComboBoxItem Content="{helpers:ResourceString Name=DateModifiedLowerCase}" />
148+
<ComboBoxItem Content="{helpers:ResourceString Name=DateCreated}" />
149+
<ComboBoxItem Content="{helpers:ResourceString Name=Size}" />
150+
<ComboBoxItem Content="{helpers:ResourceString Name=BaseLayoutContextFlyoutSortByType/Text}" />
151+
<ComboBoxItem Content="{helpers:ResourceString Name=Tag}" />
152+
</ComboBox>
153+
</local:SettingsBlockControl>
154+
</StackPanel>
155+
</local:SettingsBlockControl.ExpandableContent>
156+
</local:SettingsBlockControl>
157+
123158
<!-- Layout mode -->
124159
<local:SettingsBlockControl Title="{helpers:ResourceString Name=LayoutMode}" HorizontalAlignment="Stretch">
125160
<local:SettingsBlockControl.Icon>

src/Files.Backend/Services/Settings/IFoldersSettingsService.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,15 @@ public interface IFoldersSettingsService : IBaseSettingsService, INotifyProperty
139139
/// Gets or sets a value indicating whether or not to show folder size.
140140
/// </summary>
141141
bool CalculateFolderSizes { get; set; }
142+
143+
/// <summary>
144+
/// Gets or sets a value indicating the default sorting option.
145+
/// </summary>
146+
SortOption DefaultSortOption { get; set; }
147+
148+
/// <summary>
149+
/// Gets or sets a value indicating the default grouping option.
150+
/// </summary>
151+
GroupOption DefaultGroupOption { get; set; }
142152
}
143153
}

0 commit comments

Comments
 (0)