Set Editor Type via JS Plugin

Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
wreid
Posts: 6
Joined: Wed May 15, 2024 6:16 pm

Set Editor Type via JS Plugin

Post by wreid »

Good day,
We're using Oxygen Web XML 25.1 with a host of custom frameworks and plugins, we have a single JS based plugin that handles all our primary UI needs.

We have a requirement to open Oxygen under specific editor types or "modes" based on certain custom options detected during the editor loading cycle.

Currently all our documents are opening under the Author mode as one would typically expect, however, is there a way to programmatically change the editor type from a JavaScript plugin? We can invoke Java actions if required.

I have scoured the various GitHub examples and documentation yet cannot seem to find a clear reference on this, thanks!
wreid
Posts: 6
Joined: Wed May 15, 2024 6:16 pm

Re: Set Editor Type via JS Plugin

Post by wreid »

For some additional context we're pulling the desired editor type/mode out of the URL passed to our editor,

Code: Select all

const loadAsXml = {
  event: sync.api.Workspace.EventType.BEFORE_EDITOR_LOADED,
  event_trigger: (e) => {
    const options = e.options;
    console.log(options.url);
    //let newEditor = new sync.api.Editor();
  },
};
The event_trigger method being our signature function that gets registered as a workspace event listener. It seems like I have access to the editor via e.editor as well, just not certain where to go past this.
Bogdan Dumitru
Site Admin
Posts: 172
Joined: Tue Mar 20, 2018 5:28 pm

Re: Set Editor Type via JS Plugin

Post by Bogdan Dumitru »

Hello,

One option is to register an sync.api.EditingSupportProvider with sync.api.EditingSupportManager.registerEditingSupportProvider that looks for a URL param in the the loading options (sync.api.Workspace.LoadingOptions) and return you custom EditingSupport implementation if it's specified.

Another option is to listen to sync.api.Workspace.EventType.EDITOR_LOADED and when editor gets loaded to invoke the action that shows the text page, somewhat like this: editor.getEditingSupport().getActionsManager().invokeAction("Author/ShowXML");
Bogdan Dumitru
http://www.oxygenxml.com
wreid
Posts: 6
Joined: Wed May 15, 2024 6:16 pm

Re: Set Editor Type via JS Plugin

Post by wreid »

Bogdan Dumitru wrote: Wed Jul 10, 2024 6:13 pm Hello,

One option is to register an sync.api.EditingSupportProvider with sync.api.EditingSupportManager.registerEditingSupportProvider that looks for a URL param in the the loading options (sync.api.Workspace.LoadingOptions) and return you custom EditingSupport implementation if it's specified.

Another option is to listen to sync.api.Workspace.EventType.EDITOR_LOADED and when editor gets loaded to invoke the action that shows the text page, somewhat like this: editor.getEditingSupport().getActionsManager().invokeAction("Author/ShowXML");
Hi Bogdan,

Thanks for your input, using the Author/ShowXML action worked perfectly. We may go down the route of providing our own editing support should we end up requiring more extendibility beyond this.

I'm not sure if the Oxygen team moderates or watches this forum heavily but this is a really good thing to demonstrate on the documentation site! Here's some sample code even:

on your main plugin.js

Code: Select all

workspace.listen(sync.api.Workspace.EventType.EDITOR_LOADED, (e) => {
  console.log("Editor Loaded");
  e.editor.getEditingSupport().getActionsManager().invokeAction("Author/ShowXML");
  //see the actions manager
  console.log(e.editor.getEditingSupport().getActionsManager())
});
cosminef
Site Admin
Posts: 233
Joined: Wed Aug 30, 2023 2:33 pm

Re: Set Editor Type via JS Plugin

Post by cosminef »

Hello,

We are glad to hear that we have been helpful to you.
Also, thank you for the suggestion and we will take it into consideration.

Best,
Cosmin
Cosmin Eftenie
www.oxygenxml.com
Post Reply