[oXygen-sdk] Best way to create a new editor, insert XML and pretty print

Oxygen XML Editor Support (Radu Coravu) support at oxygenxml.com
Fri Mar 1 01:38:19 CST 2019


Hi Tobias,

Indeed our API method "XMLUtilAccess.prettyPrint(Reader, String)" does 
not take the schema information into account. I'll add an internal issue 
to take that into account as well.
In the meantime what you did remains the only alternative.
That "Source/Pretty_print_tooltip" value is a key, it does not depend on 
the actual translation for the action name, so such action keys are 
quite stable between releases. You could still check if the 
"formatAndIndentAction" is null before invoking it to avoid breaking 
your plugin if we change the key name in a future version.

Regards,
Radu

Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

On 3/1/2019 1:24 AM, Tobias Fischer | pagina GmbH wrote:
> Hey,
>
> I'm currently working on a WorkspaceAccess plugin and looking for the
> best way to create a new XML editor from scratch, insert arbitrary XML
> and then format and indent it following the rules of the loaded document
> type definitions.
>
> This is what I have – and it works:
>
>     URL newEditorUrl = pluginWorkspaceAccess.createNewEditor("xml",
> "text/xml", myXmlContentAsUnformattedString);
>     WSEditor newEditor =
> pluginWorkspaceAccess.getEditorAccess(newEditorUrl,
> PluginWorkspace.MAIN_EDITING_AREA);
>     WSEditorPage newEditorPage = newEditor.getCurrentPage();
>     if(newEditorPage instanceof WSXMLTextEditorPage) {
>         WSXMLTextEditorPage newXmlEditorPage =
> (WSXMLTextEditorPage)newEditorPage;
>         // https://www.oxygenxml.com/forum/topic13197.html
>         Object formatAndIndentAction =
> newXmlEditorPage.getActionsProvider().getTextActions().get("Source/Pretty_print_tooltip");
>
> newXmlEditorPage.getActionsProvider().invokeAction(formatAndIndentAction);
>     }
>
> However, the format and indet snippet is from a forum answer from 2016
> and seems to be a workaround if I read Radu's answer correctly:
> https://www.oxygenxml.com/forum/topic13197.html
>
> Calling an Action based on it's tooltip name seems to be quite hacky –
> is this still the recommended solution?
>
> I'm also wondering whether creating and opening a new editor the way I
> did is the right/best way to do it.
>
> Any suggestions?
>
> Best regards,
> Tobias
>



More information about the oXygen-sdk mailing list