From 1e9476eae1dd33bcfd8d5b81604a77fcb3b5dcf9 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Wed, 13 Dec 2023 00:19:47 +0900 Subject: [PATCH] Fix: Fixed issue where resizing window would reload preview (#14227) --- src/Files.App/ViewModels/MainPageViewModel.cs | 21 ++++++++++ .../UserControls/InfoPaneViewModel.cs | 2 +- src/Files.App/Views/MainPage.xaml | 9 ++-- src/Files.App/Views/MainPage.xaml.cs | 42 ++++++------------- 4 files changed, 39 insertions(+), 35 deletions(-) diff --git a/src/Files.App/ViewModels/MainPageViewModel.cs b/src/Files.App/ViewModels/MainPageViewModel.cs index 57eb525122a2..3545385b9d4f 100644 --- a/src/Files.App/ViewModels/MainPageViewModel.cs +++ b/src/Files.App/ViewModels/MainPageViewModel.cs @@ -36,6 +36,27 @@ public TabBarItem? SelectedTabItem set => SetProperty(ref selectedTabItem, value); } + private bool shouldViewControlBeDisplayed; + public bool ShouldViewControlBeDisplayed + { + get => shouldViewControlBeDisplayed; + set => SetProperty(ref shouldViewControlBeDisplayed, value); + } + + private bool shouldPreviewPaneBeActive; + public bool ShouldPreviewPaneBeActive + { + get => shouldPreviewPaneBeActive; + set => SetProperty(ref shouldPreviewPaneBeActive, value); + } + + private bool shouldPreviewPaneBeDisplayed; + public bool ShouldPreviewPaneBeDisplayed + { + get => shouldPreviewPaneBeDisplayed; + set => SetProperty(ref shouldPreviewPaneBeDisplayed, value); + } + // Commands public ICommand NavigateToNumberedTabKeyboardAcceleratorCommand { get; } diff --git a/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs b/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs index 871389efaad5..074c5fc67523 100644 --- a/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs @@ -129,7 +129,7 @@ private void ContentPageContext_PropertyChanged(object? sender, PropertyChangedE else SelectedItem = null; - var shouldUpdatePreview = ((MainWindow.Instance.Content as Frame)?.Content as MainPage)?.ShouldPreviewPaneBeActive; + var shouldUpdatePreview = ((MainWindow.Instance.Content as Frame)?.Content as MainPage)?.ViewModel.ShouldPreviewPaneBeActive; if (shouldUpdatePreview == true) _ = UpdateSelectedItemPreviewAsync(); break; diff --git a/src/Files.App/Views/MainPage.xaml b/src/Files.App/Views/MainPage.xaml index e069270dc4f4..7d046508ddbb 100644 --- a/src/Files.App/Views/MainPage.xaml +++ b/src/Files.App/Views/MainPage.xaml @@ -11,7 +11,6 @@ xmlns:sidebar="using:Files.App.UserControls.Sidebar" xmlns:tabbar="using:Files.App.UserControls.TabBar" xmlns:toolkit="using:CommunityToolkit.WinUI.UI.Controls" - xmlns:triggers="using:CommunityToolkit.WinUI.UI.Triggers" xmlns:uc="using:Files.App.UserControls" xmlns:viewmodels="using:Files.App.ViewModels" xmlns:wctconverters="using:CommunityToolkit.WinUI.UI.Converters" @@ -238,8 +237,8 @@ Grid.ColumnSpan="3" x:Load="False" Loaded="NavToolbar_Loaded" - ShowPreviewPaneButton="{x:Bind ShouldPreviewPaneBeDisplayed, Mode=OneWay}" - ShowViewControlButton="{x:Bind ShouldViewControlBeDisplayed, Mode=OneWay}" + ShowPreviewPaneButton="{x:Bind ViewModel.ShouldPreviewPaneBeDisplayed, Mode=OneWay}" + ShowViewControlButton="{x:Bind ViewModel.ShouldViewControlBeDisplayed, Mode=OneWay}" TabIndex="2" /> @@ -255,7 +254,7 @@ x:Name="PaneSplitter" Grid.Row="1" Grid.Column="1" - x:Load="{x:Bind ShouldPreviewPaneBeActive, Mode=OneWay}" + x:Load="{x:Bind ViewModel.ShouldPreviewPaneBeActive, Mode=OneWay}" ManipulationCompleted="PaneSplitter_ManipulationCompleted" ManipulationStarted="PaneSplitter_ManipulationStarted" ResizeBehavior="BasedOnAlignment" @@ -267,7 +266,7 @@ Grid.Row="1" Grid.Column="2" HorizontalContentAlignment="Stretch" - x:Load="{x:Bind ShouldPreviewPaneBeActive, Mode=OneWay}" + x:Load="{x:Bind ViewModel.ShouldPreviewPaneBeActive, Mode=OneWay}" Loaded="PreviewPane_Loaded" Unloaded="PreviewPane_Unloaded" /> diff --git a/src/Files.App/Views/MainPage.xaml.cs b/src/Files.App/Views/MainPage.xaml.cs index efd0901de528..a3fc07b0bcc4 100644 --- a/src/Files.App/Views/MainPage.xaml.cs +++ b/src/Files.App/Views/MainPage.xaml.cs @@ -12,7 +12,6 @@ using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Navigation; -using System.Runtime.CompilerServices; using Windows.ApplicationModel; using Windows.Foundation.Metadata; using Windows.Services.Store; @@ -21,7 +20,7 @@ namespace Files.App.Views { - public sealed partial class MainPage : Page, INotifyPropertyChanged + public sealed partial class MainPage : Page { public IUserSettingsService UserSettingsService { get; } public IApplicationService ApplicationService { get; } @@ -62,6 +61,7 @@ public MainPage() if (FilePropertiesHelpers.FlowDirectionSettingIsRightToLeft) FlowDirection = FlowDirection.RightToLeft; + ViewModel.PropertyChanged += ViewModel_PropertyChanged; UserSettingsService.OnSettingChangedEvent += UserSettingsService_OnSettingChangedEvent; _updateDateDisplayTimer = DispatcherQueue.CreateTimer(); @@ -363,7 +363,7 @@ private void SidebarControl_Loaded(object sender, RoutedEventArgs e) /// private void UpdatePositioning() { - if (PreviewPane is null || !ShouldPreviewPaneBeActive) + if (PreviewPane is null || !ViewModel.ShouldPreviewPaneBeActive) { PaneRow.MinHeight = 0; PaneRow.MaxHeight = double.MaxValue; @@ -434,39 +434,23 @@ private void PaneSplitter_ManipulationCompleted(object sender, ManipulationCompl this.ChangeCursor(InputSystemCursor.Create(InputSystemCursorShape.Arrow)); } - public bool ShouldViewControlBeDisplayed => SidebarAdaptiveViewModel.PaneHolder?.ActivePane?.InstanceViewModel?.IsPageTypeNotHome ?? false; - - public bool ShouldPreviewPaneBeActive => UserSettingsService.InfoPaneSettingsService.IsEnabled && ShouldPreviewPaneBeDisplayed; - - public bool ShouldPreviewPaneBeDisplayed + private void LoadPaneChanged() { - get - { - var isHomePage = !(SidebarAdaptiveViewModel.PaneHolder?.ActivePane?.InstanceViewModel?.IsPageTypeNotHome ?? false); - var isMultiPane = SidebarAdaptiveViewModel.PaneHolder?.IsMultiPaneActive ?? false; - var isBigEnough = MainWindow.Instance.Bounds.Width > 450 && MainWindow.Instance.Bounds.Height > 450 || RootGrid.ActualWidth > 700 && MainWindow.Instance.Bounds.Height > 360; - var isEnabled = (!isHomePage || isMultiPane) && isBigEnough; + var isHomePage = !(SidebarAdaptiveViewModel.PaneHolder?.ActivePane?.InstanceViewModel?.IsPageTypeNotHome ?? false); + var isMultiPane = SidebarAdaptiveViewModel.PaneHolder?.IsMultiPaneActive ?? false; + var isBigEnough = MainWindow.Instance.Bounds.Width > 450 && MainWindow.Instance.Bounds.Height > 450 || RootGrid.ActualWidth > 700 && MainWindow.Instance.Bounds.Height > 360; - return isEnabled; - } - } + ViewModel.ShouldPreviewPaneBeDisplayed = (!isHomePage || isMultiPane) && isBigEnough; + ViewModel.ShouldPreviewPaneBeActive = UserSettingsService.InfoPaneSettingsService.IsEnabled && ViewModel.ShouldPreviewPaneBeDisplayed; + ViewModel.ShouldViewControlBeDisplayed = SidebarAdaptiveViewModel.PaneHolder?.ActivePane?.InstanceViewModel?.IsPageTypeNotHome ?? false; - private void LoadPaneChanged() - { - OnPropertyChanged(nameof(ShouldViewControlBeDisplayed)); - OnPropertyChanged(nameof(ShouldPreviewPaneBeActive)); - OnPropertyChanged(nameof(ShouldPreviewPaneBeDisplayed)); UpdatePositioning(); } - public event PropertyChangedEventHandler? PropertyChanged; - - private void OnPropertyChanged([CallerMemberName] string propertyName = "") + private async void ViewModel_PropertyChanged(object? sender, PropertyChangedEventArgs e) { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - - if (propertyName == nameof(ShouldPreviewPaneBeActive) && ShouldPreviewPaneBeActive) - _ = Ioc.Default.GetRequiredService().UpdateSelectedItemPreviewAsync(); + if (e.PropertyName == nameof(ViewModel.ShouldPreviewPaneBeActive) && ViewModel.ShouldPreviewPaneBeActive) + await Ioc.Default.GetRequiredService().UpdateSelectedItemPreviewAsync(); } private void RootGrid_PreviewKeyDown(object sender, KeyRoutedEventArgs e)