Editor.addCommand
Registers a command object with the editor. You can reference the command from a user interface component such as a custom toolbar button.
//declare only once
Editor.getScope().declare("show", false);
var ShowDraftCommentsCommand =
{
execute: function (scope) {
scope.set("show", !scope.get("show"));
var canvas = Editor.Canvas.getActiveCanvas();
canvas.setViewParam("show-draft-comments", scope.get("show"));
},
getEnabled: function(scope)
{
var canvas = Editor.Canvas.getActiveCanvas();
return !!canvas;
},
getChecked: function (scope) {
return scope.get("show"); //the button shows a 'pressed' state
},
getLabel: function (scope) {
if (scope.get("show"))
return "Hide Draft Comments";
else
return "Show Draft Comments";
}
}
Editor.addCommand("showDraftCommentsCommand", ShowDraftCommentsCommand);
Another often used version of getEnabled, using selection can be:
getEnabled: function(scope) {
var selection = scope.get("xmlSelection");
return selection.getRange().getCommonAncestorContainer().getLocalName() == "para")
}
For a button that is active in paragraphs (or elements named "para" in this case) only.
- Documentation
- › API
- › Global objects API
- › Editor.addCommand
Editor.addCommand( name : String, command : Command) : Object
: String, command : Command) : ObjectArguments
- name
- String. A unique name for the command. This name binds the userCommand object to the user interface component.
- command
- Command. An object that implements the Command methods such as the code that is run when the command executes.
Return Value
History
| version | event |
|---|---|
| Xopus 4.1 | Introduction. |