Skip to main content

CommandManager

Import :

const CommandManager = brackets.getModule("command/CommandManager")

Command

Kind: global class

new Command(name, id, commandFn, [options])

Events:

  • enabledStateChange
  • checkedStateChange
  • keyBindingAdded
  • keyBindingRemoved
ParamTypeDescription
namestringtext that will be displayed in the UI to represent command
idstring
commandFnfunctionthe function that is called when the command is executed. TODO: where should this be triggered, The Command or Exports?
[options]

command.getID() ⇒ string

Get command id

Kind: instance method of Command

command.execute() ⇒ $.Promise

Executes the command. Additional arguments are passed to the executing function

Kind: instance method of Command
Returns: $.Promise - a jQuery promise that will be resolved when the command completes.

command.getEnabled() ⇒ boolean

Is command enabled?

Kind: instance method of Command

command.setEnabled(enabled)

Sets enabled state of Command and dispatches "enabledStateChange" when the enabled state changes.

Kind: instance method of Command

ParamType
enabledboolean

command.setChecked(checked)

Sets enabled state of Command and dispatches "checkedStateChange" when the enabled state changes.

Kind: instance method of Command

ParamType
checkedboolean

command.getChecked() ⇒ boolean

Is command checked?

Kind: instance method of Command

command.setName(name)

Sets the name of the Command and dispatches "nameChange" so that UI that reflects the command name can update.

Note, a Command name can appear in either HTML or native UI so HTML tags should not be used. To add a Unicode character, use \uXXXX instead of an HTML entity.

Kind: instance method of Command

ParamType
namestring

command.getName() ⇒ string

Get command name

Kind: instance method of Command

EventDispatcher

Manages global application commands that can be called from menu items, key bindings, or subparts of the application.

This module dispatches these event(s):

  • commandRegistered -- when a new command is registered
  • beforeExecuteCommand -- before dispatching a command

Kind: global constant

EVENT_BEFORE_EXECUTE_COMMAND : string

Event triggered before command executes.

Kind: global constant

SOURCE_KEYBOARD_SHORTCUT : string

Keyboard shortcut trigger.

Kind: global constant

SOURCE_UI_MENU_CLICK : string

UI menu click trigger.

Kind: global constant

SOURCE_OTHER : string

Other trigger types.

Kind: global constant

register(name, id, commandFn, [options]) ⇒ Command

Registers a global command.

Kind: global function

ParamTypeDescription
namestringtext that will be displayed in the UI to represent command
idstringunique identifier for command. Core commands in Brackets use a simple command title as an id, for example "open.file". Extensions should use the following format: "author.myextension.mycommandname". For example, "lschmitt.csswizard.format.css".
commandFnfunctionthe function to call when the command is executed. Any arguments passed to execute() (after the id) are passed as arguments to the function. If the function is asynchronous, it must return a jQuery promise that is resolved when the command completes. Otherwise, the CommandManager will assume it is synchronous, and return a promise that is already resolved.
[options]Object
options.eventSourcebooleanIf set to true, the commandFn will be called with the first argument event with details about the source(invoker) as event.eventSource(one of the CommandManager.SOURCE_*) and event.sourceType(Eg. Ctrl-K) parameter.

registerInternal(id, commandFn) ⇒ Command

Registers a global internal only command.

Kind: global function

ParamTypeDescription
idstringunique identifier for command. Core commands in Brackets use a simple command title as an id, for example "app.abort_quit". Extensions should use the following format: "author.myextension.mycommandname". For example, "lschmitt.csswizard.format.css".
commandFnfunctionthe function to call when the command is executed. Any arguments passed to execute() (after the id) are passed as arguments to the function. If the function is asynchronous, it must return a jQuery promise that is resolved when the command completes. Otherwise, the CommandManager will assume it is synchronous, and return a promise that is already resolved.

get(id) ⇒ Command

Retrieves a Command object by id

Kind: global function

ParamType
idstring

getAll() ⇒ Array.<string>

Returns the ids of all registered commands

Kind: global function

execute(id) ⇒ $.Promise

Looks up and runs a global command. Additional arguments are passed to the command.

Kind: global function
Returns: $.Promise - a jQuery promise that will be resolved when the command completes.

ParamTypeDescription
idstringThe ID of the command to run.