2017-09-06 91 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);