2017-09-06 92 views
0

我需要更改命令ID的处理程序。例如ResetPerspectiveHandler的命令ID是org.eclipse.ui.window.ResetPerspective。所以当我们给org.eclipse.ui.window.ResetPerspective的命令时,它会调用ResetPerspectiveHandler。现在我想限制不要调用ResetPerspectiveHandler,而应该在给org.eclipse.ui.window.ResetPerspective时调用我自己的Handlers。我怎么做?更改命令ID处理程序

回答

0

您无法覆盖现有的命令处理程序。

您可以使用IExecutionListener来侦听使用ICommandService执行的命令。在执行该命令之前和之后通知侦听器。

ICommandService commandService = PlatformUI.getWorkbench().getAdapter(ICommandService.class); 

commandService.addExecutionListener(listener); 

您也可以使用监听特定命令:

Command command = commandService.getCommand("command id"); 

command.addExecutionListener(listener);