Skip to content

Commit ef0b77e

Browse files
authored
RichCommand: Refresh items (#11807)
1 parent 16ec9a1 commit ef0b77e

16 files changed

+68
-52
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using CommunityToolkit.Mvvm.ComponentModel;
2+
using CommunityToolkit.Mvvm.DependencyInjection;
3+
using Files.App.Commands;
4+
using Files.App.Contexts;
5+
using Files.App.Extensions;
6+
using System.ComponentModel;
7+
using System.Threading.Tasks;
8+
using Windows.System;
9+
10+
namespace Files.App.Actions
11+
{
12+
internal class RefreshItemsAction : ObservableObject, IAction
13+
{
14+
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
15+
16+
public string Label { get; } = "Refresh".GetLocalizedResource();
17+
public string Description { get; } = "TODO";
18+
19+
public RichGlyph Glyph { get; } = new("\uE72C");
20+
21+
public HotKey HotKey { get; } = new(VirtualKey.R, VirtualKeyModifiers.Control);
22+
23+
public HotKey SecondHotKey { get; } = new(VirtualKey.F5);
24+
25+
public bool IsExecutable => context.CanRefresh;
26+
27+
public RefreshItemsAction()
28+
{
29+
context.PropertyChanged += Context_PropertyChanged;
30+
}
31+
32+
public async Task ExecuteAsync()
33+
{
34+
context.ShellPage?.Refresh_Click();
35+
}
36+
37+
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
38+
{
39+
switch (e.PropertyName)
40+
{
41+
case nameof(IContentPageContext.CanRefresh):
42+
OnPropertyChanged(nameof(IsExecutable));
43+
break;
44+
}
45+
}
46+
}
47+
}

src/Files.App/Commands/CommandCodes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public enum CommandCodes
3232
OpenItem,
3333
OpenItemWithApplicationPicker,
3434
OpenParentFolder,
35+
RefreshItems,
3536

3637
// Selection
3738
SelectAll,

src/Files.App/Commands/Manager/CommandManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ internal class CommandManager : ICommandManager
3838
public IRichCommand EmptyRecycleBin => commands[CommandCodes.EmptyRecycleBin];
3939
public IRichCommand RestoreRecycleBin => commands[CommandCodes.RestoreRecycleBin];
4040
public IRichCommand RestoreAllRecycleBin => commands[CommandCodes.RestoreAllRecycleBin];
41+
public IRichCommand RefreshItems => commands[CommandCodes.RefreshItems];
4142
public IRichCommand CreateShortcut => commands[CommandCodes.CreateShortcut];
4243
public IRichCommand CreateShortcutFromDialog => commands[CommandCodes.CreateShortcutFromDialog];
4344
public IRichCommand CreateFolder => commands[CommandCodes.CreateFolder];
@@ -161,6 +162,7 @@ public CommandManager()
161162
[CommandCodes.EmptyRecycleBin] = new EmptyRecycleBinAction(),
162163
[CommandCodes.RestoreRecycleBin] = new RestoreRecycleBinAction(),
163164
[CommandCodes.RestoreAllRecycleBin] = new RestoreAllRecycleBinAction(),
165+
[CommandCodes.RefreshItems] = new RefreshItemsAction(),
164166
[CommandCodes.CreateShortcut] = new CreateShortcutAction(),
165167
[CommandCodes.CreateShortcutFromDialog] = new CreateShortcutFromDialogAction(),
166168
[CommandCodes.CreateFolder] = new CreateFolderAction(),

src/Files.App/Commands/Manager/ICommandManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
3939
IRichCommand OpenItem { get; }
4040
IRichCommand OpenItemWithApplicationPicker { get; }
4141
IRichCommand OpenParentFolder { get; }
42+
IRichCommand RefreshItems { get; }
4243

4344
IRichCommand PinToStart { get; }
4445
IRichCommand UnpinFromStart { get; }

src/Files.App/Contexts/ContentPage/ContentPageContext.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ internal class ContentPageContext : ObservableObject, IContentPageContext
3434
private IReadOnlyList<ListedItem> selectedItems = emptyItems;
3535
public IReadOnlyList<ListedItem> SelectedItems => selectedItems;
3636

37+
public bool CanRefresh => ShellPage is not null && ShellPage.ToolbarViewModel.CanRefresh;
38+
3739
public ContentPageContext()
3840
{
3941
context.Changing += Context_Changing;
@@ -97,6 +99,7 @@ private void ToolbarViewModel_PropertyChanged(object? sender, PropertyChangedEve
9799
switch (e.PropertyName)
98100
{
99101
case nameof(ToolbarViewModel.HasItem):
102+
case nameof(ToolbarViewModel.CanRefresh):
100103
OnPropertyChanged(e.PropertyName);
101104
break;
102105
case nameof(ToolbarViewModel.SelectedItems):
@@ -118,6 +121,7 @@ private void Update()
118121

119122
OnPropertyChanged(nameof(Folder));
120123
OnPropertyChanged(nameof(HasItem));
124+
OnPropertyChanged(nameof(CanRefresh));
121125
}
122126

123127
private void UpdatePageType()

src/Files.App/Contexts/ContentPage/IContentPageContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public interface IContentPageContext : INotifyPropertyChanged
1414

1515
bool HasItem { get; }
1616
bool HasSelection { get; }
17+
bool CanRefresh { get; }
1718
ListedItem? SelectedItem { get; }
1819
IReadOnlyList<ListedItem> SelectedItems { get; }
1920
}

src/Files.App/Helpers/ContextFlyoutItemHelper.cs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,22 +190,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
190190
new ContextMenuFlyoutItemViewModelBuilder(commands.GroupDescending){IsVisible = true}.Build(),
191191
},
192192
},
193-
new ContextMenuFlyoutItemViewModel()
193+
new ContextMenuFlyoutItemViewModelBuilder(commands.RefreshItems)
194194
{
195-
Text = "BaseLayoutContextFlyoutRefresh/Text".GetLocalizedResource(),
196-
Glyph = "\uE72C",
197-
ShowInRecycleBin = true,
198-
ShowInSearchPage = true,
199-
ShowInFtpPage = true,
200-
ShowInZipPage = true,
201-
Command = commandsViewModel.RefreshCommand,
202-
KeyboardAccelerator = new KeyboardAccelerator
203-
{
204-
Key = VirtualKey.F5,
205-
IsEnabled = false,
206-
},
207-
ShowItem = !itemsSelected
208-
},
195+
IsVisible = !itemsSelected,
196+
}.Build(),
209197
new ContextMenuFlyoutItemViewModel()
210198
{
211199
ItemType = ItemType.Separator,

src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,6 @@ public virtual async Task Drop(DragEventArgs e)
291291
deferral.Complete();
292292
}
293293

294-
public virtual void RefreshItems(RoutedEventArgs e)
295-
{
296-
associatedInstance.Refresh_Click();
297-
}
298-
299294
public void SearchUnindexedItems(RoutedEventArgs e)
300295
{
301296
associatedInstance.SubmitSearch(associatedInstance.InstanceViewModel.CurrentSearchQuery, true);

src/Files.App/Interacts/BaseLayoutCommandsViewModel.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ private void InitializeCommands()
3838
PointerWheelChangedCommand = new RelayCommand<PointerRoutedEventArgs>(CommandsModel.PointerWheelChanged);
3939
DragOverCommand = new AsyncRelayCommand<DragEventArgs>(CommandsModel.DragOver);
4040
DropCommand = new AsyncRelayCommand<DragEventArgs>(CommandsModel.Drop);
41-
RefreshCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.RefreshItems);
4241
SearchUnindexedItems = new RelayCommand<RoutedEventArgs>(CommandsModel.SearchUnindexedItems);
4342
CreateFolderWithSelection = new AsyncRelayCommand<RoutedEventArgs>(CommandsModel.CreateFolderWithSelection);
4443
PlayAllCommand = new AsyncRelayCommand(CommandsModel.PlayAll);
@@ -71,8 +70,6 @@ private void InitializeCommands()
7170

7271
public ICommand DropCommand { get; private set; }
7372

74-
public ICommand RefreshCommand { get; private set; }
75-
7673
public ICommand SearchUnindexedItems { get; private set; }
7774

7875
public ICommand CreateFolderWithSelection { get; private set; }

src/Files.App/Interacts/IBaseLayoutCommandImplementationModel.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ public interface IBaseLayoutCommandImplementationModel : IDisposable
3131

3232
Task Drop(DragEventArgs e);
3333

34-
void RefreshItems(RoutedEventArgs e);
35-
3634
void SearchUnindexedItems(RoutedEventArgs e);
3735

3836
Task CreateFolderWithSelection(RoutedEventArgs e);

src/Files.App/Strings/en-GB/Resources.resw

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,6 @@
324324
<data name="NavUpButton.ToolTipService.ToolTip" xml:space="preserve">
325325
<value>Up (Alt+Up arrow)</value>
326326
</data>
327-
<data name="NavRefreshButton.ToolTipService.ToolTip" xml:space="preserve">
328-
<value>Refresh (F5)</value>
329-
</data>
330327
<data name="NavSearchButton.ToolTipService.ToolTip" xml:space="preserve">
331328
<value>Search (Ctrl+F)</value>
332329
</data>

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,6 @@
243243
<data name="Ascending" xml:space="preserve">
244244
<value>Ascending</value>
245245
</data>
246-
<data name="BaseLayoutContextFlyoutRefresh.Text" xml:space="preserve">
247-
<value>Refresh</value>
248-
</data>
249246
<data name="Paste" xml:space="preserve">
250247
<value>Paste</value>
251248
</data>
@@ -324,8 +321,8 @@
324321
<data name="NavUpButton.ToolTipService.ToolTip" xml:space="preserve">
325322
<value>Up (Alt+Up Arrow)</value>
326323
</data>
327-
<data name="NavRefreshButton.ToolTipService.ToolTip" xml:space="preserve">
328-
<value>Refresh (F5)</value>
324+
<data name="Refresh" xml:space="preserve">
325+
<value>Refresh</value>
329326
</data>
330327
<data name="NavSearchButton.ToolTipService.ToolTip" xml:space="preserve">
331328
<value>Search (Ctrl+F)</value>

src/Files.App/UserControls/AddressToolbar.xaml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,12 @@
113113
x:Name="Refresh"
114114
x:FieldModifier="public"
115115
AccessKey="R"
116-
AutomationProperties.Name="{helpers:ResourceString Name=NavResfreshButton/AutomationProperties/Name}"
117-
Command="{x:Bind ViewModel.RefreshClickCommand, Mode=OneWay}"
118-
IsEnabled="{x:Bind ViewModel.CanRefresh, Mode=OneWay}"
116+
AutomationProperties.Name="{x:Bind Commands.RefreshItems.Label}"
117+
Command="{x:Bind Commands.RefreshItems, Mode=OneWay}"
118+
IsEnabled="{x:Bind Commands.RefreshItems.IsExecutable, Mode=OneWay}"
119119
Style="{StaticResource AddressToolbarButtonStyle}"
120-
ToolTipService.ToolTip="{helpers:ResourceString Name=NavRefreshButton/ToolTipService/ToolTip}">
121-
<FontIcon FontSize="14" Glyph="&#xE72C;" />
122-
<Button.KeyboardAccelerators>
123-
<KeyboardAccelerator Key="F5" />
124-
</Button.KeyboardAccelerators>
120+
ToolTipService.ToolTip="{x:Bind Commands.RefreshItems.LabelWithHotKey}">
121+
<FontIcon FontSize="14" Glyph="{x:Bind Commands.RefreshItems.Glyph.BaseGlyph}" />
125122
</Button>
126123
</StackPanel>
127124

src/Files.App/UserControls/AddressToolbar.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using CommunityToolkit.Mvvm.DependencyInjection;
2+
using Files.App.Commands;
23
using Files.App.Helpers.XamlHelpers;
34
using Files.App.ViewModels;
45
using Files.Backend.Services.Settings;
@@ -16,6 +17,7 @@ namespace Files.App.UserControls
1617
public sealed partial class AddressToolbar : UserControl
1718
{
1819
private readonly IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
20+
public ICommandManager Commands { get; } = Ioc.Default.GetRequiredService<ICommandManager>();
1921

2022
// Using a DependencyProperty as the backing store for ShowOngoingTasks. This enables animation, styling, binding, etc...
2123
public static readonly DependencyProperty ShowOngoingTasksProperty =

src/Files.App/Views/ColumnShellPage.xaml.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,6 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo
189189
}
190190
break;
191191

192-
case (true, false, false, true, VirtualKey.R): // ctrl + r, refresh
193-
if (ToolbarViewModel.CanRefresh)
194-
Refresh_Click();
195-
break;
196-
197192
case (false, false, true, true, VirtualKey.D): // alt + d, select address bar (english)
198193
case (true, false, false, true, VirtualKey.L): // ctrl + l, select address bar
199194
ToolbarViewModel.IsEditModeEnabled = true;

src/Files.App/Views/ModernShellPage.xaml.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,6 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo
252252

253253
break;
254254

255-
case (true, false, false, true, VirtualKey.R): // ctrl + r, refresh
256-
if (ToolbarViewModel.CanRefresh)
257-
Refresh_Click();
258-
259-
break;
260-
261255
case (false, false, true, _, VirtualKey.D): // alt + d, select address bar (english)
262256
case (true, false, false, _, VirtualKey.L): // ctrl + l, select address bar
263257
if (tabInstance || CurrentPageType == typeof(WidgetsPage))

0 commit comments

Comments
 (0)