views:

79

answers:

1

Netbeans uses standard UndoManager API for implementation of undo functionality. But neither standard javax.swing.undo.UndoManager nor org.openide.awt.UndoRedo.Manager doesn't have any method to mark states as saved and check modified status. Nonetheless if you change the file and press undo, the file is marked as unmodified. How do they do that? I need the same functionality for my (non-text) editors if the Netbeans RCP application.

+1  A: 

I figured this out. The CloneableEditSupport adds UndoableEdit when someone saves the file. This edit signals when someone undos from the saved state or redos to the saved state. Also it wraps next edits (up to the first significant one) to intercept redos from the saved state and undos to the saved state.

This trick only works if all UndoableEdits you generate are significant.

Ha