Skip to content

Fix: Fixed issue where resizing window would reload preview #14227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Files.App/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions src/Files.App/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" />

<!-- Page Content -->
Expand All @@ -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"
Expand All @@ -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" />

Expand Down
42 changes: 13 additions & 29 deletions src/Files.App/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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; }
Expand Down Expand Up @@ -62,6 +61,7 @@ public MainPage()
if (FilePropertiesHelpers.FlowDirectionSettingIsRightToLeft)
FlowDirection = FlowDirection.RightToLeft;

ViewModel.PropertyChanged += ViewModel_PropertyChanged;
UserSettingsService.OnSettingChangedEvent += UserSettingsService_OnSettingChangedEvent;

_updateDateDisplayTimer = DispatcherQueue.CreateTimer();
Expand Down Expand Up @@ -363,7 +363,7 @@ private void SidebarControl_Loaded(object sender, RoutedEventArgs e)
/// </summary>
private void UpdatePositioning()
{
if (PreviewPane is null || !ShouldPreviewPaneBeActive)
if (PreviewPane is null || !ViewModel.ShouldPreviewPaneBeActive)
{
PaneRow.MinHeight = 0;
PaneRow.MaxHeight = double.MaxValue;
Expand Down Expand Up @@ -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<InfoPaneViewModel>().UpdateSelectedItemPreviewAsync();
if (e.PropertyName == nameof(ViewModel.ShouldPreviewPaneBeActive) && ViewModel.ShouldPreviewPaneBeActive)
await Ioc.Default.GetRequiredService<InfoPaneViewModel>().UpdateSelectedItemPreviewAsync();
}

private void RootGrid_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
Expand Down