diff --git a/src/Files.App/Data/Contracts/IShellPanesPage.cs b/src/Files.App/Data/Contracts/IShellPanesPage.cs index edd26225fae4..f576fc780787 100644 --- a/src/Files.App/Data/Contracts/IShellPanesPage.cs +++ b/src/Files.App/Data/Contracts/IShellPanesPage.cs @@ -62,6 +62,6 @@ public interface IShellPanesPage : IDisposable, INotifyPropertyChanged /// /// Updates the layout of open panes. /// - public void UpdatePanesLayout(bool inlcudeActive = true); + public void UpdatePanesLayout(); } } diff --git a/src/Files.App/Views/ShellPanesPage.xaml.cs b/src/Files.App/Views/ShellPanesPage.xaml.cs index 33693a6a9696..cf044f8ecf15 100644 --- a/src/Files.App/Views/ShellPanesPage.xaml.cs +++ b/src/Files.App/Views/ShellPanesPage.xaml.cs @@ -19,6 +19,7 @@ public sealed partial class ShellPanesPage : Page, IShellPanesPage, ITabBarItemC // Dependency injections private IGeneralSettingsService GeneralSettingsService { get; } = Ioc.Default.GetRequiredService(); + private ILayoutSettingsService LayoutSettingsService { get; } = Ioc.Default.GetRequiredService(); private AppModel AppModel { get; } = Ioc.Default.GetRequiredService(); // Constants @@ -357,13 +358,10 @@ public void FocusOtherPane() } /// - public void UpdatePanesLayout(bool inlcudeActive = true) + public void UpdatePanesLayout() { - if (GetPane(0) is IShellPage leftPane && (inlcudeActive || leftPane != ActivePane)) - UpdatePaneLayout(leftPane); - - if (GetPane(1) is IShellPage rightPane && (inlcudeActive || rightPane != ActivePane)) - UpdatePaneLayout(rightPane); + foreach (var pane in GetPanes()) + UpdatePaneLayout(pane); } // Private methods @@ -469,6 +467,9 @@ RootGrid.ColumnDefinitions.Count is 0 // Focus ActivePane = GetPane(GetPaneCount() - 1); + UnHookLayoutUpdateRequiredEvent(); + HookLayoutUpdateRequiredEvent(); + NotifyPropertyChanged(nameof(IsMultiPaneActive)); } @@ -533,6 +534,7 @@ private void RemovePane(int index = -1) } Pane_ContentChanged(null, null!); + UnHookLayoutUpdateRequiredEvent(); NotifyPropertyChanged(nameof(IsMultiPaneActive)); } @@ -562,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) @@ -740,6 +754,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)); @@ -759,6 +791,7 @@ public void Dispose() pane.GotFocus -= Pane_GotFocus; pane.RightTapped -= Pane_RightTapped; pane.PointerPressed -= Pane_PointerPressed; + pane.FolderSettings.LayoutPreferencesUpdateRequired -= FolderSettings_LayoutPreferencesUpdateRequired; pane.Dispose(); } diff --git a/src/Files.App/Views/Shells/BaseShellPage.cs b/src/Files.App/Views/Shells/BaseShellPage.cs index 074cbcda3224..3c9e57ffd48d 100644 --- a/src/Files.App/Views/Shells/BaseShellPage.cs +++ b/src/Files.App/Views/Shells/BaseShellPage.cs @@ -707,8 +707,6 @@ private void FolderSettings_LayoutPreferencesUpdateRequired(object sender, Layou LayoutPreferencesManager.SetLayoutPreferencesForPath(ShellViewModel.WorkingDirectory, e.LayoutPreference); if (e.IsAdaptiveLayoutUpdateRequired) AdaptiveLayoutHelpers.ApplyAdaptativeLayout(InstanceViewModel.FolderSettings, ShellViewModel.FilesAndFolders.ToList()); - - _PaneHolder.UpdatePanesLayout(false); } protected virtual void ViewModel_WorkingDirectoryModified(object sender, WorkingDirectoryModifiedEventArgs e)