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

Code Quality: Introduce flexible pane generation 1 #15368

Merged
merged 4 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task ExecuteAsync(object? parameter = null)

if (arguments is null)
{
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home", true);
await NavigationHelpers.AddNewTabByPathAsync(typeof(MainPanesPage), "Home", true);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task ExecuteAsync(object? parameter = null)

if (arguments is null)
{
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home", true);
0x5bfa marked this conversation as resolved.
Show resolved Hide resolved
await NavigationHelpers.AddNewTabByPathAsync(typeof(MainPanesPage), "Home", true);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task ExecuteAsync(object? parameter = null)
await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
{
await NavigationHelpers.AddNewTabByPathAsync(
typeof(PaneHolderPage),
typeof(MainPanesPage),
(listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath,
false);
},
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private async void Window_Closed(object sender, WindowEventArgs args)
if (instance is null)
return;

var items = (instance.TabItemContent as PaneHolderPage)?.ActivePane?.SlimContentPage?.SelectedItems;
var items = (instance.TabItemContent as MainPanesPage)?.ActivePane?.SlimContentPage?.SelectedItems;
if (items is null)
return;

Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public static class UI

// For contextmenu hacks
public const double ContextMenuItemsMaxWidth = 250;

public const double MultiplePaneWidthThreshold = 750;
}

public static class Appearance
Expand Down
14 changes: 7 additions & 7 deletions src/Files.App/Data/Contexts/ContentPage/ContentPageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ internal sealed class ContentPageContext : ObservableObject, IContentPageContext
{
private static readonly IReadOnlyList<ListedItem> emptyItems = Enumerable.Empty<ListedItem>().ToImmutableList();

private readonly IPageContext context = Ioc.Default.GetRequiredService<IPageContext>();
private readonly IMultiPanesContext context = Ioc.Default.GetRequiredService<IMultiPanesContext>();

private ItemViewModel? filesystemViewModel;

public IShellPage? ShellPage => context?.PaneOrColumn;
public IShellPage? ShellPage => context?.ActivePaneOrColumn;

public Type PageLayoutType => ShellPage?.CurrentPageType ?? typeof(DetailsLayoutPage);

Expand Down Expand Up @@ -55,8 +55,8 @@ internal sealed class ContentPageContext : ObservableObject, IContentPageContext

public ContentPageContext()
{
context.Changing += Context_Changing;
context.Changed += Context_Changed;
context.ActivePane_Changing += Context_Changing;
context.ActivePane_Changed += Context_Changed;
GitHelpers.IsExecutingGitActionChanged += GitHelpers_IsExecutingGitActionChanged;

Update();
Expand Down Expand Up @@ -122,14 +122,14 @@ private void Page_PropertyChanged(object? sender, PropertyChangedEventArgs e)
}
}

private void Page_ContentChanged(object? sender, CustomTabViewItemParameter e) => Update();
private void Page_ContentChanged(object? sender, TabBarItemParameter e) => Update();

private void PaneHolder_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IPaneHolder.IsMultiPaneEnabled):
case nameof(IPaneHolder.IsMultiPaneActive):
case nameof(IPanesPage.IsMultiPaneEnabled):
case nameof(IPanesPage.IsMultiPaneActive):
OnPropertyChanged(e.PropertyName);
break;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Files.App/Data/Contexts/DisplayPage/DisplayPageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Files.App.Data.Contexts
{
internal sealed class DisplayPageContext : ObservableObject, IDisplayPageContext
{
private readonly IPageContext context = Ioc.Default.GetRequiredService<IPageContext>();
private readonly IMultiPanesContext context = Ioc.Default.GetRequiredService<IMultiPanesContext>();
private readonly IFoldersSettingsService settings = Ioc.Default.GetRequiredService<IFoldersSettingsService>();
private readonly ILayoutSettingsService layoutSettingsService = Ioc.Default.GetRequiredService<ILayoutSettingsService>();

Expand Down Expand Up @@ -125,12 +125,12 @@ public bool SortFilesFirst
}
}

private LayoutPreferencesManager? FolderSettings => context.PaneOrColumn?.InstanceViewModel?.FolderSettings;
private LayoutPreferencesManager? FolderSettings => context.ActivePaneOrColumn?.InstanceViewModel?.FolderSettings;

public DisplayPageContext()
{
context.Changing += Context_Changing;
context.Changed += Context_Changed;
context.ActivePane_Changing += Context_Changing;
context.ActivePane_Changed += Context_Changed;
layoutSettingsService.PropertyChanged += Settings_PropertyChanged;
}

Expand Down
31 changes: 31 additions & 0 deletions src/Files.App/Data/Contexts/MultiPanes/IMultiPanesContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Data.Contexts
{
/// <summary>
/// Represents context for <see cref="MainPanesPage"/>, which manages multiple panes.
/// </summary>
public interface IMultiPanesContext
{
/// <summary>
/// Gets invoked when active pane is changing.
/// </summary>
event EventHandler? ActivePane_Changing;

/// <summary>
/// Gets invoked when active pane is changed.
/// </summary>
event EventHandler? ActivePane_Changed;
yaira2 marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Gets active pane.
/// </summary>
IShellPage? ActivePane { get; }

/// <summary>
/// Gets active pane or column.
/// </summary>
IShellPage? ActivePaneOrColumn { get; }
}
}
98 changes: 98 additions & 0 deletions src/Files.App/Data/Contexts/MultiPanes/MultiPanesContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Data.Contexts
{
/// <inheritdoc cref="IMultiPanesContext"/>
internal sealed class MultiPanesContext : IMultiPanesContext
{
private MainPanesPage? _mainPanesPage;

private IShellPage? _ActivePane;
/// <inheritdoc/>
public IShellPage? ActivePane
=> _ActivePane;

private IShellPage? _ActivePaneOrColumn;
/// <inheritdoc/>
public IShellPage? ActivePaneOrColumn
=> _ActivePaneOrColumn;

/// <inheritdoc/>
public event EventHandler? ActivePane_Changing;

/// <inheritdoc/>
public event EventHandler? ActivePane_Changed;

/// <summary>
/// Initializes an instance of <see cref="MultiPanesContext"/>.
/// </summary>
public MultiPanesContext()
{
MainPanesPage.CurrentInstanceChanged += Page_CurrentInstanceChanged;
}

private void Page_CurrentInstanceChanged(object? sender, MainPanesPage? modifiedPage)
{
if (_mainPanesPage is not null && !_mainPanesPage.IsCurrentInstance)
{
UpdatePage(null);
}
else if (modifiedPage is not null && modifiedPage.IsCurrentInstance)
{
UpdatePage(modifiedPage);
}
}

private void Page_ContentChanged(object? sender, TabBarItemParameter e)
{
UpdateContent();
}

private void Page_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IPanesPage.ActivePaneOrColumn):
UpdateContent();
break;
}
}

private void UpdatePage(MainPanesPage? newPage)
{
if (Equals(_mainPanesPage, newPage))
return;

if (_mainPanesPage is not null)
{
_mainPanesPage.ContentChanged -= Page_ContentChanged;
_mainPanesPage.PropertyChanged -= Page_PropertyChanged;
}

_mainPanesPage = newPage;

if (_mainPanesPage is not null)
{
_mainPanesPage.ContentChanged += Page_ContentChanged;
_mainPanesPage.PropertyChanged += Page_PropertyChanged;
}

UpdateContent();
}

private void UpdateContent()
{
if (_ActivePane == _mainPanesPage?.ActivePane &&
_ActivePaneOrColumn == _mainPanesPage?.ActivePaneOrColumn)
return;

ActivePane_Changing?.Invoke(this, EventArgs.Empty);

_ActivePane = _mainPanesPage?.ActivePane;
_ActivePaneOrColumn = _mainPanesPage?.ActivePaneOrColumn;

ActivePane_Changed?.Invoke(this, EventArgs.Empty);
}
}
}
16 changes: 0 additions & 16 deletions src/Files.App/Data/Contexts/Page/IPageContext.cs

This file was deleted.

89 changes: 0 additions & 89 deletions src/Files.App/Data/Contexts/Page/PageContext.cs

This file was deleted.

10 changes: 10 additions & 0 deletions src/Files.App/Data/Contracts/IMultiPaneInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Data.Contracts
{
public interface IMultiPaneInfo
{
public IPanesPage PaneHolder { get; }
}
}
31 changes: 31 additions & 0 deletions src/Files.App/Data/Contracts/IPanesPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Data.Contracts
{
public interface IPanesPage : IDisposable, INotifyPropertyChanged
{
public IShellPage? ActivePane { get; set; }

// If column view, returns the last column shell page, otherwise returns the active pane normally
public IShellPage? ActivePaneOrColumn { get; }

public IFilesystemHelpers? FilesystemHelpers { get; }

public TabBarItemParameter? TabBarItemParameter { get; set; }

public void OpenPathInNewPane(string path);

public void CloseActivePane();

public bool IsLeftPaneActive { get; }

public bool IsRightPaneActive { get; }

// Another pane is shown
public bool IsMultiPaneActive { get; }

// Multi pane is enabled
public bool IsMultiPaneEnabled { get; }
}
}