Skip to content

RichCommand: Refresh items #11807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Mar 26, 2023
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
47 changes: 47 additions & 0 deletions src/Files.App/Actions/Content/RefreshItemsAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using System.ComponentModel;
using System.Threading.Tasks;
using Windows.System;

namespace Files.App.Actions
{
internal class RefreshItemsAction : ObservableObject, IAction
{
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();

public string Label { get; } = "Refresh".GetLocalizedResource();
public string Description { get; } = "TODO";

public RichGlyph Glyph { get; } = new("\uE72C");

public HotKey HotKey { get; } = new(VirtualKey.R, VirtualKeyModifiers.Control);

public HotKey SecondHotKey { get; } = new(VirtualKey.F5);

public bool IsExecutable => context.CanRefresh;

public RefreshItemsAction()
{
context.PropertyChanged += Context_PropertyChanged;
}

public async Task ExecuteAsync()
{
context.ShellPage?.Refresh_Click();
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.CanRefresh):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}
}
}
1 change: 1 addition & 0 deletions src/Files.App/Commands/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public enum CommandCodes
OpenItem,
OpenItemWithApplicationPicker,
OpenParentFolder,
RefreshItems,

// Selection
SelectAll,
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal class CommandManager : ICommandManager
public IRichCommand EmptyRecycleBin => commands[CommandCodes.EmptyRecycleBin];
public IRichCommand RestoreRecycleBin => commands[CommandCodes.RestoreRecycleBin];
public IRichCommand RestoreAllRecycleBin => commands[CommandCodes.RestoreAllRecycleBin];
public IRichCommand RefreshItems => commands[CommandCodes.RefreshItems];
public IRichCommand CreateShortcut => commands[CommandCodes.CreateShortcut];
public IRichCommand CreateShortcutFromDialog => commands[CommandCodes.CreateShortcutFromDialog];
public IRichCommand CreateFolder => commands[CommandCodes.CreateFolder];
Expand Down Expand Up @@ -161,6 +162,7 @@ public CommandManager()
[CommandCodes.EmptyRecycleBin] = new EmptyRecycleBinAction(),
[CommandCodes.RestoreRecycleBin] = new RestoreRecycleBinAction(),
[CommandCodes.RestoreAllRecycleBin] = new RestoreAllRecycleBinAction(),
[CommandCodes.RefreshItems] = new RefreshItemsAction(),
[CommandCodes.CreateShortcut] = new CreateShortcutAction(),
[CommandCodes.CreateShortcutFromDialog] = new CreateShortcutFromDialogAction(),
[CommandCodes.CreateFolder] = new CreateFolderAction(),
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
IRichCommand OpenItem { get; }
IRichCommand OpenItemWithApplicationPicker { get; }
IRichCommand OpenParentFolder { get; }
IRichCommand RefreshItems { get; }

IRichCommand PinToStart { get; }
IRichCommand UnpinFromStart { get; }
Expand Down
4 changes: 4 additions & 0 deletions src/Files.App/Contexts/ContentPage/ContentPageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ internal class ContentPageContext : ObservableObject, IContentPageContext
private IReadOnlyList<ListedItem> selectedItems = emptyItems;
public IReadOnlyList<ListedItem> SelectedItems => selectedItems;

public bool CanRefresh => ShellPage is not null && ShellPage.ToolbarViewModel.CanRefresh;

public ContentPageContext()
{
context.Changing += Context_Changing;
Expand Down Expand Up @@ -97,6 +99,7 @@ private void ToolbarViewModel_PropertyChanged(object? sender, PropertyChangedEve
switch (e.PropertyName)
{
case nameof(ToolbarViewModel.HasItem):
case nameof(ToolbarViewModel.CanRefresh):
OnPropertyChanged(e.PropertyName);
break;
case nameof(ToolbarViewModel.SelectedItems):
Expand All @@ -118,6 +121,7 @@ private void Update()

OnPropertyChanged(nameof(Folder));
OnPropertyChanged(nameof(HasItem));
OnPropertyChanged(nameof(CanRefresh));
}

private void UpdatePageType()
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Contexts/ContentPage/IContentPageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface IContentPageContext : INotifyPropertyChanged

bool HasItem { get; }
bool HasSelection { get; }
bool CanRefresh { get; }
ListedItem? SelectedItem { get; }
IReadOnlyList<ListedItem> SelectedItems { get; }
}
Expand Down
18 changes: 3 additions & 15 deletions src/Files.App/Helpers/ContextFlyoutItemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,22 +190,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
new ContextMenuFlyoutItemViewModelBuilder(commands.GroupDescending){IsVisible = true}.Build(),
},
},
new ContextMenuFlyoutItemViewModel()
new ContextMenuFlyoutItemViewModelBuilder(commands.RefreshItems)
{
Text = "BaseLayoutContextFlyoutRefresh/Text".GetLocalizedResource(),
Glyph = "\uE72C",
ShowInRecycleBin = true,
ShowInSearchPage = true,
ShowInFtpPage = true,
ShowInZipPage = true,
Command = commandsViewModel.RefreshCommand,
KeyboardAccelerator = new KeyboardAccelerator
{
Key = VirtualKey.F5,
IsEnabled = false,
},
ShowItem = !itemsSelected
},
IsVisible = !itemsSelected,
}.Build(),
new ContextMenuFlyoutItemViewModel()
{
ItemType = ItemType.Separator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,6 @@ public virtual async Task Drop(DragEventArgs e)
deferral.Complete();
}

public virtual void RefreshItems(RoutedEventArgs e)
{
associatedInstance.Refresh_Click();
}

public void SearchUnindexedItems(RoutedEventArgs e)
{
associatedInstance.SubmitSearch(associatedInstance.InstanceViewModel.CurrentSearchQuery, true);
Expand Down
3 changes: 0 additions & 3 deletions src/Files.App/Interacts/BaseLayoutCommandsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ private void InitializeCommands()
PointerWheelChangedCommand = new RelayCommand<PointerRoutedEventArgs>(CommandsModel.PointerWheelChanged);
DragOverCommand = new AsyncRelayCommand<DragEventArgs>(CommandsModel.DragOver);
DropCommand = new AsyncRelayCommand<DragEventArgs>(CommandsModel.Drop);
RefreshCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.RefreshItems);
SearchUnindexedItems = new RelayCommand<RoutedEventArgs>(CommandsModel.SearchUnindexedItems);
CreateFolderWithSelection = new AsyncRelayCommand<RoutedEventArgs>(CommandsModel.CreateFolderWithSelection);
PlayAllCommand = new AsyncRelayCommand(CommandsModel.PlayAll);
Expand Down Expand Up @@ -71,8 +70,6 @@ private void InitializeCommands()

public ICommand DropCommand { get; private set; }

public ICommand RefreshCommand { get; private set; }

public ICommand SearchUnindexedItems { get; private set; }

public ICommand CreateFolderWithSelection { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public interface IBaseLayoutCommandImplementationModel : IDisposable

Task Drop(DragEventArgs e);

void RefreshItems(RoutedEventArgs e);

void SearchUnindexedItems(RoutedEventArgs e);

Task CreateFolderWithSelection(RoutedEventArgs e);
Expand Down
3 changes: 0 additions & 3 deletions src/Files.App/Strings/en-GB/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,6 @@
<data name="NavUpButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Up (Alt+Up arrow)</value>
</data>
<data name="NavRefreshButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Refresh (F5)</value>
</data>
<data name="NavSearchButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Search (Ctrl+F)</value>
</data>
Expand Down
7 changes: 2 additions & 5 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,6 @@
<data name="Ascending" xml:space="preserve">
<value>Ascending</value>
</data>
<data name="BaseLayoutContextFlyoutRefresh.Text" xml:space="preserve">
<value>Refresh</value>
</data>
<data name="Paste" xml:space="preserve">
<value>Paste</value>
</data>
Expand Down Expand Up @@ -324,8 +321,8 @@
<data name="NavUpButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Up (Alt+Up Arrow)</value>
</data>
<data name="NavRefreshButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Refresh (F5)</value>
<data name="Refresh" xml:space="preserve">
<value>Refresh</value>
</data>
<data name="NavSearchButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Search (Ctrl+F)</value>
Expand Down
13 changes: 5 additions & 8 deletions src/Files.App/UserControls/AddressToolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,12 @@
x:Name="Refresh"
x:FieldModifier="public"
AccessKey="R"
AutomationProperties.Name="{helpers:ResourceString Name=NavResfreshButton/AutomationProperties/Name}"
Command="{x:Bind ViewModel.RefreshClickCommand, Mode=OneWay}"
IsEnabled="{x:Bind ViewModel.CanRefresh, Mode=OneWay}"
AutomationProperties.Name="{x:Bind Commands.RefreshItems.Label}"
Command="{x:Bind Commands.RefreshItems, Mode=OneWay}"
IsEnabled="{x:Bind Commands.RefreshItems.IsExecutable, Mode=OneWay}"
Style="{StaticResource AddressToolbarButtonStyle}"
ToolTipService.ToolTip="{helpers:ResourceString Name=NavRefreshButton/ToolTipService/ToolTip}">
<FontIcon FontSize="14" Glyph="&#xE72C;" />
<Button.KeyboardAccelerators>
<KeyboardAccelerator Key="F5" />
</Button.KeyboardAccelerators>
ToolTipService.ToolTip="{x:Bind Commands.RefreshItems.LabelWithHotKey}">
<FontIcon FontSize="14" Glyph="{x:Bind Commands.RefreshItems.Glyph.BaseGlyph}" />
</Button>
</StackPanel>

Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/UserControls/AddressToolbar.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Helpers.XamlHelpers;
using Files.App.ViewModels;
using Files.Backend.Services.Settings;
Expand All @@ -16,6 +17,7 @@ namespace Files.App.UserControls
public sealed partial class AddressToolbar : UserControl
{
private readonly IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
public ICommandManager Commands { get; } = Ioc.Default.GetRequiredService<ICommandManager>();

// Using a DependencyProperty as the backing store for ShowOngoingTasks. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ShowOngoingTasksProperty =
Expand Down
5 changes: 0 additions & 5 deletions src/Files.App/Views/ColumnShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,6 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo
}
break;

case (true, false, false, true, VirtualKey.R): // ctrl + r, refresh
if (ToolbarViewModel.CanRefresh)
Refresh_Click();
break;

case (false, false, true, true, VirtualKey.D): // alt + d, select address bar (english)
case (true, false, false, true, VirtualKey.L): // ctrl + l, select address bar
ToolbarViewModel.IsEditModeEnabled = true;
Expand Down
6 changes: 0 additions & 6 deletions src/Files.App/Views/ModernShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,6 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo

break;

case (true, false, false, true, VirtualKey.R): // ctrl + r, refresh
if (ToolbarViewModel.CanRefresh)
Refresh_Click();

break;

case (false, false, true, _, VirtualKey.D): // alt + d, select address bar (english)
case (true, false, false, _, VirtualKey.L): // ctrl + l, select address bar
if (tabInstance || CurrentPageType == typeof(WidgetsPage))
Expand Down