Programatically modify Eclipse workspace and CDT options from a plugin

折月煮酒 提交于 2019-12-12 18:23:43

问题


I want to modify an Eclipse workspace programatically from within a plugin (adding existing projects is my main request). Also I want to modify CDT options (environment, indexer options) from within that plugin.

Does anyone know how to best do this or can point me to good documentations on that topic?

EDIT: Actually I don't want to modify CDT project settings but some of the global CDT settings (actually I want to disable the indexer).


回答1:


It depends the kind of modification you are after.

For instance, adding a project is best illustrated by this thread.

String theProjName = "Test";
String theLocation = "/some/test/project";

try {
    IWorkspaceRoot theRoot = ResourcesPlugin.getWorkspace().getRoot();
    IProject theProject = theRoot.getProject(theProjName);
    IProjectDescription theDesc =       theProject.getWorkspace().newProjectDescription(theProjName);
        theDesc.setLocation(new Path(theLocation));
    theProject.create(theDesc, new NullProgressMonitor());
    if (theProject.exists()) {
        theProject.open(new NullProgressMonitor());
    }
} catch (CoreException err) {
    err.printStackTrace();
}

You could also want to open an editor:

IWorkbenchWindow dw = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
try {
   if (dw != null) {
   IWorkbenchPage page = dw.getActivePage();
   if (page != null) {
    IDE.openEditor(page, file, true);                   
   }
}
} catch (PartInitException e) {

}

More generally, eclipse.dev.org can be a good source for pointers on that topic.


Since 2004, CDT has options you can modify through the Preference Setting Store (ICSettingsStorage). May be that can help.


Regarding the Indexer, beware of the Discovery Preferences.
I am not sure there is an Indexer API, but you may look at the sources for further clues.



来源:https://stackoverflow.com/questions/938439/programatically-modify-eclipse-workspace-and-cdt-options-from-a-plugin

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