I think there are default SAVE and CANCEL buttons associated with editors in Eclipse RCP. How do we make these buttons appear on an editor.
我认为Eclipse RCP中有与编辑器关联的默认SAVE和CANCEL按钮。我们如何使这些按钮出现在编辑器上。
I take it that these buttons are invisible by default and may be there is some superclass method that needs to be overridden to make the SAVE CANCEL buttons appear on editor. I remember of having heard of such a thing. (I may be wrong though)
我认为这些按钮在默认情况下是不可见的,可能有一些超类方法需要被覆盖以使SAVE CANCEL按钮出现在编辑器上。我记得听说过这样的事情。 (虽然我可能错了)
In any case, how do we achieve this? (PS: I am not looking for a custom SWT button and name it 'SAVE'. I am looking for a default SAVE button that is associated with the editor(if there is such a thing)).
无论如何,我们如何实现这一目标? (PS:我不是在寻找自定义SWT按钮并将其命名为'SAVE'。我正在寻找与编辑器相关联的默认SAVE按钮(如果有这样的事情))。
1 个解决方案
#1
The buttons are not directly related to your editors.
You must, as described there):
这些按钮与您的编辑器没有直接关系。你必须,如那里所述):
-
Add menu contribution with the commandId set to the standard command id which can be found in
IWorkbenchActionDefinitionIds
e.g.org.eclipse.ui.file.save
使用commandId设置为标准命令id添加菜单贡献,该命令id可以在IWorkbenchActionDefinitionIds中找到,例如org.eclipse.ui.file.save
-
Create a command in
ApplicationActionBarAdvisor.makeActions
and register it.在ApplicationActionBarAdvisor.makeActions中创建一个命令并注册它。
:
protected void makeActions(final IWorkbenchWindow window) {
// Creates the actions and registers them.
// Registering is needed to ensure that key bindings work.
// The corresponding commands keybindings are defined in the plugin.xml
// file.
// Registering also provides automatic disposal of the actions when
// the window is closed.
saveAction = ActionFactory.SAVE.create(window);
register(saveAction);
}
- Add dirty flag in
Editor
part and implementisDirty()
,setDirty()
andclean()
methods.
在编辑器部分添加脏标志并实现isDirty(),setDirty()和clean()方法。
Update February 2013, from user s-d:
从用户s-d更新2013年2月:
Note: Adding the saveAction
in the ActionBarContributor
is no longer necessary in RCPs based on Indigo R2 (3.7.2).
It is enough to add the menuContribution
, add getCommandStack().markSaveLocation()
to the editor's doSave()
method, and override commandStackChanged()
as follows
注意:在基于Indigo R2(3.7.2)的RCP中,不再需要在ActionBarContributor中添加saveAction。只需添加menuContribution,将getCommandStack()。markSaveLocation()添加到编辑器的doSave()方法,并覆盖commandStackChanged(),如下所示
public void commandStackChanged(EventObject event) {
firePropertyChange(PROP_DIRTY);
super.commandStackChanged(event);
}
#1
The buttons are not directly related to your editors.
You must, as described there):
这些按钮与您的编辑器没有直接关系。你必须,如那里所述):
-
Add menu contribution with the commandId set to the standard command id which can be found in
IWorkbenchActionDefinitionIds
e.g.org.eclipse.ui.file.save
使用commandId设置为标准命令id添加菜单贡献,该命令id可以在IWorkbenchActionDefinitionIds中找到,例如org.eclipse.ui.file.save
-
Create a command in
ApplicationActionBarAdvisor.makeActions
and register it.在ApplicationActionBarAdvisor.makeActions中创建一个命令并注册它。
:
protected void makeActions(final IWorkbenchWindow window) {
// Creates the actions and registers them.
// Registering is needed to ensure that key bindings work.
// The corresponding commands keybindings are defined in the plugin.xml
// file.
// Registering also provides automatic disposal of the actions when
// the window is closed.
saveAction = ActionFactory.SAVE.create(window);
register(saveAction);
}
- Add dirty flag in
Editor
part and implementisDirty()
,setDirty()
andclean()
methods.
在编辑器部分添加脏标志并实现isDirty(),setDirty()和clean()方法。
Update February 2013, from user s-d:
从用户s-d更新2013年2月:
Note: Adding the saveAction
in the ActionBarContributor
is no longer necessary in RCPs based on Indigo R2 (3.7.2).
It is enough to add the menuContribution
, add getCommandStack().markSaveLocation()
to the editor's doSave()
method, and override commandStackChanged()
as follows
注意:在基于Indigo R2(3.7.2)的RCP中,不再需要在ActionBarContributor中添加saveAction。只需添加menuContribution,将getCommandStack()。markSaveLocation()添加到编辑器的doSave()方法,并覆盖commandStackChanged(),如下所示
public void commandStackChanged(EventObject event) {
firePropertyChange(PROP_DIRTY);
super.commandStackChanged(event);
}