Home > Software engineering >  How to manually handle editor dirty state in Eclipse IDE
How to manually handle editor dirty state in Eclipse IDE

Time:09-13

I'm making an editor that manipulates the information of a file through tags.

I made some logic to detect editing these tags, but after a lot of research, I still haven't found a way to manually handle the dirty state of my editor.

With this I can get the reference of my editor:

IEditorReference[] ed = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();

for (IEditorReference iEditorReference : ed) {
   if (iEditorReference.getId().equals(*my editor's id*)) {
     ??? what to do here? ???
   }
}

CodePudding user response:

The dirty state of an editor is set by the

public boolean isDirty()

method implemented by the editor part (defined in the org.eclipse.ui.ISaveablePart interface)

Whenever the dirty state changes the editor part must call

firePropertyChange(IEditorPart.PROP_DIRTY);

If you have an editor reference as shown in your question you would have to call a method that you write in your editor to change the dirty state:

MyEditor myEditor = (MyEditor)iEditorReference.getEditor();

myEditor.setDirty();

where setDirty is a method you write. That method will have to set a flag that isDirty can use and call firePropertyChange

  • Related