Skip to content
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

RichCommands: Add Item & Edit Path #12011

Merged
merged 22 commits into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b5e1dd5
RichCommands: Add Item
ferrariofilippo Apr 7, 2023
2e17846
More rich commands & accelerators override
ferrariofilippo Apr 7, 2023
413cf53
Disable Create New In MTP
ferrariofilippo Apr 8, 2023
3751514
Use Mode=OneWay for HotKeyText and Typo
ferrariofilippo Apr 8, 2023
9228eb7
Merge branch 'main' into RichCommands_Add_Item
ferrariofilippo Apr 15, 2023
322ceb1
Build errors
ferrariofilippo Apr 16, 2023
b375845
Merge branch 'main' into RichCommands_Add_Item
ferrariofilippo Apr 16, 2023
e5c38d3
Merge branch 'main' into RichCommands_Add_Item
ferrariofilippo Apr 16, 2023
0dea2ce
Descriptions
ferrariofilippo Apr 16, 2023
8a237d7
Merge branch 'main' into RichCommands_Add_Item
ferrariofilippo Apr 17, 2023
af6eb74
Merge branch 'main' into RichCommands_Add_Item
ferrariofilippo Apr 19, 2023
67eba0d
Add commands to list
ferrariofilippo Apr 19, 2023
02fb7fe
Merge branch 'main' into RichCommands_Add_Item
ferrariofilippo Apr 19, 2023
7d82968
Merge branch 'main' into RichCommands_Add_Item
ferrariofilippo Apr 20, 2023
987bc48
Merge branch 'main' into RichCommands_Add_Item
ferrariofilippo Apr 20, 2023
74dfe53
Merge branch 'main' into RichCommands_Add_Item
yaira2 Apr 21, 2023
c9a70b6
Merge branch 'main' into RichCommands_Add_Item
ferrariofilippo Apr 21, 2023
fa86d3e
Merge branch 'main' into RichCommands_Add_Item
ferrariofilippo Apr 24, 2023
735258b
Merge branch 'main' into RichCommands_Add_Item
ferrariofilippo Apr 27, 2023
0422b47
Update specs/RichCommand/CommandList.md
ferrariofilippo Apr 29, 2023
c5029d8
Update specs/RichCommand/CommandList.md
ferrariofilippo Apr 29, 2023
d3cbfdf
Requested changes
ferrariofilippo Apr 30, 2023
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
2 changes: 2 additions & 0 deletions specs/RichCommand/CommandList.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This is the list of all commands defined in `CommandCodes` enum except `None`.
| | Search | Search | Go to search box | Ctrl+F, F3 |
| | Redo | Redo | Redo the last file operation | Ctrl+Y |
| | Undo | Undo | Undo the last file operation | Ctrl+Z |
| | EditPath | Edit path | Go to path bar | Ctrl+L, Alt+D |
ferrariofilippo marked this conversation as resolved.
Show resolved Hide resolved
| Show | ToggleShowHiddenItems | Show hidden items | Toggle whether to show hidden items | Ctrl+H |
| | ToggleShowFileExtensions | Show file extensions | Toggle whether to show file extensions | |
| | TogglePreviewPane | Toggle the preview pane | Toggle whether to show preview pane | Ctrl+P |
Expand All @@ -24,6 +25,7 @@ This is the list of all commands defined in `CommandCodes` enum except `None`.
| | DeleteItem | Delete | Delete item(s) | Delete, Ctrl+D |
| | DeletemeItemPermanently | Delete permanently | Delete item(s) permanently | Shift+Delete |
| | CreateFolder | Folder | Create new folder | |
| | AddItem | New | Open the menu to create a new item | Ctrl+Shift+N |
ferrariofilippo marked this conversation as resolved.
Show resolved Hide resolved
| | CreateShortcut | Create shortcut | Create new shortcut(s) to selected item(s) | |
| | CreateShortcutFromDialog | Shortcut | Create new shortcut to any item | |
| | EmptyRecycleBin | Empty Recycle Bin | Empty recycle bin | |
Expand Down
62 changes: 62 additions & 0 deletions src/Files.App/Actions/FileSystem/AddItemAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using Files.App.Helpers;
using Files.Backend.Enums;
using Files.Backend.Services;
using Files.Backend.ViewModels.Dialogs.AddItemDialog;
using System.ComponentModel;
using System.Threading.Tasks;

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

private readonly IDialogService dialogService = Ioc.Default.GetRequiredService<IDialogService>();

private readonly AddItemDialogViewModel viewModel = new();

public string Label { get; } = "BaseLayoutContextFlyoutNew/Label".GetLocalizedResource();

public string Description => "AddItemDescription".GetLocalizedResource();

public HotKey HotKey { get; } = new(Keys.N, KeyModifiers.CtrlShift);

public RichGlyph Glyph { get; } = new(opacityStyle: "ColorIconNew");

public bool IsExecutable => context.CanCreateItem && !context.HasSelection;

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

public async Task ExecuteAsync()
{
await dialogService.ShowDialogAsync(viewModel);

if (viewModel.ResultType.ItemType == AddItemDialogItemType.Shortcut)
await Ioc.Default.GetRequiredService<ICommandManager>().CreateShortcutFromDialog.ExecuteAsync();
else if (viewModel.ResultType.ItemType != AddItemDialogItemType.Cancel)
UIFilesystemHelpers.CreateFileFromDialogResultType(
viewModel.ResultType.ItemType,
viewModel.ResultType.ItemInfo,
context.ShellPage!);
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.CanCreateItem):
case nameof(IContentPageContext.HasSelection):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}
}
}
11 changes: 8 additions & 3 deletions src/Files.App/Actions/FileSystem/CreateFolderAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal class CreateFolderAction : BaseUIAction, IAction

public RichGlyph Glyph { get; } = new RichGlyph(baseGlyph: "\uE8B7");

public override bool IsExecutable => context.ShellPage is not null && UIHelpers.CanShowDialog;
public override bool IsExecutable => context.CanCreateItem && !context.HasSelection && UIHelpers.CanShowDialog;

public CreateFolderAction()
{
Expand All @@ -38,8 +38,13 @@ public Task ExecuteAsync()

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(IContentPageContext.HasSelection))
OnPropertyChanged(nameof(IsExecutable));
switch (e.PropertyName)
{
case nameof(IContentPageContext.CanCreateItem):
case nameof(IContentPageContext.HasSelection):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}
}
}
11 changes: 8 additions & 3 deletions src/Files.App/Actions/FileSystem/CreateShortcutAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class CreateShortcutAction : BaseUIAction, IAction

public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconShortcut");

public override bool IsExecutable => context.HasSelection && UIHelpers.CanShowDialog;
public override bool IsExecutable => context.HasSelection && context.CanCreateItem && UIHelpers.CanShowDialog;

public CreateShortcutAction()
{
Expand Down Expand Up @@ -51,8 +51,13 @@ public async Task ExecuteAsync()

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(IContentPageContext.HasSelection))
OnPropertyChanged(nameof(IsExecutable));
switch (e.PropertyName)
{
case nameof(IContentPageContext.HasSelection):
case nameof(IContentPageContext.CanCreateItem):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal class CreateShortcutFromDialogAction : BaseUIAction, IAction

public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconShortcut");

public override bool IsExecutable => context.ShellPage is not null && UIHelpers.CanShowDialog;
public override bool IsExecutable => context.CanCreateItem && UIHelpers.CanShowDialog;

public CreateShortcutFromDialogAction()
{
Expand All @@ -30,12 +30,12 @@ public CreateShortcutFromDialogAction()

public async Task ExecuteAsync()
{
await UIFilesystemHelpers.CreateShortcutFromDialogAsync(context.ShellPage);
await UIFilesystemHelpers.CreateShortcutFromDialogAsync(context.ShellPage!);
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(IContentPageContext.ShellPage))
if (e.PropertyName is nameof(IContentPageContext.CanCreateItem))
OnPropertyChanged(nameof(IsExecutable));
}
}
Expand Down
29 changes: 29 additions & 0 deletions src/Files.App/Actions/Global/EditPathAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using System.Threading.Tasks;

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

public string Label { get; } = "EditPath".GetLocalizedResource();

public string Description { get; } = "EditPathDescription".GetLocalizedResource();

public HotKey HotKey { get; } = new(Keys.L, KeyModifiers.Ctrl);

public HotKey SecondHotKey { get; } = new(Keys.D, KeyModifiers.Menu);

public Task ExecuteAsync()
{
if (context.ShellPage is not null)
context.ShellPage.ToolbarViewModel.IsEditModeEnabled = true;

return Task.CompletedTask;
}
}
}
2 changes: 2 additions & 0 deletions src/Files.App/Commands/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum CommandCodes
ExitCompactOverlay,
ToggleCompactOverlay,
Search,
EditPath,
Redo,
Undo,

Expand All @@ -32,6 +33,7 @@ public enum CommandCodes
DeleteItem,
DeleteItemPermanently,
CreateFolder,
AddItem,
CreateShortcut,
CreateShortcutFromDialog,
EmptyRecycleBin,
Expand Down
4 changes: 4 additions & 0 deletions src/Files.App/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal class CommandManager : ICommandManager
public IRichCommand ExitCompactOverlay => commands[CommandCodes.ExitCompactOverlay];
public IRichCommand ToggleCompactOverlay => commands[CommandCodes.ToggleCompactOverlay];
public IRichCommand Search => commands[CommandCodes.Search];
public IRichCommand EditPath => commands[CommandCodes.EditPath];
public IRichCommand Redo => commands[CommandCodes.Redo];
public IRichCommand Undo => commands[CommandCodes.Undo];
public IRichCommand ToggleShowHiddenItems => commands[CommandCodes.ToggleShowHiddenItems];
Expand All @@ -56,6 +57,7 @@ internal class CommandManager : ICommandManager
public IRichCommand CreateShortcut => commands[CommandCodes.CreateShortcut];
public IRichCommand CreateShortcutFromDialog => commands[CommandCodes.CreateShortcutFromDialog];
public IRichCommand CreateFolder => commands[CommandCodes.CreateFolder];
public IRichCommand AddItem => commands[CommandCodes.AddItem];
public IRichCommand PinToStart => commands[CommandCodes.PinToStart];
public IRichCommand UnpinFromStart => commands[CommandCodes.UnpinFromStart];
public IRichCommand PinItemToFavorites => commands[CommandCodes.PinItemToFavorites];
Expand Down Expand Up @@ -171,6 +173,7 @@ public CommandManager()
[CommandCodes.ExitCompactOverlay] = new ExitCompactOverlayAction(),
[CommandCodes.ToggleCompactOverlay] = new ToggleCompactOverlayAction(),
[CommandCodes.Search] = new SearchAction(),
[CommandCodes.EditPath] = new EditPathAction(),
[CommandCodes.Redo] = new RedoAction(),
[CommandCodes.Undo] = new UndoAction(),
[CommandCodes.ToggleShowHiddenItems] = new ToggleShowHiddenItemsAction(),
Expand All @@ -190,6 +193,7 @@ public CommandManager()
[CommandCodes.CreateShortcut] = new CreateShortcutAction(),
[CommandCodes.CreateShortcutFromDialog] = new CreateShortcutFromDialogAction(),
[CommandCodes.CreateFolder] = new CreateFolderAction(),
[CommandCodes.AddItem] = new AddItemAction(),
[CommandCodes.PinToStart] = new PinToStartAction(),
[CommandCodes.UnpinFromStart] = new UnpinFromStartAction(),
[CommandCodes.PinItemToFavorites] = new PinItemAction(),
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
IRichCommand ExitCompactOverlay { get; }
IRichCommand ToggleCompactOverlay { get; }
IRichCommand Search { get; }
IRichCommand EditPath { get; }
IRichCommand Redo { get; }
IRichCommand Undo { get; }

Expand All @@ -39,6 +40,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
IRichCommand ToggleSelect { get; }
IRichCommand ShareItem { get; }
IRichCommand CreateFolder { get; }
IRichCommand AddItem { get; }
IRichCommand CreateShortcut { get; }
IRichCommand CreateShortcutFromDialog { get; }
IRichCommand EmptyRecycleBin { get; }
Expand Down
15 changes: 15 additions & 0 deletions src/Files.App/Contexts/ContentPage/ContentPageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ internal class ContentPageContext : ObservableObject, IContentPageContext

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

public bool CanCreateItem => GetCanCreateItem();

public bool IsMultiPaneEnabled => ShellPage is not null && ShellPage.PaneHolder is not null && ShellPage.PaneHolder.IsMultiPaneEnabled;

public bool IsMultiPaneActive => ShellPage is not null && ShellPage.PaneHolder is not null && ShellPage.PaneHolder.IsMultiPaneActive;
Expand Down Expand Up @@ -180,6 +182,7 @@ private void Update()
OnPropertyChanged(nameof(CanGoForward));
OnPropertyChanged(nameof(CanNavigateToParent));
OnPropertyChanged(nameof(CanRefresh));
OnPropertyChanged(nameof(CanCreateItem));
OnPropertyChanged(nameof(IsMultiPaneEnabled));
OnPropertyChanged(nameof(IsMultiPaneActive));
}
Expand All @@ -200,6 +203,7 @@ private void UpdatePageType()
_ => ContentPageTypes.Folder,
};
SetProperty(ref pageType, type, nameof(PageType));
OnPropertyChanged(nameof(CanCreateItem));
}

private void UpdateSelectedItems()
Expand All @@ -216,5 +220,16 @@ private void UpdateSelectedItems()
OnPropertyChanged(nameof(SelectedItem));
}
}

private bool GetCanCreateItem()
{
return ShellPage is not null &&
pageType is not ContentPageTypes.None
and not ContentPageTypes.Home
and not ContentPageTypes.RecycleBin
and not ContentPageTypes.ZipFolder
and not ContentPageTypes.SearchResults
and not ContentPageTypes.MtpDevice;
}
}
}
2 changes: 2 additions & 0 deletions src/Files.App/Contexts/ContentPage/IContentPageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public interface IContentPageContext : INotifyPropertyChanged

bool IsSearchBoxVisible { get; }

bool CanCreateItem { get; }

bool IsMultiPaneEnabled { get; }
bool IsMultiPaneActive { get; }
}
Expand Down
19 changes: 3 additions & 16 deletions src/Files.App/Helpers/ContextFlyoutItemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,24 +204,11 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
ShowInZipPage = true,
ShowItem = !itemsSelected
},
new ContextMenuFlyoutItemViewModel()
new ContextMenuFlyoutItemViewModelBuilder(commands.AddItem)
{
Text = "BaseLayoutContextFlyoutNew/Label".GetLocalizedResource(),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconNew",
},
KeyboardAccelerator = new KeyboardAccelerator
{
Key = VirtualKey.N,
Modifiers = VirtualKeyModifiers.Control,
IsEnabled = false,
},
Items = GetNewItemItems(commandsViewModel, currentInstanceViewModel.CanCreateFileInPage),
ShowInFtpPage = true,
ShowInZipPage = true,
ShowItem = !itemsSelected
},
IsVisible = !itemsSelected
}.Build(),
new ContextMenuFlyoutItemViewModelBuilder(commands.FormatDrive).Build(),
new ContextMenuFlyoutItemViewModelBuilder(commands.EmptyRecycleBin)
{
Expand Down
12 changes: 9 additions & 3 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1851,9 +1851,6 @@
<data name="ExtractingCompleteText" xml:space="preserve">
<value>Extracting complete!</value>
</data>
<data name="BaseLayoutContextFlyoutNew.KeyboardAcceleratorTextOverride" xml:space="preserve">
<value>Ctrl+Shift+N</value>
</data>
<data name="BaseLayoutItemContextFlyoutOpenParentFolder.Text" xml:space="preserve">
<value>Open parent folder</value>
</data>
Expand Down Expand Up @@ -3151,6 +3148,9 @@
<data name="CloseTab" xml:space="preserve">
<value>Closes current tab</value>
</data>
<data name="EditPath" xml:space="preserve">
<value>Edit path</value>
</data>
<data name="Branch" xml:space="preserve">
<value>Branch: {0}</value>
</data>
Expand Down Expand Up @@ -3178,6 +3178,12 @@
<data name="ShowCheckboxesWhenSelectingItems" xml:space="preserve">
<value>Show checkboxes when selecting items</value>
</data>
<data name="EditPathDescription" xml:space="preserve">
<value>Go to path bar</value>
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
</data>
<data name="AddItemDescription" xml:space="preserve">
<value>Open the menu to create a new item</value>
</data>
<data name="SecurityNoAccessControlEntriesText" xml:space="preserve">
<value>No groups or users have permission to access this object. However, the owner of this object can assign permissions.</value>
</data>
Expand Down
18 changes: 6 additions & 12 deletions src/Files.App/UserControls/InnerNavigationToolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,11 @@
x:Name="NewEmptySpaceAppBarButton"
AccessKey="W"
AutomationProperties.AutomationId="InnerNavigationToolbarNewButton"
IsEnabled="{x:Bind ViewModel.InstanceViewModel.IsCreateButtonEnabledInPage, Mode=OneWay, FallbackValue=False}"
KeyboardAcceleratorTextOverride="{helpers:ResourceString Name=BaseLayoutContextFlyoutNew/KeyboardAcceleratorTextOverride}"
Label="{helpers:ResourceString Name=BaseLayoutContextFlyoutNew/Label}"
IsEnabled="{x:Bind Commands.AddItem.IsExecutable, Mode=OneWay, FallbackValue=False}"
KeyboardAcceleratorTextOverride="{x:Bind Commands.AddItem.HotKeyText, Mode=OneWay}"
Label="{x:Bind Commands.AddItem.Label}"
Style="{StaticResource ToolBarAppBarButtonFlyoutStyle}">

<local:OpacityIcon Style="{StaticResource ColorIconNew}" />

<AppBarButton.KeyboardAccelerators>
<KeyboardAccelerator
Key="N"
IsEnabled="False"
Modifiers="Control,Shift" />
</AppBarButton.KeyboardAccelerators>
<local:OpacityIcon Style="{x:Bind Commands.AddItem.OpacityStyle}" />

<AppBarButton.Flyout>
<MenuFlyout x:Name="NewEmptySpace" Opening="NewEmptySpace_Opening">
Expand All @@ -80,6 +72,7 @@
AccessKey="D"
AutomationProperties.AutomationId="InnerNavigationToolbarNewFolderButton"
Command="{x:Bind Commands.CreateFolder, Mode=OneWay}"
KeyboardAcceleratorTextOverride="{x:Bind Commands.CreateFolder.HotKeyText, Mode=OneWay}"
Text="{x:Bind Commands.CreateFolder.Label}">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE8B7;" />
Expand All @@ -102,6 +95,7 @@
AccessKey="S"
AutomationProperties.AutomationId="InnerNavigationToolbarNewShortcutButton"
Command="{x:Bind Commands.CreateShortcutFromDialog, Mode=OneWay}"
KeyboardAcceleratorTextOverride="{x:Bind Commands.CreateShortcutFromDialog.HotKeyText, Mode=OneWay}"
Text="{x:Bind Commands.CreateShortcutFromDialog.Label}">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE71B;" />
Expand Down
Loading