Eclipse 3.5: How to get the file name from the editor?

Can someone tell me how to get the file name from the editor?

I just made my own editor to open the xml file and create several sections to display the data. Now I want to read the XML file and put it in a section.

It seems to me that now I am reading xml-data, but I do not know how to access the file name so that it can be open.

thanks

+4
source share
2 answers

Maybe this approach may be useful in your casre

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

As said here , basically

((IFileEditorInput)editorInput).getFile().getLocation() 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; } 
+7
source

I understand this is old, but since I came across it looking for a solution to the same problem, I want to add a note to VonC's answer:

 IFileEditorInput 

is hidden in the org.eclipse.ui.ide plugin, so for the solution to work, your plugin must specify that as a dependency.

+7
source

Source: https://habr.com/ru/post/1285641/


All Articles