当Eclipse创建新项目时,如何捕捉片刻? [英] How to catch a moment when Eclipse is creating a new project?
问题描述
我正在为Eclipse IDE开发CDT插件。我想在创建项目时写入到项目范围的首选项文件,或者只存储信息以稍后识别该项目并写入文件。我该如何抓住Eclipse创建新项目并存储有关该项目的一些信息?
I am developing a CDT plug-in for Eclipse IDE. I want to write to a project-scoped preference file when creating a project or just store an info to identify this project later and write to a file. How can I seize a moment when Eclipse is creating a new project and store some info about it?
推荐答案
您可以使用 IResourceChangeListener
侦听器,以侦听所有资源更改:
You can use an IResourceChangeListener
listener to listen for all resource changes:
ResourcesPlugin.getWorkspace().addResourceChangeListener(listener);
侦听器实现单个方法:
public void resourceChanged(IResourceChangeEvent event)
从事件中您可以获得资源增量:
From the event you get the resource delta:
IResourceDelta delta = event.getDelta();
增量 getKind()
方法将是 IResourceData.ADDED
来获取新资源。
The delta getKind()
method will be IResourceData.ADDED
for a new resource.
该增量有一个 getResource
方法将为您提供资源-您对 IProject
感兴趣。
The delta has a getResource
method which will get you the resource - you are interested in an IProject
.
注意:Deltas可以包含嵌套条目。您可能必须使用增量的 getAffectedChildren()
方法来找到项目,或使用 accept
方法来查找项目。访问三角洲中的所有节点。
Note: Deltas can contain nested entries. You may have to use the getAffectedChildren()
method of the delta to find the project, or use the accept
method to visit all the nodes in the delta.
这篇关于当Eclipse创建新项目时,如何捕捉片刻?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!