Skip to content

Commit c842f2e

Browse files
authored
Fix: Fixed issue where toolbar button sometimes had the wrong icon state (#17032)
1 parent e505ace commit c842f2e

File tree

3 files changed

+62
-60
lines changed

3 files changed

+62
-60
lines changed
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,14 @@ 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.ShellPage.SlimContentPage is not null &&
26+
context.PageType != ContentPageTypes.RecycleBin &&
27+
context.PageType != ContentPageTypes.ZipFolder &&
28+
context.PageType != ContentPageTypes.ReleaseNotes &&
29+
context.PageType != ContentPageTypes.Settings &&
30+
context.HasSelection &&
31+
context.SelectedItems.All(x => FileExtensionHelpers.IsCompatibleToSetAsWindowsWallpaper(x.FileExtension));
2532

2633
public BaseRotateAction()
2734
{
@@ -40,30 +47,10 @@ public async Task ExecuteAsync(object? parameter = null)
4047
await _infoPaneViewModel.UpdateSelectedItemPreviewAsync();
4148
}
4249

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-
5350
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
5451
{
55-
if (e.PropertyName is nameof(IContentPageContext.SelectedItem))
56-
{
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-
52+
if (e.PropertyName is nameof(IContentPageContext.SelectedItems))
6553
OnPropertyChanged(nameof(IsExecutable));
66-
}
6754
}
6855
}
69-
}
56+
}

src/Files.App/UserControls/Toolbar.xaml

+24-23
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
Grid.Column="0"
7373
HorizontalAlignment="Left"
7474
x:Load="{x:Bind ViewModel.InstanceViewModel.IsPageTypeNotHome, Mode=OneWay}"
75-
DefaultLabelPosition="Right">
75+
DefaultLabelPosition="Right"
76+
IsDynamicOverflowEnabled="{x:Bind ViewModel.IsDynamicOverflowEnabled, Mode=OneWay}">
7677
<CommandBar.PrimaryCommands>
7778

7879
<!-- New Item -->
@@ -287,13 +288,13 @@
287288
x:Name="ExtractButton"
288289
Width="Auto"
289290
MinWidth="40"
290-
x:Load="{x:Bind ViewModel.CanExtract, Mode=OneWay, FallbackValue=False}"
291291
AccessKey="Z"
292292
AccessKeyInvoked="AppBarButton_AccessKeyInvoked"
293293
IsEnabled="{x:Bind ViewModel.CanExtract, Mode=OneWay, FallbackValue=False}"
294294
Label="{helpers:ResourceString Name=Extract}"
295295
LabelPosition="Default"
296-
Style="{StaticResource ToolBarAppBarButtonFlyoutStyle}">
296+
Style="{StaticResource ToolBarAppBarButtonFlyoutStyle}"
297+
Visibility="{x:Bind ViewModel.CanExtract, Mode=OneWay}">
297298

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

@@ -331,12 +332,12 @@
331332
x:Name="RunWithPowerShellButton"
332333
Width="Auto"
333334
MinWidth="40"
334-
x:Load="{x:Bind Commands.RunWithPowershell.IsExecutable, Mode=OneWay}"
335335
AutomationProperties.Name="RunWithPowerShell"
336336
Command="{x:Bind Commands.RunWithPowershell}"
337337
Label="{x:Bind Commands.RunWithPowershell.Label}"
338338
LabelPosition="Default"
339-
ToolTipService.ToolTip="{x:Bind Commands.RunWithPowershell.LabelWithHotKey, Mode=OneWay}">
339+
ToolTipService.ToolTip="{x:Bind Commands.RunWithPowershell.LabelWithHotKey, Mode=OneWay}"
340+
Visibility="{x:Bind Commands.RunWithPowershell.IsExecutable, Mode=OneWay}">
340341
<AppBarButton.Icon>
341342
<FontIcon Foreground="{ThemeResource App.Theme.IconBaseBrush}" Glyph="{x:Bind Commands.RunWithPowershell.Glyph.BaseGlyph}" />
342343
</AppBarButton.Icon>
@@ -347,12 +348,12 @@
347348
x:Name="EditInNotepadButton"
348349
Width="Auto"
349350
MinWidth="40"
350-
x:Load="{x:Bind Commands.EditInNotepad.IsExecutable, Mode=OneWay}"
351351
AutomationProperties.Name="EditInNotepad"
352352
Command="{x:Bind Commands.EditInNotepad}"
353353
Label="{x:Bind Commands.EditInNotepad.Label}"
354354
LabelPosition="Default"
355-
ToolTipService.ToolTip="{x:Bind Commands.EditInNotepad.LabelWithHotKey, Mode=OneWay}">
355+
ToolTipService.ToolTip="{x:Bind Commands.EditInNotepad.LabelWithHotKey, Mode=OneWay}"
356+
Visibility="{x:Bind Commands.EditInNotepad.IsExecutable, Mode=OneWay}">
356357
<AppBarButton.Icon>
357358
<FontIcon Foreground="{ThemeResource App.Theme.IconBaseBrush}" Glyph="{x:Bind Commands.EditInNotepad.Glyph.BaseGlyph}" />
358359
</AppBarButton.Icon>
@@ -363,11 +364,11 @@
363364
x:Name="SetAsBackgroundButton"
364365
Width="Auto"
365366
MinWidth="40"
366-
x:Load="{x:Bind Commands.SetAsWallpaperBackground.IsExecutable, Mode=OneWay}"
367367
Label="{helpers:ResourceString Name=SetAsBackgroundFlyout}"
368368
LabelPosition="Default"
369369
Style="{StaticResource ToolBarAppBarButtonFlyoutStyle}"
370-
ToolTipService.ToolTip="{helpers:ResourceString Name=SetAsBackgroundFlyout}">
370+
ToolTipService.ToolTip="{helpers:ResourceString Name=SetAsBackgroundFlyout}"
371+
Visibility="{x:Bind Commands.SetAsWallpaperBackground.IsExecutable, Mode=OneWay}">
371372

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

@@ -410,21 +411,21 @@
410411
x:Name="SetAsSlideshowButton"
411412
Width="Auto"
412413
MinWidth="40"
413-
x:Load="{x:Bind Commands.SetAsSlideshowBackground.IsExecutable, Mode=OneWay}"
414414
Command="{x:Bind Commands.SetAsSlideshowBackground}"
415415
Icon="{x:Bind Commands.SetAsSlideshowBackground.FontIcon}"
416416
Label="{x:Bind Commands.SetAsSlideshowBackground.Label}"
417417
LabelPosition="Default"
418-
ToolTipService.ToolTip="{x:Bind Commands.SetAsSlideshowBackground.LabelWithHotKey, Mode=OneWay}" />
418+
ToolTipService.ToolTip="{x:Bind Commands.SetAsSlideshowBackground.LabelWithHotKey, Mode=OneWay}"
419+
Visibility="{x:Bind Commands.SetAsSlideshowBackground.IsExecutable, Mode=OneWay}" />
419420

420421
<!-- Install Inf -->
421422
<AppBarButton
422423
x:Name="InstallInfButton"
423-
x:Load="{x:Bind Commands.InstallInfDriver.IsExecutable, Mode=OneWay, FallbackValue=False}"
424424
Command="{x:Bind Commands.InstallInfDriver, Mode=OneWay}"
425425
Label="{x:Bind Commands.InstallInfDriver.Label}"
426426
LabelPosition="Default"
427-
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}">
427+
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}"
428+
Visibility="{x:Bind Commands.InstallInfDriver.IsExecutable, Mode=OneWay}">
428429
<AppBarButton.Icon>
429430
<FontIcon Foreground="{ThemeResource App.Theme.IconBaseBrush}" Glyph="{x:Bind Commands.InstallInfDriver.Glyph.BaseGlyph}" />
430431
</AppBarButton.Icon>
@@ -433,44 +434,44 @@
433434
<!-- Rotate Image Left -->
434435
<AppBarButton
435436
x:Name="RotateImageLeftButton"
436-
x:Load="{x:Bind ViewModel.IsImage, Mode=OneWay, FallbackValue=False}"
437437
Command="{x:Bind Commands.RotateLeft, Mode=OneWay}"
438438
Label="{x:Bind Commands.RotateLeft.Label}"
439439
LabelPosition="Default"
440-
ToolTipService.ToolTip="{helpers:ResourceString Name=RotateLeft}">
440+
ToolTipService.ToolTip="{helpers:ResourceString Name=RotateLeft}"
441+
Visibility="{x:Bind Commands.RotateLeft.IsExecutable, Mode=OneWay}">
441442
<controls:ThemedIcon Style="{x:Bind Commands.RotateLeft.ThemedIconStyle}" />
442443
</AppBarButton>
443444

444445
<!-- Rotate Image Right -->
445446
<AppBarButton
446447
x:Name="RotateImageRightButton"
447-
x:Load="{x:Bind ViewModel.IsImage, Mode=OneWay, FallbackValue=False}"
448448
Command="{x:Bind Commands.RotateRight, Mode=OneWay}"
449449
Label="{x:Bind Commands.RotateRight.Label}"
450450
LabelPosition="Default"
451-
ToolTipService.ToolTip="{helpers:ResourceString Name=RotateRight}">
451+
ToolTipService.ToolTip="{helpers:ResourceString Name=RotateRight}"
452+
Visibility="{x:Bind Commands.RotateRight.IsExecutable, Mode=OneWay}">
452453
<controls:ThemedIcon Style="{x:Bind Commands.RotateRight.ThemedIconStyle}" />
453454
</AppBarButton>
454455

455456
<!-- Install Font -->
456457
<AppBarButton
457458
x:Name="InstallFontButton"
458-
x:Load="{x:Bind Commands.InstallFont.IsExecutable, Mode=OneWay, FallbackValue=False}"
459459
Command="{x:Bind Commands.InstallFont, Mode=OneWay}"
460460
Label="{x:Bind Commands.InstallFont.Label}"
461461
LabelPosition="Default"
462-
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}">
462+
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}"
463+
Visibility="{x:Bind Commands.InstallFont.IsExecutable, Mode=OneWay}">
463464
<controls:ThemedIcon Style="{x:Bind Commands.InstallFont.ThemedIconStyle}" />
464465
</AppBarButton>
465466

466467
<!-- Install Certificate -->
467468
<AppBarButton
468469
x:Name="InstallCertificateButton"
469-
x:Load="{x:Bind Commands.InstallCertificate.IsExecutable, Mode=OneWay, FallbackValue=False}"
470470
Command="{x:Bind Commands.InstallCertificate, Mode=OneWay}"
471471
Label="{x:Bind Commands.InstallCertificate.Label}"
472472
LabelPosition="Default"
473-
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}">
473+
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}"
474+
Visibility="{x:Bind Commands.InstallCertificate.IsExecutable, Mode=OneWay}">
474475
<AppBarButton.Icon>
475476
<FontIcon Foreground="{ThemeResource App.Theme.IconBaseBrush}" Glyph="{x:Bind Commands.InstallCertificate.Glyph.BaseGlyph, Mode=OneTime}" />
476477
</AppBarButton.Icon>
@@ -479,12 +480,12 @@
479480
<!-- Play All Media -->
480481
<AppBarButton
481482
x:Name="PlayAllMediaButton"
482-
x:Load="{x:Bind Commands.PlayAll.IsExecutable, Mode=OneWay, FallbackValue=False}"
483483
Command="{x:Bind Commands.PlayAll, Mode=OneWay}"
484484
KeyboardAcceleratorTextOverride="{x:Bind Commands.PlayAll.HotKeyText, Mode=OneWay}"
485485
Label="{x:Bind Commands.PlayAll.Label}"
486486
LabelPosition="Default"
487-
ToolTipService.ToolTip="{x:Bind Commands.PlayAll.LabelWithHotKey, Mode=OneWay}">
487+
ToolTipService.ToolTip="{x:Bind Commands.PlayAll.LabelWithHotKey, Mode=OneWay}"
488+
Visibility="{x:Bind Commands.PlayAll.IsExecutable, Mode=OneWay}">
488489
<AppBarButton.Icon>
489490
<FontIcon Foreground="{ThemeResource App.Theme.IconBaseBrush}" Glyph="{x:Bind Commands.PlayAll.Glyph.BaseGlyph}" />
490491
</AppBarButton.Icon>

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

+27-13
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;
@@ -126,6 +139,9 @@ public sealed partial class NavigationToolbarViewModel : ObservableObject, IAddr
126139
private bool _IsCommandPaletteOpen;
127140
public bool IsCommandPaletteOpen { get => _IsCommandPaletteOpen; set => SetProperty(ref _IsCommandPaletteOpen, value); }
128141

142+
private bool _IsDynamicOverflowEnabled;
143+
public bool IsDynamicOverflowEnabled { get => _IsDynamicOverflowEnabled; set => SetProperty(ref _IsDynamicOverflowEnabled, value); }
144+
129145
private bool _IsUpdating;
130146
public bool IsUpdating { get => _IsUpdating; set => SetProperty(ref _IsUpdating, value); }
131147

@@ -242,14 +258,12 @@ public List<ListedItem>? SelectedItems
242258
{
243259
if (SetProperty(ref _SelectedItems, value))
244260
{
245-
OnPropertyChanged(nameof(CanCopy));
246261
OnPropertyChanged(nameof(CanExtract));
247-
OnPropertyChanged(nameof(IsInfFile));
248-
OnPropertyChanged(nameof(IsPowerShellScript));
249-
OnPropertyChanged(nameof(IsImage));
250-
OnPropertyChanged(nameof(IsMultipleImageSelected));
251-
OnPropertyChanged(nameof(IsFont));
252262
OnPropertyChanged(nameof(HasAdditionalAction));
263+
264+
// Workaround to ensure the overflow button is only displayed when there are overflow items
265+
IsDynamicOverflowEnabled = false;
266+
IsDynamicOverflowEnabled = true;
253267
}
254268
}
255269
}

0 commit comments

Comments
 (0)