prettyPrint with oXygen settings

Post here questions and problems related to oXygen frameworks/document types.
msklvsk
Posts: 9
Joined: Wed May 04, 2016 2:53 pm

prettyPrint with oXygen settings

Post by msklvsk »

Documentation states that pluginWorkspaceAccess.getXMLUtilAccess().prettyPrint() will print with oXygen settings, however for me it doesn't. Particularly, it line-breaks elements which have no whitespace in between, while Format and Indent action behaves as expected. I tried null and "http://www.tei-c.org/Lite/DTD/teixlite.dtd" as systemId parameter. How can I simulate Format and Indent action? And more generally, what is the proper way to programmatically invoke oXygen's action?
Radu
Posts: 9049
Joined: Fri Jul 09, 2004 5:18 pm

Re: prettyPrint with oXygen settings

Post by Radu »

Hi,

There indeed seems to be a difference between the API and the "Format and Indent" action. The "Format and indent" action also looks at the schema (RNG or DTD) referenced by the XML while the API method ignores it. I will add an issue to see if we can fix this on our side.
But you seem to want to actually call the toolbar action on the current opened file contents. Do you use a workspace access plugin extension? For example if you want to format and indent the file on open you could use some code like:

Code: Select all

      @Override
public void applicationStarted(final StandalonePluginWorkspace pluginWorkspaceAccess) {
pluginWorkspaceAccess.addEditorChangeListener(new WSEditorChangeListener(){
public void editorOpened(URL editorLocation) {
WSEditor editor = pluginWorkspaceAccess.getEditorAccess(editorLocation, PluginWorkspace.MAIN_EDITING_AREA);
WSEditorPage edPage = editor.getCurrentPage();
if(edPage instanceof WSXMLTextEditorPage){
WSXMLTextEditorPage tp = (WSXMLTextEditorPage)edPage;
Object formatAndIndentAction = tp.getActionsProvider().getTextActions().get("Source/Pretty_print_tooltip");
tp.getActionsProvider().invokeAction(formatAndIndentAction);
}
}
}, PluginWorkspace.MAIN_EDITING_AREA);
}
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
msklvsk
Posts: 9
Joined: Wed May 04, 2016 2:53 pm

Re: prettyPrint with oXygen settings

Post by msklvsk »

Hi Radu!

Yes, I am using workspace access plugin extension.
Invoking actions in your snippet's way works, but now the question is where can I get actions' ID strings, like that "Source/Pretty_print_tooltip"?
Radu
Posts: 9049
Joined: Fri Jul 09, 2004 5:18 pm

Re: prettyPrint with oXygen settings

Post by Radu »

Hi,

We do not have particular documentation for each action ID but you can use System.err to print to console the entire map tp.getActionsProvider().getTextActions(). If you start Oxygen using the command line startup script you should see in the console messages from your plugins.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
msklvsk
Posts: 9
Joined: Wed May 04, 2016 2:53 pm

Re: prettyPrint with oXygen settings

Post by msklvsk »

Oh, I see, It's just a Map. Thanks, it works.
Post Reply