Show SPACE marks programmatically

Post here questions and problems related to oXygen frameworks/document types.
peterls
Posts: 9

Show SPACE marks programmatically

Fri Mar 20, 2015 2:34 pm

Hi,

I know that users can set whether they want to see dots for spaces (and EOL/TAB/etc. marks) in the Options/Preferences/Editor dialog, but is there a way to manipulate these settings from a framework action? I'd want to create a simple button on the toolbar that would allow them to toggle the settings between two pre-set values (basically all markers on or off).

Peter
alex_jitianu
Posts: 627

Re: Show SPACE marks programmatically

Fri Mar 20, 2015 4:12 pm

Hello Peter,

We have a recorded issue to provide such a built-in action ourselves. Until then, it can be done using the Java based API. Would you like this action to be presented for the Author page or for both the Author and Text page? Depending on your answer yo can:

1. only for the Author page. You can create a custom AuthorOperation and create an author action over it. put this action on the toolbar. This author action should look like this:

Code: Select all


public class ShowSpaceOperation implements AuthorOperation {

   public void doOperation(AuthorAccess authorAccess, ArgumentsMap args)
         throws IllegalArgumentException, AuthorOperationException {
      
      String showSpaces = authorAccess.getOptionsStorage().getOption("spaces", "false");
      Boolean nextShowPaces = !Boolean.parseBoolean(showSpaces);
      authorAccess.getOptionsStorage().setOption("spaces", String.valueOf(nextShowPaces));
      
      PluginWorkspaceProvider.getPluginWorkspace().setGlobalObjectProperty("editor.show.tab.eol_eof", nextShowPaces);
      PluginWorkspaceProvider.getPluginWorkspace().setGlobalObjectProperty("editor.show.space", nextShowPaces);
   }
   
   @Override
   public String getDescription() {
      return "Toggles the space presentation";
   }

   @Override
   public ArgumentDescriptor[] getArguments() {
      return null;
   }

}



2. If you want the action to be available on all pages, you will have to add it from an Workspace Access plugin. From such a plugin you can add actions to the toolbar following this procedure:
- in plugin.xml you must define a toolbar
- from the Java code you intercept that toolbar and you add an action into it:

Code: Select all

  pluginWorkspaceAccess.addToolbarComponentsCustomizer(new ToolbarComponentsCustomizer() {
     /**
   * @see ro.sync.exml.workspace.api.standalone.ToolbarComponentsCustomizer#customizeToolbar(ro.sync.exml.workspace.api.standalone.ToolbarInfo)
   */
  @Override
  public void customizeToolbar(ToolbarInfo toolbarInfo) {
     //The toolbar ID is defined in the "plugin.xml"
     if("SampleWorkspaceAccessToolbarID".equals(toolbarInfo.getToolbarID())) {
        List<JComponent> comps = new ArrayList<JComponent>();
        Action showSpacesAction = new AbstractAction() {
           @Override
           public void actionPerformed(ActionEvent arg0) {
              String showSpaces = pluginWorkspaceAccess.getOptionsStorage().getOption("spaces", "false");
              Boolean nextShowPaces = !Boolean.parseBoolean(showSpaces);
              pluginWorkspaceAccess.getOptionsStorage().setOption("spaces", String.valueOf(nextShowPaces));

              pluginWorkspaceAccess.setGlobalObjectProperty("editor.show.tab.eol_eof", nextShowPaces);
              pluginWorkspaceAccess.setGlobalObjectProperty("editor.show.space", nextShowPaces);
           }
        };;
      ToolbarButton showSpacesButton = new ToolbarButton(showSpacesAction, true);
        showSpacesButton.setText("Show spaces");

        // Add in toolbar
           comps.add(showSpacesButton);
           toolbarInfo.setComponents(comps.toArray(new JComponent[0]));
        }
     }
  });


The only drawback of these toggle actions is the fact that they don't know the initial value for the options. So the user first click might look like it's not doing anything.

Best regards,
Alex
peterls
Posts: 9

Re: Show SPACE marks programmatically

Fri Mar 20, 2015 5:50 pm

Thanks for the quick reply, Alex. I need option 1 and we could probably live without being able to read the initial config values.

So all look great except for some reason nothing I put in the OptionsStorage object is actually stored. Whenever my action is triggered, I start with an empty OptionsStorage. And even if I do a getOption() straight after a setOption(), I still get a missing value, so I suspect there's something in OptionsStorage.setOption() that prevents writing into the options storage.
alex_jitianu
Posts: 627

Re: Show SPACE marks programmatically

Mon Mar 23, 2015 11:49 am

Hello Peter,

Are you adding the action from a Workspace Access plugin or from the author operation?
Best regards,
Alex
peterls
Posts: 9

Re: Show SPACE marks programmatically

Mon Mar 23, 2015 1:25 pm

alex_jitianu wrote:Hello Peter,

Are you adding the action from a Workspace Access plugin or from the author operation?
Best regards,
Alex


Author operation, as I only really need it in Author mode.
alex_jitianu
Posts: 627

Re: Show SPACE marks programmatically

Mon Mar 23, 2015 4:20 pm

Hello Peter,

This is strange. I've implemented such an operation myself and test it and it worked. I've tested on a DITA document. I've edited the DITA document type in Oxygen Preferences and created an author action over this operation. I've added it on the toolbar and it toggled the spaces display mode. I've test it on an Oxygen 16.1 installation. Can you send me a small framework sample on the support list so that I can take a look at it? Basically if you edit your document type and look at the external location you will find out the location of the framework. Zip the entire directory and send it with a sample XML that matches on that framework.

Best regards,
Alex

Return to “SDK-API, Frameworks - Document Types”

Who is online

Users browsing this forum: No registered users and 0 guests