Reputation: 31
I have been attempting to find the location of a selected project in Eclipse via code from my editor plugin and I have had some success. I have not been able to locate the project in one scenario. When a file using the editor was left open from the last session in Eclipse and Eclipse is reopened, I cannot find the location of the current project without opening and closing the file because this method: Eclipse Plugin: how to get the path to the currently selected project will not work. Any suggestions? Thanks in advance.
Upvotes: 3
Views: 113
Reputation: 111142
Eclipse doesn't really have a notion of a 'current project'. There is a current selection in each view but most views don't save the selection between sessions.
In an editor you probably want the project that the file you are current editing belongs to. In the editor you can use something like:
IEditorInput editorInput = getEditorInput();
IFile file = (IFile)editorInput.getAdapter(IFile.class);
IProject project = file.getProject();
Note: file
might be null if you are editing a file which is not in the workspace. You don't need the (IFile)
cast on the most recent versions of Eclipse.
Upvotes: 1