set word wrap and font size api?

Post here questions and problems related to oXygen frameworks/document types.
sderrick
Posts: 236
Joined: Sat Jul 10, 2010 4:03 pm

set word wrap and font size api?

Post by sderrick » Mon Apr 01, 2019 9:36 pm

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

Radu
Posts: 6435
Joined: Fri Jul 09, 2004 5:18 pm

Re: set word wrap and font size api?

Post by Radu » Tue Apr 02, 2019 9:23 am

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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

sderrick
Posts: 236
Joined: Sat Jul 10, 2010 4:03 pm

Re: set word wrap and font size api?

Post by sderrick » Wed Apr 03, 2019 6:28 pm

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

Radu
Posts: 6435
Joined: Fri Jul 09, 2004 5:18 pm

Re: set word wrap and font size api?

Post by Radu » Thu Apr 04, 2019 12:00 pm

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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

sderrick
Posts: 236
Joined: Sat Jul 10, 2010 4:03 pm

Re: set word wrap and font size api?

Post by sderrick » Sun Apr 07, 2019 2:53 am

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

Radu
Posts: 6435
Joined: Fri Jul 09, 2004 5:18 pm

Re: set word wrap and font size api?

Post by Radu » Mon Apr 08, 2019 12:06 pm

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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Post Reply