From c9a5ecf438f1ab99fbba3f49049d95ba4b0334bf Mon Sep 17 00:00:00 2001 From: Quaint Mako <110472580+QuaintMako@users.noreply.github.com> Date: Thu, 29 Dec 2022 00:34:05 +0100 Subject: [PATCH 01/19] Removed PaneControl --- .../UserControls/Pane/PaneControl.xaml | 16 ----- .../UserControls/Pane/PaneControl.xaml.cs | 64 ------------------- .../UserControls/Pane/PreviewPane.xaml.cs | 3 + src/Files.App/Views/MainPage.xaml | 4 +- src/Files.App/Views/MainPage.xaml.cs | 30 ++++----- 5 files changed, 20 insertions(+), 97 deletions(-) delete mode 100644 src/Files.App/UserControls/Pane/PaneControl.xaml delete mode 100644 src/Files.App/UserControls/Pane/PaneControl.xaml.cs diff --git a/src/Files.App/UserControls/Pane/PaneControl.xaml b/src/Files.App/UserControls/Pane/PaneControl.xaml deleted file mode 100644 index 07762ba559bf..000000000000 --- a/src/Files.App/UserControls/Pane/PaneControl.xaml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/Files.App/UserControls/Pane/PaneControl.xaml.cs b/src/Files.App/UserControls/Pane/PaneControl.xaml.cs deleted file mode 100644 index 7da41c562512..000000000000 --- a/src/Files.App/UserControls/Pane/PaneControl.xaml.cs +++ /dev/null @@ -1,64 +0,0 @@ -using CommunityToolkit.Mvvm.DependencyInjection; -using Files.Backend.Services.Settings; -using Files.Shared.Enums; -using Microsoft.UI.Xaml.Controls; -using System.ComponentModel; - -namespace Files.App.UserControls -{ - public sealed partial class PaneControl : UserControl, IPane - { - private PaneContents content; - - private IPaneSettingsService PaneSettingsService { get; } = Ioc.Default.GetService(); - - public PanePositions Position => Panel.Content is IPane pane ? pane.Position : PanePositions.Right; - - public PaneControl() - { - InitializeComponent(); - - PaneSettingsService.PropertyChanged += PaneService_PropertyChanged; - Update(); - } - - public void UpdatePosition(double panelWidth, double panelHeight) - { - if (Panel.Content is IPane pane) - { - pane.UpdatePosition(panelWidth, panelHeight); - } - if (Panel.Content is Control control) - { - MinWidth = control.MinWidth; - MaxWidth = control.MaxWidth; - MinHeight = control.MinHeight; - MaxHeight = control.MaxHeight; - } - } - - private void PaneService_PropertyChanged(object sender, PropertyChangedEventArgs e) - { - if (e.PropertyName is nameof(IPaneSettingsService.Content)) - { - Update(); - } - } - - private void Update() - { - var newContent = PaneSettingsService.Content; - if (content != newContent) - { - content = newContent; - Panel.Content = GetPane(content); - } - } - - private static Control GetPane(PaneContents content) => content switch - { - PaneContents.Preview => new PreviewPane(), - _ => null, - }; - } -} diff --git a/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs b/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs index 7dfeece64521..a73e1c8afefd 100644 --- a/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs +++ b/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs @@ -6,6 +6,7 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Input; +using System.ComponentModel; namespace Files.App.UserControls { @@ -39,11 +40,13 @@ public void UpdatePosition(double panelWidth, double panelHeight) private void Root_Loading(FrameworkElement sender, object args) => ViewModel.UpdateSelectedItemPreview(); + private void Root_Unloaded(object sender, RoutedEventArgs e) { PreviewControlPresenter.Content = null; Bindings.StopTracking(); } + private void Root_SizeChanged(object sender, SizeChangedEventArgs e) => Context.IsHorizontal = Root.ActualWidth >= Root.ActualHeight; diff --git a/src/Files.App/Views/MainPage.xaml b/src/Files.App/Views/MainPage.xaml index 4159bfa9399b..dbb00357644d 100644 --- a/src/Files.App/Views/MainPage.xaml +++ b/src/Files.App/Views/MainPage.xaml @@ -331,8 +331,8 @@ ResizeBehavior="BasedOnAlignment" Style="{StaticResource DefaultGridSplitterStyle}" /> - private void UpdatePositioning() { - if (Pane is null || !IsPaneEnabled) + if (PreviewPane is null || !IsPaneEnabled) { PaneRow.MinHeight = 0; PaneRow.MaxHeight = double.MaxValue; @@ -418,8 +418,8 @@ private void UpdatePositioning() } else { - Pane.UpdatePosition(RootGrid.ActualWidth, RootGrid.ActualHeight); - switch (Pane.Position) + PreviewPane.UpdatePosition(RootGrid.ActualWidth, RootGrid.ActualHeight); + switch (PreviewPane.Position) { case PanePositions.None: PaneRow.MinHeight = 0; @@ -428,23 +428,23 @@ private void UpdatePositioning() PaneColumn.Width = new GridLength(0); break; case PanePositions.Right: - Pane.SetValue(Grid.RowProperty, 1); - Pane.SetValue(Grid.ColumnProperty, 2); + PreviewPane.SetValue(Grid.RowProperty, 1); + PreviewPane.SetValue(Grid.ColumnProperty, 2); PaneSplitter.SetValue(Grid.RowProperty, 1); PaneSplitter.SetValue(Grid.ColumnProperty, 1); PaneSplitter.Width = 2; PaneSplitter.Height = RootGrid.ActualHeight; PaneSplitter.GripperCursor = GridSplitter.GripperCursorType.SizeWestEast; - PaneColumn.MinWidth = Pane.MinWidth; - PaneColumn.MaxWidth = Pane.MaxWidth; + PaneColumn.MinWidth = PreviewPane.MinWidth; + PaneColumn.MaxWidth = PreviewPane.MaxWidth; PaneColumn.Width = new GridLength(UserSettingsService.PaneSettingsService.VerticalSizePx, GridUnitType.Pixel); PaneRow.MinHeight = 0; PaneRow.MaxHeight = double.MaxValue; PaneRow.Height = new GridLength(0); break; case PanePositions.Bottom: - Pane.SetValue(Grid.RowProperty, 3); - Pane.SetValue(Grid.ColumnProperty, 0); + PreviewPane.SetValue(Grid.RowProperty, 3); + PreviewPane.SetValue(Grid.ColumnProperty, 0); PaneSplitter.SetValue(Grid.RowProperty, 2); PaneSplitter.SetValue(Grid.ColumnProperty, 0); PaneSplitter.Height = 2; @@ -453,8 +453,8 @@ private void UpdatePositioning() PaneColumn.MinWidth = 0; PaneColumn.MaxWidth = double.MaxValue; PaneColumn.Width = new GridLength(0); - PaneRow.MinHeight = Pane.MinHeight; - PaneRow.MaxHeight = Pane.MaxHeight; + PaneRow.MinHeight = PreviewPane.MinHeight; + PaneRow.MaxHeight = PreviewPane.MaxHeight; PaneRow.Height = new GridLength(UserSettingsService.PaneSettingsService.HorizontalSizePx, GridUnitType.Pixel); break; } @@ -463,13 +463,13 @@ private void UpdatePositioning() private void PaneSplitter_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e) { - switch (Pane?.Position) + switch (PreviewPane?.Position) { case PanePositions.Right: - UserSettingsService.PaneSettingsService.VerticalSizePx = Pane.ActualWidth; + UserSettingsService.PaneSettingsService.VerticalSizePx = PreviewPane.ActualWidth; break; case PanePositions.Bottom: - UserSettingsService.PaneSettingsService.HorizontalSizePx = Pane.ActualHeight; + UserSettingsService.PaneSettingsService.HorizontalSizePx = PreviewPane.ActualHeight; break; } } From 434e8128be307fd449f6e646b1481642e31214bc Mon Sep 17 00:00:00 2001 From: Quaint Mako <110472580+QuaintMako@users.noreply.github.com> Date: Thu, 29 Dec 2022 00:44:30 +0100 Subject: [PATCH 02/19] Removed unneeded using --- src/Files.App/UserControls/Pane/PreviewPane.xaml.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs b/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs index a73e1c8afefd..3acd27b51bcd 100644 --- a/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs +++ b/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs @@ -6,7 +6,6 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Input; -using System.ComponentModel; namespace Files.App.UserControls { From b25e0f5e2af6265aa17c047e1158cab52ec13ba3 Mon Sep 17 00:00:00 2001 From: Quaint Mako <110472580+QuaintMako@users.noreply.github.com> Date: Sat, 31 Dec 2022 14:16:18 +0100 Subject: [PATCH 03/19] Renamed Service To PreviewPaneSettingsService --- src/Files.App/App.xaml.cs | 2 +- .../{PaneSettingsService.cs => PreviewPaneSettingsService.cs} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/Files.App/ServicesImplementation/Settings/{PaneSettingsService.cs => PreviewPaneSettingsService.cs} (85%) diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs index 9fda3c5d3b34..abc643a828d1 100644 --- a/src/Files.App/App.xaml.cs +++ b/src/Files.App/App.xaml.cs @@ -110,7 +110,7 @@ private IServiceProvider ConfigureServices() .AddSingleton((sp) => new PreferencesSettingsService((sp.GetService() as UserSettingsService).GetSharingContext())) .AddSingleton((sp) => new FoldersSettingsService((sp.GetService() as UserSettingsService).GetSharingContext())) .AddSingleton((sp) => new ApplicationSettingsService((sp.GetService() as UserSettingsService).GetSharingContext())) - .AddSingleton((sp) => new PaneSettingsService((sp.GetService() as UserSettingsService).GetSharingContext())) + .AddSingleton((sp) => new PreviewPaneSettingsService((sp.GetService() as UserSettingsService).GetSharingContext())) .AddSingleton((sp) => new LayoutSettingsService((sp.GetService() as UserSettingsService).GetSharingContext())) .AddSingleton((sp) => new AppSettingsService((sp.GetService() as UserSettingsService).GetSharingContext())) // Settings not related to IUserSettingsService: diff --git a/src/Files.App/ServicesImplementation/Settings/PaneSettingsService.cs b/src/Files.App/ServicesImplementation/Settings/PreviewPaneSettingsService.cs similarity index 85% rename from src/Files.App/ServicesImplementation/Settings/PaneSettingsService.cs rename to src/Files.App/ServicesImplementation/Settings/PreviewPaneSettingsService.cs index bc70b71352d4..99320ffecc1b 100644 --- a/src/Files.App/ServicesImplementation/Settings/PaneSettingsService.cs +++ b/src/Files.App/ServicesImplementation/Settings/PreviewPaneSettingsService.cs @@ -7,7 +7,7 @@ namespace Files.App.ServicesImplementation.Settings { - internal sealed class PaneSettingsService : BaseObservableJsonSettings, IPaneSettingsService + internal sealed class PreviewPaneSettingsService : BaseObservableJsonSettings, IPaneSettingsService { public PaneContents Content { @@ -39,7 +39,7 @@ public bool ShowPreviewOnly set => Set(value); } - public PaneSettingsService(ISettingsSharingContext settingsSharingContext) + public PreviewPaneSettingsService(ISettingsSharingContext settingsSharingContext) { RegisterSettingsContext(settingsSharingContext); } From 4ab50bad3b8ab6d3f75d6d4e4e647db892973913 Mon Sep 17 00:00:00 2001 From: Quaint Mako <110472580+QuaintMako@users.noreply.github.com> Date: Sat, 31 Dec 2022 14:24:08 +0100 Subject: [PATCH 04/19] Removed IPane --- src/Files.App/UserControls/Pane/Pane.cs | 16 ---------------- .../UserControls/Pane/PreviewPane.xaml.cs | 9 ++++++++- 2 files changed, 8 insertions(+), 17 deletions(-) delete mode 100644 src/Files.App/UserControls/Pane/Pane.cs diff --git a/src/Files.App/UserControls/Pane/Pane.cs b/src/Files.App/UserControls/Pane/Pane.cs deleted file mode 100644 index 27d9c1693578..000000000000 --- a/src/Files.App/UserControls/Pane/Pane.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace Files.App.UserControls -{ - public interface IPane - { - PanePositions Position { get; } - - void UpdatePosition(double panelWidth, double panelHeight); - } - - public enum PanePositions : ushort - { - None, - Right, - Bottom, - } -} diff --git a/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs b/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs index 3acd27b51bcd..719cf8077cea 100644 --- a/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs +++ b/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs @@ -9,7 +9,14 @@ namespace Files.App.UserControls { - public sealed partial class PreviewPane : UserControl, IPane + public enum PanePositions : ushort + { + None, + Right, + Bottom, + } + + public sealed partial class PreviewPane : UserControl { public PanePositions Position { get; private set; } = PanePositions.None; From 18fd0d15da985ef93b9f7618762cb58b0e6031b3 Mon Sep 17 00:00:00 2001 From: Quaint Mako <110472580+QuaintMako@users.noreply.github.com> Date: Sat, 31 Dec 2022 14:37:11 +0100 Subject: [PATCH 05/19] Renamed service --- src/Files.App/App.xaml.cs | 2 +- .../Settings/PreviewPaneSettingsService.cs | 2 +- .../ServicesImplementation/Settings/UserSettingsService.cs | 4 ++-- src/Files.App/UserControls/Pane/PreviewPane.xaml.cs | 2 +- src/Files.App/ViewModels/PaneViewModel.cs | 4 ++-- src/Files.App/ViewModels/PreviewPaneViewModel.cs | 2 +- src/Files.App/Views/MainPage.xaml.cs | 2 +- src/Files.Backend/Services/Settings/IPaneSettingsService.cs | 2 +- src/Files.Backend/Services/Settings/IUserSettingsService.cs | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs index abc643a828d1..63e2816564d6 100644 --- a/src/Files.App/App.xaml.cs +++ b/src/Files.App/App.xaml.cs @@ -110,7 +110,7 @@ private IServiceProvider ConfigureServices() .AddSingleton((sp) => new PreferencesSettingsService((sp.GetService() as UserSettingsService).GetSharingContext())) .AddSingleton((sp) => new FoldersSettingsService((sp.GetService() as UserSettingsService).GetSharingContext())) .AddSingleton((sp) => new ApplicationSettingsService((sp.GetService() as UserSettingsService).GetSharingContext())) - .AddSingleton((sp) => new PreviewPaneSettingsService((sp.GetService() as UserSettingsService).GetSharingContext())) + .AddSingleton((sp) => new PreviewPaneSettingsService((sp.GetService() as UserSettingsService).GetSharingContext())) .AddSingleton((sp) => new LayoutSettingsService((sp.GetService() as UserSettingsService).GetSharingContext())) .AddSingleton((sp) => new AppSettingsService((sp.GetService() as UserSettingsService).GetSharingContext())) // Settings not related to IUserSettingsService: diff --git a/src/Files.App/ServicesImplementation/Settings/PreviewPaneSettingsService.cs b/src/Files.App/ServicesImplementation/Settings/PreviewPaneSettingsService.cs index 99320ffecc1b..a76a1d1bdf9f 100644 --- a/src/Files.App/ServicesImplementation/Settings/PreviewPaneSettingsService.cs +++ b/src/Files.App/ServicesImplementation/Settings/PreviewPaneSettingsService.cs @@ -7,7 +7,7 @@ namespace Files.App.ServicesImplementation.Settings { - internal sealed class PreviewPaneSettingsService : BaseObservableJsonSettings, IPaneSettingsService + internal sealed class PreviewPaneSettingsService : BaseObservableJsonSettings, IPreviewPaneSettingsService { public PaneContents Content { diff --git a/src/Files.App/ServicesImplementation/Settings/UserSettingsService.cs b/src/Files.App/ServicesImplementation/Settings/UserSettingsService.cs index 6ab73a1ab148..05787a95ac5e 100644 --- a/src/Files.App/ServicesImplementation/Settings/UserSettingsService.cs +++ b/src/Files.App/ServicesImplementation/Settings/UserSettingsService.cs @@ -36,8 +36,8 @@ public IAppearanceSettingsService AppearanceSettingsService get => GetSettingsService(ref _AppearanceSettingsService); } - private IPaneSettingsService _PaneSettingsService; - public IPaneSettingsService PaneSettingsService + private IPreviewPaneSettingsService _PaneSettingsService; + public IPreviewPaneSettingsService PaneSettingsService { get => GetSettingsService(ref _PaneSettingsService); } diff --git a/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs b/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs index 719cf8077cea..69b06388ab40 100644 --- a/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs +++ b/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs @@ -20,7 +20,7 @@ public sealed partial class PreviewPane : UserControl { public PanePositions Position { get; private set; } = PanePositions.None; - private IPaneSettingsService PaneSettingsService { get; } = Ioc.Default.GetService(); + private IPreviewPaneSettingsService PaneSettingsService { get; } = Ioc.Default.GetService(); private PreviewPaneViewModel ViewModel => App.PreviewPaneViewModel; diff --git a/src/Files.App/ViewModels/PaneViewModel.cs b/src/Files.App/ViewModels/PaneViewModel.cs index fbd264c80d0c..d1d460402f21 100644 --- a/src/Files.App/ViewModels/PaneViewModel.cs +++ b/src/Files.App/ViewModels/PaneViewModel.cs @@ -16,7 +16,7 @@ public interface IPaneViewModel : INotifyPropertyChanged, IDisposable public class PaneViewModel : ObservableObject, IPaneViewModel { - private readonly IPaneSettingsService settings = Ioc.Default.GetRequiredService(); + private readonly IPreviewPaneSettingsService settings = Ioc.Default.GetRequiredService(); private PaneContents content = PaneContents.None; @@ -38,7 +38,7 @@ public PaneViewModel() private void Settings_PropertyChanged(object sender, PropertyChangedEventArgs e) { - if (e.PropertyName is nameof(IPaneSettingsService.Content)) + if (e.PropertyName is nameof(IPreviewPaneSettingsService.Content)) { var newContent = settings.Content; if (content != newContent) diff --git a/src/Files.App/ViewModels/PreviewPaneViewModel.cs b/src/Files.App/ViewModels/PreviewPaneViewModel.cs index 1905cd207d69..fa86f8c43611 100644 --- a/src/Files.App/ViewModels/PreviewPaneViewModel.cs +++ b/src/Files.App/ViewModels/PreviewPaneViewModel.cs @@ -267,7 +267,7 @@ public async void UpdateSelectedItemPreview(bool downloadItem = false) private void UserSettingsService_OnSettingChangedEvent(object sender, SettingChangedEventArgs e) { - if (e.SettingName == nameof(IPaneSettingsService.ShowPreviewOnly)) + if (e.SettingName == nameof(IPreviewPaneSettingsService.ShowPreviewOnly)) { // The preview will need refreshing as the file details won't be accurate needsRefresh = true; diff --git a/src/Files.App/Views/MainPage.xaml.cs b/src/Files.App/Views/MainPage.xaml.cs index dc3099cff7ab..04658e1d8a3c 100644 --- a/src/Files.App/Views/MainPage.xaml.cs +++ b/src/Files.App/Views/MainPage.xaml.cs @@ -145,7 +145,7 @@ private void UserSettingsService_OnSettingChangedEvent(object? sender, SettingCh { switch (e.SettingName) { - case nameof(IPaneSettingsService.Content): + case nameof(IPreviewPaneSettingsService.Content): LoadPaneChanged(); break; } diff --git a/src/Files.Backend/Services/Settings/IPaneSettingsService.cs b/src/Files.Backend/Services/Settings/IPaneSettingsService.cs index 472985566559..a5699c4cae38 100644 --- a/src/Files.Backend/Services/Settings/IPaneSettingsService.cs +++ b/src/Files.Backend/Services/Settings/IPaneSettingsService.cs @@ -3,7 +3,7 @@ namespace Files.Backend.Services.Settings { - public interface IPaneSettingsService : IBaseSettingsService, INotifyPropertyChanged + public interface IPreviewPaneSettingsService : IBaseSettingsService, INotifyPropertyChanged { /// /// Gets or sets the selected content. diff --git a/src/Files.Backend/Services/Settings/IUserSettingsService.cs b/src/Files.Backend/Services/Settings/IUserSettingsService.cs index 403830511f48..f7a7397947d7 100644 --- a/src/Files.Backend/Services/Settings/IUserSettingsService.cs +++ b/src/Files.Backend/Services/Settings/IUserSettingsService.cs @@ -21,7 +21,7 @@ public interface IUserSettingsService : IBaseSettingsService IApplicationSettingsService ApplicationSettingsService { get; } - IPaneSettingsService PaneSettingsService { get; } + IPreviewPaneSettingsService PaneSettingsService { get; } ILayoutSettingsService LayoutSettingsService { get; } From 4da03048dcd23bb8aba4a7892f8b7ac95e5b4e06 Mon Sep 17 00:00:00 2001 From: Quaint Mako <110472580+QuaintMako@users.noreply.github.com> Date: Tue, 3 Jan 2023 13:40:30 +0100 Subject: [PATCH 06/19] [WIP] Introducing new setting in the PreviewPaneSettings --- .../Settings/PreviewPaneSettingsService.cs | 6 ++++ .../ViewModels/PreviewPaneViewModel.cs | 32 +++++++++++++++---- .../Services/Settings/IPaneSettingsService.cs | 14 ++------ 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/Files.App/ServicesImplementation/Settings/PreviewPaneSettingsService.cs b/src/Files.App/ServicesImplementation/Settings/PreviewPaneSettingsService.cs index a76a1d1bdf9f..30f6653158d8 100644 --- a/src/Files.App/ServicesImplementation/Settings/PreviewPaneSettingsService.cs +++ b/src/Files.App/ServicesImplementation/Settings/PreviewPaneSettingsService.cs @@ -9,6 +9,12 @@ namespace Files.App.ServicesImplementation.Settings { internal sealed class PreviewPaneSettingsService : BaseObservableJsonSettings, IPreviewPaneSettingsService { + public bool IsEnabled + { + get => Get(false); + set => Set(value); + } + public PaneContents Content { get => Get(PaneContents.None); diff --git a/src/Files.App/ViewModels/PreviewPaneViewModel.cs b/src/Files.App/ViewModels/PreviewPaneViewModel.cs index fa86f8c43611..1f9a0cf10a34 100644 --- a/src/Files.App/ViewModels/PreviewPaneViewModel.cs +++ b/src/Files.App/ViewModels/PreviewPaneViewModel.cs @@ -11,6 +11,7 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using System; +using System.ComponentModel; using System.Diagnostics; using System.Threading; using System.Threading.Tasks; @@ -23,10 +24,19 @@ public class PreviewPaneViewModel : ObservableObject, IDisposable { private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService(); + private IPreviewPaneSettingsService PreviewSettingsService { get; } = Ioc.Default.GetRequiredService(); + + private CancellationTokenSource loadCancellationTokenSource; - private bool isItemSelected; + private bool isEnabled; + public bool IsEnabled + { + get => isEnabled; + set => SetProperty(ref isEnabled, value); + } + private bool isItemSelected; public bool IsItemSelected { get => isItemSelected; @@ -34,7 +44,6 @@ public bool IsItemSelected } private ListedItem selectedItem; - public ListedItem SelectedItem { get => selectedItem; @@ -42,7 +51,6 @@ public ListedItem SelectedItem } private PreviewPaneStates previewPaneState; - public PreviewPaneStates PreviewPaneState { get => previewPaneState; @@ -50,7 +58,6 @@ public PreviewPaneStates PreviewPaneState } private bool showCloudItemButton; - public bool ShowCloudItemButton { get => showCloudItemButton; @@ -58,7 +65,6 @@ public bool ShowCloudItemButton } private UIElement previewPaneContent; - public UIElement PreviewPaneContent { get => previewPaneContent; @@ -70,6 +76,7 @@ public PreviewPaneViewModel() ShowPreviewOnlyInvoked = new RelayCommand(() => UpdateSelectedItemPreview()); UserSettingsService.OnSettingChangedEvent += UserSettingsService_OnSettingChangedEvent; + PreviewSettingsService.PropertyChanged += PreviewSettingsService_OnPropertyChangedEvent; } private async Task LoadPreviewControlAsync(CancellationToken token, bool downloadItem) @@ -267,13 +274,26 @@ public async void UpdateSelectedItemPreview(bool downloadItem = false) private void UserSettingsService_OnSettingChangedEvent(object sender, SettingChangedEventArgs e) { - if (e.SettingName == nameof(IPreviewPaneSettingsService.ShowPreviewOnly)) + if (e.SettingName is nameof(IPreviewPaneSettingsService.ShowPreviewOnly)) { // The preview will need refreshing as the file details won't be accurate needsRefresh = true; } } + private void PreviewSettingsService_OnPropertyChangedEvent(object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName is nameof(IPreviewPaneSettingsService.IsEnabled)) + { + var newEnablingStatus = PreviewSettingsService.IsEnabled; + if(isEnabled != newEnablingStatus) + { + isEnabled = newEnablingStatus; + OnPropertyChanged(nameof(IsEnabled)); + } + } + } + private async Task LoadBasicPreviewAsync() { try diff --git a/src/Files.Backend/Services/Settings/IPaneSettingsService.cs b/src/Files.Backend/Services/Settings/IPaneSettingsService.cs index a5699c4cae38..da3ac7c4b6a3 100644 --- a/src/Files.Backend/Services/Settings/IPaneSettingsService.cs +++ b/src/Files.Backend/Services/Settings/IPaneSettingsService.cs @@ -5,24 +5,14 @@ namespace Files.Backend.Services.Settings { public interface IPreviewPaneSettingsService : IBaseSettingsService, INotifyPropertyChanged { - /// - /// Gets or sets the selected content. - /// + bool IsEnabled { get; set; } + PaneContents Content { get; set; } - /// - /// Gets or sets a value indicating the height of the pane in a horizontal layout. - /// double HorizontalSizePx { get; set; } - /// - /// Gets or sets a value indicating the width of the pane in a vertical layout. - /// double VerticalSizePx { get; set; } - /// - /// Gets or sets a value indicating the default volume on media. - /// double MediaVolume { get; set; } /// From def6063fdd539893c79870a3256ec8f1dba7c39d Mon Sep 17 00:00:00 2001 From: Quaint Mako <110472580+QuaintMako@users.noreply.github.com> Date: Tue, 3 Jan 2023 13:43:45 +0100 Subject: [PATCH 07/19] Forgotten unsubscribe event --- src/Files.App/ViewModels/PreviewPaneViewModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Files.App/ViewModels/PreviewPaneViewModel.cs b/src/Files.App/ViewModels/PreviewPaneViewModel.cs index 1f9a0cf10a34..c7e5dfb84621 100644 --- a/src/Files.App/ViewModels/PreviewPaneViewModel.cs +++ b/src/Files.App/ViewModels/PreviewPaneViewModel.cs @@ -328,6 +328,7 @@ public void TryRefresh() public void Dispose() { UserSettingsService.OnSettingChangedEvent -= UserSettingsService_OnSettingChangedEvent; + PreviewSettingsService.PropertyChanged -= PreviewSettingsService_OnPropertyChangedEvent; } } From 4c88ef14992aff940b3926e6aef9d28938a644dc Mon Sep 17 00:00:00 2001 From: Quaint Mako <110472580+QuaintMako@users.noreply.github.com> Date: Tue, 3 Jan 2023 13:57:04 +0100 Subject: [PATCH 08/19] [WIP] Removing PaneViewModel and adapt existing code --- src/Files.App/App.xaml.cs | 3 - src/Files.App/BaseLayout.cs | 8 +-- src/Files.App/DataModels/AppModel.cs | 2 +- src/Files.App/IBaseLayout.cs | 2 +- .../Settings/PreviewPaneSettingsService.cs | 6 -- .../Settings/UserSettingsService.cs | 6 +- .../FilePreviews/MediaPreview.xaml.cs | 6 +- .../UserControls/InnerNavigationToolbar.xaml | 2 +- src/Files.App/ViewModels/ItemViewModel.cs | 2 +- src/Files.App/ViewModels/PaneViewModel.cs | 66 ------------------- .../ViewModels/Previews/BasePreviewModel.cs | 2 +- src/Files.App/Views/ColumnShellPage.xaml.cs | 2 +- src/Files.App/Views/MainPage.xaml | 6 +- src/Files.App/Views/MainPage.xaml.cs | 26 ++++---- src/Files.App/Views/ModernShellPage.xaml.cs | 2 +- .../Services/Settings/IPaneSettingsService.cs | 2 - .../Services/Settings/IUserSettingsService.cs | 2 +- src/Files.Shared/Enums/PaneContents.cs | 9 --- 18 files changed, 34 insertions(+), 120 deletions(-) delete mode 100644 src/Files.App/ViewModels/PaneViewModel.cs delete mode 100644 src/Files.Shared/Enums/PaneContents.cs diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs index 63e2816564d6..cf56cc40eaaa 100644 --- a/src/Files.App/App.xaml.cs +++ b/src/Files.App/App.xaml.cs @@ -55,7 +55,6 @@ public partial class App : Application public static StorageHistoryWrapper HistoryWrapper = new StorageHistoryWrapper(); public static SettingsViewModel AppSettings { get; private set; } public static AppModel AppModel { get; private set; } - public static PaneViewModel PaneViewModel { get; private set; } public static PreviewPaneViewModel PreviewPaneViewModel { get; private set; } public static JumpListManager JumpList { get; private set; } public static RecentItems RecentItemsManager { get; private set; } @@ -150,7 +149,6 @@ private static void EnsureSettingsAndConfigurationAreBootstrapped() JumpList ??= new JumpListManager(); RecentItemsManager ??= new RecentItems(); AppModel ??= new AppModel(); - PaneViewModel ??= new PaneViewModel(); PreviewPaneViewModel ??= new PreviewPaneViewModel(); LibraryManager ??= new LibraryManager(); DrivesManager ??= new DrivesManager(); @@ -297,7 +295,6 @@ await SafetyExtensions.IgnoreExceptions(async () => } DrivesManager?.Dispose(); - PaneViewModel?.Dispose(); PreviewPaneViewModel?.Dispose(); // Try to maintain clipboard data after app close diff --git a/src/Files.App/BaseLayout.cs b/src/Files.App/BaseLayout.cs index d67cb014ba68..6fd79923bdde 100644 --- a/src/Files.App/BaseLayout.cs +++ b/src/Files.App/BaseLayout.cs @@ -58,7 +58,7 @@ public abstract class BaseLayout : Page, IBaseLayout, INotifyPropertyChanged public CurrentInstanceViewModel? InstanceViewModel => ParentShellPageInstance?.InstanceViewModel; - public IPaneViewModel PaneViewModel => App.PaneViewModel; + public PreviewPaneViewModel PreviewPaneViewModel => App.PreviewPaneViewModel; public AppModel AppModel => App.AppModel; public DirectoryPropertiesViewModel DirectoryPropertiesViewModel { get; } @@ -205,9 +205,9 @@ internal set App.PreviewPaneViewModel.SelectedItem = value?.Count == 1 ? value.First() : null; // check if the preview pane is open before updating the model - if (PaneViewModel.IsPreviewSelected) + if (PreviewPaneViewModel.IsEnabled) { - bool isPaneEnabled = ((App.Window.Content as Frame)?.Content as MainPage)?.IsPaneEnabled ?? false; + bool isPaneEnabled = ((App.Window.Content as Frame)?.Content as MainPage)?.IsPreviewPaneEnabled ?? false; if (isPaneEnabled) App.PreviewPaneViewModel.UpdateSelectedItemPreview(); } @@ -1046,7 +1046,7 @@ protected void UninitializeDrag(UIElement element) public virtual void Dispose() { - PaneViewModel?.Dispose(); + PreviewPaneViewModel?.Dispose(); UnhookBaseEvents(); } diff --git a/src/Files.App/DataModels/AppModel.cs b/src/Files.App/DataModels/AppModel.cs index 23db1380354a..079658abb649 100644 --- a/src/Files.App/DataModels/AppModel.cs +++ b/src/Files.App/DataModels/AppModel.cs @@ -12,7 +12,7 @@ namespace Files.App.DataModels public class AppModel : ObservableObject { // todo: refactor PaneViewModel, this doesn't belong here - public IPaneViewModel PaneViewModel { get; } = new PaneViewModel(); + public PreviewPaneViewModel PreviewPaneViewModel { get; } = new PreviewPaneViewModel(); public AppModel() { diff --git a/src/Files.App/IBaseLayout.cs b/src/Files.App/IBaseLayout.cs index b9feb6cf2181..a40f9e5633d1 100644 --- a/src/Files.App/IBaseLayout.cs +++ b/src/Files.App/IBaseLayout.cs @@ -21,7 +21,7 @@ public interface IBaseLayout : IDisposable ItemManipulationModel ItemManipulationModel { get; } - IPaneViewModel PaneViewModel { get; } + PreviewPaneViewModel PreviewPaneViewModel { get; } public SelectedItemsPropertiesViewModel SelectedItemsPropertiesViewModel { get; } public DirectoryPropertiesViewModel DirectoryPropertiesViewModel { get; } diff --git a/src/Files.App/ServicesImplementation/Settings/PreviewPaneSettingsService.cs b/src/Files.App/ServicesImplementation/Settings/PreviewPaneSettingsService.cs index 30f6653158d8..bbebd1db25eb 100644 --- a/src/Files.App/ServicesImplementation/Settings/PreviewPaneSettingsService.cs +++ b/src/Files.App/ServicesImplementation/Settings/PreviewPaneSettingsService.cs @@ -15,12 +15,6 @@ public bool IsEnabled set => Set(value); } - public PaneContents Content - { - get => Get(PaneContents.None); - set => Set(value); - } - public double HorizontalSizePx { get => Math.Max(100d, Get(300d)); diff --git a/src/Files.App/ServicesImplementation/Settings/UserSettingsService.cs b/src/Files.App/ServicesImplementation/Settings/UserSettingsService.cs index 05787a95ac5e..dbcd2f2215ad 100644 --- a/src/Files.App/ServicesImplementation/Settings/UserSettingsService.cs +++ b/src/Files.App/ServicesImplementation/Settings/UserSettingsService.cs @@ -36,10 +36,10 @@ public IAppearanceSettingsService AppearanceSettingsService get => GetSettingsService(ref _AppearanceSettingsService); } - private IPreviewPaneSettingsService _PaneSettingsService; - public IPreviewPaneSettingsService PaneSettingsService + private IPreviewPaneSettingsService _PreviewPaneSettingsService; + public IPreviewPaneSettingsService PreviewPaneSettingsService { - get => GetSettingsService(ref _PaneSettingsService); + get => GetSettingsService(ref _PreviewPaneSettingsService); } private ILayoutSettingsService _LayoutSettingsService; diff --git a/src/Files.App/UserControls/FilePreviews/MediaPreview.xaml.cs b/src/Files.App/UserControls/FilePreviews/MediaPreview.xaml.cs index df8829b351ed..1e5b5dcf23c2 100644 --- a/src/Files.App/UserControls/FilePreviews/MediaPreview.xaml.cs +++ b/src/Files.App/UserControls/FilePreviews/MediaPreview.xaml.cs @@ -26,16 +26,16 @@ public MediaPreview(MediaPreviewViewModel model) private void PlayerContext_Loaded(object sender, RoutedEventArgs e) { - PlayerContext.MediaPlayer.Volume = UserSettingsService.PaneSettingsService.MediaVolume; + PlayerContext.MediaPlayer.Volume = UserSettingsService.PreviewPaneSettingsService.MediaVolume; PlayerContext.MediaPlayer.VolumeChanged += MediaPlayer_VolumeChanged; ViewModel.TogglePlaybackRequested += TogglePlaybackRequestInvoked; } private void MediaPlayer_VolumeChanged(MediaPlayer sender, object args) { - if (sender.Volume != UserSettingsService.PaneSettingsService.MediaVolume) + if (sender.Volume != UserSettingsService.PreviewPaneSettingsService.MediaVolume) { - UserSettingsService.PaneSettingsService.MediaVolume = sender.Volume; + UserSettingsService.PreviewPaneSettingsService.MediaVolume = sender.Volume; } } diff --git a/src/Files.App/UserControls/InnerNavigationToolbar.xaml b/src/Files.App/UserControls/InnerNavigationToolbar.xaml index db90c5a36df7..d42381184de6 100644 --- a/src/Files.App/UserControls/InnerNavigationToolbar.xaml +++ b/src/Files.App/UserControls/InnerNavigationToolbar.xaml @@ -814,7 +814,7 @@ MinWidth="40" AccessKey="P" AutomationProperties.Name="{helpers:ResourceString Name=PreviewPaneToggle/AutomationProperties/Name}" - IsChecked="{x:Bind AppModel.PaneViewModel.IsPreviewSelected, Mode=TwoWay}" + IsChecked="{x:Bind AppModel.PreviewPaneViewModel.IsEnabled, Mode=TwoWay}" IsEnabled="{x:Bind ShowPreviewPaneButton, Mode=OneWay}" Label="{helpers:ResourceString Name=PreviewPaneToggle/Label}" LabelPosition="Collapsed" diff --git a/src/Files.App/ViewModels/ItemViewModel.cs b/src/Files.App/ViewModels/ItemViewModel.cs index 6a11c2402cb2..90e4be431f08 100644 --- a/src/Files.App/ViewModels/ItemViewModel.cs +++ b/src/Files.App/ViewModels/ItemViewModel.cs @@ -1262,7 +1262,7 @@ private async void RapidAddItemsToCollectionAsync(string path, string previousDi AdaptiveLayoutHelpers.PredictLayoutMode(folderSettings, WorkingDirectory, filesAndFolders); - if (App.PaneViewModel.IsPreviewSelected) + if (App.PreviewPaneViewModel.IsEnabled) { // Find and select README file foreach (var item in filesAndFolders) diff --git a/src/Files.App/ViewModels/PaneViewModel.cs b/src/Files.App/ViewModels/PaneViewModel.cs deleted file mode 100644 index d1d460402f21..000000000000 --- a/src/Files.App/ViewModels/PaneViewModel.cs +++ /dev/null @@ -1,66 +0,0 @@ -using CommunityToolkit.Mvvm.ComponentModel; -using CommunityToolkit.Mvvm.DependencyInjection; -using Files.Backend.Services.Settings; -using Files.Shared.Enums; -using System; -using System.ComponentModel; - -namespace Files.App.ViewModels -{ - public interface IPaneViewModel : INotifyPropertyChanged, IDisposable - { - bool HasContent { get; } - - bool IsPreviewSelected { get; set; } - } - - public class PaneViewModel : ObservableObject, IPaneViewModel - { - private readonly IPreviewPaneSettingsService settings = Ioc.Default.GetRequiredService(); - - private PaneContents content = PaneContents.None; - - public bool HasContent => content is not PaneContents.None; - - public bool IsPreviewSelected - { - get => content is PaneContents.Preview; - set => SetState(value, PaneContents.Preview); - } - - public PaneViewModel() - { - settings.PropertyChanged += Settings_PropertyChanged; - content = settings.Content; - } - - public void Dispose() => settings.PropertyChanged -= Settings_PropertyChanged; - - private void Settings_PropertyChanged(object sender, PropertyChangedEventArgs e) - { - if (e.PropertyName is nameof(IPreviewPaneSettingsService.Content)) - { - var newContent = settings.Content; - if (content != newContent) - { - content = newContent; - - OnPropertyChanged(nameof(HasContent)); - OnPropertyChanged(nameof(IsPreviewSelected)); - } - } - } - - private void SetState(bool state, PaneContents field) - { - if (state && content != field) - { - settings.Content = field; - } - else if (!state && content == field) - { - settings.Content = PaneContents.None; - } - } - } -} diff --git a/src/Files.App/ViewModels/Previews/BasePreviewModel.cs b/src/Files.App/ViewModels/Previews/BasePreviewModel.cs index a89973f77e30..bc0b214889b4 100644 --- a/src/Files.App/ViewModels/Previews/BasePreviewModel.cs +++ b/src/Files.App/ViewModels/Previews/BasePreviewModel.cs @@ -66,7 +66,7 @@ public virtual async Task LoadAsync() await Task.Run(async () => { DetailsFromPreview = await LoadPreviewAndDetailsAsync(); - if (!userSettingsService.PaneSettingsService.ShowPreviewOnly) + if (!userSettingsService.PreviewPaneSettingsService.ShowPreviewOnly) { // Add the details from the preview function, then the system file properties DetailsFromPreview?.ForEach(i => detailsFull.Add(i)); diff --git a/src/Files.App/Views/ColumnShellPage.xaml.cs b/src/Files.App/Views/ColumnShellPage.xaml.cs index 0ecaca3ada72..cb8401152f4f 100644 --- a/src/Files.App/Views/ColumnShellPage.xaml.cs +++ b/src/Files.App/Views/ColumnShellPage.xaml.cs @@ -755,7 +755,7 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo break; case (true, false, false, true, VirtualKey.P): // ctrl + p, toggle preview pane - App.PaneViewModel.IsPreviewSelected = !App.PaneViewModel.IsPreviewSelected; + App.PreviewPaneViewModel.IsEnabled = !App.PreviewPaneViewModel.IsEnabled; break; case (true, false, false, true, VirtualKey.R): // ctrl + r, refresh diff --git a/src/Files.App/Views/MainPage.xaml b/src/Files.App/Views/MainPage.xaml index dbb00357644d..6d9dc8b56701 100644 --- a/src/Files.App/Views/MainPage.xaml +++ b/src/Files.App/Views/MainPage.xaml @@ -326,7 +326,7 @@ x:Name="PaneSplitter" Grid.Row="1" Grid.Column="1" - x:Load="{x:Bind IsPaneEnabled, Mode=OneWay}" + x:Load="{x:Bind IsPreviewPaneEnabled, Mode=OneWay}" ManipulationCompleted="PaneSplitter_ManipulationCompleted" ResizeBehavior="BasedOnAlignment" Style="{StaticResource DefaultGridSplitterStyle}" /> @@ -336,8 +336,8 @@ Grid.Row="1" Grid.Column="2" HorizontalContentAlignment="Stretch" - x:Load="{x:Bind IsPaneEnabled, Mode=OneWay}" - Visibility="{x:Bind IsPaneEnabled, Mode=OneWay}" /> + x:Load="{x:Bind IsPreviewPaneEnabled, Mode=OneWay}" + Visibility="{x:Bind IsPreviewPaneEnabled, Mode=OneWay}" /> private void UpdatePositioning() { - if (PreviewPane is null || !IsPaneEnabled) + if (PreviewPane is null || !IsPreviewPaneEnabled) { PaneRow.MinHeight = 0; PaneRow.MaxHeight = double.MaxValue; @@ -437,7 +437,7 @@ private void UpdatePositioning() PaneSplitter.GripperCursor = GridSplitter.GripperCursorType.SizeWestEast; PaneColumn.MinWidth = PreviewPane.MinWidth; PaneColumn.MaxWidth = PreviewPane.MaxWidth; - PaneColumn.Width = new GridLength(UserSettingsService.PaneSettingsService.VerticalSizePx, GridUnitType.Pixel); + PaneColumn.Width = new GridLength(UserSettingsService.PreviewPaneSettingsService.VerticalSizePx, GridUnitType.Pixel); PaneRow.MinHeight = 0; PaneRow.MaxHeight = double.MaxValue; PaneRow.Height = new GridLength(0); @@ -455,7 +455,7 @@ private void UpdatePositioning() PaneColumn.Width = new GridLength(0); PaneRow.MinHeight = PreviewPane.MinHeight; PaneRow.MaxHeight = PreviewPane.MaxHeight; - PaneRow.Height = new GridLength(UserSettingsService.PaneSettingsService.HorizontalSizePx, GridUnitType.Pixel); + PaneRow.Height = new GridLength(UserSettingsService.PreviewPaneSettingsService.HorizontalSizePx, GridUnitType.Pixel); break; } } @@ -466,21 +466,21 @@ private void PaneSplitter_ManipulationCompleted(object sender, ManipulationCompl switch (PreviewPane?.Position) { case PanePositions.Right: - UserSettingsService.PaneSettingsService.VerticalSizePx = PreviewPane.ActualWidth; + UserSettingsService.PreviewPaneSettingsService.VerticalSizePx = PreviewPane.ActualWidth; break; case PanePositions.Bottom: - UserSettingsService.PaneSettingsService.HorizontalSizePx = PreviewPane.ActualHeight; + UserSettingsService.PreviewPaneSettingsService.HorizontalSizePx = PreviewPane.ActualHeight; break; } } - public bool IsPaneEnabled => UserSettingsService.PaneSettingsService.Content switch + public bool IsPreviewPaneEnabled => UserSettingsService.PreviewPaneSettingsService.IsEnabled switch { - PaneContents.Preview => IsPreviewPaneEnabled, - _ => false, + true => ShouldPreviewPaneBeDisplayed, + false => false, }; - public bool IsPreviewPaneEnabled + public bool ShouldPreviewPaneBeDisplayed { get { @@ -495,8 +495,8 @@ public bool IsPreviewPaneEnabled private void LoadPaneChanged() { - OnPropertyChanged(nameof(IsPaneEnabled)); OnPropertyChanged(nameof(IsPreviewPaneEnabled)); + OnPropertyChanged(nameof(ShouldPreviewPaneBeDisplayed)); UpdatePositioning(); } diff --git a/src/Files.App/Views/ModernShellPage.xaml.cs b/src/Files.App/Views/ModernShellPage.xaml.cs index 469657d3bf78..53aa3a99e4e1 100644 --- a/src/Files.App/Views/ModernShellPage.xaml.cs +++ b/src/Files.App/Views/ModernShellPage.xaml.cs @@ -757,7 +757,7 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo break; case (true, false, false, true, VirtualKey.P): // ctrl + p, toggle preview pane - App.PaneViewModel.IsPreviewSelected = !App.PaneViewModel.IsPreviewSelected; + App.PreviewPaneViewModel.IsEnabled = !App.PreviewPaneViewModel.IsEnabled; break; case (true, false, false, true, VirtualKey.R): // ctrl + r, refresh diff --git a/src/Files.Backend/Services/Settings/IPaneSettingsService.cs b/src/Files.Backend/Services/Settings/IPaneSettingsService.cs index da3ac7c4b6a3..ecdc26233f1d 100644 --- a/src/Files.Backend/Services/Settings/IPaneSettingsService.cs +++ b/src/Files.Backend/Services/Settings/IPaneSettingsService.cs @@ -7,8 +7,6 @@ public interface IPreviewPaneSettingsService : IBaseSettingsService, INotifyProp { bool IsEnabled { get; set; } - PaneContents Content { get; set; } - double HorizontalSizePx { get; set; } double VerticalSizePx { get; set; } diff --git a/src/Files.Backend/Services/Settings/IUserSettingsService.cs b/src/Files.Backend/Services/Settings/IUserSettingsService.cs index f7a7397947d7..7ed773c5e5a8 100644 --- a/src/Files.Backend/Services/Settings/IUserSettingsService.cs +++ b/src/Files.Backend/Services/Settings/IUserSettingsService.cs @@ -21,7 +21,7 @@ public interface IUserSettingsService : IBaseSettingsService IApplicationSettingsService ApplicationSettingsService { get; } - IPreviewPaneSettingsService PaneSettingsService { get; } + IPreviewPaneSettingsService PreviewPaneSettingsService { get; } ILayoutSettingsService LayoutSettingsService { get; } diff --git a/src/Files.Shared/Enums/PaneContents.cs b/src/Files.Shared/Enums/PaneContents.cs deleted file mode 100644 index 4f5cefb85950..000000000000 --- a/src/Files.Shared/Enums/PaneContents.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Files.Shared.Enums -{ - // Inherits from `long` since others enums do not work as settings. - public enum PaneContents : long - { - None, - Preview, - } -} From 2ebb9fe2b1d380076828d8e9e011c9433089eb2b Mon Sep 17 00:00:00 2001 From: Quaint Mako <110472580+QuaintMako@users.noreply.github.com> Date: Tue, 3 Jan 2023 22:34:21 +0100 Subject: [PATCH 09/19] Now displaying the preview button correctly --- src/Files.App/Views/MainPage.xaml | 2 +- src/Files.App/Views/MainPage.xaml.cs | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Files.App/Views/MainPage.xaml b/src/Files.App/Views/MainPage.xaml index 6d9dc8b56701..7b6eaf59fc77 100644 --- a/src/Files.App/Views/MainPage.xaml +++ b/src/Files.App/Views/MainPage.xaml @@ -312,7 +312,7 @@ IsCompactOverlay="{x:Bind ViewModel.IsWindowCompactOverlay, Mode=OneWay}" Loaded="NavToolbar_Loaded" SetCompactOverlayCommand="{x:Bind SetCompactOverlayCommand}" - ShowPreviewPaneButton="{x:Bind IsPreviewPaneEnabled, Mode=OneWay}" + ShowPreviewPaneButton="{x:Bind ShouldPreviewPaneBeDisplayed, Mode=OneWay}" TabIndex="2" /> UserSettingsService.PreviewPaneSettingsService.IsEnabled switch - { - true => ShouldPreviewPaneBeDisplayed, - false => false, - }; + public bool IsPreviewPaneEnabled => UserSettingsService.PreviewPaneSettingsService.IsEnabled; public bool ShouldPreviewPaneBeDisplayed { From 6b79ae276d17be1565d634fafecdd3be9617f83d Mon Sep 17 00:00:00 2001 From: Quaint Mako <110472580+QuaintMako@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:08:07 +0100 Subject: [PATCH 10/19] Now notifying correctly the settings when the preview pane is toggled. --- src/Files.App/ViewModels/PreviewPaneViewModel.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Files.App/ViewModels/PreviewPaneViewModel.cs b/src/Files.App/ViewModels/PreviewPaneViewModel.cs index c7e5dfb84621..1b9c45fd8b5f 100644 --- a/src/Files.App/ViewModels/PreviewPaneViewModel.cs +++ b/src/Files.App/ViewModels/PreviewPaneViewModel.cs @@ -26,14 +26,17 @@ public class PreviewPaneViewModel : ObservableObject, IDisposable private IPreviewPaneSettingsService PreviewSettingsService { get; } = Ioc.Default.GetRequiredService(); - private CancellationTokenSource loadCancellationTokenSource; private bool isEnabled; public bool IsEnabled { get => isEnabled; - set => SetProperty(ref isEnabled, value); + set + { + PreviewSettingsService.IsEnabled = value; + SetProperty(ref isEnabled, value); + } } private bool isItemSelected; @@ -286,7 +289,7 @@ private void PreviewSettingsService_OnPropertyChangedEvent(object sender, Proper if (e.PropertyName is nameof(IPreviewPaneSettingsService.IsEnabled)) { var newEnablingStatus = PreviewSettingsService.IsEnabled; - if(isEnabled != newEnablingStatus) + if (isEnabled != newEnablingStatus) { isEnabled = newEnablingStatus; OnPropertyChanged(nameof(IsEnabled)); From 7cacf6abab07ad65f7b89a8b53984e81f8657032 Mon Sep 17 00:00:00 2001 From: Quaint Mako <110472580+QuaintMako@users.noreply.github.com> Date: Tue, 10 Jan 2023 22:46:02 +0100 Subject: [PATCH 11/19] Button state is now correctly iniatilized. --- src/Files.App/ViewModels/PreviewPaneViewModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Files.App/ViewModels/PreviewPaneViewModel.cs b/src/Files.App/ViewModels/PreviewPaneViewModel.cs index 1b9c45fd8b5f..0125b3a2a1fa 100644 --- a/src/Files.App/ViewModels/PreviewPaneViewModel.cs +++ b/src/Files.App/ViewModels/PreviewPaneViewModel.cs @@ -78,6 +78,7 @@ public PreviewPaneViewModel() { ShowPreviewOnlyInvoked = new RelayCommand(() => UpdateSelectedItemPreview()); + IsEnabled = PreviewSettingsService.IsEnabled; UserSettingsService.OnSettingChangedEvent += UserSettingsService_OnSettingChangedEvent; PreviewSettingsService.PropertyChanged += PreviewSettingsService_OnPropertyChangedEvent; } From 5b1378d06af2a6400b40bba5ea7be4e91551b82a Mon Sep 17 00:00:00 2001 From: Quaint Mako <110472580+QuaintMako@users.noreply.github.com> Date: Tue, 10 Jan 2023 22:59:46 +0100 Subject: [PATCH 12/19] Preview Pane display is correctly evaluated on home page --- src/Files.App/BaseLayout.cs | 2 +- src/Files.App/Views/MainPage.xaml | 6 +++--- src/Files.App/Views/MainPage.xaml.cs | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Files.App/BaseLayout.cs b/src/Files.App/BaseLayout.cs index 3d7c8a520639..05cb6b75d3bd 100644 --- a/src/Files.App/BaseLayout.cs +++ b/src/Files.App/BaseLayout.cs @@ -207,7 +207,7 @@ internal set // check if the preview pane is open before updating the model if (PreviewPaneViewModel.IsEnabled) { - bool isPaneEnabled = ((App.Window.Content as Frame)?.Content as MainPage)?.IsPreviewPaneEnabled ?? false; + bool isPaneEnabled = ((App.Window.Content as Frame)?.Content as MainPage)?.ShouldPreviewPaneBeActive ?? false; if (isPaneEnabled) App.PreviewPaneViewModel.UpdateSelectedItemPreview(); } diff --git a/src/Files.App/Views/MainPage.xaml b/src/Files.App/Views/MainPage.xaml index 7b6eaf59fc77..b5c9ff4b1a8a 100644 --- a/src/Files.App/Views/MainPage.xaml +++ b/src/Files.App/Views/MainPage.xaml @@ -326,7 +326,7 @@ x:Name="PaneSplitter" Grid.Row="1" Grid.Column="1" - x:Load="{x:Bind IsPreviewPaneEnabled, Mode=OneWay}" + x:Load="{x:Bind ShouldPreviewPaneBeActive, Mode=OneWay}" ManipulationCompleted="PaneSplitter_ManipulationCompleted" ResizeBehavior="BasedOnAlignment" Style="{StaticResource DefaultGridSplitterStyle}" /> @@ -336,8 +336,8 @@ Grid.Row="1" Grid.Column="2" HorizontalContentAlignment="Stretch" - x:Load="{x:Bind IsPreviewPaneEnabled, Mode=OneWay}" - Visibility="{x:Bind IsPreviewPaneEnabled, Mode=OneWay}" /> + x:Load="{x:Bind ShouldPreviewPaneBeActive, Mode=OneWay}" + Visibility="{x:Bind ShouldPreviewPaneBeActive, Mode=OneWay}" /> private void UpdatePositioning() { - if (PreviewPane is null || !IsPreviewPaneEnabled) + if (PreviewPane is null || !ShouldPreviewPaneBeActive) { PaneRow.MinHeight = 0; PaneRow.MaxHeight = double.MaxValue; @@ -474,7 +474,7 @@ private void PaneSplitter_ManipulationCompleted(object sender, ManipulationCompl } } - public bool IsPreviewPaneEnabled => UserSettingsService.PreviewPaneSettingsService.IsEnabled; + public bool ShouldPreviewPaneBeActive => UserSettingsService.PreviewPaneSettingsService.IsEnabled && ShouldPreviewPaneBeDisplayed; public bool ShouldPreviewPaneBeDisplayed { @@ -491,7 +491,7 @@ public bool ShouldPreviewPaneBeDisplayed private void LoadPaneChanged() { - OnPropertyChanged(nameof(IsPreviewPaneEnabled)); + OnPropertyChanged(nameof(ShouldPreviewPaneBeActive)); OnPropertyChanged(nameof(ShouldPreviewPaneBeDisplayed)); UpdatePositioning(); } From 72ac22274cbba85f6b22906f5f6d18c9e385b8c8 Mon Sep 17 00:00:00 2001 From: Quaint Mako <110472580+QuaintMako@users.noreply.github.com> Date: Tue, 10 Jan 2023 23:04:50 +0100 Subject: [PATCH 13/19] Added and completed documentation in SDK. --- .../Services/Settings/IPaneSettingsService.cs | 21 ------------ .../Settings/IPreviewPaneSettingsService.cs | 33 +++++++++++++++++++ 2 files changed, 33 insertions(+), 21 deletions(-) delete mode 100644 src/Files.Backend/Services/Settings/IPaneSettingsService.cs create mode 100644 src/Files.Backend/Services/Settings/IPreviewPaneSettingsService.cs diff --git a/src/Files.Backend/Services/Settings/IPaneSettingsService.cs b/src/Files.Backend/Services/Settings/IPaneSettingsService.cs deleted file mode 100644 index ecdc26233f1d..000000000000 --- a/src/Files.Backend/Services/Settings/IPaneSettingsService.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Files.Shared.Enums; -using System.ComponentModel; - -namespace Files.Backend.Services.Settings -{ - public interface IPreviewPaneSettingsService : IBaseSettingsService, INotifyPropertyChanged - { - bool IsEnabled { get; set; } - - double HorizontalSizePx { get; set; } - - double VerticalSizePx { get; set; } - - double MediaVolume { get; set; } - - /// - /// Gets or sets a value indicating if the preview pane should only show the item preview without the details section - /// - bool ShowPreviewOnly { get; set; } - } -} diff --git a/src/Files.Backend/Services/Settings/IPreviewPaneSettingsService.cs b/src/Files.Backend/Services/Settings/IPreviewPaneSettingsService.cs new file mode 100644 index 000000000000..71b16fc7caba --- /dev/null +++ b/src/Files.Backend/Services/Settings/IPreviewPaneSettingsService.cs @@ -0,0 +1,33 @@ +using Files.Shared.Enums; +using System.ComponentModel; + +namespace Files.Backend.Services.Settings +{ + public interface IPreviewPaneSettingsService : IBaseSettingsService, INotifyPropertyChanged + { + /// + /// Gets or sets a value indicating if the preview pane is enabled. + /// + bool IsEnabled { get; set; } + + /// + /// Gets or sets a value indicating the height of the pane in a horizontal layout. + /// + double HorizontalSizePx { get; set; } + + /// + /// Gets or sets a value indicating the width of the pane in a vertical layout. + /// + double VerticalSizePx { get; set; } + + /// + /// Gets or sets a value indicating the preview pane media volume. + /// + double MediaVolume { get; set; } + + /// + /// Gets or sets a value indicating if the preview pane should only show the item preview without the details section. + /// + bool ShowPreviewOnly { get; set; } + } +} From 48272df2b76aeaad069a885d8bad629b5c990a18 Mon Sep 17 00:00:00 2001 From: Quaint Mako <110472580+QuaintMako@users.noreply.github.com> Date: Tue, 10 Jan 2023 23:08:55 +0100 Subject: [PATCH 14/19] Corrected comment --- src/Files.App/DataModels/AppModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/DataModels/AppModel.cs b/src/Files.App/DataModels/AppModel.cs index 079658abb649..a1af2f71c18b 100644 --- a/src/Files.App/DataModels/AppModel.cs +++ b/src/Files.App/DataModels/AppModel.cs @@ -11,7 +11,7 @@ namespace Files.App.DataModels { public class AppModel : ObservableObject { - // todo: refactor PaneViewModel, this doesn't belong here + // todo: refactor PreviewPaneViewModel, this doesn't belong here public PreviewPaneViewModel PreviewPaneViewModel { get; } = new PreviewPaneViewModel(); public AppModel() From 5b13eabff3cfc294709e85910e2e67f5fc766cdf Mon Sep 17 00:00:00 2001 From: Quaint Mako <110472580+QuaintMako@users.noreply.github.com> Date: Tue, 10 Jan 2023 23:10:20 +0100 Subject: [PATCH 15/19] Renamed enum --- .../UserControls/Pane/PreviewPane.xaml.cs | 8 ++++---- src/Files.App/Views/MainPage.xaml.cs | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs b/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs index 69b06388ab40..7ca2589792cd 100644 --- a/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs +++ b/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs @@ -9,7 +9,7 @@ namespace Files.App.UserControls { - public enum PanePositions : ushort + public enum PreviewPanePositions : ushort { None, Right, @@ -18,7 +18,7 @@ public enum PanePositions : ushort public sealed partial class PreviewPane : UserControl { - public PanePositions Position { get; private set; } = PanePositions.None; + public PreviewPanePositions Position { get; private set; } = PreviewPanePositions.None; private IPreviewPaneSettingsService PaneSettingsService { get; } = Ioc.Default.GetService(); @@ -32,12 +32,12 @@ public void UpdatePosition(double panelWidth, double panelHeight) { if (panelWidth > 700) { - Position = PanePositions.Right; + Position = PreviewPanePositions.Right; (MinWidth, MinHeight) = (150, 0); } else { - Position = PanePositions.Bottom; + Position = PreviewPanePositions.Bottom; (MinWidth, MinHeight) = (0, 140); } } diff --git a/src/Files.App/Views/MainPage.xaml.cs b/src/Files.App/Views/MainPage.xaml.cs index d8b8d8a6d3dc..20b10ee677ac 100644 --- a/src/Files.App/Views/MainPage.xaml.cs +++ b/src/Files.App/Views/MainPage.xaml.cs @@ -365,11 +365,11 @@ private void Page_SizeChanged(object sender, SizeChangedEventArgs e) { switch (PreviewPane?.Position) { - case PanePositions.Right when ContentColumn.ActualWidth == ContentColumn.MinWidth: + case PreviewPanePositions.Right when ContentColumn.ActualWidth == ContentColumn.MinWidth: UserSettingsService.PreviewPaneSettingsService.VerticalSizePx += e.NewSize.Width - e.PreviousSize.Width; UpdatePositioning(); break; - case PanePositions.Bottom when ContentRow.ActualHeight == ContentRow.MinHeight: + case PreviewPanePositions.Bottom when ContentRow.ActualHeight == ContentRow.MinHeight: UserSettingsService.PreviewPaneSettingsService.HorizontalSizePx += e.NewSize.Height - e.PreviousSize.Height; UpdatePositioning(); break; @@ -421,13 +421,13 @@ private void UpdatePositioning() PreviewPane.UpdatePosition(RootGrid.ActualWidth, RootGrid.ActualHeight); switch (PreviewPane.Position) { - case PanePositions.None: + case PreviewPanePositions.None: PaneRow.MinHeight = 0; PaneRow.Height = new GridLength(0); PaneColumn.MinWidth = 0; PaneColumn.Width = new GridLength(0); break; - case PanePositions.Right: + case PreviewPanePositions.Right: PreviewPane.SetValue(Grid.RowProperty, 1); PreviewPane.SetValue(Grid.ColumnProperty, 2); PaneSplitter.SetValue(Grid.RowProperty, 1); @@ -442,7 +442,7 @@ private void UpdatePositioning() PaneRow.MaxHeight = double.MaxValue; PaneRow.Height = new GridLength(0); break; - case PanePositions.Bottom: + case PreviewPanePositions.Bottom: PreviewPane.SetValue(Grid.RowProperty, 3); PreviewPane.SetValue(Grid.ColumnProperty, 0); PaneSplitter.SetValue(Grid.RowProperty, 2); @@ -465,10 +465,10 @@ private void PaneSplitter_ManipulationCompleted(object sender, ManipulationCompl { switch (PreviewPane?.Position) { - case PanePositions.Right: + case PreviewPanePositions.Right: UserSettingsService.PreviewPaneSettingsService.VerticalSizePx = PreviewPane.ActualWidth; break; - case PanePositions.Bottom: + case PreviewPanePositions.Bottom: UserSettingsService.PreviewPaneSettingsService.HorizontalSizePx = PreviewPane.ActualHeight; break; } From b3c38d09f2f551819b46c4af01b36230af302d9d Mon Sep 17 00:00:00 2001 From: Quaint Mako <110472580+QuaintMako@users.noreply.github.com> Date: Wed, 11 Jan 2023 13:04:50 +0100 Subject: [PATCH 16/19] Update src/Files.App/Views/MainPage.xaml Co-authored-by: yaira2 <39923744+yaira2@users.noreply.github.com> --- src/Files.App/Views/MainPage.xaml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Files.App/Views/MainPage.xaml b/src/Files.App/Views/MainPage.xaml index b5c9ff4b1a8a..bb40e4191638 100644 --- a/src/Files.App/Views/MainPage.xaml +++ b/src/Files.App/Views/MainPage.xaml @@ -337,7 +337,6 @@ Grid.Column="2" HorizontalContentAlignment="Stretch" x:Load="{x:Bind ShouldPreviewPaneBeActive, Mode=OneWay}" - Visibility="{x:Bind ShouldPreviewPaneBeActive, Mode=OneWay}" /> Date: Wed, 11 Jan 2023 17:11:00 +0100 Subject: [PATCH 17/19] Fixed wrongly added suggestion from Github --- src/Files.App/Views/MainPage.xaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Files.App/Views/MainPage.xaml b/src/Files.App/Views/MainPage.xaml index bb40e4191638..94bc3c356695 100644 --- a/src/Files.App/Views/MainPage.xaml +++ b/src/Files.App/Views/MainPage.xaml @@ -331,14 +331,14 @@ ResizeBehavior="BasedOnAlignment" Style="{StaticResource DefaultGridSplitterStyle}" /> - - Date: Wed, 11 Jan 2023 11:11:15 -0500 Subject: [PATCH 18/19] Update src/Files.App/Views/MainPage.xaml --- src/Files.App/Views/MainPage.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/Views/MainPage.xaml b/src/Files.App/Views/MainPage.xaml index bb40e4191638..14c4081d783c 100644 --- a/src/Files.App/Views/MainPage.xaml +++ b/src/Files.App/Views/MainPage.xaml @@ -336,7 +336,7 @@ Grid.Row="1" Grid.Column="2" HorizontalContentAlignment="Stretch" - x:Load="{x:Bind ShouldPreviewPaneBeActive, Mode=OneWay}" + x:Load="{x:Bind ShouldPreviewPaneBeActive, Mode=OneWay}"/> Date: Wed, 11 Jan 2023 17:13:40 +0100 Subject: [PATCH 19/19] Removed AppModel mention for Preview Pane --- src/Files.App/DataModels/AppModel.cs | 3 --- src/Files.App/UserControls/InnerNavigationToolbar.xaml | 2 +- src/Files.App/UserControls/InnerNavigationToolbar.xaml.cs | 2 ++ 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Files.App/DataModels/AppModel.cs b/src/Files.App/DataModels/AppModel.cs index a1af2f71c18b..ab94edce680b 100644 --- a/src/Files.App/DataModels/AppModel.cs +++ b/src/Files.App/DataModels/AppModel.cs @@ -11,9 +11,6 @@ namespace Files.App.DataModels { public class AppModel : ObservableObject { - // todo: refactor PreviewPaneViewModel, this doesn't belong here - public PreviewPaneViewModel PreviewPaneViewModel { get; } = new PreviewPaneViewModel(); - public AppModel() { Clipboard.ContentChanged += Clipboard_ContentChanged; diff --git a/src/Files.App/UserControls/InnerNavigationToolbar.xaml b/src/Files.App/UserControls/InnerNavigationToolbar.xaml index 4a3ffa90de8c..5cac0ffa65b1 100644 --- a/src/Files.App/UserControls/InnerNavigationToolbar.xaml +++ b/src/Files.App/UserControls/InnerNavigationToolbar.xaml @@ -823,7 +823,7 @@ MinWidth="40" AccessKey="P" AutomationProperties.Name="{helpers:ResourceString Name=PreviewPaneToggle/AutomationProperties/Name}" - IsChecked="{x:Bind AppModel.PreviewPaneViewModel.IsEnabled, Mode=TwoWay}" + IsChecked="{x:Bind PreviewPaneViewModel.IsEnabled, Mode=TwoWay}" IsEnabled="{x:Bind ShowPreviewPaneButton, Mode=OneWay}" Label="{helpers:ResourceString Name=PreviewPaneToggle/Label}" LabelPosition="Collapsed" diff --git a/src/Files.App/UserControls/InnerNavigationToolbar.xaml.cs b/src/Files.App/UserControls/InnerNavigationToolbar.xaml.cs index b340a93d34db..a8b4f9076201 100644 --- a/src/Files.App/UserControls/InnerNavigationToolbar.xaml.cs +++ b/src/Files.App/UserControls/InnerNavigationToolbar.xaml.cs @@ -27,6 +27,8 @@ public InnerNavigationToolbar() public AppModel AppModel => App.AppModel; + public PreviewPaneViewModel PreviewPaneViewModel => App.PreviewPaneViewModel; + public ToolbarViewModel ViewModel { get => (ToolbarViewModel)GetValue(ViewModelProperty);