diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs index dd705b0d7a08..b2ae46af4f63 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; } @@ -109,7 +108,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: @@ -149,7 +148,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 1be572b990d7..80e49e3c7159 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)?.ShouldPreviewPaneBeActive ?? false; if (isPaneEnabled) App.PreviewPaneViewModel.UpdateSelectedItemPreview(); } @@ -1039,7 +1039,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..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 PaneViewModel, this doesn't belong here - public IPaneViewModel PaneViewModel { get; } = new PaneViewModel(); - public AppModel() { Clipboard.ContentChanged += Clipboard_ContentChanged; 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/PaneSettingsService.cs b/src/Files.App/ServicesImplementation/Settings/PreviewPaneSettingsService.cs similarity index 81% rename from src/Files.App/ServicesImplementation/Settings/PaneSettingsService.cs rename to src/Files.App/ServicesImplementation/Settings/PreviewPaneSettingsService.cs index bc70b71352d4..bbebd1db25eb 100644 --- a/src/Files.App/ServicesImplementation/Settings/PaneSettingsService.cs +++ b/src/Files.App/ServicesImplementation/Settings/PreviewPaneSettingsService.cs @@ -7,11 +7,11 @@ namespace Files.App.ServicesImplementation.Settings { - internal sealed class PaneSettingsService : BaseObservableJsonSettings, IPaneSettingsService + internal sealed class PreviewPaneSettingsService : BaseObservableJsonSettings, IPreviewPaneSettingsService { - public PaneContents Content + public bool IsEnabled { - get => Get(PaneContents.None); + get => Get(false); set => Set(value); } @@ -39,7 +39,7 @@ public bool ShowPreviewOnly set => Set(value); } - public PaneSettingsService(ISettingsSharingContext settingsSharingContext) + public PreviewPaneSettingsService(ISettingsSharingContext settingsSharingContext) { RegisterSettingsContext(settingsSharingContext); } diff --git a/src/Files.App/ServicesImplementation/Settings/UserSettingsService.cs b/src/Files.App/ServicesImplementation/Settings/UserSettingsService.cs index ee93bdf5fcbc..41a57f802d28 100644 --- a/src/Files.App/ServicesImplementation/Settings/UserSettingsService.cs +++ b/src/Files.App/ServicesImplementation/Settings/UserSettingsService.cs @@ -30,10 +30,10 @@ public IAppearanceSettingsService AppearanceSettingsService get => GetSettingsService(ref _AppearanceSettingsService); } - private IPaneSettingsService _PaneSettingsService; - public IPaneSettingsService 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 c0202e3778a3..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.PaneViewModel.IsPreviewSelected, 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); 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/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..7ca2589792cd 100644 --- a/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs +++ b/src/Files.App/UserControls/Pane/PreviewPane.xaml.cs @@ -9,11 +9,18 @@ namespace Files.App.UserControls { - public sealed partial class PreviewPane : UserControl, IPane + public enum PreviewPanePositions : ushort { - public PanePositions Position { get; private set; } = PanePositions.None; + None, + Right, + Bottom, + } + + public sealed partial class PreviewPane : UserControl + { + public PreviewPanePositions Position { get; private set; } = PreviewPanePositions.None; - private IPaneSettingsService PaneSettingsService { get; } = Ioc.Default.GetService(); + private IPreviewPaneSettingsService PaneSettingsService { get; } = Ioc.Default.GetService(); private PreviewPaneViewModel ViewModel => App.PreviewPaneViewModel; @@ -25,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); } } @@ -39,11 +46,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/ViewModels/ItemViewModel.cs b/src/Files.App/ViewModels/ItemViewModel.cs index 7f5ca6c029ea..cbc299d4522d 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 fbd264c80d0c..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 IPaneSettingsService 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(IPaneSettingsService.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/PreviewPaneViewModel.cs b/src/Files.App/ViewModels/PreviewPaneViewModel.cs index 1905cd207d69..0125b3a2a1fa 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,22 @@ 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 + { + PreviewSettingsService.IsEnabled = value; + SetProperty(ref isEnabled, value); + } + } + private bool isItemSelected; public bool IsItemSelected { get => isItemSelected; @@ -34,7 +47,6 @@ public bool IsItemSelected } private ListedItem selectedItem; - public ListedItem SelectedItem { get => selectedItem; @@ -42,7 +54,6 @@ public ListedItem SelectedItem } private PreviewPaneStates previewPaneState; - public PreviewPaneStates PreviewPaneState { get => previewPaneState; @@ -50,7 +61,6 @@ public PreviewPaneStates PreviewPaneState } private bool showCloudItemButton; - public bool ShowCloudItemButton { get => showCloudItemButton; @@ -58,7 +68,6 @@ public bool ShowCloudItemButton } private UIElement previewPaneContent; - public UIElement PreviewPaneContent { get => previewPaneContent; @@ -69,7 +78,9 @@ public PreviewPaneViewModel() { ShowPreviewOnlyInvoked = new RelayCommand(() => UpdateSelectedItemPreview()); + IsEnabled = PreviewSettingsService.IsEnabled; UserSettingsService.OnSettingChangedEvent += UserSettingsService_OnSettingChangedEvent; + PreviewSettingsService.PropertyChanged += PreviewSettingsService_OnPropertyChangedEvent; } private async Task LoadPreviewControlAsync(CancellationToken token, bool downloadItem) @@ -267,13 +278,26 @@ public async void UpdateSelectedItemPreview(bool downloadItem = false) private void UserSettingsService_OnSettingChangedEvent(object sender, SettingChangedEventArgs e) { - if (e.SettingName == nameof(IPaneSettingsService.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 @@ -308,6 +332,7 @@ public void TryRefresh() public void Dispose() { UserSettingsService.OnSettingChangedEvent -= UserSettingsService_OnSettingChangedEvent; + PreviewSettingsService.PropertyChanged -= PreviewSettingsService_OnPropertyChangedEvent; } } 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 c55faeaff117..458245260d87 100644 --- a/src/Files.App/Views/ColumnShellPage.xaml.cs +++ b/src/Files.App/Views/ColumnShellPage.xaml.cs @@ -756,7 +756,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 4159bfa9399b..5fd7ba6563b8 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" /> - - - + + private void UpdatePositioning() { - if (Pane is null || !IsPaneEnabled) + if (PreviewPane is null || !ShouldPreviewPaneBeActive) { PaneRow.MinHeight = 0; PaneRow.MaxHeight = double.MaxValue; @@ -418,33 +418,33 @@ 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: + case PreviewPanePositions.None: PaneRow.MinHeight = 0; PaneRow.Height = new GridLength(0); PaneColumn.MinWidth = 0; PaneColumn.Width = new GridLength(0); break; - case PanePositions.Right: - Pane.SetValue(Grid.RowProperty, 1); - Pane.SetValue(Grid.ColumnProperty, 2); + case PreviewPanePositions.Right: + 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.Width = new GridLength(UserSettingsService.PaneSettingsService.VerticalSizePx, GridUnitType.Pixel); + PaneColumn.MinWidth = PreviewPane.MinWidth; + PaneColumn.MaxWidth = PreviewPane.MaxWidth; + PaneColumn.Width = new GridLength(UserSettingsService.PreviewPaneSettingsService.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); + case PreviewPanePositions.Bottom: + PreviewPane.SetValue(Grid.RowProperty, 3); + PreviewPane.SetValue(Grid.ColumnProperty, 0); PaneSplitter.SetValue(Grid.RowProperty, 2); PaneSplitter.SetValue(Grid.ColumnProperty, 0); PaneSplitter.Height = 2; @@ -453,9 +453,9 @@ private void UpdatePositioning() PaneColumn.MinWidth = 0; PaneColumn.MaxWidth = double.MaxValue; PaneColumn.Width = new GridLength(0); - PaneRow.MinHeight = Pane.MinHeight; - PaneRow.MaxHeight = Pane.MaxHeight; - PaneRow.Height = new GridLength(UserSettingsService.PaneSettingsService.HorizontalSizePx, GridUnitType.Pixel); + PaneRow.MinHeight = PreviewPane.MinHeight; + PaneRow.MaxHeight = PreviewPane.MaxHeight; + PaneRow.Height = new GridLength(UserSettingsService.PreviewPaneSettingsService.HorizontalSizePx, GridUnitType.Pixel); break; } } @@ -463,24 +463,20 @@ 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; + case PreviewPanePositions.Right: + UserSettingsService.PreviewPaneSettingsService.VerticalSizePx = PreviewPane.ActualWidth; break; - case PanePositions.Bottom: - UserSettingsService.PaneSettingsService.HorizontalSizePx = Pane.ActualHeight; + case PreviewPanePositions.Bottom: + UserSettingsService.PreviewPaneSettingsService.HorizontalSizePx = PreviewPane.ActualHeight; break; } } - public bool IsPaneEnabled => UserSettingsService.PaneSettingsService.Content switch - { - PaneContents.Preview => IsPreviewPaneEnabled, - _ => false, - }; + public bool ShouldPreviewPaneBeActive => UserSettingsService.PreviewPaneSettingsService.IsEnabled && ShouldPreviewPaneBeDisplayed; - public bool IsPreviewPaneEnabled + public bool ShouldPreviewPaneBeDisplayed { get { @@ -495,8 +491,8 @@ public bool IsPreviewPaneEnabled private void LoadPaneChanged() { - OnPropertyChanged(nameof(IsPaneEnabled)); - OnPropertyChanged(nameof(IsPreviewPaneEnabled)); + OnPropertyChanged(nameof(ShouldPreviewPaneBeActive)); + OnPropertyChanged(nameof(ShouldPreviewPaneBeDisplayed)); UpdatePositioning(); } diff --git a/src/Files.App/Views/ModernShellPage.xaml.cs b/src/Files.App/Views/ModernShellPage.xaml.cs index 20494af888c0..3b77ffa02c6e 100644 --- a/src/Files.App/Views/ModernShellPage.xaml.cs +++ b/src/Files.App/Views/ModernShellPage.xaml.cs @@ -760,7 +760,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/IPreviewPaneSettingsService.cs similarity index 67% rename from src/Files.Backend/Services/Settings/IPaneSettingsService.cs rename to src/Files.Backend/Services/Settings/IPreviewPaneSettingsService.cs index 472985566559..71b16fc7caba 100644 --- a/src/Files.Backend/Services/Settings/IPaneSettingsService.cs +++ b/src/Files.Backend/Services/Settings/IPreviewPaneSettingsService.cs @@ -3,12 +3,12 @@ namespace Files.Backend.Services.Settings { - public interface IPaneSettingsService : IBaseSettingsService, INotifyPropertyChanged + public interface IPreviewPaneSettingsService : IBaseSettingsService, INotifyPropertyChanged { /// - /// Gets or sets the selected content. + /// Gets or sets a value indicating if the preview pane is enabled. /// - PaneContents Content { get; set; } + bool IsEnabled { get; set; } /// /// Gets or sets a value indicating the height of the pane in a horizontal layout. @@ -21,12 +21,12 @@ public interface IPaneSettingsService : IBaseSettingsService, INotifyPropertyCha double VerticalSizePx { get; set; } /// - /// Gets or sets a value indicating the default volume on media. + /// 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 + /// 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/IUserSettingsService.cs b/src/Files.Backend/Services/Settings/IUserSettingsService.cs index ab1112190f88..46fe503a34d2 100644 --- a/src/Files.Backend/Services/Settings/IUserSettingsService.cs +++ b/src/Files.Backend/Services/Settings/IUserSettingsService.cs @@ -19,7 +19,7 @@ public interface IUserSettingsService : IBaseSettingsService IApplicationSettingsService ApplicationSettingsService { get; } - IPaneSettingsService 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, - } -}