Skip to content

Commit a481974

Browse files
Feature: Added an option to group by day (#14299)
1 parent 496e03f commit a481974

File tree

12 files changed

+135
-25
lines changed

12 files changed

+135
-25
lines changed

docs/rich-commands.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,13 @@ This is the list of all commands defined in `CommandCodes` enum except `None`.
114114
| | GroupByFolderPath | Folder path | Group items by folder path | |
115115
| | GroupByDateModifiedYear | Year | Group items by year of date modified | |
116116
| | GroupByDateModifiedMonth | Month | Group items by month of date modified | |
117+
| | GroupByDateModifiedDay | Day | Group items by day of date modified | |
117118
| | GroupByDateCreatedYear | Year | Group items by year of date created | |
118119
| | GroupByDateCreatedMonth | Month | Group items by month of date created | |
120+
| | GroupByDateCreatedDay | Day | Group items by day of date created | |
119121
| | GroupByDateDeletedYear | Year | Group items by year of date deleted | |
120122
| | GroupByDateDeletedMonth | Month | Group items by month of date deleted | |
123+
| | GroupByDateDeletedDay | Day | Group items by day of date deleted | |
121124
| | GroupAscending | Ascending | Sort groups in ascending order | |
122125
| | GroupDescending | Descending | Sort groups in descending order | |
123126
| | ToggleGroupDirection | Toggle sort direction | Toggle group sort direction | |

src/Files.App/Actions/Display/GroupAction.cs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,21 @@ public override string Description
229229
=> "GroupByDateModifiedMonthDescription".GetLocalizedResource();
230230
}
231231

232+
internal class GroupByDateModifiedDayAction : GroupByDateAction
233+
{
234+
protected override GroupOption GroupOption
235+
=> GroupOption.DateModified;
236+
237+
protected override GroupByDateUnit GroupByDateUnit
238+
=> GroupByDateUnit.Day;
239+
240+
public override string Label
241+
=> "Day".GetLocalizedResource();
242+
243+
public override string Description
244+
=> "GroupByDateModifiedDayDescription".GetLocalizedResource();
245+
}
246+
232247
internal class GroupByDateCreatedYearAction : GroupByDateAction
233248
{
234249
protected override GroupOption GroupOption
@@ -259,6 +274,21 @@ public override string Description
259274
=> "GroupByDateCreatedMonthDescription".GetLocalizedResource();
260275
}
261276

277+
internal class GroupByDateCreatedDayAction : GroupByDateAction
278+
{
279+
protected override GroupOption GroupOption
280+
=> GroupOption.DateCreated;
281+
282+
protected override GroupByDateUnit GroupByDateUnit
283+
=> GroupByDateUnit.Day;
284+
285+
public override string Label
286+
=> "Day".GetLocalizedResource();
287+
288+
public override string Description
289+
=> "GroupByDateCreatedDayDescription".GetLocalizedResource();
290+
}
291+
262292
internal class GroupByDateDeletedYearAction : GroupByDateAction
263293
{
264294
protected override GroupOption GroupOption
@@ -295,6 +325,24 @@ protected override bool GetIsExecutable(ContentPageTypes pageType)
295325
=> pageType is ContentPageTypes.RecycleBin;
296326
}
297327

328+
internal class GroupByDateDeletedDayAction : GroupByDateAction
329+
{
330+
protected override GroupOption GroupOption
331+
=> GroupOption.DateDeleted;
332+
333+
protected override GroupByDateUnit GroupByDateUnit
334+
=> GroupByDateUnit.Day;
335+
336+
public override string Label
337+
=> "Day".GetLocalizedResource();
338+
339+
public override string Description
340+
=> "GroupByDateDeletedDayDescription".GetLocalizedResource();
341+
342+
protected override bool GetIsExecutable(ContentPageTypes pageType)
343+
=> pageType is ContentPageTypes.RecycleBin;
344+
}
345+
298346
internal abstract class GroupByDateAction : ObservableObject, IToggleAction
299347
{
300348
protected IContentPageContext ContentContext;
@@ -567,7 +615,12 @@ public ToggleGroupByDateUnitAction()
567615

568616
public Task ExecuteAsync()
569617
{
570-
context.GroupByDateUnit = context.GroupByDateUnit is GroupByDateUnit.Month ? GroupByDateUnit.Year : GroupByDateUnit.Month;
618+
context.GroupByDateUnit = context.GroupByDateUnit switch
619+
{
620+
GroupByDateUnit.Year => GroupByDateUnit.Month,
621+
GroupByDateUnit.Month => GroupByDateUnit.Day,
622+
_ => GroupByDateUnit.Year
623+
};
571624

572625
return Task.CompletedTask;
573626
}

src/Files.App/Data/Commands/CommandCodes.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,13 @@ public enum CommandCodes
151151
GroupByFolderPath,
152152
GroupByDateModifiedYear,
153153
GroupByDateModifiedMonth,
154+
GroupByDateModifiedDay,
154155
GroupByDateCreatedYear,
155156
GroupByDateCreatedMonth,
157+
GroupByDateCreatedDay,
156158
GroupByDateDeletedYear,
157159
GroupByDateDeletedMonth,
160+
GroupByDateDeletedDay,
158161
GroupAscending,
159162
GroupDescending,
160163
ToggleGroupDirection,

src/Files.App/Data/Commands/Manager/CommandManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,13 @@ public IRichCommand this[HotKey hotKey]
147147
public IRichCommand GroupByFolderPath => commands[CommandCodes.GroupByFolderPath];
148148
public IRichCommand GroupByDateModifiedYear => commands[CommandCodes.GroupByDateModifiedYear];
149149
public IRichCommand GroupByDateModifiedMonth => commands[CommandCodes.GroupByDateModifiedMonth];
150+
public IRichCommand GroupByDateModifiedDay => commands[CommandCodes.GroupByDateModifiedDay];
150151
public IRichCommand GroupByDateCreatedYear => commands[CommandCodes.GroupByDateCreatedYear];
151152
public IRichCommand GroupByDateCreatedMonth => commands[CommandCodes.GroupByDateCreatedMonth];
153+
public IRichCommand GroupByDateCreatedDay => commands[CommandCodes.GroupByDateCreatedDay];
152154
public IRichCommand GroupByDateDeletedYear => commands[CommandCodes.GroupByDateDeletedYear];
153155
public IRichCommand GroupByDateDeletedMonth => commands[CommandCodes.GroupByDateDeletedMonth];
156+
public IRichCommand GroupByDateDeletedDay => commands[CommandCodes.GroupByDateDeletedDay];
154157
public IRichCommand GroupAscending => commands[CommandCodes.GroupAscending];
155158
public IRichCommand GroupDescending => commands[CommandCodes.GroupDescending];
156159
public IRichCommand ToggleGroupDirection => commands[CommandCodes.ToggleGroupDirection];
@@ -314,10 +317,13 @@ public CommandManager()
314317
[CommandCodes.GroupByFolderPath] = new GroupByFolderPathAction(),
315318
[CommandCodes.GroupByDateModifiedYear] = new GroupByDateModifiedYearAction(),
316319
[CommandCodes.GroupByDateModifiedMonth] = new GroupByDateModifiedMonthAction(),
320+
[CommandCodes.GroupByDateModifiedDay] = new GroupByDateModifiedDayAction(),
317321
[CommandCodes.GroupByDateCreatedYear] = new GroupByDateCreatedYearAction(),
318322
[CommandCodes.GroupByDateCreatedMonth] = new GroupByDateCreatedMonthAction(),
323+
[CommandCodes.GroupByDateCreatedDay] = new GroupByDateCreatedDayAction(),
319324
[CommandCodes.GroupByDateDeletedYear] = new GroupByDateDeletedYearAction(),
320325
[CommandCodes.GroupByDateDeletedMonth] = new GroupByDateDeletedMonthAction(),
326+
[CommandCodes.GroupByDateDeletedDay] = new GroupByDateDeletedDayAction(),
321327
[CommandCodes.GroupAscending] = new GroupAscendingAction(),
322328
[CommandCodes.GroupDescending] = new GroupDescendingAction(),
323329
[CommandCodes.ToggleGroupDirection] = new ToggleGroupDirectionAction(),

src/Files.App/Data/Commands/Manager/ICommandManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,13 @@ public interface ICommandManager : IEnumerable<IRichCommand>
135135
IRichCommand GroupByFolderPath { get; }
136136
IRichCommand GroupByDateModifiedYear { get; }
137137
IRichCommand GroupByDateModifiedMonth { get; }
138+
IRichCommand GroupByDateModifiedDay { get; }
138139
IRichCommand GroupByDateCreatedYear { get; }
139140
IRichCommand GroupByDateCreatedMonth { get; }
141+
IRichCommand GroupByDateCreatedDay { get; }
140142
IRichCommand GroupByDateDeletedYear { get; }
141143
IRichCommand GroupByDateDeletedMonth { get; }
144+
IRichCommand GroupByDateDeletedDay { get; }
142145
IRichCommand GroupAscending { get; }
143146
IRichCommand GroupDescending { get; }
144147
IRichCommand ToggleGroupDirection { get; }

src/Files.App/Helpers/MenuFlyout/ContextFlyoutItemHelper.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
245245
{
246246
IsToggle = true
247247
}.Build(),
248+
new ContextMenuFlyoutItemViewModelBuilder(commands.GroupByDateModifiedDay)
249+
{
250+
IsToggle = true
251+
}.Build(),
248252
},
249253
},
250254
new ContextMenuFlyoutItemViewModel()
@@ -264,6 +268,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
264268
{
265269
IsToggle = true
266270
}.Build(),
271+
new ContextMenuFlyoutItemViewModelBuilder(commands.GroupByDateCreatedDay)
272+
{
273+
IsToggle = true
274+
}.Build(),
267275
},
268276
},
269277
new ContextMenuFlyoutItemViewModelBuilder(commands.GroupByType)
@@ -301,6 +309,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
301309
{
302310
IsToggle = true
303311
}.Build(),
312+
new ContextMenuFlyoutItemViewModelBuilder(commands.GroupByDateDeletedDay)
313+
{
314+
IsToggle = true
315+
}.Build(),
304316
},
305317
},
306318
new ContextMenuFlyoutItemViewModelBuilder(commands.GroupByFolderPath)

src/Files.App/Services/DateTimeFormatter/AbstractDateTimeFormatter.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,34 @@ public ITimeSpanLabel ToTimeSpanLabel(DateTimeOffset offset, GroupByDateUnit uni
2828
return 0 switch
2929
{
3030
_ when now.Date < time.Date
31-
=> new Label("Future".GetLocalizedResource(), "\uED28", 1000006),
31+
=> new Label("Future".GetLocalizedResource(), "\uED28", 1000000006),
3232
_ when now.Date == time.Date
33-
=> new Label("Today".GetLocalizedResource(), "\uE8D1", 1000005),
33+
=> new Label("Today".GetLocalizedResource(), "\uE8D1", 1000000005),
3434
_ when now.AddDays(-1).Date == time.Date
35-
=> new Label("Yesterday".GetLocalizedResource(), "\uE8BF", 1000004),
35+
=> new Label("Yesterday".GetLocalizedResource(), "\uE8BF", 1000000004),
36+
37+
// Group by day
38+
_ when unit == GroupByDateUnit.Day
39+
=> new Label(ToString(time, "D"), "\uE8BF", time.Year * 10000 + time.Month * 100 + time.Day),
40+
3641
_ when diff.Days <= 7 && GetWeekOfYear(now) == GetWeekOfYear(time)
37-
=> new Label("EarlierThisWeek".GetLocalizedResource(), "\uE8C0", 1000003),
42+
=> new Label("EarlierThisWeek".GetLocalizedResource(), "\uE8C0", 1000000003),
3843
_ when diff.Days <= 14 && GetWeekOfYear(now.AddDays(-7)) == GetWeekOfYear(time)
39-
=> new Label("LastWeek".GetLocalizedResource(), "\uE8C0", 1000002),
44+
=> new Label("LastWeek".GetLocalizedResource(), "\uE8C0", 1000000002),
4045
_ when now.Year == time.Year && now.Month == time.Month
41-
=> new Label("EarlierThisMonth".GetLocalizedResource(), "\uE787", 1000001),
46+
=> new Label("EarlierThisMonth".GetLocalizedResource(), "\uE787", 1000000001),
4247
_ when now.AddMonths(-1).Year == time.Year && now.AddMonths(-1).Month == time.Month
43-
=> new Label("LastMonth".GetLocalizedResource(), "\uE787", 1000000),
48+
=> new Label("LastMonth".GetLocalizedResource(), "\uE787", 1000000000),
4449

4550
// Group by month
4651
_ when unit == GroupByDateUnit.Month
47-
=> new Label(ToString(time, "Y"), "\uE787", time.Year * 100 + time.Month),
52+
=> new Label(ToString(time, "Y"), "\uE787", time.Year * 10000 + time.Month * 100),
4853

4954
// Group by year
5055
_ when now.Year == time.Year
51-
=> new Label("EarlierThisYear".GetLocalizedResource(), "\uEC92", 10001),
56+
=> new Label("EarlierThisYear".GetLocalizedResource(), "\uEC92", 10000001),
5257
_ when now.AddYears(-1).Year == time.Year
53-
=> new Label("LastYear".GetLocalizedResource(), "\uEC92", 10000),
58+
=> new Label("LastYear".GetLocalizedResource(), "\uEC92", 10000000),
5459
_
5560
=> new Label(string.Format("YearN".GetLocalizedResource(), time.Year), "\uEC92", time.Year),
5661
};

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,6 +2998,9 @@
29982998
<data name="Month" xml:space="preserve">
29992999
<value>Month</value>
30003000
</data>
3001+
<data name="Day" xml:space="preserve">
3002+
<value>Day</value>
3003+
</data>
30013004
<data name="ToggleGroupByDateUnitDescription" xml:space="preserve">
30023005
<value>Toggle unit for grouping by date</value>
30033006
</data>
@@ -3007,21 +3010,30 @@
30073010
<data name="Year" xml:space="preserve">
30083011
<value>Year</value>
30093012
</data>
3010-
<data name="GroupByMonthInsteadOfYear" xml:space="preserve">
3011-
<value>Group by month instead of year</value>
3013+
<data name="GroupByDateUnit" xml:space="preserve">
3014+
<value>Group by date unit</value>
3015+
</data>
3016+
<data name="GroupByDateCreatedDayDescription" xml:space="preserve">
3017+
<value>Group items by day of date created</value>
30123018
</data>
30133019
<data name="GroupByDateCreatedMonthDescription" xml:space="preserve">
30143020
<value>Group items by month of date created</value>
30153021
</data>
30163022
<data name="GroupByDateCreatedYearDescription" xml:space="preserve">
30173023
<value>Group items by year of date created</value>
3024+
</data>
3025+
<data name="GroupByDateDeletedDayDescription" xml:space="preserve">
3026+
<value>Group items by day of date deleted</value>
30183027
</data>
30193028
<data name="GroupByDateDeletedMonthDescription" xml:space="preserve">
30203029
<value>Group items by month of date deleted</value>
30213030
</data>
30223031
<data name="GroupByDateDeletedYearDescription" xml:space="preserve">
30233032
<value>Group items by year of date deleted</value>
30243033
</data>
3034+
<data name="GroupByDateModifiedDayDescription" xml:space="preserve">
3035+
<value>Group items by day of date modified</value>
3036+
</data>
30253037
<data name="GroupByDateModifiedMonthDescription" xml:space="preserve">
30263038
<value>Group items by month of date modified</value>
30273039
</data>

src/Files.App/UserControls/InnerNavigationToolbar.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,10 +552,12 @@
552552
<MenuFlyoutSubItem Text="{x:Bind Commands.GroupByDateModified.Label}">
553553
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupByDateModifiedYear.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupByDateModifiedYear.Label}" />
554554
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupByDateModifiedMonth.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupByDateModifiedMonth.Label}" />
555+
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupByDateModifiedDay.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupByDateModifiedDay.Label}" />
555556
</MenuFlyoutSubItem>
556557
<MenuFlyoutSubItem Text="{x:Bind Commands.GroupByDateCreated.Label}">
557558
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupByDateCreatedYear.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupByDateCreatedYear.Label}" />
558559
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupByDateCreatedMonth.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupByDateCreatedMonth.Label}" />
560+
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupByDateCreatedDay.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupByDateCreatedDay.Label}" />
559561
</MenuFlyoutSubItem>
560562
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupBySize.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupBySize.Label}" />
561563
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupByType.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupByType.Label}" />
@@ -571,6 +573,7 @@
571573
<MenuFlyoutSubItem IsEnabled="{x:Bind Commands.GroupByDateDeleted.IsExecutable, Mode=OneWay}" Text="{x:Bind Commands.GroupByDateDeleted.Label}">
572574
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupByDateDeletedYear.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupByDateDeletedYear.Label}" />
573575
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupByDateDeletedMonth.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupByDateDeletedMonth.Label}" />
576+
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupByDateDeletedDay.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupByDateDeletedDay.Label}" />
574577
</MenuFlyoutSubItem>
575578
<ToggleMenuFlyoutItem
576579
IsChecked="{x:Bind Commands.GroupByFolderPath.IsOn, Mode=TwoWay}"

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public FoldersViewModel()
1616
SelectedDefaultLayoutModeIndex = (int)DefaultLayoutMode;
1717
SelectedDefaultSortingIndex = UserSettingsService.FoldersSettingsService.DefaultSortOption == SortOption.FileTag ? FileTagSortingIndex : (int)UserSettingsService.FoldersSettingsService.DefaultSortOption;
1818
SelectedDefaultGroupingIndex = UserSettingsService.FoldersSettingsService.DefaultGroupOption == GroupOption.FileTag ? FileTagGroupingIndex : (int)UserSettingsService.FoldersSettingsService.DefaultGroupOption;
19+
SelectedDefaultGroupByDateUnitIndex = (int)UserSettingsService.FoldersSettingsService.DefaultGroupByDateUnit;
1920
SelectedDefaultSortPriorityIndex = UserSettingsService.FoldersSettingsService.DefaultSortDirectoriesAlongsideFiles ? 2 : UserSettingsService.FoldersSettingsService.DefaultSortFilesFirst ? 1 : 0;
2021
SelectedDeleteConfirmationPolicyIndex = (int)DeleteConfirmationPolicy;
2122
}
@@ -276,15 +277,16 @@ public bool GroupInDescendingOrder
276277
public bool IsDefaultGrouped
277278
=> UserSettingsService.FoldersSettingsService.DefaultGroupOption != GroupOption.None;
278279

279-
public bool GroupByMonth
280+
private int defaultGroupByDateUnitIndex;
281+
public int SelectedDefaultGroupByDateUnitIndex
280282
{
281-
get => UserSettingsService.FoldersSettingsService.DefaultGroupByDateUnit == GroupByDateUnit.Month;
283+
get => defaultGroupByDateUnitIndex;
282284
set
283285
{
284-
if (value != (UserSettingsService.FoldersSettingsService.DefaultGroupByDateUnit == GroupByDateUnit.Month))
286+
if (SetProperty(ref defaultGroupByDateUnitIndex, value))
285287
{
286-
UserSettingsService.FoldersSettingsService.DefaultGroupByDateUnit = value ? GroupByDateUnit.Month : GroupByDateUnit.Year;
287-
OnPropertyChanged();
288+
OnPropertyChanged(nameof(SelectedDefaultGroupByDateUnitIndex));
289+
UserSettingsService.FoldersSettingsService.DefaultGroupByDateUnit = (GroupByDateUnit)value;
288290
}
289291
}
290292
}

0 commit comments

Comments
 (0)