Detect switch to EDIT_AS_XML_DESCRIPTION action

Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
Isabelle
Posts: 163
Joined: Fri Jan 20, 2017 1:11 pm

Detect switch to EDIT_AS_XML_DESCRIPTION action

Post by Isabelle »

Hello,

We use Author web in version 27.0.0, and we are looking for an equivalent of the method :

Code: Select all

WSEditorPageChangedListener.editorPageChanged
For our desktop version, with oxygen sdk, we use this to update our available actions if we are in Author or Text mode.

I tried to add it this way :

Code: Select all

public class S1000DWorkspaceAccessPluginExtension implements WorkspaceAccessPluginExtension {
    @Override
    public void applicationStarted(StandalonePluginWorkspace pluginWorkspaceAccess) {
        WebappPluginWorkspace workspace = (WebappPluginWorkspace) pluginWorkspaceAccess;
        workspace.addEditingSessionLifecycleListener(new WebappEditingSessionLifecycleListener() {

            @Override
            public void editingSessionStarted(String sessionId, AuthorDocumentModel documentModel) {              
                documentModel.getWSEditor().addEditorListener(new WSEditorSwitchTabListener(documentModel));
            }
        });
    }

    @Override
    public boolean applicationClosing() {
        return true;
    }
}
With WSEditorSwitchTabListener extends WSEditorListener and S1000DWorkspaceAccessPluginExtension added in plugin.xml file

Code: Select all

<extension type="WorkspaceAccess" class="com._4dconcept.adam.author.web.s1000d.plugin.extension.S1000DWorkspaceAccessPluginExtension"/>
The listener is well added to documentModel.getWSEditor() but it does not work.

I try to find the event listener to handle it like that in javascript

Code: Select all

goog.events.listen(workspace, sync.api.Workspace.EventType.EDITOR_LOADED, function (e) {
  let editor = e.editor;
  let editingSupport = editor.getEditingSupport();
  if (editingSupport.getType() === sync.api.Editor.EditorTypes.TEXT) {
    clearActions();
  }
But I did not find the good EventType.

Can you tell me how to do it properly ?
Thank you
Regards,
Isabelle
Bogdan Dumitru
Site Admin
Posts: 170
Joined: Tue Mar 20, 2018 5:28 pm

Re: Detect switch to EDIT_AS_XML_DESCRIPTION action

Post by Bogdan Dumitru »

Hello Isabelle,

The WSEditorSwitchTabListener API works just in Oxygen XML Editor, it doesn't work in Oxygen XML Web Author.
Web Author doesn't have a dedicated API to listen for switches to text page, but please tell us more about your use-case, why you need to listen to switches to text page and maybe we can give you some hooks.
Bogdan Dumitru
http://www.oxygenxml.com
Isabelle
Posts: 163
Joined: Fri Jan 20, 2017 1:11 pm

Re: Detect switch to EDIT_AS_XML_DESCRIPTION action

Post by Isabelle »

Hello,

It is really annoying for us !
As I explain in my initial post, we use this listener to update custom available actions if we are in Author or Text mode.
For exemple, in Author mode we will show in contextual menu some actions, and hide them in Text mode.

But more important, we have implemented our own grammatical checker et we need to clear all AuthorHighlighter every time user switch to Text mode and go back to Author mode to force user to refresh grammatical checker.

Regards,
Isabelle
Bogdan Dumitru
Site Admin
Posts: 170
Joined: Tue Mar 20, 2018 5:28 pm

Re: Detect switch to EDIT_AS_XML_DESCRIPTION action

Post by Bogdan Dumitru »

Hello Isabelle,

For the contextual menu I don't think there should be done something specific because in Text mode there is no contextual menu. But indeed, the AuthorHighlighter have to be cleared after switching to Author mode.

To intercept the switch to Author mode you can use the EDITABLE_WIDGET_ACTIVE_STATE_CHANGED JavaScript event:

Code: Select all

editor.getEditingSupport().listen(sync.internal_api.EditableWidgetActiveStateChangedEvent.EDITABLE_WIDGET_ACTIVE_STATE_CHANGED, e => console.log("is text page active: ", e.isActive));
To clear the AuthorHighlighter you can define an operation that clears it, annotate it with WebappRestSafe and WebappCompatible and invoke it from JavaScript using the ActionsManager [1].

[1] https://www.oxygenxml.com/maven/com/oxy ... on__anchor
Bogdan Dumitru
http://www.oxygenxml.com
Isabelle
Posts: 163
Joined: Fri Jan 20, 2017 1:11 pm

Re: Detect switch to EDIT_AS_XML_DESCRIPTION action

Post by Isabelle »

Hello Bogdan,

I have tried your solution and it works fine.
Thank you.

Regards,
Isabelle
Post Reply