Search code examples
eclipse-plugineditor

In Eclipse Plugin, how can I make standard editor dirty?


I am trying to programatically make an Eclipse editor dirty.

I know that firePropertyChange(IEditorPart.PROP_DIRTY) can do that, on my own editors.

But in this case I am using a standard editor. Can I make any editors dirty (how?) - or does the editor need to support this?

I have a org.eclipse.ui.IPartListener2. From here I want to make the Editor dirty, when I get the partOpened(IWorkbenchPartReference arg0) event.

I have tried to look through simalar questuions in here. But I am stuck.

Any hints?


Solution

  • Found a trick.

    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    try {
        EditorPart ep = (EditorPart) IDE.openEditor( page, iFile );
        IEditorInput input = ep.getEditorInput();
        IDocument doc = ((ITextEditor) ep).getDocumentProvider().getDocument(input);
        doc.set(doc.get());
    } catch ( Exception e ) {
        //Put your exception handler here if you wish to
        e.printStackTrace();
    }
    

    This will leave the editor dirty.