Skip to content

Commit

Permalink
Requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ferrariofilippo committed Dec 15, 2024
1 parent 520057b commit 2c33a81
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Files.App/Data/Contracts/IShellPanesPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ public interface IShellPanesPage : IDisposable, INotifyPropertyChanged
/// <summary>
/// Updates the layout of open panes.
/// </summary>
public void UpdatePanesLayout(bool inlcudeActive = true);
public void UpdatePanesLayout();
}
}
45 changes: 39 additions & 6 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 @@ -357,13 +358,10 @@ public void FocusOtherPane()
}

/// <inheritdoc/>
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
Expand Down Expand Up @@ -469,6 +467,9 @@ RootGrid.ColumnDefinitions.Count is 0
// Focus
ActivePane = GetPane(GetPaneCount() - 1);

UnHookLayoutUpdateRequiredEvent();
HookLayoutUpdateRequiredEvent();

NotifyPropertyChanged(nameof(IsMultiPaneActive));
}

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

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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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));
Expand All @@ -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();
}

Expand Down
2 changes: 0 additions & 2 deletions src/Files.App/Views/Shells/BaseShellPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2c33a81

Please sign in to comment.