Dynamic Menu Item to select Theme in Eclipse IDE

In Bug 514458, I added the “Theme” dynamic menu to the Eclipse IDE. This post explains how I did this.

Menu Eclipse 3.x style

First edit the plugin.xml, and add a menu contribution. With the locationURI menu:org.eclipse.ui.appearance?after=org.eclipse.ui.window.appearance.separator1, you’ll contribute a submenu to the Window > Appearance menu, just after the separator.

appearance-menu-structure

Add a Theme menu under the menuContribution, and then add a child dynamic element.

Next, create the java class implementing the dynamic menu, and add mock code to verify the menu works.

 

Verify the menu is displayed where you expect, and the submenu dynamic entries are working.

new-theme-dynamic-menu

Now remove the line which adds the “Theme 1” item, and rewrite the body of the widgetSelected.

The menu should have one menu item for each available theme, and each widgetSelected(){…} should activate the corresponding theme.

The theme selection code is inspired tothe ViewsPreferencePage one.

Finally, launch the Eclipse IDE to check the menu works as expected.

theming-menu

Leave a Reply

Your email address will not be published. Required fields are marked *