adding a menu spearator to the contextual menu via JS

Oxygen general issues.
ttasovac
Posts: 74
Joined: Fri Dec 19, 2003 6:02 pm

adding a menu spearator to the contextual menu via JS

Post by ttasovac »

Hi,

I have used https://github.com/oxygenxml/wsaccess-j ... sAccess.js from wsaccess-javascript-sample-plugins as a model for adding actions to the contextual menu in Author View.

Everything works as expected. I would like to implement two improvements:

1. add an icon to each menu item that I'm creating; and
2. add a menu separator above

Does anybody have a handy example to share?

Many thanks in advance.

All best,
Toma
Radu
Posts: 8010
Joined: Fri Jul 09, 2004 5:18 pm

Re: adding a menu spearator to the contextual menu via JS

Post by Radu »

Hi Toma,

The Javascript code just calls Java Swing API methods, for example the "popUp" parameter in the sample plugin is an instance of the Swing "JPopupMenu" class and has the method:
https://docs.oracle.com/javase/7/docs/a ... eparator()

The menu item which gets created:

Code: Select all

mi = new Packages.javax.swing.JMenuItem("Wrap In Bold");
https://docs.oracle.com/javase/7/docs/a ... uItem.html

has a "setIcon" method. Something like:

Code: Select all

mi.setIcon(new javax.swing.ImageIcon.ImageIcon(location));
That "location" would need to be an URL, something like:

Code: Select all

new Packages.java.net.URL(jsDirURL + "/icon.png");
The jsDirURL is a predefined variable which expands to an URL pointing to the plugin base folder, so the "icon.png" would need to be placed in the plugin base folder for the example above to work.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
ttasovac
Posts: 74
Joined: Fri Dec 19, 2003 6:02 pm

Re: adding a menu spearator to the contextual menu via JS

Post by ttasovac »

Very cool. Thanks a million for your help.

All best,
Toma
Post Reply