Skip to content

Commit aa487de

Browse files
committed
MacOSXPlatform: remove all "app-command" commands
Any command tagged with that attribute should be removed from the menus. This is a more extensible approach than relying on the AppEventService to inform of us every single such command. See also: scijava/scijava-common@ca91f4e imagej/imagej-plugins-commands@403d3e2
1 parent 24438aa commit aa487de

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/main/java/org/scijava/plugins/platforms/macosx/MacOSXPlatform.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import javax.swing.JFrame;
3939
import javax.swing.JMenuBar;
4040

41-
import org.scijava.command.Command;
4241
import org.scijava.command.CommandInfo;
4342
import org.scijava.command.CommandService;
4443
import org.scijava.display.event.window.WinActivatedEvent;
@@ -48,7 +47,6 @@
4847
import org.scijava.module.ModuleInfo;
4948
import org.scijava.module.event.ModulesUpdatedEvent;
5049
import org.scijava.platform.AbstractPlatform;
51-
import org.scijava.platform.AppEventService;
5250
import org.scijava.platform.Platform;
5351
import org.scijava.platform.PlatformService;
5452
import org.scijava.plugin.Plugin;
@@ -150,20 +148,16 @@ private void removeAppCommandsFromMenu() {
150148
final PlatformService platformService = getPlatformService();
151149
final EventService eventService = platformService.getEventService();
152150
final CommandService commandService = platformService.getCommandService();
153-
final AppEventService appEventService =
154-
platformService.getAppEventService();
155151

156-
// get the list of commands being handled at the application level
157-
final List<Class<? extends Command>> commands =
158-
appEventService.getCommands();
159-
160-
// remove said commands from the main menu bar
161-
// (the Mac application menu will trigger them instead)
152+
// NB: Search for commands being handled at the application level.
153+
// We remove such commands from the main menu bar;
154+
// the Mac application menu will trigger them instead.
162155
final ArrayList<ModuleInfo> infos = new ArrayList<ModuleInfo>();
163-
for (final Class<? extends Command> command : commands) {
164-
final CommandInfo info = commandService.getCommand(command);
165-
info.setMenuPath(null);
166-
infos.add(info);
156+
for (final CommandInfo info : commandService.getCommands()) {
157+
if (info.is("app-command")) {
158+
info.setMenuPath(null);
159+
infos.add(info);
160+
}
167161
}
168162
eventService.publish(new ModulesUpdatedEvent(infos));
169163
}

0 commit comments

Comments
 (0)