Skip to content

Commit

Permalink
Fix: Fixed issue where changing a folder's grouping preference wouldn…
Browse files Browse the repository at this point in the history
…'t update other open tabs (files-community#16572)
  • Loading branch information
ferrariofilippo authored Jan 26, 2025
1 parent 02c2320 commit f20e3a9
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/Files.App/Actions/Display/GroupAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public GroupByAction()
public Task ExecuteAsync(object? parameter = null)
{
DisplayContext.GroupOption = GroupOption;
LayoutHelpers.UpdateOpenTabsPreferences();

return Task.CompletedTask;
}
Expand Down Expand Up @@ -377,6 +378,7 @@ public Task ExecuteAsync(object? parameter = null)
{
DisplayContext.GroupOption = GroupOption;
DisplayContext.GroupByDateUnit = GroupByDateUnit;
LayoutHelpers.UpdateOpenTabsPreferences();

return Task.CompletedTask;
}
Expand Down Expand Up @@ -425,6 +427,7 @@ public GroupAscendingAction()
public Task ExecuteAsync(object? parameter = null)
{
context.GroupDirection = SortDirection.Ascending;
LayoutHelpers.UpdateOpenTabsPreferences();

return Task.CompletedTask;
}
Expand Down Expand Up @@ -469,6 +472,7 @@ public GroupDescendingAction()
public Task ExecuteAsync(object? parameter = null)
{
context.GroupDirection = SortDirection.Descending;
LayoutHelpers.UpdateOpenTabsPreferences();

return Task.CompletedTask;
}
Expand Down Expand Up @@ -505,6 +509,7 @@ public ToggleGroupDirectionAction()
public Task ExecuteAsync(object? parameter = null)
{
context.GroupDirection = context.SortDirection is SortDirection.Descending ? SortDirection.Ascending : SortDirection.Descending;
LayoutHelpers.UpdateOpenTabsPreferences();

return Task.CompletedTask;
}
Expand Down Expand Up @@ -536,6 +541,7 @@ public GroupByYearAction()
public Task ExecuteAsync(object? parameter = null)
{
context.GroupByDateUnit = GroupByDateUnit.Year;
LayoutHelpers.UpdateOpenTabsPreferences();

return Task.CompletedTask;
}
Expand Down Expand Up @@ -580,6 +586,7 @@ public GroupByMonthAction()
public Task ExecuteAsync(object? parameter = null)
{
context.GroupByDateUnit = GroupByDateUnit.Month;
LayoutHelpers.UpdateOpenTabsPreferences();

return Task.CompletedTask;
}
Expand Down Expand Up @@ -621,6 +628,7 @@ public Task ExecuteAsync(object? parameter = null)
GroupByDateUnit.Month => GroupByDateUnit.Day,
_ => GroupByDateUnit.Year
};
LayoutHelpers.UpdateOpenTabsPreferences();

return Task.CompletedTask;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Files.App/Actions/Display/SortAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public SortByAction()
public Task ExecuteAsync(object? parameter = null)
{
displayContext.SortOption = SortOption;
LayoutHelpers.UpdateOpenTabsPreferences();

return Task.CompletedTask;
}
Expand Down Expand Up @@ -207,6 +208,7 @@ public SortAscendingAction()
public Task ExecuteAsync(object? parameter = null)
{
context.SortDirection = SortDirection.Ascending;
LayoutHelpers.UpdateOpenTabsPreferences();

return Task.CompletedTask;
}
Expand Down Expand Up @@ -241,6 +243,7 @@ public SortDescendingAction()
public Task ExecuteAsync(object? parameter = null)
{
context.SortDirection = SortDirection.Descending;
LayoutHelpers.UpdateOpenTabsPreferences();

return Task.CompletedTask;
}
Expand Down Expand Up @@ -274,6 +277,8 @@ context.SortDirection is SortDirection.Descending
? SortDirection.Ascending
: SortDirection.Descending;

LayoutHelpers.UpdateOpenTabsPreferences();

return Task.CompletedTask;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public SortFilesAndFoldersTogetherAction()
public Task ExecuteAsync(object? parameter = null)
{
context.SortDirectoriesAlongsideFiles = true;
LayoutHelpers.UpdateOpenTabsPreferences();

return Task.CompletedTask;
}
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Actions/Display/SortFilesFirstAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public Task ExecuteAsync(object? parameter = null)
{
context.SortFilesFirst = true;
context.SortDirectoriesAlongsideFiles = false;
LayoutHelpers.UpdateOpenTabsPreferences();

return Task.CompletedTask;
}
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Actions/Display/SortFoldersFirstAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public Task ExecuteAsync(object? parameter = null)
{
context.SortFilesFirst = false;
context.SortDirectoriesAlongsideFiles = false;
LayoutHelpers.UpdateOpenTabsPreferences();

return Task.CompletedTask;
}
Expand Down
6 changes: 6 additions & 0 deletions src/Files.App/Data/Contracts/IShellPanesPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,11 @@ public interface IShellPanesPage : IDisposable, INotifyPropertyChanged
/// Focuses the other pane.
/// </summary>
public void FocusOtherPane();

/// <summary>
/// Gets open panes.
/// </summary>
/// <returns>An enumerable containing open panes.</returns>
public IEnumerable<ModernShellPage> GetPanes();
}
}
48 changes: 48 additions & 0 deletions src/Files.App/Helpers/Layout/LayoutHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

namespace Files.App.Helpers
{
static class LayoutHelpers
{
public static void UpdateOpenTabsPreferences()
{
// Services
var multitaskingContext = Ioc.Default.GetRequiredService<IMultitaskingContext>();
var layoutSettingsService = Ioc.Default.GetRequiredService<ILayoutSettingsService>();

// Get all tab instances and active path
var tabs = multitaskingContext.Control?.GetAllTabInstances();
var activePath = (multitaskingContext.CurrentTabItem?.TabItemContent as ShellPanesPage)?.ActivePane?.TabBarItemParameter?.NavigationParameter as string;

// Return if required data is missing
if (tabs is null || activePath is null)
return;

for (int i = 0; i < tabs.Count; i++)
{
var isNotCurrentTab = i != multitaskingContext.CurrentTabIndex;
var shPage = tabs[i] as ShellPanesPage;

if (shPage is not null)
{
foreach (var pane in shPage.GetPanes())
{
var path = pane.ShellViewModel?.CurrentFolder?.ItemPath;

// Skip panes without a valid path
if (path is null)
continue;

// Check if we need to update preferences for this pane
if ((isNotCurrentTab || pane != shPage.ActivePane) &&
(layoutSettingsService.SyncFolderPreferencesAcrossDirectories ||
path.Equals(activePath, StringComparison.OrdinalIgnoreCase)))
if (pane.SlimContentPage is BaseLayoutPage page)
page.FolderSettings?.ReloadGroupAndSortPreferences(path);
}
}
}
}
}
}
18 changes: 18 additions & 0 deletions src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,24 @@ public Type GetLayoutType(string path, bool changeLayoutMode = true)
};
}

public void ReloadGroupAndSortPreferences(string? path)
{
if (string.IsNullOrWhiteSpace(path))
return;

var preferencesItem = GetLayoutPreferencesForPath(path);
if (preferencesItem is null)
return;

DirectorySortOption = preferencesItem.DirectorySortOption;
DirectorySortDirection = preferencesItem.DirectorySortDirection;
DirectoryGroupOption = preferencesItem.DirectoryGroupOption;
DirectoryGroupByDateUnit = preferencesItem.DirectoryGroupByDateUnit;
DirectoryGroupDirection = preferencesItem.DirectoryGroupDirection;
SortDirectoriesAlongsideFiles = preferencesItem.SortDirectoriesAlongsideFiles;
SortFilesFirst = preferencesItem.SortFilesFirst;
}

public bool IsPathUsingDefaultLayout(string? path)
{
return UserSettingsService.LayoutSettingsService.SyncFolderPreferencesAcrossDirectories ||
Expand Down
11 changes: 6 additions & 5 deletions src/Files.App/Views/ShellPanesPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,12 @@ public void FocusOtherPane()
GetPane(0)?.Focus(FocusState.Programmatic);
}

/// <inheritdoc/>
public IEnumerable<ModernShellPage> GetPanes()
{
return RootGrid.Children.Where(x => RootGrid.Children.IndexOf(x) % 2 == 0).Cast<ModernShellPage>();
}

// Private methods

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

private IEnumerable<ModernShellPage> GetPanes()
{
return RootGrid.Children.Where(x => RootGrid.Children.IndexOf(x) % 2 == 0).Cast<ModernShellPage>();
}

private IEnumerable<GridSplitter> GetSizers()
{
return RootGrid.Children.Where(x => RootGrid.Children.IndexOf(x) % 2 == 1).Cast<GridSplitter>();
Expand Down

0 comments on commit f20e3a9

Please sign in to comment.