forked from files-community/Files
-
Notifications
You must be signed in to change notification settings - Fork 0
CommandManager
0x5BFA edited this page Jan 19, 2025
·
12 revisions
CommandManager.Initialize(CommandExecutionContexts.Browser);
CommandManager.Initialize(CommandExecutionContexts.Sidebar);
CommandManager.Initialize(CommandExecutionContexts.Home); // Temporary
CommandManager.Initialize(CommandExecutionContexts.Tabs);
// Sync
if (CommandManager.NavigateBack.CanExecute())
CommandManager.NavigateBack.Execute();
// Async
if (async CommandManager.NavigateBack.CanExecuteAsync())
async CommandManager.NavigateBack.ExecuteAsync();
// Sync with parameter
if (CommandManager.NavigateBack.CanExecute(parameter))
CommandManager.NavigateBack.Execute(parameter);
[RichCommand]
internal class DeleteAction : IAction
{
// Only can executes with the Browser context
public static CommandExecutionContexts ExecutableContexts = CommandExecutionContexts.Browser;
public string Title => "";
public string Description => "";
public HotKey DefaultHotKey => new(...);
public Task<bool> CanExecuteAsync()
{
// Verify the executability
return Task.FromResult(...);
}
public Task ExecuteAsync(CommandExecutionContexts context, object? parameter)
{
if (!ExecutableContexts.HasFlag(context)
return throw new InvalidOperarionException($"This command cannot be executed with the given context: {context}");
// Execute...
}
}
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public sealed class RichCommandAttribute : Attribute {}
// CommandManager.g.cs
namespace global::Files.App.Data
{
internal partial class CommandManager
{
private readonly FrozenDictionary<CommandCodes, IRichCommand> commands;
private readonly FrozenDictionary<CommandCodes, IRichCommand> modifiableCommands;
public IRichCommand NavigateBack { get; } = new ActionCommand(CommandCodes.NavigateBack, new NavigateBackAction());
...
public bool Initialize(CommandExecutionContexts context)
{
..
commands =
[
[CommandCodes.NavigateBack] = new NavigateBackAction(),
...
];
...
}
}
internal enum CommandCodes
{
NavigateBack,
...
}
}
public void AppendModifiableCommands()
{
modifiableCommands = [ ... ];
}
```c#
This documentation is not open for everyone. Do not copy.
Controls
- FolderBrowser
- DetailsFolderView
- GridFolderView
- ListFolderView
- TilesFolderView
- ContentFolderView
- ColumnsFolderView
- TreeFolderView
- GalleryFolderView
- HomeFolderView
- RectanglurSelectionVisual
- DataGrid
- SidebarView
- Omnibar
- Toolbar
- FilePreviewPresenter
- ColorTags
- RichTokens
- TerminalView
API
- WindowsStorable
- ArchiveStorable
- HomeStorable
- FtpStorable
- SftpStorable
- WebDAVStorable
Infrastructure
- CommandManager
- MultitaskingManager
- DialogManager
- AppSettings
- OperationServer
Copyright © 2025 0x5BFA. All rights reserved. Do not copy or redistribute modified versions.