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

Tobias Fischer | pagina GmbH tobias.fischer at pagina.gmbh
Fri Mar 1 10:16:59 CST 2019


Hi Radu,

alright, thanks for the explanation!

Best,
Tobias

Am 01.03.19 um 08:38 schrieb Oxygen XML Editor Support (Radu Coravu):
> 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
>>
> _______________________________________________
> oXygen-sdk mailing list
> oXygen-sdk at oxygenxml.com
> https://www.oxygenxml.com/mailman/listinfo/oxygen-sdk



More information about the oXygen-sdk mailing list