views:

321

answers:

1

Hi,

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

+1  A: 

May be this approach could be useful in you casre

cast the editor input to IFileEditorInput and use the IFile to call getLocation() or getLocationURI().

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;
}
VonC
thanks for the code but I got an error on IFileEditorInput.it say's IFileEditorInput cannot be resolved to a type.There is suitable solution on quick fix either.
Iso