Reload Editor Contents from Workspace Plugin

Post here questions and problems related to oXygen frameworks/document types.
ankitr
Posts: 12
Joined: Thu Dec 14, 2017 11:52 am

Reload Editor Contents from Workspace Plugin

Post by ankitr »

Hi,

I am creating a CMS plugin. I have implemented my plugin as a WorkspaceAccess plugin with a custom protocol handler implementation.
Now, I need to give the user an option of reloading the contents of their editor (discarding any local changes) from the original source (the custom protocol URL). I found the following 2 methods in the SDK documentation:

1) WSEditor.reloadContent(Reader) -- Reloads from provided reader.
2) ro.sync.ecss.extensions.commons.operations.ReloadContentOperation.doOperation(AuthorAccess, ArgumentsMap) -- Reloads from the original source.

I am currently using the first (1) method, but it doesn't quite fit my requirement as it marks the file dirty. While all I want is to just tell the editor that the file has been modified from outside, and just reload from the original source and mark it not dirty instead.

The second method seems perfect for my use case, just that I could not find a way to obtain an instance of AuthorAccess in a WorkspaceAccess plugin.

I want to know if there is a better way of achieving what I'm trying to do? Or how to obtain the AuthorAccess instance so that I can call ReloadContentOperation.

Thanks,
Ankit
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

Re: Reload Editor Contents from Workspace Plugin

Post by mihaela »

Hi,

To obtain the AuthorAccess in a WorkspaceAccess plugin you have to add an editor changed listener that allows you to get access to the editor page:

Code: Select all


    @Override
public void applicationStarted(final StandalonePluginWorkspace pluginWorkspaceAccess) {
pluginWorkspaceAccess.addEditorChangeListener(new WSEditorChangeListener(){
@Override
public void editorOpened(URL editorLocation) {
WSEditor editorAccess = pluginWorkspaceAccess.getEditorAccess(editorLocation, PluginWorkspace.MAIN_EDITING_AREA);
WSEditorPage edPage = editorAccess.getCurrentPage();
if(edPage instanceof WSAuthorEditorPage){
// Get the author access
AuthorAccess authorAccess = ((WSAuthorEditorPage)edPage).getAuthorAccess();
// Your code here...
}
}
}, PluginWorkspace.MAIN_EDITING_AREA);
}
Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
ankitr
Posts: 12
Joined: Thu Dec 14, 2017 11:52 am

Re: Reload Editor Contents from Workspace Plugin

Post by ankitr »

Hi Mihaela,

Thanks for your reply.

I am using the ReloadContentOperation class for this purpose. The doOperation() method takes 2 parameters. I checked the documentation (https://www.oxygenxml.com/InstData/Edit ... ation.html) but couldn't figure out what I'm supposed to pass in the second parameter: ArgumentsMap. I tried passing null to this and it seems to work. Although, I am not very sure of any unintended side effects. Could you help me with this?

My usage of this API is as below. Could you please confirm if this is correct:

Code: Select all

URL url = /* get a url instance */
WSEditor editor = Globals.workspaceAccess.getEditorAccess(url, PluginWorkspace.MAIN_EDITING_AREA);

if (editor != null) {
WSEditorPage edPage = editor.getCurrentPage();
if (edPage instanceof WSAuthorEditorPage) {
AuthorAccess authAccess = ((WSAuthorEditorPage) edPage).getAuthorAccess();
ReloadContentOperation operation = new ReloadContentOperation();

operation.doOperation(authAccess, null);
}
}
Regards,
Ankit
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

Re: Reload Editor Contents from Workspace Plugin

Post by mihaela »

Hi,

The ReloadContentOperation accepts a single argument named "markAsNotModified" that can be used to prevent the editor from showing as modified after reload. The default value is "false", so you must explicitly set it to "true" if you want the file not being marked as dirty.

In general, to find what arguments are available for a specific operation you can:
  • Check the "Author Mode Default Operations" documentaton page [1] (the ReloadContentOperation is not yet included, but we will add it in a near future)
  • Invoke the getArguments() method on the operation and list the arguments names
  • Create an action in the Oxygen XML Editor that uses this operation [2] and check the arguments listed in the "Action" dialog [3]
[1] https://www.oxygenxml.com/doc/ug-editor ... tions.html
[2] https://www.oxygenxml.com/doc/ug-editor ... b-tab.html
[3] https://www.oxygenxml.com/doc/ug-editor ... ion-dialog

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
Post Reply