Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fixed issue where changing a folder's grouping preference wouldn't update other open tabs #16572

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 7 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,12 @@ public interface IShellPanesPage : IDisposable, INotifyPropertyChanged
/// Focuses the other pane.
/// </summary>
public void FocusOtherPane();

/// <summary>
/// Updates the layout of open panes.
/// </summary>
/// <param name="targetPath">The path of panes to update</param>
/// <param name="includeActivePane">Whether the active pane should be updated or not</param>
public void UpdatePanesLayout(string targetPath, bool includeActivePane = false);
}
}
22 changes: 22 additions & 0 deletions src/Files.App/Helpers/Layout/LayoutHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

namespace Files.App.Helpers
{
static class LayoutHelpers
{
public static void UpdateOpenTabsPreferences()
{
var multitaskingContext = Ioc.Default.GetRequiredService<IMultitaskingContext>();
var tabs = multitaskingContext.Control?.GetAllTabInstances();
var activePath = ((ShellPanesPage)multitaskingContext.CurrentTabItem.TabItemContent)?.ActivePane?.TabBarItemParameter?.NavigationParameter as string;
if (tabs is null || activePath is null)
return;

for (int i = 0; i < tabs.Count; i++)
{
((ShellPanesPage)tabs[i]).UpdatePanesLayout(activePath, i != multitaskingContext.CurrentTabIndex);
}
}
}
}
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 @@ -265,6 +265,24 @@ public Type GetLayoutType(string path, bool changeLayoutMode = true)
};
}

public void UpdateGroupAndSortOptions(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
18 changes: 18 additions & 0 deletions src/Files.App/Views/ShellPanesPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public sealed partial class ShellPanesPage : Page, IShellPanesPage, ITabBarItemC
// Dependency injections

private IGeneralSettingsService GeneralSettingsService { get; } = Ioc.Default.GetRequiredService<IGeneralSettingsService>();
private ILayoutSettingsService LayoutSettingsService { get; } = Ioc.Default.GetRequiredService<ILayoutSettingsService>();
private AppModel AppModel { get; } = Ioc.Default.GetRequiredService<AppModel>();

// Constants
Expand Down Expand Up @@ -356,6 +357,23 @@ public void FocusOtherPane()
GetPane(0)?.Focus(FocusState.Programmatic);
}

/// <inheritdoc/>
public void UpdatePanesLayout(string targetPath, bool includeActivePane = false)
{
foreach (var pane in GetPanes())
{
var path = pane.ShellViewModel.CurrentFolder?.ItemPath;
if ((includeActivePane || pane != ActivePane) &&
(LayoutSettingsService.SyncFolderPreferencesAcrossDirectories ||
path is not null &&
path.Equals(targetPath, StringComparison.OrdinalIgnoreCase)))
{
var page = pane.SlimContentPage as BaseLayoutPage;
page?.FolderSettings?.UpdateGroupAndSortOptions(path);
}
}
}

// Private methods

private ModernShellPage? GetPane(int index = -1)
Expand Down