Setting Linebreaks around elements via plugin

Post here questions and problems related to oXygen frameworks/document types.
cedporter
Posts: 18
Joined: Thu Mar 16, 2017 8:44 pm

Setting Linebreaks around elements via plugin

Post by cedporter »

In the UI, one can use Preferences > XML > Element Spacing > Line Break tab to add elements to a list to insert line breaks before and after. For many Preferences, we have used the approach described in the documentation of saving our preferences to an external file, finding the string name that describes it, and using the pluginWorkspaceAccess.setGlobalObjectProperty() method to set them in our plugin. For this particular setting, named editor.format.break.line.elements in the preferences XML, it expects a breakLineElement-array element. Is there a way to create one and set this preference via plugin?
Radu
Posts: 8992
Joined: Fri Jul 09, 2004 5:18 pm

Re: Setting Linebreaks around elements via plugin

Post by Radu »

Hi,

You can do something like this:

Code: Select all

PluginWorkspaceProvider.getPluginWorkspace().setGlobalObjectProperty("editor.format.break.line.elements", new ro.sync.exml.serialize.state.BreakLineElement[] {
        new BreakLineElement("*", BreakLineElement.NO_BREAK)
    });
but we also have this API:

Code: Select all

PluginWorkspaceProvider.getPluginWorkspace().importGlobalOptions(optionsFile)
allowing you to use an XML options file to impose global settings. Our main menu Options->"Export global options" action allows you to export such an XML options file.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
cedporter
Posts: 18
Joined: Thu Mar 16, 2017 8:44 pm

Re: Setting Linebreaks around elements via plugin

Post by cedporter »

Thanks, Radu! We knew of the ability to import a global options xml file, but it overrides the users settings. It appears by setting it via setGlobalObjectProperty() we can set the default, and the user can override it if they so choose, hence our preference to use the latter approach.
Radu
Posts: 8992
Joined: Fri Jul 09, 2004 5:18 pm

Re: Setting Linebreaks around elements via plugin

Post by Radu »

Hi,

About this remark:
It appears by setting it via setGlobalObjectProperty() we can set the default
Actually you are imposing the option, so it's exactly like calling "importGlobalOptions(optionsFile)".
If you do not want to impose the option all the time when Oxygen is started, maybe you can impose the option only the first time the add-on is initialized, use another custom setting set in the "ro.sync.exml.workspace.api.PluginWorkspace.getOptionsStorage()" to remember that the add-on has already imposed global options so it must no longer do that every time Oxygen is started.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply