Can anyone tell me how to get file name from editor?
I just made my own editor to open xml file and create a few section to display the data. Now I want to read the XML file and place it inside the section.
I think I now how to read xml data but I don't know how to access the file name so that it can be open.
Thanks
I realise this is old, but since I stumbled upon it while searching for a solution to the exact same problem, I want to add a note to the answer by VonC:
IFileEditorInput
is hidden in the org.eclipse.ui.ide plug-in, so in order for the solution to work your plug-in needs to state that as a dependency.
May be this approach could be useful in you casre
cast the editor input to
IFileEditorInput
and use theIFile
to callgetLocation()
orgetLocationURI()
.
As said here, basically
((IFileEditorInput)editorInput).getFile().getLocation()
is enough.
See also this code:
public static String getCurrentFileRealPath(){
IWorkbenchWindow win = PlatformUI.getWorkbench
().getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
if (page != null) {
IEditorPart editor = page.getActiveEditor();
if (editor != null) {
IEditorInput input = editor.getEditorInput();
if (input instanceof IFileEditorInput) {
return ((IFileEditorInput)input).getFile
().getLocation().toOSString();
}
}
}
return null;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With