Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Mark eclipse editor as not dirty if there aren't any changes
Mark eclipse editor as not dirty if there aren't any changes [message #1756059] Fri, 10 March 2017 12:51 Go to next message
kozhaev Vladimir is currently offline kozhaev VladimirFriend
Messages: 108
Registered: July 2009
Senior Member
I develop editor extended from org.eclipse.ui.editors.text.TextEditor. I use FileDocumentProvider for it

setDocumentProvider(new FileDocumentProvider());

Problem is that when I make some changes and undo them all, my editor is still marked as dirty. How to prevent it?

I.e. I want to set dirty flag as false when I undo all changes. Look like I need somehow to override isDirty method, but how to do it?

Regards, Vladimir
Re: Mark eclipse editor as not dirty if there aren't any changes [message #1756134 is a reply to message #1756059] Mon, 13 March 2017 03:25 Go to previous message
Vivien Jovet is currently offline Vivien JovetFriend
Messages: 11
Registered: February 2017
Junior Member
What I do usually in this case is to override the isDirty method like this:
public boolean isDirty() {
    return dirty;

Then you can add a IOperationHistoryListener like this:
OperationHistoryFactory.getOperationHistory().addOperationHistoryListener(e -> {
    if(e.getOperation().hasContext(undoContext)) {
        // if there is no more operation to undo
        if(!OperationHistoryFactory.getOperationHistory().canUndo(undoContext)) {
            dirty = false;

But depending of how you set the limit of undo history, having undone all operation don't necessarily mean that the editor is not dirty anymore.
Hope it helps.
Previous Topic:Register a ToolBar in an e4 view
Next Topic:Restricting Target Platform's API usage when developing Eclipse plugins
Goto Forum:

Current Time: Mon Jul 04 09:59:35 GMT 2022

Powered by FUDForum. Page generated in 0.01360 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top