Page 1 of 1

set word wrap and font size api?

Posted: Mon Apr 01, 2019 9:36 pm
by sderrick
Using the SDK text mode editor.

Some of our users like to change the font size in the editor when starting, I would like to save off the last font change and restore that change when they next start the editor.

Some of our users like word wrap on by default, some like it off by default. Is there an API to turn it on or off?

thanks,

Scott

Re: set word wrap and font size api?

Posted: Tue Apr 02, 2019 9:23 am
by Radu
Hi Scott,

Something like this should work for newly opened XML documents:

Code: Select all

    /**
* The font for the text controls. A property with a string value of the form "name,style,size".
* For example: "MS Gothic,0,15" where "0" style means plain font, "1" means bold font and "2" means italic font.
*/
AuthorComponentFactory.getInstance().setObjectProperty("font.for.text", "MS Gothic,0,15");
//Line wrap
AuthorComponentFactory.getInstance().setObjectProperty("editor.line.wrap", Boolean.TRUE);
The settings should also be persisted automatically.
But we do not have a simplified preferences dialog for the component so you would have to implement a dialog to allow the end user to choose the font and to set the line wrap choice.

Regards,
Radu

Re: set word wrap and font size api?

Posted: Wed Apr 03, 2019 6:28 pm
by sderrick
Is there a corresponding get()? for the current font and line wrap setting?

I looked for

AuthorComponentFactory.getInstance().getObjectProperty("editor.line.wrap"); but don't see it?

thanks,

Scott

Re: set word wrap and font size api?

Posted: Thu Apr 04, 2019 12:00 pm
by Radu
Hi Scott,

The AuthorComponent was originally intended as being heavily customized but without exposing settings to the end user.
We do have this API which should work also in the AuthorComponent:

PluginWorkspaceProvider.getPluginWorkspace().getGlobalObjectProperty("font.for.text")

but this will not work:

PluginWorkspaceProvider.getPluginWorkspace().getGlobalObjectProperty("editor.line.wrap")

because for each key that the API wants to read we need to pre-approve it by adding it to a list of approved keys.
Maybe you could set and get the user-related settings separately using PluginWorkspaceProvider.getPluginWorkspace().getOptionsStorage(), have some defaults for them and always impose the local settings using "setObjectProperty" after initializing the AuthorComponentFactory.

Regards,
Radu

Re: set word wrap and font size api?

Posted: Sun Apr 07, 2019 2:53 am
by sderrick
Radu,

The word wrap is working great and I can persist the settings across editors and across sessions.

The font size not so good.

I tried

Object globalObjectProperty = PluginWorkspaceProvider.getPluginWorkspace().getGlobalObjectProperty("font.for.text");

which returns null until I do

AuthorComponentFactory.getInstance().setObjectProperty("font.for.text", "MS Gothic,0,15");

Then getGlobalObjectProperty returns the font that I set with setObjectProperty.

The problem with that is
1.) I need the default font for the text editor. How do I get or set that that.

2.) When I call AuthorComponentFactory.getInstance().setObjectProperty("font.for.text", "MS Gothic,0,20"); it sets the property but the text size in the editor doesn;t change as It does when I use the Font_size/Decrease_font action or the reduce action? Is there no way to call that increase size or decrease size action function?

thanks,
Scott

Re: set word wrap and font size api?

Posted: Mon Apr 08, 2019 12:06 pm
by Radu
Hi Scott,

Sorry, my bad. The key you need to set and read is this one: "editor.font". The "font.for.text" is for text fields and other text-based controls.
This will fix (1). For (2) the setting does not get automatically propagated to the opened editor. I will look into this on my side. You probably need to advice the end user to re-start the application.

Regards,
Radu

Re: set word wrap and font size api?

Posted: Tue Feb 18, 2020 4:32 pm
by Radu
Hi,

We released Oxygen 22 and its corresponding SDK. The (2) API usage should now work without restarting the component.

Regards,
Radu