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 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 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,10 @@ public interface IShellPanesPage : IDisposable, INotifyPropertyChanged
/// Focuses the other pane.
/// </summary>
public void FocusOtherPane();

/// <summary>
/// Updates the layout of open panes.
/// </summary>
public void UpdatePanesLayout();
}
}
16 changes: 16 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,22 @@ 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;
}

public bool IsPathUsingDefaultLayout(string? path)
{
return UserSettingsService.LayoutSettingsService.SyncFolderPreferencesAcrossDirectories ||
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public async void MultitaskingControl_CurrentInstanceChanged(object? sender, Cur
{
SidebarAdaptiveViewModel.PaneHolder = currentInstance;
SidebarAdaptiveViewModel.PaneHolder.PropertyChanged += PaneHolder_PropertyChanged;
currentInstance.UpdatePanesLayout();
}
SidebarAdaptiveViewModel.NotifyInstanceRelatedPropertiesChanged((navArgs as PaneNavigationArguments)?.LeftPaneNavPathParam);

Expand Down
50 changes: 50 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,13 @@ public void FocusOtherPane()
GetPane(0)?.Focus(FocusState.Programmatic);
}

/// <inheritdoc/>
public void UpdatePanesLayout()
{
foreach (var pane in GetPanes())
UpdatePaneLayout(pane);
}

// Private methods

private ModernShellPage? GetPane(int index = -1)
Expand Down Expand Up @@ -459,6 +467,9 @@ RootGrid.ColumnDefinitions.Count is 0
// Focus
ActivePane = GetPane(GetPaneCount() - 1);

UnHookLayoutUpdateRequiredEvent();
HookLayoutUpdateRequiredEvent();

NotifyPropertyChanged(nameof(IsMultiPaneActive));
}

Expand Down Expand Up @@ -523,6 +534,7 @@ private void RemovePane(int index = -1)
}

Pane_ContentChanged(null, null!);
UnHookLayoutUpdateRequiredEvent();
NotifyPropertyChanged(nameof(IsMultiPaneActive));
}

Expand Down Expand Up @@ -552,6 +564,18 @@ private void SetShadow()
}
}

private void HookLayoutUpdateRequiredEvent()
{
foreach (var pane in GetPanes())
pane.FolderSettings.LayoutPreferencesUpdateRequired += FolderSettings_LayoutPreferencesUpdateRequired;
}

private void UnHookLayoutUpdateRequiredEvent()
{
foreach (var pane in GetPanes())
pane.FolderSettings.LayoutPreferencesUpdateRequired -= FolderSettings_LayoutPreferencesUpdateRequired;
}

// Override methods

protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
Expand Down Expand Up @@ -603,6 +627,13 @@ paneArgs.ShellPaneArrangement is ShellPaneArrangement.None
};
}

private void UpdatePaneLayout(IShellPage pane)
{
var page = pane.SlimContentPage as BaseLayoutPage;
var path = pane.ShellViewModel.CurrentFolder?.ItemPath;
page?.FolderSettings?.UpdateGroupAndSortOptions(path);
}

// Event methods

public Task TabItemDragOver(object sender, DragEventArgs e)
Expand Down Expand Up @@ -724,6 +755,24 @@ private void Sizer_ManipulationCompleted(object sender, ManipulationCompletedRou
this.ChangeCursor(InputSystemCursor.Create(InputSystemCursorShape.Arrow));
}

private void FolderSettings_LayoutPreferencesUpdateRequired(object? sender, LayoutPreferenceEventArgs e)
{
var currentPath = ActivePane?.TabBarItemParameter?.NavigationParameter as string;
if (string.IsNullOrEmpty(currentPath))
return;

foreach (var pane in GetPanes())
{
if (pane != ActivePane &&
(LayoutSettingsService.SyncFolderPreferencesAcrossDirectories ||
pane.TabBarItemParameter?.NavigationParameter is string path &&
path.Equals(currentPath, StringComparison.OrdinalIgnoreCase)))
{
UpdatePaneLayout(pane);
}
}
}

private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
Expand All @@ -743,6 +792,7 @@ public void Dispose()
pane.GotFocus -= Pane_GotFocus;
pane.RightTapped -= Pane_RightTapped;
pane.PointerPressed -= Pane_PointerPressed;
pane.FolderSettings.LayoutPreferencesUpdateRequired -= FolderSettings_LayoutPreferencesUpdateRequired;
pane.Dispose();
}

Expand Down