覆盖 Eclipse 文件 >保存操作
我正在尝试覆盖 Eclipse File >保存菜单操作以添加一些功能。 我尝试了以下操作
a) 创建一个新操作并将其添加到全局操作处理程序
actionBars.setGlobalActionHandler(ActionFactory.SAVE.getId(), mySaveAction); actionRegistry.registerAction(action);
b) 创建一个新的处理程序并覆盖保存命令
<extension point="org.eclipse.ui.handlers">
<handler commandId="org.eclipse.ui.file.save"
class="com.diagrams.ui.SaveFileHandler">
<enabledWhen>
<with variable="activePartId">
<equals
value="com.diagrams.editors.MultiPageEditor" />
</with>
</enabledWhen>
<activeWhen>
<with variable="activePartId">
<equals
value="com.diagrams.editors.MultiPageEditor" />
</with>
</activeWhen>
</handler>
</extension>
通过这两种方法,我已经能够覆盖键盘 Ctrl+S 功能,但“文件 > 保存”菜单的工作方式似乎有所不同。
非常感谢任何帮助,谢谢
I am trying to override the Eclipse File > Save menu action to add some functionality.
I have tried the following things
a) Create a new action and add it to the global action handler
actionBars.setGlobalActionHandler(ActionFactory.SAVE.getId(), mySaveAction);
actionRegistry.registerAction(action);
b) Create a new handler and override the save command
<extension point="org.eclipse.ui.handlers">
<handler commandId="org.eclipse.ui.file.save"
class="com.diagrams.ui.SaveFileHandler">
<enabledWhen>
<with variable="activePartId">
<equals
value="com.diagrams.editors.MultiPageEditor" />
</with>
</enabledWhen>
<activeWhen>
<with variable="activePartId">
<equals
value="com.diagrams.editors.MultiPageEditor" />
</with>
</activeWhen>
</handler>
</extension>
With both these approaches I have been able to override the Keyboard Ctrl+S functionality but the "File > Save" menu seem to work differently.
Would really appreciate any help, Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 RCP 应用程序中,您可以在 ActionBarAdvisor 中贡献“保存”操作。这还会注册该操作,以便可以通过保存命令使用该操作。
但作为 Eclipse IDE 中的插件,IDE 提供了 ActionBarAdvisor 并连接了“文件”菜单中的“保存”操作。因为从技术上讲这不是一个命令(操作是 SWT.Selection 侦听器之上的一步),所以您无法覆盖 File>Save 操作。
但是,每个部分都提供自己的保存实现,因此您可以在 MultiPageEditor 中执行任何操作。
另一种选择是使用 org.eclipse.ui.commands.ICommandService.addExecutionListener(IExecutionListener) 并添加 IExecutionListener(或 IEL2)。可以监听save命令,ID在
org.eclipse.ui.IWorkbenchCommandConstants
中声明。In an RCP application, you can contribute the Save action in your ActionBarAdvisor. This also registers the action so it is available from the save command.
But as a plugin in the Eclipse IDE, the IDE provides the ActionBarAdvisor and hooks up the Save action in the File menu. Because that's not technically a command (Actions are a step above an SWT.Selection listener) that's why you can't override the File>Save action.
However, each part provides its own save implementation, so you can do whatever you want in your MultiPageEditor.
The other option is to use
org.eclipse.ui.commands.ICommandService.addExecutionListener(IExecutionListener)
and add an IExecutionListener (or IEL2). That can listen for the save command, the ID is declared inorg.eclipse.ui.IWorkbenchCommandConstants
.这可能与选择主菜单与击键或使用右键菜单时的 activePartId 不同有关。您是否看过其他扩展点?
It might have something to do with the activePartId being different when the main menu is selected versus a keystroke or using the right-click menu. Have you looked at other extension points?