Refresh contextual menu action name

Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
NicoAMP
Posts: 98
Joined: Tue Mar 06, 2018 2:07 pm
Contact:

Refresh contextual menu action name

Post by NicoAMP »

Hello,

In Oxygen web Author, I would like to add an action that takes name of current selected element in contextual menu.
Each time the contextual menu is displayed, this action's name will have the name of the current selected element.

So I use this code to get current tag name:

Code: Select all

//display name
DisplayCurrentElementAction.prototype.getDisplayName = function () {
   var oxyNode = this.editor.getSelectionManager().getSelection().getNodeAtCaret().getTagName();
   return oxyNode;
};
And I add action to the contextuel menu:

Code: Select all

goog.events.listen(workspace, sync.api.Workspace.EventType.EDITOR_LOADED, function (e) {
    var editor = e.editor;
    editor.getActionsManager().registerAction('display.current.element.action', new DisplayCurrentElementAction(editor));
    addToContextMenu(editor, 'display.current.element.action');
});    

function addToContextMenu(editor, actionId) {
    editor.listen(sync.api.Editor.EventTypes.ACTIONS_LOADED, function (e) {
        var contextualItems = e.actionsConfiguration.contextualItems;
        if (contextualItems) {
            contextualItems.unshift({
                id: actionId,
                type: "action"
            });
        }
    });
}
It works but just one time, because ACTIONS_LOADED is triggered only once
The action's name in contextual menu is not refreshed when the selection change.

Is there a way to achieve this behavior?

Thanks.
Nicolas Delobel
AmeXio
nicolas.delobel at amexiogroup.com
Gabriel Titerlea
Site Admin
Posts: 95
Joined: Thu Jun 09, 2016 2:01 pm

Re: Refresh contextual menu action name

Post by Gabriel Titerlea »

Hello,

Refreshing the displayName of actions is not possible at the moment. I registered a feature request and we'll update this forum post when we have a fix available.

Meanwhile, as a workaround, you can change the DOM of the menu-item yourself, during the isEnabled method execution. Something like this:

Code: Select all

DisplayCurrentElementAction.prototype.isEnabled = function () {
  var tagName = this.editor.getSelectionManager().getSelection().getNodeAtCaret().getTagName();

  let menuItemNode = document.querySelector('.goog-menuitem[name="display.current.element.action"] span');
  if (menuItemNode) {
    menuItemNode.textContent = tagName;
  }

  // isEnabled logic.
  return true;
}
Best,
Gabriel
NicoAMP
Posts: 98
Joined: Tue Mar 06, 2018 2:07 pm
Contact:

Re: Refresh contextual menu action name

Post by NicoAMP »

Hello Gabriel,
Thanks a lot for this workaround. It works like a charm!
Regards,
Nicolas
Nicolas Delobel
AmeXio
nicolas.delobel at amexiogroup.com
Post Reply