Skip to content

Commit f20e3a9

Browse files
Fix: Fixed issue where changing a folder's grouping preference wouldn't update other open tabs (#16572)
1 parent 02c2320 commit f20e3a9

9 files changed

+94
-5
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ public GroupByAction()
177177
public Task ExecuteAsync(object? parameter = null)
178178
{
179179
DisplayContext.GroupOption = GroupOption;
180+
LayoutHelpers.UpdateOpenTabsPreferences();
180181

181182
return Task.CompletedTask;
182183
}
@@ -377,6 +378,7 @@ public Task ExecuteAsync(object? parameter = null)
377378
{
378379
DisplayContext.GroupOption = GroupOption;
379380
DisplayContext.GroupByDateUnit = GroupByDateUnit;
381+
LayoutHelpers.UpdateOpenTabsPreferences();
380382

381383
return Task.CompletedTask;
382384
}
@@ -425,6 +427,7 @@ public GroupAscendingAction()
425427
public Task ExecuteAsync(object? parameter = null)
426428
{
427429
context.GroupDirection = SortDirection.Ascending;
430+
LayoutHelpers.UpdateOpenTabsPreferences();
428431

429432
return Task.CompletedTask;
430433
}
@@ -469,6 +472,7 @@ public GroupDescendingAction()
469472
public Task ExecuteAsync(object? parameter = null)
470473
{
471474
context.GroupDirection = SortDirection.Descending;
475+
LayoutHelpers.UpdateOpenTabsPreferences();
472476

473477
return Task.CompletedTask;
474478
}
@@ -505,6 +509,7 @@ public ToggleGroupDirectionAction()
505509
public Task ExecuteAsync(object? parameter = null)
506510
{
507511
context.GroupDirection = context.SortDirection is SortDirection.Descending ? SortDirection.Ascending : SortDirection.Descending;
512+
LayoutHelpers.UpdateOpenTabsPreferences();
508513

509514
return Task.CompletedTask;
510515
}
@@ -536,6 +541,7 @@ public GroupByYearAction()
536541
public Task ExecuteAsync(object? parameter = null)
537542
{
538543
context.GroupByDateUnit = GroupByDateUnit.Year;
544+
LayoutHelpers.UpdateOpenTabsPreferences();
539545

540546
return Task.CompletedTask;
541547
}
@@ -580,6 +586,7 @@ public GroupByMonthAction()
580586
public Task ExecuteAsync(object? parameter = null)
581587
{
582588
context.GroupByDateUnit = GroupByDateUnit.Month;
589+
LayoutHelpers.UpdateOpenTabsPreferences();
583590

584591
return Task.CompletedTask;
585592
}
@@ -621,6 +628,7 @@ public Task ExecuteAsync(object? parameter = null)
621628
GroupByDateUnit.Month => GroupByDateUnit.Day,
622629
_ => GroupByDateUnit.Year
623630
};
631+
LayoutHelpers.UpdateOpenTabsPreferences();
624632

625633
return Task.CompletedTask;
626634
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public SortByAction()
165165
public Task ExecuteAsync(object? parameter = null)
166166
{
167167
displayContext.SortOption = SortOption;
168+
LayoutHelpers.UpdateOpenTabsPreferences();
168169

169170
return Task.CompletedTask;
170171
}
@@ -207,6 +208,7 @@ public SortAscendingAction()
207208
public Task ExecuteAsync(object? parameter = null)
208209
{
209210
context.SortDirection = SortDirection.Ascending;
211+
LayoutHelpers.UpdateOpenTabsPreferences();
210212

211213
return Task.CompletedTask;
212214
}
@@ -241,6 +243,7 @@ public SortDescendingAction()
241243
public Task ExecuteAsync(object? parameter = null)
242244
{
243245
context.SortDirection = SortDirection.Descending;
246+
LayoutHelpers.UpdateOpenTabsPreferences();
244247

245248
return Task.CompletedTask;
246249
}
@@ -274,6 +277,8 @@ context.SortDirection is SortDirection.Descending
274277
? SortDirection.Ascending
275278
: SortDirection.Descending;
276279

280+
LayoutHelpers.UpdateOpenTabsPreferences();
281+
277282
return Task.CompletedTask;
278283
}
279284
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public SortFilesAndFoldersTogetherAction()
2626
public Task ExecuteAsync(object? parameter = null)
2727
{
2828
context.SortDirectoriesAlongsideFiles = true;
29+
LayoutHelpers.UpdateOpenTabsPreferences();
2930

3031
return Task.CompletedTask;
3132
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public Task ExecuteAsync(object? parameter = null)
2727
{
2828
context.SortFilesFirst = true;
2929
context.SortDirectoriesAlongsideFiles = false;
30+
LayoutHelpers.UpdateOpenTabsPreferences();
3031

3132
return Task.CompletedTask;
3233
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public Task ExecuteAsync(object? parameter = null)
2727
{
2828
context.SortFilesFirst = false;
2929
context.SortDirectoriesAlongsideFiles = false;
30+
LayoutHelpers.UpdateOpenTabsPreferences();
3031

3132
return Task.CompletedTask;
3233
}

src/Files.App/Data/Contracts/IShellPanesPage.cs

+6
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,11 @@ public interface IShellPanesPage : IDisposable, INotifyPropertyChanged
5858
/// Focuses the other pane.
5959
/// </summary>
6060
public void FocusOtherPane();
61+
62+
/// <summary>
63+
/// Gets open panes.
64+
/// </summary>
65+
/// <returns>An enumerable containing open panes.</returns>
66+
public IEnumerable<ModernShellPage> GetPanes();
6167
}
6268
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
namespace Files.App.Helpers
5+
{
6+
static class LayoutHelpers
7+
{
8+
public static void UpdateOpenTabsPreferences()
9+
{
10+
// Services
11+
var multitaskingContext = Ioc.Default.GetRequiredService<IMultitaskingContext>();
12+
var layoutSettingsService = Ioc.Default.GetRequiredService<ILayoutSettingsService>();
13+
14+
// Get all tab instances and active path
15+
var tabs = multitaskingContext.Control?.GetAllTabInstances();
16+
var activePath = (multitaskingContext.CurrentTabItem?.TabItemContent as ShellPanesPage)?.ActivePane?.TabBarItemParameter?.NavigationParameter as string;
17+
18+
// Return if required data is missing
19+
if (tabs is null || activePath is null)
20+
return;
21+
22+
for (int i = 0; i < tabs.Count; i++)
23+
{
24+
var isNotCurrentTab = i != multitaskingContext.CurrentTabIndex;
25+
var shPage = tabs[i] as ShellPanesPage;
26+
27+
if (shPage is not null)
28+
{
29+
foreach (var pane in shPage.GetPanes())
30+
{
31+
var path = pane.ShellViewModel?.CurrentFolder?.ItemPath;
32+
33+
// Skip panes without a valid path
34+
if (path is null)
35+
continue;
36+
37+
// Check if we need to update preferences for this pane
38+
if ((isNotCurrentTab || pane != shPage.ActivePane) &&
39+
(layoutSettingsService.SyncFolderPreferencesAcrossDirectories ||
40+
path.Equals(activePath, StringComparison.OrdinalIgnoreCase)))
41+
if (pane.SlimContentPage is BaseLayoutPage page)
42+
page.FolderSettings?.ReloadGroupAndSortPreferences(path);
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}

src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs

+18
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,24 @@ public Type GetLayoutType(string path, bool changeLayoutMode = true)
225225
};
226226
}
227227

228+
public void ReloadGroupAndSortPreferences(string? path)
229+
{
230+
if (string.IsNullOrWhiteSpace(path))
231+
return;
232+
233+
var preferencesItem = GetLayoutPreferencesForPath(path);
234+
if (preferencesItem is null)
235+
return;
236+
237+
DirectorySortOption = preferencesItem.DirectorySortOption;
238+
DirectorySortDirection = preferencesItem.DirectorySortDirection;
239+
DirectoryGroupOption = preferencesItem.DirectoryGroupOption;
240+
DirectoryGroupByDateUnit = preferencesItem.DirectoryGroupByDateUnit;
241+
DirectoryGroupDirection = preferencesItem.DirectoryGroupDirection;
242+
SortDirectoriesAlongsideFiles = preferencesItem.SortDirectoriesAlongsideFiles;
243+
SortFilesFirst = preferencesItem.SortFilesFirst;
244+
}
245+
228246
public bool IsPathUsingDefaultLayout(string? path)
229247
{
230248
return UserSettingsService.LayoutSettingsService.SyncFolderPreferencesAcrossDirectories ||

src/Files.App/Views/ShellPanesPage.xaml.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,12 @@ public void FocusOtherPane()
356356
GetPane(0)?.Focus(FocusState.Programmatic);
357357
}
358358

359+
/// <inheritdoc/>
360+
public IEnumerable<ModernShellPage> GetPanes()
361+
{
362+
return RootGrid.Children.Where(x => RootGrid.Children.IndexOf(x) % 2 == 0).Cast<ModernShellPage>();
363+
}
364+
359365
// Private methods
360366

361367
private ModernShellPage? GetPane(int index = -1)
@@ -372,11 +378,6 @@ private int GetPaneCount()
372378
return (RootGrid.Children.Count + 1) / 2;
373379
}
374380

375-
private IEnumerable<ModernShellPage> GetPanes()
376-
{
377-
return RootGrid.Children.Where(x => RootGrid.Children.IndexOf(x) % 2 == 0).Cast<ModernShellPage>();
378-
}
379-
380381
private IEnumerable<GridSplitter> GetSizers()
381382
{
382383
return RootGrid.Children.Where(x => RootGrid.Children.IndexOf(x) % 2 == 1).Cast<GridSplitter>();

0 commit comments

Comments
 (0)