如何在 Eclipse 中以编程方式获取信息
我正在开发一个 Eclipse 插件。 我需要以编程方式获取 Eclipse 编辑器中所选/活动文件的文件路径和文件名。
还需要以编程方式将现有文件(位于项目外部)添加到项目中,然后在编辑器上打开它。
我是 Eclipse 的初学者,所以完整的解决方案将不胜感激。
I'm developing an Eclipse Plug-in.
I need to programmatically get both filepath and filename of the selected/active file in the eclipse editor.
Also need to programmatically add an existing file (located outside the project) to the project and then open it on the editor.
I'm a totally beginner with Eclipse, so complete solution would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的问题很笼统,但这应该可以澄清一些问题:
Eclipse 插件开发教程
关于向项目中添加文件,您必须阅读文档并找到 eclipse 处理项目的位置。我认为如果您有该项目的参考,那应该很容易。
希望有帮助 =)
You question is quite general, but this should clear things up a bit:
Eclipse Plugin Development Tutorial
About adding a file to the project, you have to read the documentation and find where eclipse handles projects. I think that if you have a reference to the project it should be easy.
Hope it helps =)
您的编辑器很可能继承自
IEditorPart
,因此您应该能够调用getEditorInput()
,然后它可能会或可能不会成为FileEditorInput<例如,/代码>。从那里,您可以获取文件的底层详细信息。
对于第二个问题,您可以使用
IProject.create()
然后执行IFile.createLink()
并使用本地文件系统路径,或者使用 <代码>IFile.appendContents()。Your editor is most likely inheriting from
IEditorPart
, so you should be able to callgetEditorInput()
, which then may or may not turn out to be aFileEditorInput
, for example. From there, you can get at the underlying details of the file.For your second problem, you can use
IProject.create()
and then e.g. do anIFile.createLink()
and use a local filesystem path, or copy the file usingIFile.appendContents()
.您是否尝试过 http://www 中提出的解决方案.eclipse.org/forums/index.php/mv/msg/97927/300308/#msg_300308?
Have you tried the solution proposed in http://www.eclipse.org/forums/index.php/mv/msg/97927/300308/#msg_300308?