Edit online


Is there a way to disable menu items for custom Author mode actions depending on the cursor context?


By default, Oxygen XML Author does not toggle the enabled/disabled states for actions based on whether or not the activation XPath expressions for that certain Author mode action are fulfilled. This is done because the actions can be many and evaluating XPath expression on each cursor move can lead to performance problems. However, if you have your own ro.sync.ecss.extensions.api.ExtensionsBundle implementation you can overwrite the method:


and when the extension state listener gets activated, you can use the API like this:
     * @see ro.sync.ecss.extensions.api.AuthorExtensionStateListener#activated
    public void activated(final AuthorAccess authorAccess) {

      //Add a caret listener to enable/disable extension actions:
authorAccess.getEditorAccess().addAuthorCaretListener(new AuthorCaretListener() 
    public void caretMoved(AuthorCaretEvent caretEvent) {
      try {
        Map<String, Object> authorExtensionActions = 
        //Get the action used to insert a paragraph. It's ID is "paragraph"
        AbstractAction insertParagraph = (
AbstractAction) authorExtensionActions.get("paragraph");
        //Evaluate an XPath expression in context of the current node
     Object[] evaluateXPath = authorAccess.getDocumentController().evaluateXPath
(".[ancestor-or-self::p]", false, false, false, false);
        if(evaluateXPath != null && evaluateXPath.length > 0 && 
evaluateXPath[0] != null) {
          //We are inside a paragraph, disable the action.
        } else {
          //Enable the action
      } catch (AuthorOperationException e) {
When the extension is deactivated, you should remove the CaretListener to avoid adding multiple listeners that perform the same functionality.