Save an Eclipse editor programmatically

﹥>﹥吖頭↗ 提交于 2019-11-26 22:08:08

问题


I am developing a plug-in.

On clicking a button, I'd like to call the save method of Eclipse or call the save button on Eclipse toolbar.

What is the way to do it?


回答1:


org.eclipse.ui.PlatformUI.getWorkbench().saveAll(..) 

should do the trick.

If you want to save the active editor, please try

IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = page.getActiveEditor();
page.saveEditor(editor, true /* confirm */);

Note that the elements in the navigation path may be null.




回答2:


I use this to save dirty editors for one or more projects:

//Save all changes
    Display.getDefault().syncExec(new Runnable() { // save all editors needs to be called by the ui thread!
        @Override
        public void run() {
            IDE.saveAllEditors(new IResource[]{prj}, true);
        }
    });

where prj is an IProject object.

hope this helps

bye




回答3:


I used -

IDEWorkbenchPlugin.getDefault().getWorkbench().saveAllEditors(true);    


来源:https://stackoverflow.com/questions/5879218/save-an-eclipse-editor-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!