Vixen
dd8b0a81
csharp
public sealed class CommandRegistry

Every command an application knows, by id.

Read the guide page for this →

Remarks

One table, and everything that shows a command reads it. That is what makes a new action appear in the menu, the palette and the keymap editor at once, and it is why a plugin adding a command is one Add call rather than an entry in four places.

⚠ Registering an id twice throws. A silent replace would let a plugin take over file.save by naming it, and a silent ignore would leave the plugin's own command quietly dead — both of which are found weeks later. The loader catches this and reports which plugin collided with what.

Insertion order is kept, because it is the order a palette shows commands in when the query is empty and there is nothing better to sort by. A ranked query reorders it.

⚠ It is also an application's IResponder — the last link of CommandRoute's chain, installed by the editor's shell as its document's ApplicationCommandResponder. That is what makes a Vixen.Ui control bound to edit.rename resolve, enable and run the application's command with no application-specific wiring in the control.

The interface rather than a mirror. A CommandResponder filled in alongside this table would be a second copy of the same map, wrong the first time a plugin registered into one and not the other. The lookup already exists here; the interface is three lines over it.

Fields and properties (3)

  • public IReadOnlyList<EditorCommand> Commands

    The commands, in the order they were registered.

  • public Func<string?>? FocusedContext

    Which context has the focus, asked whenever a scoped command is looked at.

  • public EditorCommand? this[string id]

    The command with an id, or null.

Events (2)

  • public Action<CommandRegistry>? Changed

    Raised when a command is added or removed.

  • public Action<EditorCommand>? Executed

    Raised after a command runs, whatever ran it.

Methods (9)

  • public bool IsInScope(EditorCommand command)

    Whether a command belongs to the context the user is in.

  • public EditorCommand Add(EditorCommand command)

    Adds a command.

  • public EditorCommand Add(string id, StringId title, Action run)

    Adds a command built from its parts.

  • public bool Remove(string id)

    Takes a command out.

  • public bool TryGetCommandHandler(string id, out CommandHandler handler)

    The handler the command route gets for an id, if this table knows it.

  • public bool TryGet(string id, out EditorCommand? command)

    Looks a command up.

  • public bool CanExecute(string id)

    Whether a command exists and can run right now.

  • public bool CanExecute(EditorCommand command)

    Whether a command is in scope and enabled.

  • public bool Execute(string id)

    Runs a command.

Used by (100, showing 40)

  • CommandDispatcherVixen.Ui.Controls
  • CommandRegistryTestsVixen.Ui.Controls.Tests
  • AgentDebuggerPanelTestsVixen.Editor.App.Tests
  • BlockoutHoverTestsVixen.Editor.Blockout.Tests
  • BlockoutKnifeTestsVixen.Editor.Blockout.Tests
  • BlockoutModeVixen.Editor.Blockout
  • BlockoutModeTestsVixen.Editor.Blockout.Tests
  • BlockoutModuleVixen.Editor.Blockout
  • BlockoutSelectionTestsVixen.Editor.Blockout.Tests
  • ChordRouteTestsVixen.Editor.Ui.Tests
  • ChromeFixtureVixen.Editor.Ui.Tests
  • CommandChainTestsVixen.Editor.Ui.Tests
  • CommandContextTestsVixen.Editor.App.Tests
  • CommandPaletteSourceVixen.Editor.Ui
  • CommandTestsVixen.Editor.Ui.Tests
  • ConsolePanelTestsVixen.Editor.App.Tests
  • CreateMenuTestsVixen.Editor.App.Tests
  • DiagnosticsPanelTestsVixen.Editor.App.Tests
  • EditorAffordanceTestsVixen.Editor.App.Tests
  • EditorApplicationVixen.Editor.App
  • EditorHostVixen.Editor.Host
  • EditorModeTestsVixen.Editor.App.Tests
  • EditorModesVixen.Editor.Ui
  • EditorScriptTestsVixen.Editor.Scripts.Tests
  • EditorSessionVixen.Editor.Testing
  • EditorShellVixen.Editor.Ui
  • EditorShellTestsVixen.Editor.Ui.Tests
  • EditorUndoManagerTestsVixen.Editor.App.Tests
  • EvaluatorDeviceChangeTestsVixen.Editor.Texturing.Tests
  • ExpiredRefusalTestsVixen.Editor.App.Tests
  • ExternalEditPumpTestsVixen.Editor.App.Tests
  • FoliageModeVixen.Editor.Terrain
  • FoliageModeTestsVixen.Editor.Terrain.Tests
  • ForceBakeDeviceTestsVixen.Editor.Texturing.Tests
  • ImageViewBarWiringTestsVixen.Editor.Texturing.Tests
  • InputDebugPanelTestsVixen.Editor.App.Tests
  • KeyBindingsPanelTestsVixen.Editor.App.Tests
  • KeyBindingsViewVixen.Editor.Ui
  • KeyBindingsViewTestsVixen.Editor.Ui.Tests
  • LayerRowKeyTestsVixen.Editor.Texturing.Tests