diff --git a/src/Files.App/UserControls/Pane/InfoPane.xaml b/src/Files.App/UserControls/Pane/InfoPane.xaml index f63a282945e6..aebb8af4b9e3 100644 --- a/src/Files.App/UserControls/Pane/InfoPane.xaml +++ b/src/Files.App/UserControls/Pane/InfoPane.xaml @@ -20,7 +20,6 @@ d:DesignHeight="300" d:DesignWidth="400" AutomationProperties.Name="{helpers:ResourceString Name=SelectedFilePreviewPane/AutomationProperties/Name}" - Loaded="Root_Loaded" SizeChanged="Root_SizeChanged" Unloaded="Root_Unloaded" mc:Ignorable="d"> diff --git a/src/Files.App/UserControls/Pane/InfoPane.xaml.cs b/src/Files.App/UserControls/Pane/InfoPane.xaml.cs index 4946bba7f010..747511ec31f3 100644 --- a/src/Files.App/UserControls/Pane/InfoPane.xaml.cs +++ b/src/Files.App/UserControls/Pane/InfoPane.xaml.cs @@ -52,9 +52,6 @@ public void UpdatePosition(double panelWidth, double panelHeight) private string GetLocalizedResource(string resName) => resName.GetLocalizedResource(); - private void Root_Loaded(object sender, RoutedEventArgs e) - => ViewModel?.UpdateSelectedItemPreviewAsync(); - private void Root_Unloaded(object sender, RoutedEventArgs e) { PreviewControlPresenter.Content = null; diff --git a/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs b/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs index b6949d59ac48..871389efaad5 100644 --- a/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs @@ -13,11 +13,13 @@ namespace Files.App.ViewModels.UserControls public class InfoPaneViewModel : ObservableObject, IDisposable { private IInfoPaneSettingsService infoPaneSettingsService { get; } = Ioc.Default.GetRequiredService(); - - private readonly IContentPageContext contentPageContextService; + private IContentPageContext contentPageContext { get; } = Ioc.Default.GetRequiredService(); private CancellationTokenSource loadCancellationTokenSource; + /// + /// Value indicating if the info pane is on/off + /// private bool isEnabled; public bool IsEnabled { @@ -30,13 +32,10 @@ public bool IsEnabled } } - private bool isItemSelected; - public bool IsItemSelected - { - get => isItemSelected; - set => SetProperty(ref isItemSelected, value); - } - + /// + /// Current selected item in the file list. + /// TODO see about removing this and accessing it from the page context instead + /// private ListedItem selectedItem; public ListedItem SelectedItem { @@ -57,6 +56,9 @@ public ListedItem SelectedItem } } + /// + /// Enum indicating whether to show the details or preview tab + /// public InfoPaneTabs SelectedTab { get => infoPaneSettingsService.SelectedTab; @@ -69,6 +71,9 @@ public InfoPaneTabs SelectedTab } } + /// + /// Enum indicating if details/preview are available + /// private PreviewPaneStates previewPaneState; public PreviewPaneStates PreviewPaneState { @@ -80,6 +85,9 @@ public PreviewPaneStates PreviewPaneState } } + /// + /// Value indicating if the download cloud files option should be displayed + /// private bool showCloudItemButton; public bool ShowCloudItemButton { @@ -101,13 +109,31 @@ PreviewPaneState is PreviewPaneStates.NoPreviewAvailable || public ObservableCollection Items { get; } = new(); - public InfoPaneViewModel(IContentPageContext contentPageContextService = null) + public InfoPaneViewModel() { infoPaneSettingsService.PropertyChanged += PreviewSettingsService_OnPropertyChangedEvent; + contentPageContext.PropertyChanged += ContentPageContext_PropertyChanged; IsEnabled = infoPaneSettingsService.IsEnabled; + } - this.contentPageContextService = contentPageContextService ?? Ioc.Default.GetRequiredService(); + private void ContentPageContext_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + switch (e.PropertyName) + { + case nameof(IContentPageContext.Folder): + case nameof(IContentPageContext.SelectedItem): + + if (contentPageContext.SelectedItems.Count == 1) + SelectedItem = contentPageContext.SelectedItems.First(); + else + SelectedItem = null; + + var shouldUpdatePreview = ((MainWindow.Instance.Content as Frame)?.Content as MainPage)?.ShouldPreviewPaneBeActive; + if (shouldUpdatePreview == true) + _ = UpdateSelectedItemPreviewAsync(); + break; + } } private async Task LoadPreviewControlAsync(CancellationToken token, bool downloadItem) @@ -148,7 +174,7 @@ private async Task GetBuiltInPreviewControlAsync(ListedItem item, b { ShowCloudItemButton = false; - if (SelectedItem.IsRecycleBinItem) + if (item.IsRecycleBinItem) { if (item.PrimaryItemAttribute == StorageItemTypes.Folder && !item.IsArchive) { @@ -159,7 +185,7 @@ private async Task GetBuiltInPreviewControlAsync(ListedItem item, b } else { - var model = new BasicPreviewViewModel(SelectedItem); + var model = new BasicPreviewViewModel(item); await model.LoadAsync(); return new BasicPreview(model); @@ -168,7 +194,7 @@ private async Task GetBuiltInPreviewControlAsync(ListedItem item, b if (item.IsShortcut) { - var model = new ShortcutPreviewViewModel(SelectedItem); + var model = new ShortcutPreviewViewModel(item); await model.LoadAsync(); return new BasicPreview(model); @@ -187,7 +213,7 @@ private async Task GetBuiltInPreviewControlAsync(ListedItem item, b var model = new FolderPreviewViewModel(item); await model.LoadAsync(); - if (!isItemSelected) + if (contentPageContext.SelectedItems.Count == 0) item.FileTags ??= FileTagsHelper.ReadFileTag(item.ItemPath); return new FolderPreview(model); @@ -206,7 +232,7 @@ private async Task GetBuiltInPreviewControlAsync(ListedItem item, b var ext = item.FileExtension.ToLowerInvariant(); if (!item.IsFtpItem && - contentPageContextService.PageType != ContentPageTypes.ZipFolder && + contentPageContext.PageType != ContentPageTypes.ZipFolder && (FileExtensionHelpers.IsAudioFile(ext) || FileExtensionHelpers.IsVideoFile(ext))) { var model = new MediaPreviewViewModel(item); @@ -291,7 +317,7 @@ private async Task GetBuiltInPreviewControlAsync(ListedItem item, b public async Task UpdateSelectedItemPreviewAsync(bool downloadItem = false) { loadCancellationTokenSource?.Cancel(); - if (SelectedItem is not null && IsItemSelected) + if (SelectedItem is not null && contentPageContext.SelectedItems.Count == 1) { SelectedItem?.FileDetails?.Clear(); @@ -328,7 +354,7 @@ public async Task UpdateSelectedItemPreviewAsync(bool downloadItem = false) PreviewPaneState = PreviewPaneStates.NoPreviewOrDetailsAvailable; } } - else if (IsItemSelected) + else if (contentPageContext.SelectedItems.Count > 0) { PreviewPaneContent = null; PreviewPaneState = PreviewPaneStates.NoPreviewOrDetailsAvailable; @@ -336,7 +362,7 @@ public async Task UpdateSelectedItemPreviewAsync(bool downloadItem = false) else { SelectedItem?.FileDetails?.Clear(); - var currentFolder = contentPageContextService.Folder; + var currentFolder = contentPageContext.Folder; if (currentFolder is null) { @@ -388,6 +414,7 @@ private async void PreviewSettingsService_OnPropertyChangedEvent(object? sender, if (isEnabled != newEnablingStatus) { isEnabled = newEnablingStatus; + _ = UpdateSelectedItemPreviewAsync(); OnPropertyChanged(nameof(IsEnabled)); } } diff --git a/src/Files.App/Views/Layouts/BaseLayoutPage.cs b/src/Files.App/Views/Layouts/BaseLayoutPage.cs index 58eec8c1256a..ff1315ff446a 100644 --- a/src/Files.App/Views/Layouts/BaseLayoutPage.cs +++ b/src/Files.App/Views/Layouts/BaseLayoutPage.cs @@ -225,8 +225,6 @@ internal set { if (value != selectedItems) { - UpdatePreviewPaneSelection(value); - selectedItems = value; if (selectedItems?.Count == 0 || selectedItems?[0] is null) @@ -507,9 +505,6 @@ navigationArguments.SelectItems is not null && } else if (navigationArguments is not null && navigationArguments.FocusOnNavigation) { - if (SelectedItems?.Count == 0) - UpdatePreviewPaneSelection(null); - // Set focus on layout specific file list control ItemManipulationModel.FocusFileList(); } @@ -1429,32 +1424,6 @@ await DispatcherQueue.EnqueueOrInvokeAsync(() => } } - public void ReloadPreviewPane() - { - UpdatePreviewPaneSelection(SelectedItems); - } - - protected void UpdatePreviewPaneSelection(List? value) - { - if (LockPreviewPaneContent) - return; - - if (value?.FirstOrDefault() != InfoPaneViewModel.SelectedItem) - { - // Update preview pane properties - InfoPaneViewModel.IsItemSelected = value?.Count > 0; - InfoPaneViewModel.SelectedItem = value?.Count == 1 ? value.First() : null; - - // Check if the preview pane is open before updating the model - if (InfoPaneViewModel.IsEnabled && !App.AppModel.IsMainWindowClosed) - { - var isPaneEnabled = ((MainWindow.Instance.Content as Frame)?.Content as MainPage)?.ShouldPreviewPaneBeActive ?? false; - if (isPaneEnabled) - _ = InfoPaneViewModel.UpdateSelectedItemPreviewAsync(); - } - } - } - public class ContextMenuExtensions : DependencyObject { public static ItemsControl GetItemsControl(DependencyObject obj) diff --git a/src/Files.App/Views/Layouts/ColumnsLayoutPage.xaml.cs b/src/Files.App/Views/Layouts/ColumnsLayoutPage.xaml.cs index 199d1e4e6369..dd64edc69379 100644 --- a/src/Files.App/Views/Layouts/ColumnsLayoutPage.xaml.cs +++ b/src/Files.App/Views/Layouts/ColumnsLayoutPage.xaml.cs @@ -331,9 +331,6 @@ public void MoveFocusToNextBlade(int currentBladeIndex) if (activeBladeColumnViewBase is not null) { activeBladeColumnViewBase.FileList.SelectedIndex = 0; - var selectedItem = activeBladeColumnViewBase.FileList.Items.FirstOrDefault() as ListedItem; - if (selectedItem is not null) - UpdatePreviewPaneSelection(new List() { selectedItem }); } } diff --git a/src/Files.App/Views/Layouts/IBaseLayoutPage.cs b/src/Files.App/Views/Layouts/IBaseLayoutPage.cs index fe407891a733..a4145c345733 100644 --- a/src/Files.App/Views/Layouts/IBaseLayoutPage.cs +++ b/src/Files.App/Views/Layouts/IBaseLayoutPage.cs @@ -36,7 +36,5 @@ public interface IBaseLayoutPage : IDisposable CommandBarFlyout ItemContextMenuFlyout { get; set; } CommandBarFlyout BaseContextMenuFlyout { get; set; } - - void ReloadPreviewPane(); } } diff --git a/src/Files.App/Views/MainPage.xaml.cs b/src/Files.App/Views/MainPage.xaml.cs index 2535ded919e4..15f2ee8da516 100644 --- a/src/Files.App/Views/MainPage.xaml.cs +++ b/src/Files.App/Views/MainPage.xaml.cs @@ -189,8 +189,6 @@ public void MultitaskingControl_CurrentInstanceChanged(object? sender, CurrentIn e.CurrentInstance.ContentChanged -= TabItemContent_ContentChanged; e.CurrentInstance.ContentChanged += TabItemContent_ContentChanged; - - SidebarAdaptiveViewModel.PaneHolder?.ActivePaneOrColumn.SlimContentPage?.ReloadPreviewPane(); } private void PaneHolder_PropertyChanged(object? sender, PropertyChangedEventArgs e) diff --git a/src/Files.App/Views/PaneHolderPage.xaml.cs b/src/Files.App/Views/PaneHolderPage.xaml.cs index 040277a106d5..64b88a00641c 100644 --- a/src/Files.App/Views/PaneHolderPage.xaml.cs +++ b/src/Files.App/Views/PaneHolderPage.xaml.cs @@ -352,15 +352,7 @@ private async void Pane_GotFocus(object sender, RoutedEventArgs e) var activePane = isLeftPane ? PaneLeft : PaneRight; if (ActivePane != activePane) - { ActivePane = activePane; - - if (ActivePane?.SlimContentPage is IBaseLayoutPage page && !page.IsItemSelected) - { - page.InfoPaneViewModel.IsItemSelected = false; - await page.InfoPaneViewModel.UpdateSelectedItemPreviewAsync(); - } - } } private void Pane_RightTapped(object sender, RoutedEventArgs e)