简体   繁体   English

以编程方式保存 Eclipse 编辑器

[英]Save an Eclipse editor programmatically

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.单击按钮时,我想调用 Eclipse 的保存方法或调用 Eclipse 工具栏上的保存按钮。

What is the way to do it?这样做的方法是什么?

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.注意导航路径中的元素可能是null。

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.其中prj是 IProject object。

hope this helps希望这可以帮助

bye再见

I used -我用了 -

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM