Refresh contextual menu action name
Posted: Fri Mar 11, 2022 2:05 pm
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:
And I add action to the contextuel menu:
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.
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;
};
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"
});
}
});
}
The action's name in contextual menu is not refreshed when the selection change.
Is there a way to achieve this behavior?
Thanks.