Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 149214 - [Commands] Diagram Editor's dirty state does not reset on UNDO
Summary: [Commands] Diagram Editor's dirty state does not reset on UNDO
Status: CLOSED FIXED
Alias: None
Product: GMF-Runtime
Classification: Modeling
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal
Target Milestone: 2.2   Edit
Assignee: Linda Damus CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-29 15:08 EDT by Randy Hudson CLA
Modified: 2010-07-19 21:57 EDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Randy Hudson CLA 2006-06-29 15:08:18 EDT
If the user accidentally changes something and then undoes it, the editor should be marked clean.  If the user saves, then invokes UNDO, REDO, the editor should be clean. In both cases GMF leaves the editor marked dirty, which prevents closing the editor without being prompted to save.

This behavior is inconsistent with platform text framework and normal GEF editors such as the Logic example. Reproduced in the GMF version of the logic example.
Comment 1 Anthony Hunter CLA 2006-06-29 15:51:03 EDT
Marking as minor for 1.0.1 as there are workarounds.
Comment 2 Randy Hudson CLA 2006-06-29 16:19:40 EDT
Could you please share the workaround? As far as I know, the workaround is quite involved since GMF does not use the GEF commandstack.
Comment 3 Anthony Hunter CLA 2006-06-29 16:29:11 EDT
The end user has a workaround by cancelling the save dialog.
Comment 4 Alex Shatalin CLA 2006-11-10 11:53:44 EST
The possible reason is: GMF currently listening for the resource changes using FileDiagramModificationListener (attached to the diagram file in FileDiagramDocumentProvider.createFileInfo()), but not for the CommandStack like EMF-generated editor.
Comment 5 Anthony Hunter CLA 2007-06-19 11:43:52 EDT
Moving to the next release, GMF 2.1. 
Comment 6 Anthony Hunter CLA 2008-05-21 16:38:01 EDT
Hi Alex, here we should see we can fix in 2.1.
Comment 7 Marc Gobeil CLA 2008-06-26 14:50:28 EDT
The command stack has this functionality built in.  If it's notified when a save occurs, it will place a marker at the current location in the stack, and its isSaveNeeded() method can be used to query whether the diagram is dirty.

To notify the command stack of saving, ((BasicCommandStack)getEditingDomain().getCommandStack()).saveIsDone(); can be placed in FileDiagramModificationListener's notifyChanged method.  However, GMF's actions don't appear to be routed through the (emf) command stack.  Theoretically, there's somewhere along the call path of GlobalUndo/RedoAction.run() where we could put ((IEditingDomainProvider)getWorkbenchPart().getAdapter(IEditingDomainProvider.class)).getEditingDomain().getCommandStack().undo(); and with all that tracking in place, then the editor's dirty state need only be sync'd to isSaveNeeded().  In practice, haven't been able to do that yet, deferring continued work on this till later.
Comment 8 Bouchet Stéphane CLA 2008-07-31 11:07:24 EDT
Hi,

I get the same bug when doing these actions : 

- open a diagram
- move a node
- undo

The diagram is still dirty.

Is the workaround provided can fix that too ?? 
Comment 9 Linda Damus CLA 2008-07-31 11:15:39 EDT
The workaround was just to cancel the save dialog when you close the editor so that the resource is reverted to its original state. It will work in your case, too.
Comment 10 Bouchet Stéphane CLA 2008-07-31 12:02:50 EDT
Well, I was asking about comment #7 :) 
Comment 11 Linda Damus CLA 2008-10-31 10:38:26 EDT
Adding dependency on bug 240775, which will allow GMF to provide its own policy for when to add the ResourceUndoContexts for operations affecting its resources.  Our policy will exclude notifications on transient features, in order to match our the logic in GMFResource that overrides ResourceImpl.ModificationTrackingAdapter to exclude notifications on transient features.
Comment 12 Linda Damus CLA 2008-10-31 11:24:58 EDT
In reply to comment #10, the solution I am working on now will fix the scenario that is described in comment #8.

In GMF we use the isModified state of the resource to determine whether or not
a given GMF editor is dirty.

In order to remove the dirty marker from GMF editors when changes to the resource are undone back to the last save point, my approach will be to make use of the ResourceUndoContexts added to undoable operations by the WorkspaceCommandStackImpl.DomainListener.  

This approach assumes that if an operation has a ResourceUndoContext for a given resource, then the operation has in some way changed the state of that resource.  Once all operations with the context for a given resource have been undone back to the last known save point, if the resource is in a GMF editing domain I will set the isModified state back to false. 



 
Comment 13 Linda Damus CLA 2008-11-07 17:18:03 EST
Added a new GMFResourceModificationManager to manage the isModified state of resources in a given GMF editing domain.  Editing domains created through the GMFEditingDomainFactory are configured with a GMFResourceModificationManager.

10 new JUnit tests in org.eclipse.gmf.tests.runtime.emf.core
Comment 14 Linda Damus CLA 2008-11-13 09:58:47 EST
Fix available in HEAD: 2.2.0M3.
Comment 15 Eclipse Webmaster CLA 2010-07-19 21:57:38 EDT
[GMF Restructure] Bug 319140 : product GMF and component
Runtime was the original product and component for this bug