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

docs: refine API docs for files in Command dir #1906

Merged
merged 3 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
159 changes: 128 additions & 31 deletions docs/API-Reference/command/CommandManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,148 @@
const CommandManager = brackets.getModule("command/CommandManager")
```

<a name="_commands"></a>
<a name="Command"></a>

## \_commands : <code>Object</code>
Map of all registered global commands
## Command
**Kind**: global class

**Kind**: global variable
**Properties**
* [Command](#Command)
* [new Command(name, id, commandFn, [options])](#new_Command_new)
* [.getID()](#Command+getID) ⇒ <code>string</code>
* [.execute()](#Command+execute) ⇒ <code>$.Promise</code>
* [.getEnabled()](#Command+getEnabled) ⇒ <code>boolean</code>
* [.setEnabled(enabled)](#Command+setEnabled)
* [.setChecked(checked)](#Command+setChecked)
* [.getChecked()](#Command+getChecked) ⇒ <code>boolean</code>
* [.setName(name)](#Command+setName)
* [.getName()](#Command+getName) ⇒ <code>string</code>

| Name | Type | Description |
<a name="new_Command_new"></a>

### new Command(name, id, commandFn, [options])
Events:
- enabledStateChange
- checkedStateChange
- keyBindingAdded
- keyBindingRemoved


| Param | Type | Description |
| --- | --- | --- |
| commands | <code>Object.&lt;string, Command&gt;</code> | A map of command IDs to Command objects. |
| name | <code>string</code> | text that will be displayed in the UI to represent command |
| id | <code>string</code> | |
| commandFn | <code>function</code> | the function that is called when the command is executed. TODO: where should this be triggered, The Command or Exports? |
| [options] | | |

<a name="_commandsOriginal"></a>
<a name="Command+getID"></a>

## \_commandsOriginal : <code>Object</code>
Temporary copy of commands map for restoring after testingTODO (issue #1039): implement separate require contexts for unit tests
### command.getID() ⇒ <code>string</code>
Get command id

**Kind**: global variable
**Properties**
**Kind**: instance method of [<code>Command</code>](#Command)
<a name="Command+execute"></a>

| Name | Type | Description |
| --- | --- | --- |
| commands | <code>Object.&lt;string, Command&gt;</code> | A map of command IDs to Command objects. |
### command.execute() ⇒ <code>$.Promise</code>
Executes the command. Additional arguments are passed to the executing function

**Kind**: instance method of [<code>Command</code>](#Command)
**Returns**: <code>$.Promise</code> - a jQuery promise that will be resolved when the command completes.
<a name="Command+getEnabled"></a>

### command.getEnabled() ⇒ <code>boolean</code>
Is command enabled?

**Kind**: instance method of [<code>Command</code>](#Command)
<a name="Command+setEnabled"></a>

### command.setEnabled(enabled)
Sets enabled state of Command and dispatches "enabledStateChange"
when the enabled state changes.

**Kind**: instance method of [<code>Command</code>](#Command)

| Param | Type |
| --- | --- |
| enabled | <code>boolean</code> |

<a name="Command+setChecked"></a>

### command.setChecked(checked)
Sets enabled state of Command and dispatches "checkedStateChange"
when the enabled state changes.

**Kind**: instance method of [<code>Command</code>](#Command)

| Param | Type |
| --- | --- |
| checked | <code>boolean</code> |

<a name="Command+getChecked"></a>

### command.getChecked() ⇒ <code>boolean</code>
Is command checked?

**Kind**: instance method of [<code>Command</code>](#Command)
<a name="Command+setName"></a>

### 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 [<code>Command</code>](#Command)

| Param | Type |
| --- | --- |
| name | <code>string</code> |

<a name="Command+getName"></a>

### command.getName() ⇒ <code>string</code>
Get command name

**Kind**: instance method of [<code>Command</code>](#Command)
<a name="EventDispatcher"></a>

## EventDispatcher
Manages global application commands that can be called from menu items, key bindings, or subpartsof the application.This module dispatches these event(s): - commandRegistered -- when a new command is registered - beforeExecuteCommand -- before dispatching a command
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
<a name="EVENT_BEFORE_EXECUTE_COMMAND"></a>

## EVENT\_BEFORE\_EXECUTE\_COMMAND : <code>string</code>
Event triggered before command executes.

**Kind**: global constant
<a name="SOURCE_KEYBOARD_SHORTCUT"></a>

## SOURCE\_KEYBOARD\_SHORTCUT : <code>string</code>
Keyboard shortcut trigger.

**Kind**: global constant
<a name="SOURCE_UI_MENU_CLICK"></a>

## SOURCE\_UI\_MENU\_CLICK : <code>string</code>
UI menu click trigger.

**Kind**: global constant
<a name="SOURCE_OTHER"></a>

## SOURCE\_OTHER : <code>string</code>
Other trigger types.

**Kind**: global constant
<a name="register"></a>

## register(name, id, commandFn, [options]) ⇒ [<code>Command</code>](#new_Command_new)
## register(name, id, commandFn, [options]) ⇒ [<code>Command</code>](#Command)
Registers a global command.

**Kind**: global function
Expand All @@ -50,7 +159,7 @@ Registers a global command.

<a name="registerInternal"></a>

## registerInternal(id, commandFn) ⇒ [<code>Command</code>](#new_Command_new)
## registerInternal(id, commandFn) ⇒ [<code>Command</code>](#Command)
Registers a global internal only command.

**Kind**: global function
Expand All @@ -60,21 +169,9 @@ Registers a global internal only command.
| id | <code>string</code> | 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 | <code>function</code> | 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. |

<a name="_testReset"></a>

## \_testReset()
Clear all commands for unit testing, but first make copy of commands so thatthey can be restored afterward

**Kind**: global function
<a name="_testRestore"></a>

## \_testRestore()
Restore original commands after test and release copy

**Kind**: global function
<a name="get"></a>

## get(id) ⇒ [<code>Command</code>](#new_Command_new)
## get(id) ⇒ [<code>Command</code>](#Command)
Retrieves a Command object by id

**Kind**: global function
Expand Down
Loading
Loading