Mixin JSActionMixin

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 $.

Properties

name:String

Set or get the name.

get
Replies the name as string, or undefined, if no name is set.
set
Set null or undefined, to clear the name. Any other value is converted to a string.

onExecute:function

Set or get the function to be called when the action is executed.

get
Replies the function or undefined, if no function has been assigned.
set
Set the function, or null or undefined to remove the function.

onInitEnabled:function

Set or get the function to be called when the enabled state should be initialized.

get
Replies the function or undefined, if no function has been assigned.
set
Set the function, or null or undefined to remove the function.

onUpdateEnabled:function

Set or get the function to be called when the enabled state of the action should be reevaluated.

get
Replies the function or undefined, if no function has been assigned.
set
Set the function, or null or undefined to remove the function.

tooltip:String

Set or get the tooltip text.

get
Replies the tooltip as string, or undefined, if no tooltip is set.
set
Set null or undefined, to clear the tooltip. Any other value is converted to a string.

Functions

addToMenu

Adds an action to a menu.

Parameters

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

Examples

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
Optional toolbar id, overriding an already assigned toolbar id.
at: number, "start", "end"
Display the toolbar entry at a specific position, at the start or at the end of the toolbar.
after: string
Display the toolbar entry after the entry with toolbar id after.
before: string
Display the toolbar entry before the entry with toolbar id before.

Parameters

Name Type Description
options objects optional named parameters

Examples

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"});