1

I'm new at plugin development. I have my own editor for files *.example. I extend org.eclipse.ui.editors.text.TextEditor to edit it.

I want to catch the moment when this file is opened and post it to log (something like "file new.example is opened). But I really don't understand how to do it.

greg-449
  • 109,219
  • 232
  • 102
  • 145
Ivan Salosin
  • 343
  • 1
  • 2
  • 8

1 Answers1

0

One way is to override the init method of the editor and use the editor input parameter:

@Override
public void init(final IEditorSite site, final IEditorInput input) throws PartInitException {

    super.init(site, input);

    if (input instanceof IFileEditorInput) {
      IFile file = ((IFileEditorInput)input).getFile();

      // TODO log the IFile
    }
}

Note: The editor input is not always IFileEditorInput, see this answer for more details.

Community
  • 1
  • 1
greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Overriding `protected void doSetInput(IEditorInput input) throws CoreException` would handle the cases where the editor is reused. – nitind Nov 03 '16 at 09:02