
package imagej.core.tools.global;

import imagej.ImageJ;
import imagej.ext.display.event.input.KyPressedEvent;
import imagej.ext.module.ModuleInfo;
import imagej.ext.module.ModuleService;
import imagej.ext.tool.AbstractTool;
import imagej.ext.tool.Tool;

@Tool(name = "Keyboard Shortcuts", global = true, priority = Integer.MIN_VALUE)
public class AcceleratorHandler extends AbstractTool {

	private final ModuleService moduleService;

	public AcceleratorHandler() {
		moduleService = ImageJ.get(ModuleService.class);
	}

	@Override
	public boolean onKeyDown(final KyPressedEvent evt) {
		// TODO: enquire the OptionService whether the Control modifier should be
		// forced
		final ModuleInfo moduleInfo =
			moduleService.getModuleForAccelerator(evt.getAcceleratorString(true));
		if (moduleInfo == null) return false;
		moduleService.run(moduleInfo);
		return true;
	}
}

@@ -182,16 +182,56 @@
 ervice;%0A
+import imagej.ext.plugin.PluginService;%0A
 import i
@@ -259,16 +259,16 @@
 ctTool;%0A
-
 import i
@@ -468,16 +468,60 @@
 Service;
+%0A%09private final PluginService pluginService;
 %0A%0A%09publi
@@ -596,16 +596,67 @@
 class);%0A
+%09%09pluginService = ImageJ.get(PluginService.class);%0A
 %09%7D%0A%0A%09@Ov
@@ -952,22 +952,93 @@
 alse;%0A%09%09
-module
+// need to run via pluginService, otherwise no preprocessors are run%0A%09%09plugin
 Service.

use PluginService to run the modules