以编程方式修改Eclipse工作区和CDT选项

时间:2021-07-10 21:30:02

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.

我想从插件中以编程方式修改Eclipse工作区(添加现有项目是我的主要请求)。此外,我想从该插件中修改CDT选项(环境,索引器选项)。

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).

编辑:其实我不想修改CDT项目设置,但有些全局CDT设置(实际上我想禁用索引器)。

1 个解决方案

#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.

更一般地说,eclipse.dev.org可以成为关于该主题的指针的良好来源。


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

自2004年以来,CDT可以通过首选项设置存储(ICSettingsStorage)进行修改。可能会有所帮助。


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.

关于Indexer,请注意发现首选项。我不确定是否有Indexer API,但您可以查看源代码以获取更多线索。

#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.

更一般地说,eclipse.dev.org可以成为关于该主题的指针的良好来源。


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

自2004年以来,CDT可以通过首选项设置存储(ICSettingsStorage)进行修改。可能会有所帮助。


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.

关于Indexer,请注意发现首选项。我不确定是否有Indexer API,但您可以查看源代码以获取更多线索。