开发者

How Netbeans Editors know that file is not modified after undo?

Netbeans uses standard UndoManager API for implementation of undo functionality. But n开发者_JS百科either 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜