I’m trying to implement undo/redo feature in my custom application that displays code using ICSharpCode.TextEditor.
TextEditor fully supports undo and redo. But unfortunately, the control is poorly documented. It’s not clear how to detect change of the undo state, so the program can gray out and re-enable the undo and redo buttons on the toolbar.
Is there any suitable event I can subscribe to? Should I then use EnableUndo and EnableRedo properties?
Check out the
IDocumentbeing edited, not theTextEditor. Make sure that you are editing the document using theIDocumentmethods. You can group actions together usingIDocument.UndoStack.StartUndoGroupandIDocument.UndoStack.EndUndoGroup. To see if there are undos possible, you can check if theIDocument.UndoStackis empty.