### Import :
```js
const CommandManager = brackets.getModule("command/CommandManager")
```
## Command
**Kind**: global class
* [Command](#Command)
* [new Command(name, id, commandFn, [options])](#new_Command_new)
* [.getID()](#Command+getID) ⇒ string
* [.execute()](#Command+execute) ⇒ $.Promise
* [.getEnabled()](#Command+getEnabled) ⇒ boolean
* [.getOptions()](#Command+getOptions) ⇒ object
* [.setEnabled(enabled)](#Command+setEnabled)
* [.setChecked(checked)](#Command+setChecked)
* [.getChecked()](#Command+getChecked) ⇒ boolean
* [.setName(name, htmlName)](#Command+setName)
* [.getName()](#Command+getName) ⇒ string
### new Command(name, id, commandFn, [options])
Events:
- enabledStateChange
- checkedStateChange
- keyBindingAdded
- keyBindingRemoved
| Param | Type | Description |
| --- | --- | --- |
| name | string | text that will be displayed in the UI to represent command |
| id | string | |
| commandFn | function | the 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)
### command.execute() ⇒ $.Promise
Executes the command. Additional arguments are passed to the executing function
**Kind**: instance method of [Command](#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)
### command.getOptions() ⇒ object
get the command options
**Kind**: instance method of [Command](#Command)
### command.setEnabled(enabled)
Sets enabled state of Command and dispatches "enabledStateChange"
when the enabled state changes.
**Kind**: instance method of [Command](#Command)
| Param | Type |
| --- | --- |
| enabled | boolean |
### command.setChecked(checked)
Sets enabled state of Command and dispatches "checkedStateChange"
when the enabled state changes.
**Kind**: instance method of [Command](#Command)
| Param | Type |
| --- | --- |
| checked | boolean |
### command.getChecked() ⇒ boolean
Is command checked?
**Kind**: instance method of [Command](#Command)
### command.setName(name, htmlName)
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](#Command)
| Param | Type | Description |
| --- | --- | --- |
| name | string | |
| htmlName | string | If set, this will be displayed in ui menus instead of the name given. Example: `"Phoenix menu"` |
### command.getName() ⇒ string
Get command name
**Kind**: instance method of [Command](#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](#Command)
Registers a global command.
**Kind**: global function
| Param | Type | Description |
| --- | --- | --- |
| name | string | text that will be displayed in the UI to represent command |
| id | string | unique 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". |
| commandFn | function | the 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.eventSource | boolean | If 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. |
| options.htmlName | string | If set, this will be displayed in ui menus instead of the name given. Example: `"Phoenix menu"` |
## registerInternal(id, commandFn) ⇒ [Command](#Command)
Registers a global internal only command.
**Kind**: global function
| Param | Type | Description |
| --- | --- | --- |
| id | string | unique 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". |
| commandFn | function | the 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](#Command)
Retrieves a Command object by id
**Kind**: global function
| Param | Type |
| --- | --- |
| id | string |
## 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.
| Param | Type | Description |
| --- | --- | --- |
| id | string | The ID of the command to run. |