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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
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
7 changes: 7 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;
DisplayContext.UpdateAllTabsAndPanesLayout();

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

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

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

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

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

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

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;
displayContext.UpdateAllTabsAndPanesLayout();

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

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

return Task.CompletedTask;
}
Expand Down Expand Up @@ -273,6 +276,8 @@ public Task ExecuteAsync(object? parameter = null)
context.SortDirection is SortDirection.Descending
? SortDirection.Ascending
: SortDirection.Descending;

context.UpdateAllTabsAndPanesLayout();

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;
context.UpdateAllTabsAndPanesLayout();

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;
context.UpdateAllTabsAndPanesLayout();

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;
context.UpdateAllTabsAndPanesLayout();

return Task.CompletedTask;
}
Expand Down
14 changes: 14 additions & 0 deletions src/Files.App/Data/Contexts/DisplayPage/DisplayPageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ public DisplayPageContext()
layoutSettingsService.PropertyChanged += Settings_PropertyChanged;
}

public void UpdateAllTabsAndPanesLayout()
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
{
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);
}
}

private void Context_Changing(object? sender, EventArgs e)
{
var viewModel = FolderSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ public interface IDisplayPageContext : INotifyPropertyChanging, INotifyPropertyC

bool SortDirectoriesAlongsideFiles { get; set; }
bool SortFilesFirst { get; set; }

void UpdateAllTabsAndPanesLayout();
}
}
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);
}
}
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to reload the preferences, or can we simplify this further by just invoking the related events (eg GroupDirectionPreferenceUpdated)?

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