Page 1 of 1

adding a menu spearator to the contextual menu via JS

Posted: Sun May 22, 2022 2:25 pm
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

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

Posted: Mon May 23, 2022 7:20 am
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

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

Posted: Mon May 23, 2022 7:50 am
by ttasovac
Very cool. Thanks a million for your help.

All best,
Toma