diff --git a/src/Files.App/Actions/Content/ImageManipulation/BaseRotateAction.cs b/src/Files.App/Actions/Content/ImageManipulation/BaseRotateAction.cs index f4ddf3d598ef..c340de656f63 100644 --- a/src/Files.App/Actions/Content/ImageManipulation/BaseRotateAction.cs +++ b/src/Files.App/Actions/Content/ImageManipulation/BaseRotateAction.cs @@ -1,6 +1,7 @@ // Copyright (c) Files Community // Licensed under the MIT License. +using Files.Shared.Helpers; using Windows.Graphics.Imaging; namespace Files.App.Actions @@ -20,8 +21,14 @@ internal abstract class BaseRotateAction : ObservableObject, IAction protected abstract BitmapRotation Rotation { get; } public bool IsExecutable => - IsContextPageTypeAdaptedToCommand() && - (context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsCompatibleToSetAsWindowsWallpaper ?? false); + context.ShellPage is not null && + context.ShellPage.SlimContentPage is not null && + context.PageType != ContentPageTypes.RecycleBin && + context.PageType != ContentPageTypes.ZipFolder && + context.PageType != ContentPageTypes.ReleaseNotes && + context.PageType != ContentPageTypes.Settings && + context.HasSelection && + context.SelectedItems.All(x => FileExtensionHelpers.IsCompatibleToSetAsWindowsWallpaper(x.FileExtension)); public BaseRotateAction() { @@ -40,30 +47,10 @@ public async Task ExecuteAsync(object? parameter = null) await _infoPaneViewModel.UpdateSelectedItemPreviewAsync(); } - private bool IsContextPageTypeAdaptedToCommand() - { - return - context.PageType != ContentPageTypes.RecycleBin && - context.PageType != ContentPageTypes.ZipFolder && - context.PageType != ContentPageTypes.ReleaseNotes && - context.PageType != ContentPageTypes.Settings && - context.PageType != ContentPageTypes.None; - } - private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) { - if (e.PropertyName is nameof(IContentPageContext.SelectedItem)) - { - if (context.ShellPage is not null && context.ShellPage.SlimContentPage is not null) - { - var viewModel = context.ShellPage.SlimContentPage.SelectedItemsPropertiesViewModel; - var extensions = context.SelectedItems.Select(selectedItem => selectedItem.FileExtension).Distinct().ToList(); - - viewModel.CheckAllFileExtensions(extensions); - } - + if (e.PropertyName is nameof(IContentPageContext.SelectedItems)) OnPropertyChanged(nameof(IsExecutable)); - } } } -} +} \ No newline at end of file diff --git a/src/Files.App/UserControls/Toolbar.xaml b/src/Files.App/UserControls/Toolbar.xaml index ef2c1a2cf2cf..a167218e65e0 100644 --- a/src/Files.App/UserControls/Toolbar.xaml +++ b/src/Files.App/UserControls/Toolbar.xaml @@ -72,7 +72,8 @@ Grid.Column="0" HorizontalAlignment="Left" x:Load="{x:Bind ViewModel.InstanceViewModel.IsPageTypeNotHome, Mode=OneWay}" - DefaultLabelPosition="Right"> + DefaultLabelPosition="Right" + IsDynamicOverflowEnabled="{x:Bind ViewModel.IsDynamicOverflowEnabled, Mode=OneWay}"> @@ -287,13 +288,13 @@ x:Name="ExtractButton" Width="Auto" MinWidth="40" - x:Load="{x:Bind ViewModel.CanExtract, Mode=OneWay, FallbackValue=False}" AccessKey="Z" AccessKeyInvoked="AppBarButton_AccessKeyInvoked" IsEnabled="{x:Bind ViewModel.CanExtract, Mode=OneWay, FallbackValue=False}" Label="{helpers:ResourceString Name=Extract}" LabelPosition="Default" - Style="{StaticResource ToolBarAppBarButtonFlyoutStyle}"> + Style="{StaticResource ToolBarAppBarButtonFlyoutStyle}" + Visibility="{x:Bind ViewModel.CanExtract, Mode=OneWay}"> @@ -331,12 +332,12 @@ x:Name="RunWithPowerShellButton" Width="Auto" MinWidth="40" - x:Load="{x:Bind Commands.RunWithPowershell.IsExecutable, Mode=OneWay}" AutomationProperties.Name="RunWithPowerShell" Command="{x:Bind Commands.RunWithPowershell}" Label="{x:Bind Commands.RunWithPowershell.Label}" LabelPosition="Default" - ToolTipService.ToolTip="{x:Bind Commands.RunWithPowershell.LabelWithHotKey, Mode=OneWay}"> + ToolTipService.ToolTip="{x:Bind Commands.RunWithPowershell.LabelWithHotKey, Mode=OneWay}" + Visibility="{x:Bind Commands.RunWithPowershell.IsExecutable, Mode=OneWay}"> @@ -347,12 +348,12 @@ x:Name="EditInNotepadButton" Width="Auto" MinWidth="40" - x:Load="{x:Bind Commands.EditInNotepad.IsExecutable, Mode=OneWay}" AutomationProperties.Name="EditInNotepad" Command="{x:Bind Commands.EditInNotepad}" Label="{x:Bind Commands.EditInNotepad.Label}" LabelPosition="Default" - ToolTipService.ToolTip="{x:Bind Commands.EditInNotepad.LabelWithHotKey, Mode=OneWay}"> + ToolTipService.ToolTip="{x:Bind Commands.EditInNotepad.LabelWithHotKey, Mode=OneWay}" + Visibility="{x:Bind Commands.EditInNotepad.IsExecutable, Mode=OneWay}"> @@ -363,11 +364,11 @@ x:Name="SetAsBackgroundButton" Width="Auto" MinWidth="40" - x:Load="{x:Bind Commands.SetAsWallpaperBackground.IsExecutable, Mode=OneWay}" Label="{helpers:ResourceString Name=SetAsBackgroundFlyout}" LabelPosition="Default" Style="{StaticResource ToolBarAppBarButtonFlyoutStyle}" - ToolTipService.ToolTip="{helpers:ResourceString Name=SetAsBackgroundFlyout}"> + ToolTipService.ToolTip="{helpers:ResourceString Name=SetAsBackgroundFlyout}" + Visibility="{x:Bind Commands.SetAsWallpaperBackground.IsExecutable, Mode=OneWay}"> @@ -410,21 +411,21 @@ x:Name="SetAsSlideshowButton" Width="Auto" MinWidth="40" - x:Load="{x:Bind Commands.SetAsSlideshowBackground.IsExecutable, Mode=OneWay}" Command="{x:Bind Commands.SetAsSlideshowBackground}" Icon="{x:Bind Commands.SetAsSlideshowBackground.FontIcon}" Label="{x:Bind Commands.SetAsSlideshowBackground.Label}" LabelPosition="Default" - ToolTipService.ToolTip="{x:Bind Commands.SetAsSlideshowBackground.LabelWithHotKey, Mode=OneWay}" /> + ToolTipService.ToolTip="{x:Bind Commands.SetAsSlideshowBackground.LabelWithHotKey, Mode=OneWay}" + Visibility="{x:Bind Commands.SetAsSlideshowBackground.IsExecutable, Mode=OneWay}" /> + ToolTipService.ToolTip="{helpers:ResourceString Name=Install}" + Visibility="{x:Bind Commands.InstallInfDriver.IsExecutable, Mode=OneWay}"> @@ -433,44 +434,44 @@ + ToolTipService.ToolTip="{helpers:ResourceString Name=RotateLeft}" + Visibility="{x:Bind Commands.RotateLeft.IsExecutable, Mode=OneWay}"> + ToolTipService.ToolTip="{helpers:ResourceString Name=RotateRight}" + Visibility="{x:Bind Commands.RotateRight.IsExecutable, Mode=OneWay}"> + ToolTipService.ToolTip="{helpers:ResourceString Name=Install}" + Visibility="{x:Bind Commands.InstallFont.IsExecutable, Mode=OneWay}"> + ToolTipService.ToolTip="{helpers:ResourceString Name=Install}" + Visibility="{x:Bind Commands.InstallCertificate.IsExecutable, Mode=OneWay}"> @@ -479,12 +480,12 @@ + ToolTipService.ToolTip="{x:Bind Commands.PlayAll.LabelWithHotKey, Mode=OneWay}" + Visibility="{x:Bind Commands.PlayAll.IsExecutable, Mode=OneWay}"> diff --git a/src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs b/src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs index 455aea1d3c4a..05e632463d26 100644 --- a/src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using CommunityToolkit.WinUI; +using Files.App.Actions; using Files.Shared.Helpers; using Microsoft.UI.Dispatching; using Microsoft.UI.Xaml; @@ -75,14 +76,26 @@ public sealed partial class NavigationToolbarViewModel : ObservableObject, IAddr public SearchBoxViewModel SearchBoxViewModel => (SearchBoxViewModel)SearchBox; - public bool HasAdditionalAction => InstanceViewModel.IsPageTypeRecycleBin || IsPowerShellScript || CanExtract || IsImage || IsFont || IsInfFile; - public bool CanCopy => SelectedItems is not null && SelectedItems.Any(); + public bool HasAdditionalAction => + InstanceViewModel.IsPageTypeRecycleBin || + Commands.RunWithPowershell.IsExecutable || + CanExtract || + Commands.DecompressArchive.IsExecutable || + Commands.DecompressArchiveHere.IsExecutable || + Commands.DecompressArchiveHereSmart.IsExecutable || + Commands.DecompressArchiveToChildFolder.IsExecutable || + Commands.EditInNotepad.IsExecutable || + Commands.RotateLeft.IsExecutable || + Commands.RotateRight.IsExecutable || + Commands.SetAsAppBackground.IsExecutable || + Commands.SetAsWallpaperBackground.IsExecutable || + Commands.SetAsLockscreenBackground.IsExecutable || + Commands.SetAsSlideshowBackground.IsExecutable || + Commands.InstallFont.IsExecutable || + Commands.InstallInfDriver.IsExecutable || + Commands.InstallCertificate.IsExecutable; + public bool CanExtract => Commands.DecompressArchive.CanExecute(null) || Commands.DecompressArchiveHere.CanExecute(null) || Commands.DecompressArchiveHereSmart.CanExecute(null) || Commands.DecompressArchiveToChildFolder.CanExecute(null); - public bool IsPowerShellScript => SelectedItems is not null && SelectedItems.Count == 1 && FileExtensionHelpers.IsPowerShellFile(SelectedItems.First().FileExtension) && !InstanceViewModel.IsPageTypeRecycleBin; - public bool IsImage => SelectedItems is not null && SelectedItems.Any() && SelectedItems.All(x => FileExtensionHelpers.IsImageFile(x.FileExtension)) && !InstanceViewModel.IsPageTypeRecycleBin; - public bool IsMultipleImageSelected => SelectedItems is not null && SelectedItems.Count > 1 && SelectedItems.All(x => FileExtensionHelpers.IsImageFile(x.FileExtension)) && !InstanceViewModel.IsPageTypeRecycleBin; - public bool IsInfFile => SelectedItems is not null && SelectedItems.Count == 1 && FileExtensionHelpers.IsInfFile(SelectedItems.First().FileExtension) && !InstanceViewModel.IsPageTypeRecycleBin; - public bool IsFont => SelectedItems is not null && SelectedItems.Any() && SelectedItems.All(x => FileExtensionHelpers.IsFontFile(x.FileExtension)) && !InstanceViewModel.IsPageTypeRecycleBin; public bool IsCardsLayout => _InstanceViewModel.FolderSettings.LayoutMode is FolderLayoutModes.CardsView; public bool IsColumnLayout => _InstanceViewModel.FolderSettings.LayoutMode is FolderLayoutModes.ColumnView; @@ -126,6 +139,9 @@ public sealed partial class NavigationToolbarViewModel : ObservableObject, IAddr private bool _IsCommandPaletteOpen; public bool IsCommandPaletteOpen { get => _IsCommandPaletteOpen; set => SetProperty(ref _IsCommandPaletteOpen, value); } + private bool _IsDynamicOverflowEnabled; + public bool IsDynamicOverflowEnabled { get => _IsDynamicOverflowEnabled; set => SetProperty(ref _IsDynamicOverflowEnabled, value); } + private bool _IsUpdating; public bool IsUpdating { get => _IsUpdating; set => SetProperty(ref _IsUpdating, value); } @@ -242,14 +258,12 @@ public List? SelectedItems { if (SetProperty(ref _SelectedItems, value)) { - OnPropertyChanged(nameof(CanCopy)); OnPropertyChanged(nameof(CanExtract)); - OnPropertyChanged(nameof(IsInfFile)); - OnPropertyChanged(nameof(IsPowerShellScript)); - OnPropertyChanged(nameof(IsImage)); - OnPropertyChanged(nameof(IsMultipleImageSelected)); - OnPropertyChanged(nameof(IsFont)); OnPropertyChanged(nameof(HasAdditionalAction)); + + // Workaround to ensure the overflow button is only displayed when there are overflow items + IsDynamicOverflowEnabled = false; + IsDynamicOverflowEnabled = true; } } }