0

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.

Crazy Ivan
  • 21
  • 2

3 Answers3

1

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

rambo
  • 418
  • 4
  • 16
0

Your editor is most likely inheriting from IEditorPart, so you should be able to call getEditorInput(), which then may or may not turn out to be a FileEditorInput, 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 an IFile.createLink() and use a local filesystem path, or copy the file using IFile.appendContents().

Volker Stolz
  • 7,274
  • 1
  • 32
  • 50
  • editorPart returns a null value, and cannot advance from there. – Crazy Ivan Jun 15 '11 at 12:53
  • @Crazy-Ivan: Are you calling `page.getActiveEditor()`? That one isn't reliable, depending on where you are coming from. Which editor do you concretely want to extend? – Volker Stolz Jun 15 '11 at 16:41
  • I have a JavaScript file opened in the editor, and I need to programmatically get it's filename and filepath. I have very few acknoledges in eclipse. – Crazy Ivan Jun 16 '11 at 14:58
0

Have you tried the solution proposed in http://www.eclipse.org/forums/index.php/mv/msg/97927/300308/#msg_300308?

reprogrammer
  • 14,298
  • 16
  • 57
  • 93