Class Action
An action encapsulates the functionality of a menu item, by making it
possible to register an event listener on the action
event
which is triggered when the menu item is clicked.
Actions are typically created by invoking actions.createAction()
-
Constructor Attributes | Constructor Name and Description |
---|---|
Action(name, accelerator)
Create an Action instance.
|
Method Attributes | Method Name and Description |
---|---|
enabled(value)
Sets or retrieves the enabled state of the action.
|
|
Returns the desired accelerator for the action, or
undefined if none has been defined. |
|
getName()
Returns the name of the action.
|
|
setAccelerator(accelerator)
Changes the accelerator for an action.
|
|
setName(newName)
Changes the name of the action.
|
Class Detail
Action(name, accelerator)
Create an Action instance.
var hello = actions.createAction('Hello World', 'shortcut shift F5'); actions.addAction(hello,'file'); hello.once('action', function() { actions.removeAction(hello, 'file'); });
- Parameters:
- {String} name
- name of the action.
- {String} accelerator
- the keyboard shortcut of the action.
Method Detail
{Boolean}
enabled(value)
Sets or retrieves the enabled state of the action. When an action is enabled
any menu item associated with the action are possible to click on.
When an action is disabled, the menu items can not be clicked on and will appear
disabled to the user.
This method can also be used to see the current enable/disable state. When called with no parameters it will just return the current enable/disable state.
// toggle an enabled action if (hello.enabled()) { hello.enabled(false); } else { hello.enabled(true) }
- Parameters:
- {Boolean} value
- true to enable this
Action
, false to disable it
- Returns:
- true or false when called without any parameters, and
undefined
if called with any parameters.
getAccelerator()
Returns the desired accelerator for the action, or
undefined
if none has been defined.
Please note that if the existing accelerator is invalid
this method will still return the "invalid" accelerator
even though it's not used in the actual user interface.
getName()
Returns the name of the action.
setAccelerator(accelerator)
Changes the accelerator for an action. If an invalid (or empty)
accelerator is specified, the action will have no accelerator.
- Parameters:
- {String} accelerator
- the new accelerator, e.g. "shortcut F11"
setName(newName)
Changes the name of the action. This will result in the UI changing
to reflect the new name of the action.
- Parameters:
- newName