我需要一個eclipse插件,用於保存打開的編輯器。 我知道Extended VS Presentation很好,但還有其他更好的插件嗎?如何在eclipse中保存打開的編輯器?
1
A
回答
1
此代碼應保存所有打開的(骯髒)編輯在eclipse:
IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
NullProgressMonitor monitor = new NullProgressMonitor();
if (editorReferences != null){
for (IEditorReference iEditorReference : editorReferences) {
IEditorPart editor = iEditorReference.getEditor(false);
if (editor.isDirty())
editor.doSave(monitor);
}
}
在Eclipse的新版本,你可以做一個小捷徑:
IEditorPart[] dirtyEditors = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getDirtyEditors();
for (IEditorPart iEditorPart : dirtyEditors) {
iEditorPart.doSave(monitor);
}
希望幫助...
+0
非常感謝Protostome答案,但我不會RCP,但沒關係我會嘗試它。再次感謝你。 – 2012-07-21 01:34:52
0
你的也保存一次所有的編輯..
private void doCloseEditors(IWorkbenchPage pActivePage) {
ArrayList<IEditorReference> openParts = new ArrayList<IEditorReference>();
for (IEditorReference part : pActivePage.getEditorReferences()) {
if (part.isDirty()) {
openParts.add(part);
}
}
if (openParts.size() > 0) {
pActivePage.closeEditors(openParts.toArray(new IEditorReference[0]), true);
}
}
我不明白。你是否要求在eclipse中保存所有當前打開的編輯器的代碼? – Protostome 2012-07-19 11:32:49
是的,我想在eclipse中保存所有當前打開的編輯器,方便下次打開。你有這樣一個插件嗎?(謝謝你的回答!) – 2012-07-20 01:51:13
可能重複的[如何在eclipse插件開發中以編程方式調用save方法](http://stackoverflow.com/questions/5879218/how-can-i-call-save-method-in-eclipse-plugin-development-programmatically) – 2016-02-01 13:20:25