From e504653323eb85404276fb962aeba82da44cbcab Mon Sep 17 00:00:00 2001 From: Samuel Chapleau Date: Wed, 7 Dec 2022 20:47:35 -0800 Subject: [PATCH] Update titlebar filecount text --- src/modules/peek/Peek.UI/FolderItemsQuery.cs | 9 +- src/modules/peek/Peek.UI/MainWindow.xaml | 2 + .../peek/Peek.UI/Strings/en-us/Resources.resw | 2 +- src/modules/peek/Peek.UI/Views/TitleBar.xaml | 5 +- .../peek/Peek.UI/Views/TitleBar.xaml.cs | 105 +++++++++++------- 5 files changed, 79 insertions(+), 44 deletions(-) diff --git a/src/modules/peek/Peek.UI/FolderItemsQuery.cs b/src/modules/peek/Peek.UI/FolderItemsQuery.cs index caff1fe1d0..6da09fc047 100644 --- a/src/modules/peek/Peek.UI/FolderItemsQuery.cs +++ b/src/modules/peek/Peek.UI/FolderItemsQuery.cs @@ -26,7 +26,11 @@ namespace Peek.UI [ObservableProperty] private List files = new (); - public int CurrentItemIndex { get; private set; } = UninitializedItemIndex; + [ObservableProperty] + private bool isMultiSelection; + + [ObservableProperty] + private int currentItemIndex = UninitializedItemIndex; private CancellationTokenSource CancellationTokenSource { get; set; } = new CancellationTokenSource(); @@ -35,6 +39,7 @@ namespace Peek.UI public void Clear() { CurrentFile = null; + IsMultiSelection = false; if (InitializeFilesTask != null && InitializeFilesTask.Status == TaskStatus.Running) { @@ -89,6 +94,8 @@ namespace Peek.UI return; } + IsMultiSelection = selectedItems.Count > 1; + // Prioritize setting CurrentFile, which notifies UI var firstSelectedItem = selectedItems.Item(0); CurrentFile = new File(firstSelectedItem.Path); diff --git a/src/modules/peek/Peek.UI/MainWindow.xaml b/src/modules/peek/Peek.UI/MainWindow.xaml index 78d554c5c0..66fc23003c 100644 --- a/src/modules/peek/Peek.UI/MainWindow.xaml +++ b/src/modules/peek/Peek.UI/MainWindow.xaml @@ -30,6 +30,8 @@ x:Name="TitleBarControl" Grid.Row="0" File="{x:Bind ViewModel.FolderItemsQuery.CurrentFile, Mode=OneWay}" + FileIndex="{x:Bind ViewModel.FolderItemsQuery.CurrentItemIndex, Mode=OneWay}" + IsMultiSelection="{x:Bind ViewModel.FolderItemsQuery.IsMultiSelection, Mode=OneWay}" NumberOfFiles="{x:Bind ViewModel.FolderItemsQuery.Files.Count, Mode=OneWay}" /> Name of application. - ({0}/{1} files) + ({0}/{1}) Text for the file count in the titlebar. 0: the index of the current file. 1: the total number of files selected. diff --git a/src/modules/peek/Peek.UI/Views/TitleBar.xaml b/src/modules/peek/Peek.UI/Views/TitleBar.xaml index 4e3239446f..e705b1b8bd 100644 --- a/src/modules/peek/Peek.UI/Views/TitleBar.xaml +++ b/src/modules/peek/Peek.UI/Views/TitleBar.xaml @@ -42,7 +42,7 @@ FontWeight="Bold" Style="{StaticResource CaptionTextBlockStyle}" Text="{x:Bind FileCountText, Mode=OneWay}" - Visibility="Collapsed" /> + Visibility="{x:Bind IsMultiSelection, Mode=OneWay}" /> - @@ -105,7 +104,6 @@ - @@ -115,7 +113,6 @@ - diff --git a/src/modules/peek/Peek.UI/Views/TitleBar.xaml.cs b/src/modules/peek/Peek.UI/Views/TitleBar.xaml.cs index 24c27900f3..f0426b7e1e 100644 --- a/src/modules/peek/Peek.UI/Views/TitleBar.xaml.cs +++ b/src/modules/peek/Peek.UI/Views/TitleBar.xaml.cs @@ -23,18 +23,32 @@ namespace Peek.UI.Views public sealed partial class TitleBar : UserControl { public static readonly DependencyProperty FileProperty = - DependencyProperty.Register( - nameof(File), - typeof(File), - typeof(TitleBar), - new PropertyMetadata(null, (d, e) => ((TitleBar)d).OnFilePropertyChanged())); + DependencyProperty.Register( + nameof(File), + typeof(File), + typeof(TitleBar), + new PropertyMetadata(null, (d, e) => ((TitleBar)d).OnFilePropertyChanged())); + + public static readonly DependencyProperty FileIndexProperty = + DependencyProperty.Register( + nameof(FileIndex), + typeof(int), + typeof(TitleBar), + new PropertyMetadata(-1, (d, e) => ((TitleBar)d).OnFileIndexPropertyChanged())); + + public static readonly DependencyProperty IsMultiSelectionProperty = + DependencyProperty.Register( + nameof(IsMultiSelection), + typeof(bool), + typeof(TitleBar), + new PropertyMetadata(false)); public static readonly DependencyProperty NumberOfFilesProperty = - DependencyProperty.Register( - nameof(NumberOfFiles), - typeof(int), - typeof(TitleBar), - new PropertyMetadata(null, null)); + DependencyProperty.Register( + nameof(NumberOfFiles), + typeof(int), + typeof(TitleBar), + new PropertyMetadata(null, null)); private string? defaultAppName; @@ -58,6 +72,18 @@ namespace Peek.UI.Views set => SetValue(FileProperty, value); } + public int FileIndex + { + get => (int)GetValue(FileIndexProperty); + set => SetValue(FileIndexProperty, value); + } + + public bool IsMultiSelection + { + get => (bool)GetValue(IsMultiSelectionProperty); + set => SetValue(IsMultiSelectionProperty, value); + } + public int NumberOfFiles { get => (int)GetValue(NumberOfFilesProperty); @@ -83,6 +109,31 @@ namespace Peek.UI.Views } } + [RelayCommand] + private async void LaunchDefaultAppButtonAsync() + { + StorageFile storageFile = await File.GetStorageFileAsync(); + LauncherOptions options = new (); + + if (string.IsNullOrEmpty(defaultAppName)) + { + // If there's no default app found, open the App picker + options.DisplayApplicationPicker = true; + } + else + { + // Try to launch the default app for current file format + bool result = await Launcher.LaunchFileAsync(storageFile, options); + + if (!result) + { + // If we couldn't successfully open the default app, open the App picker as a fallback + options.DisplayApplicationPicker = true; + await Launcher.LaunchFileAsync(storageFile, options); + } + } + } + private void UpdateTitleBarCustomization(MainWindow mainWindow) { if (AppWindowTitleBar.IsCustomizationSupported()) @@ -111,15 +162,18 @@ namespace Peek.UI.Views UpdateDefaultAppToLaunch(); } + private void OnFileIndexPropertyChanged() + { + UpdateFileCountText(); + } + private void UpdateFileCountText() { // Update file count if (NumberOfFiles > 1) { - // TODO: Update the hardcoded fileIndex when the NFQ PR gets merged - int currentFileIndex = 1; string fileCountTextFormat = ResourceLoader.GetForViewIndependentUse().GetString("AppTitle_FileCounts_Text"); - FileCountText = string.Format(fileCountTextFormat, currentFileIndex, NumberOfFiles); + FileCountText = string.Format(fileCountTextFormat, FileIndex + 1, NumberOfFiles); } } @@ -134,30 +188,5 @@ namespace Peek.UI.Views string openWithAppToolTipFormat = ResourceLoader.GetForViewIndependentUse().GetString("LaunchAppButton_OpenWithApp_ToolTip"); OpenWithAppToolTip = string.Format(openWithAppToolTipFormat, defaultAppName); } - - [RelayCommand] - private async void LaunchDefaultAppButtonAsync() - { - StorageFile storageFile = await File.GetStorageFileAsync(); - LauncherOptions options = new (); - - if (string.IsNullOrEmpty(defaultAppName)) - { - // If there's no default app found, open the App picker - options.DisplayApplicationPicker = true; - } - else - { - // Try to launch the default app for current file format - bool result = await Launcher.LaunchFileAsync(storageFile, options); - - if (!result) - { - // If we couldn't successfully open the default app, open the App picker as a fallback - options.DisplayApplicationPicker = true; - await Launcher.LaunchFileAsync(storageFile, options); - } - } - } } }