This mixin is auto-loaded by the scripting plugin and mixed into the native java class JSAction. It provides additional properties and methods which you can invoke on an instance of JSAction.
Name | Description |
---|---|
Properties | |
name | Set or get the name. |
onExecute | Set or get the function to be called when the action is executed. |
onInitEnabled | Set or get the function to be called when the enabled state of the action should be reevaluated. |
onUpdateEnabled | Set or get the function to be called when the enabled state of the action should be reevaluated. |
tooltip | Set or get the tooltip text. |
Methods | |
addToMenu | Adds an action to a menu. |
addToToolbar | Adds an action to the toolbar. |
This mixin provides additional properties and methods for the native Java class
JSAction, whose native public methods are available
for scripting, too. If a native method name is hidden by a property name in the mixin,
then prefix the native name with $
.
name:String
Set or get the name.
onExecute:function
Set or get the function to be called when the action is executed.
onInitEnabled:function
Set or get the function to be called when the enabled state should be initialized.
onUpdateEnabled:function
Set or get the function to be called when the enabled state of the action should be reevaluated.
tooltip:String
Set or get the tooltip text.
addToMenu
Adds an action to a menu.
Name | Type | Description |
---|---|---|
menu | JMenu | the menu. This should be one of the global JOSM menus. |
index | number | (optional) the index where to add the menu. Default if missing: adds the menu at the end |
var JSAction = require("josm/ui/menu").JSAction;
// adds a new action to the JOSM edit menu
new JSAction({name: "My Action"})
.addTo(josm.menu.get("edit"));
addToToolbar
Adds an action to the toolbar.
If no parameters are passed in, the action is registered with its toolbar id (see property tooblarId) for being displayed in the toolbar. It isn't displayed, however, unless the toolbar id is already included in the toolbar preferences. If not, the user first have to configure it manually in the preference dialog.
Use one of the named options described below, if you want to enforce, that the action is displayed at a a specific position in the toolbar. If you use one of these options, the toolbar configuration is saved to the preferences.
options
supports the following named parameters:
toolbarId: string
at: number, "start", "end"
after: string
after
.before: string
before
.Name | Type | Description |
---|---|---|
options | objects | optional named parameters |
var JSAction = require("josm/ui/menu").JSAction;
var action = new JSAction({name: "My Action", toolbarId: "myaction"});
// at the action after the "open" action in the toolbar
action.addToToolbar({after: "open"});
// at the action at the end of the toolbar
action.addToToolbar({at: "end"});