#cp.commands

Commands Module.


#Submodules


#API Overview

Constants - Useful values which cannot be changed

Functions - API calls offered directly by the extension

Fields - Variables which can only be accessed from an object returned by a constructor

Methods - API calls which can only be made on an object returned by a constructor


#API Documentation

#Constants

Signaturecp.commands.DEFAULT_EXTENSION -> string
TypeConstant
DescriptionThe menubar position priority.
NotesNone
Sourcesrc/extensions/cp/commands/init.lua line 33

#Functions

Signaturecp.commands.getShortcutsPath(name) -> string
TypeFunction
DescriptionReturns the path to the named shortcut set.
Parameters
  • None
Returns
  • A string
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/commands/init.lua line 379

Signaturecp.commands.group(id) -> cp.command or nil
TypeFunction
DescriptionCreates a collection of commands. These commands can be enabled or disabled as a group.
Parameters
  • id - The ID to retrieve
Returns
  • cp.commands - The command group with the specified ID, or nil if none exists.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/commands/init.lua line 57

Signaturecp.commands.groupIds() -> table
TypeFunction
DescriptionReturns an array of IDs of command groups which have been created.
Parameters
  • None
Returns
  • table - The array of group IDs.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/commands/init.lua line 40

Signaturecp.commands.groups(id) -> table of cp.commands
TypeFunction
DescriptionReturns a table with the set of commands.
Parameters
  • id - The ID to retrieve
Returns
  • cp.commands - The command group with the specified ID, or nil if none exists.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/commands/init.lua line 70

Signaturecp.commands.loadFromFile(name) -> boolean
TypeFunction
DescriptionLoads a shortcut set from the standard location with the specified name.
Parameters
  • name - The name of the shortcut set. E.g. "My Custom Shortcuts"
Returns
  • true if the file was found and loaded successfully.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/commands/init.lua line 404

Signaturecp.commands.new(id) -> cp.commands
TypeFunction
DescriptionCreates a collection of commands. These commands can be enabled or disabled as a group.
Parameters
  • id - The unique ID for this command group.
Returns
  • cp.commands - The command group that was created.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/commands/init.lua line 83

Signaturecp.commands.saveToFile(name) -> boolean
TypeFunction
DescriptionSaves the current shortcuts for all groups to a file in the standard location with the provided name.
Parameters
  • name - The name of the command set. E.g. "My Custom Commands"
Returns
  • true if the shortcuts were saved successfully.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/commands/init.lua line 456

#Fields

Signaturecp.commands.enabled <cp.prop: boolean>
TypeField
DescriptionIf enabled, the commands in the group will be active as well.
NotesNone
Sourcesrc/extensions/cp/commands/init.lua line 104

Signaturecp.commands.isEditable <cp.prop: boolean>
TypeField
DescriptionIf set to false, the command group is not user-editable.
NotesNone
Sourcesrc/extensions/cp/commands/init.lua line 116

#Methods

Signaturecp.commands:activate(successFn, failureFn) -> nil
TypeMethod
DescriptionWill trigger an 'activate' event, and then execute either the successFn or failureFn if the command group is not enabled within 5 seconds.
Parameters
  • successFn - the function to call if successfully activated.
  • failureFn - the function to call if not activated after 5 seconds.
Returns
  • Nothing.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/commands/init.lua line 300

Signaturecp.commands:add(commandId) -> cp.commands.command
TypeMethod
DescriptionAdds a new command with the specified ID to this group. Additional configuration should be applied to the returned command instance. Eg:
Parameters
  • commandId - The unique ID for the new command.
Returns
  • The new cp.commands.command instance.
Notes
  • For example:
  • lua</li><li>myCommands:add("fooBar"):groupedBy("foo"):whenActivated(function() ... end)`</li><li>
ExamplesNone
Sourcesrc/extensions/cp/commands/init.lua line 139

Signaturecp.commands:clear() -> cp.commands
TypeMethod
DescriptionClears all commands and their shortcuts.
Parameters
  • None
Returns
  • The command group instance.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/commands/init.lua line 197

Signaturecp.commands:deleteShortcuts() -> cp.commands
TypeMethod
DescriptionClears all shortcuts associated with commands in this command group.
Parameters
  • None
Returns
  • The command group instance.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/commands/init.lua line 212

Signaturecp.commands:disable() -> cp.commands
TypeMethod
DescriptionDisables the command group.
Parameters
  • None
Returns
  • The command group instance.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/commands/init.lua line 242

Signaturecp.commands:enable() -> cp.commands
TypeMethod
DescriptionEnables the command group.
Parameters
  • None
Returns
  • The command group instance.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/commands/init.lua line 228

Signaturecp.commands:get(commandId) -> cp.commands.command
TypeMethod
DescriptionReturns the command with the specified ID, or nil if none exists.
Parameters
  • commandId - The command ID to retrieve.
Returns
  • The cp.commands.command, or nil.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/commands/init.lua line 162

Signaturecp.commands:getAll() -> table of cp.commands.command
TypeMethod
DescriptionReturns the table of commands, with the key being the ID and the value being the command instance.
Parameters
  • None
Returns
  • A table
Notes
  • For example:
  • lua</li><li>for id,cmd in pairs(myCommands:getAll()) do</li><li> ...</li><li>end</li><li>
ExamplesNone
Sourcesrc/extensions/cp/commands/init.lua line 175

Signaturecp.commands:id() -> string
TypeMethod
DescriptionReturns the unique ID of the command group.
Parameters
  • None
Returns
  • The command group ID string.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/commands/init.lua line 126

Signaturecp.commands:loadShortcuts(data) -> nil
TypeMethod
DescriptionLoads the shortcut details in the data table and applies them to the commands in this group. The data should probably come from the saveShortcuts method.
Parameters
  • data - The data table containing shortcuts.
Returns
  • Nothing
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/commands/init.lua line 358

Signaturecp.commands:saveShortcuts() -> table
TypeMethod
DescriptionReturns a table that is approprate to be saved to file that contains the shortuct for all contained cp.commands.command instances.
Parameters
  • None
Returns
  • The table of shortcuts for commands.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/commands/init.lua line 333

Signaturecp.commands:watch(events) -> cp.commands
TypeMethod
DescriptionAdds an event watcher to the command group.
Parameters
  • events - The table of events to watch for (see Notes).
Returns
  • The command group instance.
Notes
  • The table can have properties with the following functions, which will be called for the specific event:
  • ** add(command): Called after the provided cp.commands.command instance has been added.
  • ** activate() Called when the command group is activated.
  • ** enable(): Called when the command group is enabled.
  • ** disable(): Called when the command group is disabled.
ExamplesNone
Sourcesrc/extensions/cp/commands/init.lua line 256