Skip to content

Commit 3b7ce00

Browse files
committed
Attempted fix
1 parent e505ace commit 3b7ce00

File tree

3 files changed

+56
-57
lines changed

3 files changed

+56
-57
lines changed

src/Files.App/Actions/Content/ImageManipulation/BaseRotateAction.cs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

4+
using Files.Shared.Helpers;
45
using Windows.Graphics.Imaging;
56

67
namespace Files.App.Actions
@@ -20,8 +21,13 @@ internal abstract class BaseRotateAction : ObservableObject, IAction
2021
protected abstract BitmapRotation Rotation { get; }
2122

2223
public bool IsExecutable =>
23-
IsContextPageTypeAdaptedToCommand() &&
24-
(context.ShellPage?.SlimContentPage?.SelectedItemsPropertiesViewModel?.IsCompatibleToSetAsWindowsWallpaper ?? false);
24+
context.ShellPage is not null &&
25+
context.PageType != ContentPageTypes.RecycleBin &&
26+
context.PageType != ContentPageTypes.ZipFolder &&
27+
context.PageType != ContentPageTypes.ReleaseNotes &&
28+
context.PageType != ContentPageTypes.Settings &&
29+
context.HasSelection &&
30+
context.SelectedItems.All(x => FileExtensionHelpers.IsCompatibleToSetAsWindowsWallpaper(x.FileExtension));
2531

2632
public BaseRotateAction()
2733
{
@@ -40,29 +46,15 @@ public async Task ExecuteAsync(object? parameter = null)
4046
await _infoPaneViewModel.UpdateSelectedItemPreviewAsync();
4147
}
4248

43-
private bool IsContextPageTypeAdaptedToCommand()
44-
{
45-
return
46-
context.PageType != ContentPageTypes.RecycleBin &&
47-
context.PageType != ContentPageTypes.ZipFolder &&
48-
context.PageType != ContentPageTypes.ReleaseNotes &&
49-
context.PageType != ContentPageTypes.Settings &&
50-
context.PageType != ContentPageTypes.None;
51-
}
52-
5349
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
5450
{
55-
if (e.PropertyName is nameof(IContentPageContext.SelectedItem))
51+
switch (e.PropertyName)
5652
{
57-
if (context.ShellPage is not null && context.ShellPage.SlimContentPage is not null)
58-
{
59-
var viewModel = context.ShellPage.SlimContentPage.SelectedItemsPropertiesViewModel;
60-
var extensions = context.SelectedItems.Select(selectedItem => selectedItem.FileExtension).Distinct().ToList();
61-
62-
viewModel.CheckAllFileExtensions(extensions);
63-
}
64-
65-
OnPropertyChanged(nameof(IsExecutable));
53+
case nameof(IContentPageContext.SelectedItems):
54+
{
55+
OnPropertyChanged(nameof(IsExecutable));
56+
break;
57+
}
6658
}
6759
}
6860
}

src/Files.App/UserControls/Toolbar.xaml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,13 @@
287287
x:Name="ExtractButton"
288288
Width="Auto"
289289
MinWidth="40"
290-
x:Load="{x:Bind ViewModel.CanExtract, Mode=OneWay, FallbackValue=False}"
291290
AccessKey="Z"
292291
AccessKeyInvoked="AppBarButton_AccessKeyInvoked"
293292
IsEnabled="{x:Bind ViewModel.CanExtract, Mode=OneWay, FallbackValue=False}"
294293
Label="{helpers:ResourceString Name=Extract}"
295294
LabelPosition="Default"
296-
Style="{StaticResource ToolBarAppBarButtonFlyoutStyle}">
295+
Style="{StaticResource ToolBarAppBarButtonFlyoutStyle}"
296+
Visibility="{x:Bind ViewModel.CanExtract, Mode=OneWay}">
297297

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

@@ -331,12 +331,12 @@
331331
x:Name="RunWithPowerShellButton"
332332
Width="Auto"
333333
MinWidth="40"
334-
x:Load="{x:Bind Commands.RunWithPowershell.IsExecutable, Mode=OneWay}"
335334
AutomationProperties.Name="RunWithPowerShell"
336335
Command="{x:Bind Commands.RunWithPowershell}"
337336
Label="{x:Bind Commands.RunWithPowershell.Label}"
338337
LabelPosition="Default"
339-
ToolTipService.ToolTip="{x:Bind Commands.RunWithPowershell.LabelWithHotKey, Mode=OneWay}">
338+
ToolTipService.ToolTip="{x:Bind Commands.RunWithPowershell.LabelWithHotKey, Mode=OneWay}"
339+
Visibility="{x:Bind Commands.RunWithPowershell.IsExecutable, Mode=OneWay}">
340340
<AppBarButton.Icon>
341341
<FontIcon Foreground="{ThemeResource App.Theme.IconBaseBrush}" Glyph="{x:Bind Commands.RunWithPowershell.Glyph.BaseGlyph}" />
342342
</AppBarButton.Icon>
@@ -347,12 +347,12 @@
347347
x:Name="EditInNotepadButton"
348348
Width="Auto"
349349
MinWidth="40"
350-
x:Load="{x:Bind Commands.EditInNotepad.IsExecutable, Mode=OneWay}"
351350
AutomationProperties.Name="EditInNotepad"
352351
Command="{x:Bind Commands.EditInNotepad}"
353352
Label="{x:Bind Commands.EditInNotepad.Label}"
354353
LabelPosition="Default"
355-
ToolTipService.ToolTip="{x:Bind Commands.EditInNotepad.LabelWithHotKey, Mode=OneWay}">
354+
ToolTipService.ToolTip="{x:Bind Commands.EditInNotepad.LabelWithHotKey, Mode=OneWay}"
355+
Visibility="{x:Bind Commands.EditInNotepad.IsExecutable, Mode=OneWay}">
356356
<AppBarButton.Icon>
357357
<FontIcon Foreground="{ThemeResource App.Theme.IconBaseBrush}" Glyph="{x:Bind Commands.EditInNotepad.Glyph.BaseGlyph}" />
358358
</AppBarButton.Icon>
@@ -363,11 +363,11 @@
363363
x:Name="SetAsBackgroundButton"
364364
Width="Auto"
365365
MinWidth="40"
366-
x:Load="{x:Bind Commands.SetAsWallpaperBackground.IsExecutable, Mode=OneWay}"
367366
Label="{helpers:ResourceString Name=SetAsBackgroundFlyout}"
368367
LabelPosition="Default"
369368
Style="{StaticResource ToolBarAppBarButtonFlyoutStyle}"
370-
ToolTipService.ToolTip="{helpers:ResourceString Name=SetAsBackgroundFlyout}">
369+
ToolTipService.ToolTip="{helpers:ResourceString Name=SetAsBackgroundFlyout}"
370+
Visibility="{x:Bind Commands.SetAsWallpaperBackground.IsExecutable, Mode=OneWay}">
371371

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

@@ -410,21 +410,21 @@
410410
x:Name="SetAsSlideshowButton"
411411
Width="Auto"
412412
MinWidth="40"
413-
x:Load="{x:Bind Commands.SetAsSlideshowBackground.IsExecutable, Mode=OneWay}"
414413
Command="{x:Bind Commands.SetAsSlideshowBackground}"
415414
Icon="{x:Bind Commands.SetAsSlideshowBackground.FontIcon}"
416415
Label="{x:Bind Commands.SetAsSlideshowBackground.Label}"
417416
LabelPosition="Default"
418-
ToolTipService.ToolTip="{x:Bind Commands.SetAsSlideshowBackground.LabelWithHotKey, Mode=OneWay}" />
417+
ToolTipService.ToolTip="{x:Bind Commands.SetAsSlideshowBackground.LabelWithHotKey, Mode=OneWay}"
418+
Visibility="{x:Bind Commands.SetAsSlideshowBackground.IsExecutable, Mode=OneWay}" />
419419

420420
<!-- Install Inf -->
421421
<AppBarButton
422422
x:Name="InstallInfButton"
423-
x:Load="{x:Bind Commands.InstallInfDriver.IsExecutable, Mode=OneWay, FallbackValue=False}"
424423
Command="{x:Bind Commands.InstallInfDriver, Mode=OneWay}"
425424
Label="{x:Bind Commands.InstallInfDriver.Label}"
426425
LabelPosition="Default"
427-
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}">
426+
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}"
427+
Visibility="{x:Bind Commands.InstallInfDriver.IsExecutable, Mode=OneWay}">
428428
<AppBarButton.Icon>
429429
<FontIcon Foreground="{ThemeResource App.Theme.IconBaseBrush}" Glyph="{x:Bind Commands.InstallInfDriver.Glyph.BaseGlyph}" />
430430
</AppBarButton.Icon>
@@ -433,44 +433,44 @@
433433
<!-- Rotate Image Left -->
434434
<AppBarButton
435435
x:Name="RotateImageLeftButton"
436-
x:Load="{x:Bind ViewModel.IsImage, Mode=OneWay, FallbackValue=False}"
437436
Command="{x:Bind Commands.RotateLeft, Mode=OneWay}"
438437
Label="{x:Bind Commands.RotateLeft.Label}"
439438
LabelPosition="Default"
440-
ToolTipService.ToolTip="{helpers:ResourceString Name=RotateLeft}">
439+
ToolTipService.ToolTip="{helpers:ResourceString Name=RotateLeft}"
440+
Visibility="{x:Bind Commands.RotateLeft.IsExecutable, Mode=OneWay}">
441441
<controls:ThemedIcon Style="{x:Bind Commands.RotateLeft.ThemedIconStyle}" />
442442
</AppBarButton>
443443

444444
<!-- Rotate Image Right -->
445445
<AppBarButton
446446
x:Name="RotateImageRightButton"
447-
x:Load="{x:Bind ViewModel.IsImage, Mode=OneWay, FallbackValue=False}"
448447
Command="{x:Bind Commands.RotateRight, Mode=OneWay}"
449448
Label="{x:Bind Commands.RotateRight.Label}"
450449
LabelPosition="Default"
451-
ToolTipService.ToolTip="{helpers:ResourceString Name=RotateRight}">
450+
ToolTipService.ToolTip="{helpers:ResourceString Name=RotateRight}"
451+
Visibility="{x:Bind Commands.RotateRight.IsExecutable, Mode=OneWay}">
452452
<controls:ThemedIcon Style="{x:Bind Commands.RotateRight.ThemedIconStyle}" />
453453
</AppBarButton>
454454

455455
<!-- Install Font -->
456456
<AppBarButton
457457
x:Name="InstallFontButton"
458-
x:Load="{x:Bind Commands.InstallFont.IsExecutable, Mode=OneWay, FallbackValue=False}"
459458
Command="{x:Bind Commands.InstallFont, Mode=OneWay}"
460459
Label="{x:Bind Commands.InstallFont.Label}"
461460
LabelPosition="Default"
462-
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}">
461+
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}"
462+
Visibility="{x:Bind Commands.InstallFont.IsExecutable, Mode=OneWay}">
463463
<controls:ThemedIcon Style="{x:Bind Commands.InstallFont.ThemedIconStyle}" />
464464
</AppBarButton>
465465

466466
<!-- Install Certificate -->
467467
<AppBarButton
468468
x:Name="InstallCertificateButton"
469-
x:Load="{x:Bind Commands.InstallCertificate.IsExecutable, Mode=OneWay, FallbackValue=False}"
470469
Command="{x:Bind Commands.InstallCertificate, Mode=OneWay}"
471470
Label="{x:Bind Commands.InstallCertificate.Label}"
472471
LabelPosition="Default"
473-
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}">
472+
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}"
473+
Visibility="{x:Bind Commands.InstallCertificate.IsExecutable, Mode=OneWay}">
474474
<AppBarButton.Icon>
475475
<FontIcon Foreground="{ThemeResource App.Theme.IconBaseBrush}" Glyph="{x:Bind Commands.InstallCertificate.Glyph.BaseGlyph, Mode=OneTime}" />
476476
</AppBarButton.Icon>
@@ -479,12 +479,12 @@
479479
<!-- Play All Media -->
480480
<AppBarButton
481481
x:Name="PlayAllMediaButton"
482-
x:Load="{x:Bind Commands.PlayAll.IsExecutable, Mode=OneWay, FallbackValue=False}"
483482
Command="{x:Bind Commands.PlayAll, Mode=OneWay}"
484483
KeyboardAcceleratorTextOverride="{x:Bind Commands.PlayAll.HotKeyText, Mode=OneWay}"
485484
Label="{x:Bind Commands.PlayAll.Label}"
486485
LabelPosition="Default"
487-
ToolTipService.ToolTip="{x:Bind Commands.PlayAll.LabelWithHotKey, Mode=OneWay}">
486+
ToolTipService.ToolTip="{x:Bind Commands.PlayAll.LabelWithHotKey, Mode=OneWay}"
487+
Visibility="{x:Bind Commands.PlayAll.IsExecutable, Mode=OneWay}">
488488
<AppBarButton.Icon>
489489
<FontIcon Foreground="{ThemeResource App.Theme.IconBaseBrush}" Glyph="{x:Bind Commands.PlayAll.Glyph.BaseGlyph}" />
490490
</AppBarButton.Icon>

src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using CommunityToolkit.WinUI;
5+
using Files.App.Actions;
56
using Files.Shared.Helpers;
67
using Microsoft.UI.Dispatching;
78
using Microsoft.UI.Xaml;
@@ -75,14 +76,26 @@ public sealed partial class NavigationToolbarViewModel : ObservableObject, IAddr
7576

7677
public SearchBoxViewModel SearchBoxViewModel => (SearchBoxViewModel)SearchBox;
7778

78-
public bool HasAdditionalAction => InstanceViewModel.IsPageTypeRecycleBin || IsPowerShellScript || CanExtract || IsImage || IsFont || IsInfFile;
79-
public bool CanCopy => SelectedItems is not null && SelectedItems.Any();
79+
public bool HasAdditionalAction =>
80+
InstanceViewModel.IsPageTypeRecycleBin ||
81+
Commands.RunWithPowershell.IsExecutable ||
82+
CanExtract ||
83+
Commands.DecompressArchive.IsExecutable ||
84+
Commands.DecompressArchiveHere.IsExecutable ||
85+
Commands.DecompressArchiveHereSmart.IsExecutable ||
86+
Commands.DecompressArchiveToChildFolder.IsExecutable ||
87+
Commands.EditInNotepad.IsExecutable ||
88+
Commands.RotateLeft.IsExecutable ||
89+
Commands.RotateRight.IsExecutable ||
90+
Commands.SetAsAppBackground.IsExecutable ||
91+
Commands.SetAsWallpaperBackground.IsExecutable ||
92+
Commands.SetAsLockscreenBackground.IsExecutable ||
93+
Commands.SetAsSlideshowBackground.IsExecutable ||
94+
Commands.InstallFont.IsExecutable ||
95+
Commands.InstallInfDriver.IsExecutable ||
96+
Commands.InstallCertificate.IsExecutable;
97+
8098
public bool CanExtract => Commands.DecompressArchive.CanExecute(null) || Commands.DecompressArchiveHere.CanExecute(null) || Commands.DecompressArchiveHereSmart.CanExecute(null) || Commands.DecompressArchiveToChildFolder.CanExecute(null);
81-
public bool IsPowerShellScript => SelectedItems is not null && SelectedItems.Count == 1 && FileExtensionHelpers.IsPowerShellFile(SelectedItems.First().FileExtension) && !InstanceViewModel.IsPageTypeRecycleBin;
82-
public bool IsImage => SelectedItems is not null && SelectedItems.Any() && SelectedItems.All(x => FileExtensionHelpers.IsImageFile(x.FileExtension)) && !InstanceViewModel.IsPageTypeRecycleBin;
83-
public bool IsMultipleImageSelected => SelectedItems is not null && SelectedItems.Count > 1 && SelectedItems.All(x => FileExtensionHelpers.IsImageFile(x.FileExtension)) && !InstanceViewModel.IsPageTypeRecycleBin;
84-
public bool IsInfFile => SelectedItems is not null && SelectedItems.Count == 1 && FileExtensionHelpers.IsInfFile(SelectedItems.First().FileExtension) && !InstanceViewModel.IsPageTypeRecycleBin;
85-
public bool IsFont => SelectedItems is not null && SelectedItems.Any() && SelectedItems.All(x => FileExtensionHelpers.IsFontFile(x.FileExtension)) && !InstanceViewModel.IsPageTypeRecycleBin;
8699

87100
public bool IsCardsLayout => _InstanceViewModel.FolderSettings.LayoutMode is FolderLayoutModes.CardsView;
88101
public bool IsColumnLayout => _InstanceViewModel.FolderSettings.LayoutMode is FolderLayoutModes.ColumnView;
@@ -242,13 +255,7 @@ public List<ListedItem>? SelectedItems
242255
{
243256
if (SetProperty(ref _SelectedItems, value))
244257
{
245-
OnPropertyChanged(nameof(CanCopy));
246258
OnPropertyChanged(nameof(CanExtract));
247-
OnPropertyChanged(nameof(IsInfFile));
248-
OnPropertyChanged(nameof(IsPowerShellScript));
249-
OnPropertyChanged(nameof(IsImage));
250-
OnPropertyChanged(nameof(IsMultipleImageSelected));
251-
OnPropertyChanged(nameof(IsFont));
252259
OnPropertyChanged(nameof(HasAdditionalAction));
253260
}
254261
}

0 commit comments

Comments
 (0)