how to implement selection plugin in author mode

Post here questions and problems related to oXygen frameworks/document types.
np18
Posts: 5
Joined: Tue Mar 16, 2021 10:01 pm

how to implement selection plugin in author mode

Post by np18 » Wed Mar 17, 2021 9:59 am

Hi,
I have a problem with developing a plugin for author mode of oxygenxml editor and wonder if you might point me in the right direction.

I made a small plugin for textmode that takes the current selection by getSelection()), does some string manipulation (deleting some XML if present) and then sends the string to a database using rest api. If there is a match in the database, it sends this match back, the XML gets included again and the selection is replaced with the SelectionPluginResultImpl(newstring).

(Its about abbreviated word, so in most cases, only a one word string is selected, but sometimes including an <hi> tag around the first character. So f.i., '<hi>a</hi>bbr.' will be send to the database as 'abbr.', send back as 'abbreviation' and will be returned to oxygen as '<hi>a</hi>bbreviation')

Now, as I need to implement this for author mode I am a bit lost. Basically, I have two questions:

1) more general: what structure do I need for a selection plugin to work in author mode? Do I have to specify the mode in any way?
2) how can I get my selection in author mode similar to the get.selection function in text mode. I realsie this is more complicated due to the author modes way of presenting text, but there must be a way to do this?

Any help where to start with this would be greatly appreciated
Best
Michael

alex_jitianu
Posts: 820
Joined: Wed Nov 16, 2005 11:11 am

Re: how to implement selection plugin in author mode

Post by alex_jitianu » Wed Mar 17, 2021 1:49 pm

Hello,

The Selection Plugin Extension works only in the Text page. You can use an Workspace Access Extension instead, which works in both Text and Author page. A startup sample plugin can be found on our Github account. What this plugin needs to do:

1. Contribute an action in the contextual menu
2. Retreive selected text when the action is invoked
3. Replace the selection

Code: Select all

ro.sync.ecss.extensions.api.AuthorDocumentController controller = ...;
controller.beginCompoundEdit();
try {
  boolean done = controller.delete(authorPageAccess.getSelectionStart(), authorPageAccess.getSelectionEnd() - 1);
  if (done) {
    controller.insertXMLFragment(processedXML, caretOffset);
  }
} finally {
  end.endCompoundEdit();
}


Best regards,
Alex

np18
Posts: 5
Joined: Tue Mar 16, 2021 10:01 pm

Re: how to implement selection plugin in author mode

Post by np18 » Wed Mar 17, 2021 2:42 pm

Dear Alex,
thanks very much for your quick and helpful reply! I will try this during the next days and report when/if I am successful!
Best,
Michael

np18
Posts: 5
Joined: Tue Mar 16, 2021 10:01 pm

Re: how to implement selection plugin in author mode

Post by np18 » Thu Mar 18, 2021 12:06 pm

Dear Alex,
again, thank you very much for your help: I was able to transform my plugin for textmode into an workspace access plugin that now works in text as well as author mode! Everything works as intended - with one exception, so sorry for my follow up question:
I used to have a key binding for my selectionProcessor plugin specified in the plugin.xml. How can I call my new plugin from such a key binding? Currently, I can only access it through the context menu, but I need a key binding as I have to use the plugin quite frequently. Is there any way to do this?
Again many thanks and all the best,
Michael

np18
Posts: 5
Joined: Tue Mar 16, 2021 10:01 pm

Re: how to implement selection plugin in author mode

Post by np18 » Thu Mar 18, 2021 5:16 pm

Dear Alex,

I was able to make the key bindings work.
I only added the action into the popup menu, so the key bindings were only working when the context menu is opened. Now I also added a toolbar menu and they work!

Thanks again and all the best,
Michael

np18
Posts: 5
Joined: Tue Mar 16, 2021 10:01 pm

Re: how to implement selection plugin in author mode

Post by np18 » Thu Mar 18, 2021 5:47 pm

for some reason my previous post wasn't posted: I was able to get the key bindings working.

I had to add a toolbar menu for them to work. If you only have a popup menu entry, the key bindings only work when the context menu is opened.

Again thanks and all the best

alex_jitianu
Posts: 820
Joined: Wed Nov 16, 2005 11:11 am

Re: how to implement selection plugin in author mode

Post by alex_jitianu » Fri Mar 19, 2021 10:59 am

Hello Michael,
I'm sorry for the delay! You can use ro.sync.exml.workspace.api.standalone.actions.ActionsProvider to register an action. You reach it though ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace.getActionsProvider(). The shortcut will appear inside the Menu Shortcut Keys preferences page too.

Best regards,
Alex

Post Reply