Page 1 of 1

Setting Linebreaks around elements via plugin

Posted: Thu Apr 01, 2021 3:49 pm
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?

Re: Setting Linebreaks around elements via plugin

Posted: Fri Apr 02, 2021 9:59 am
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

Re: Setting Linebreaks around elements via plugin

Posted: Fri Apr 02, 2021 4:00 pm
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.

Re: Setting Linebreaks around elements via plugin

Posted: Fri Apr 02, 2021 4:21 pm
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