Skip to content
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
35 changes: 11 additions & 24 deletions src/Files.App/Actions/Content/ImageManipulation/BaseRotateAction.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 &&
Comment on lines +26 to +29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're interested, you can use is, and, or:

Suggested change
context.PageType != ContentPageTypes.RecycleBin &&
context.PageType != ContentPageTypes.ZipFolder &&
context.PageType != ContentPageTypes.ReleaseNotes &&
context.PageType != ContentPageTypes.Settings &&
context.PageType is not ContentPageTypes.RecycleBin and
not ContentPageTypes.ZipFolder and
not ContentPageTypes.ReleaseNotes and
not ContentPageTypes.Settings &&

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They have the same results here so I would just leave it as is.

context.HasSelection &&
context.SelectedItems.All(x => FileExtensionHelpers.IsCompatibleToSetAsWindowsWallpaper(x.FileExtension));

public BaseRotateAction()
{
Expand All @@ -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);
Comment on lines -57 to -62
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this deleted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic was moved to IsExecutable.

}

if (e.PropertyName is nameof(IContentPageContext.SelectedItems))
OnPropertyChanged(nameof(IsExecutable));
}
}
}
}
}
47 changes: 24 additions & 23 deletions src/Files.App/UserControls/Toolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}">
<CommandBar.PrimaryCommands>

<!-- New Item -->
Expand Down Expand Up @@ -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}">

<controls:ThemedIcon Style="{StaticResource App.ThemedIcons.Zip}" />

Expand Down Expand Up @@ -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}">
<AppBarButton.Icon>
<FontIcon Foreground="{ThemeResource App.Theme.IconBaseBrush}" Glyph="{x:Bind Commands.RunWithPowershell.Glyph.BaseGlyph}" />
</AppBarButton.Icon>
Expand All @@ -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}">
<AppBarButton.Icon>
<FontIcon Foreground="{ThemeResource App.Theme.IconBaseBrush}" Glyph="{x:Bind Commands.EditInNotepad.Glyph.BaseGlyph}" />
</AppBarButton.Icon>
Expand All @@ -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}">

<controls:ThemedIcon Style="{StaticResource App.ThemedIcons.SetWallpaper.16}" />

Expand Down Expand Up @@ -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}" />

<!-- Install Inf -->
<AppBarButton
x:Name="InstallInfButton"
x:Load="{x:Bind Commands.InstallInfDriver.IsExecutable, Mode=OneWay, FallbackValue=False}"
Command="{x:Bind Commands.InstallInfDriver, Mode=OneWay}"
Label="{x:Bind Commands.InstallInfDriver.Label}"
LabelPosition="Default"
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}">
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}"
Visibility="{x:Bind Commands.InstallInfDriver.IsExecutable, Mode=OneWay}">
<AppBarButton.Icon>
<FontIcon Foreground="{ThemeResource App.Theme.IconBaseBrush}" Glyph="{x:Bind Commands.InstallInfDriver.Glyph.BaseGlyph}" />
</AppBarButton.Icon>
Expand All @@ -433,44 +434,44 @@
<!-- Rotate Image Left -->
<AppBarButton
x:Name="RotateImageLeftButton"
x:Load="{x:Bind ViewModel.IsImage, Mode=OneWay, FallbackValue=False}"
Command="{x:Bind Commands.RotateLeft, Mode=OneWay}"
Label="{x:Bind Commands.RotateLeft.Label}"
LabelPosition="Default"
ToolTipService.ToolTip="{helpers:ResourceString Name=RotateLeft}">
ToolTipService.ToolTip="{helpers:ResourceString Name=RotateLeft}"
Visibility="{x:Bind Commands.RotateLeft.IsExecutable, Mode=OneWay}">
<controls:ThemedIcon Style="{x:Bind Commands.RotateLeft.ThemedIconStyle}" />
</AppBarButton>

<!-- Rotate Image Right -->
<AppBarButton
x:Name="RotateImageRightButton"
x:Load="{x:Bind ViewModel.IsImage, Mode=OneWay, FallbackValue=False}"
Command="{x:Bind Commands.RotateRight, Mode=OneWay}"
Label="{x:Bind Commands.RotateRight.Label}"
LabelPosition="Default"
ToolTipService.ToolTip="{helpers:ResourceString Name=RotateRight}">
ToolTipService.ToolTip="{helpers:ResourceString Name=RotateRight}"
Visibility="{x:Bind Commands.RotateRight.IsExecutable, Mode=OneWay}">
<controls:ThemedIcon Style="{x:Bind Commands.RotateRight.ThemedIconStyle}" />
</AppBarButton>

<!-- Install Font -->
<AppBarButton
x:Name="InstallFontButton"
x:Load="{x:Bind Commands.InstallFont.IsExecutable, Mode=OneWay, FallbackValue=False}"
Command="{x:Bind Commands.InstallFont, Mode=OneWay}"
Label="{x:Bind Commands.InstallFont.Label}"
LabelPosition="Default"
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}">
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}"
Visibility="{x:Bind Commands.InstallFont.IsExecutable, Mode=OneWay}">
<controls:ThemedIcon Style="{x:Bind Commands.InstallFont.ThemedIconStyle}" />
</AppBarButton>

<!-- Install Certificate -->
<AppBarButton
x:Name="InstallCertificateButton"
x:Load="{x:Bind Commands.InstallCertificate.IsExecutable, Mode=OneWay, FallbackValue=False}"
Command="{x:Bind Commands.InstallCertificate, Mode=OneWay}"
Label="{x:Bind Commands.InstallCertificate.Label}"
LabelPosition="Default"
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}">
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}"
Visibility="{x:Bind Commands.InstallCertificate.IsExecutable, Mode=OneWay}">
<AppBarButton.Icon>
<FontIcon Foreground="{ThemeResource App.Theme.IconBaseBrush}" Glyph="{x:Bind Commands.InstallCertificate.Glyph.BaseGlyph, Mode=OneTime}" />
</AppBarButton.Icon>
Expand All @@ -479,12 +480,12 @@
<!-- Play All Media -->
<AppBarButton
x:Name="PlayAllMediaButton"
x:Load="{x:Bind Commands.PlayAll.IsExecutable, Mode=OneWay, FallbackValue=False}"
Command="{x:Bind Commands.PlayAll, Mode=OneWay}"
KeyboardAcceleratorTextOverride="{x:Bind Commands.PlayAll.HotKeyText, Mode=OneWay}"
Label="{x:Bind Commands.PlayAll.Label}"
LabelPosition="Default"
ToolTipService.ToolTip="{x:Bind Commands.PlayAll.LabelWithHotKey, Mode=OneWay}">
ToolTipService.ToolTip="{x:Bind Commands.PlayAll.LabelWithHotKey, Mode=OneWay}"
Visibility="{x:Bind Commands.PlayAll.IsExecutable, Mode=OneWay}">
<AppBarButton.Icon>
<FontIcon Foreground="{ThemeResource App.Theme.IconBaseBrush}" Glyph="{x:Bind Commands.PlayAll.Glyph.BaseGlyph}" />
</AppBarButton.Icon>
Expand Down
40 changes: 27 additions & 13 deletions src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Comment on lines +79 to +96
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 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;

This might look prettier, since the above is similar to other large statements in the codebase.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather stick with the current formatting.


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;
Expand Down Expand Up @@ -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); }

Expand Down Expand Up @@ -242,14 +258,12 @@ public List<ListedItem>? 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;
}
}
}
Expand Down
Loading