Andy Thomas
Andy Thomas

Reputation: 86429

How to hide "Preferences" item in Mac application menu

I have an application built atop the Eclipse rich-client platform. It does not yet have any user preferences.

Currently on the Mac, the "Preferences" menu item in the application menu is enabled, but does nothing.

Is there an easy way to hide or disable it?

Upvotes: 2

Views: 559

Answers (2)

csa
csa

Reputation: 2015

App menu is populated during the creation of the org.eclipse.swt.widgets.Display.

You can remove the "Preferences" menu as follows:

public static void configureAppMenu() {
    final NSMenu appMenu = getAppMenu();
    final Collection<NSMenuItem> itemsToRemove = newArrayList();
    for (int i = 0; i < appMenu.numberOfItems(); i++) {
        final NSMenuItem item = appMenu.itemAtIndex(i);
        if (item.tag() == SWT.ID_PREFERENCES) {
            itemsToRemove.add(item);
        }
    }
    itemsToRemove.forEach(appMenu::removeItem);
}

private static NSMenu getAppMenu() {
    return NSApplication.sharedApplication().mainMenu().itemAtIndex(0).submenu();
}

Upvotes: 1

Andy Thomas
Andy Thomas

Reputation: 86429

In case anyone else runs into the same problem, I chose a simple solution to the root problem -- show the Preferences dialog.

Even in the absence of application-layer user preferences, there were still preferences panels contributed by the help plug-ins.

With the current implementation of org.eclipse.ui.internal.carbon.CarbonUIEnhancer, the application-menu "Preferences" item requires and executes a preferences menu item elsewhere in the menus (e.g., ActionFactory.PREFERENCES).

Upvotes: 1

Related Questions