I assume that you want to register undo / redo of extension commands of your editor. If this is not so ... this description below will not be useful .:-)
First you need to create a small class derived from ITextUndoPrimitive , which is a small βoperationβ included in the undo transaction part. This has two important methods: Undo() , which is called when the user cancels the transaction, and Do() , which is called if the user disconnected the transaction and then clicked the Retry button. For the rest of the methods, just follow the trivial implementation: CanUndo / CanRedo should always return true and make the parent read / write property simple. CanMerge should always return false, and you can leave Merge() unimplemented. Of course, you can save any additional state in ITextUndoPrimitive.
How much you do in Do / Undo is up to you. Therefore, if your extension, say, modifies a text buffer and also writes to another file in a user project, you can cancel the recording of the file. I understand that you are simply trying to track what operations the user has disabled (perhaps for statistical purposes?), And therefore you can just update the user bit to "disable this" in your log and do with it.
When you complete your action, call CreateTransaction to start a new transaction, and then in this transaction call AddUndo () pass a new instance of your undo primitive. Then the editor will call Do / Undo, as described as appropriate.
Last note: the editor will automatically get rid of cancellation transactions when the transaction history is too long, or in some cases when the history is destroyed, and it should be reset. Therefore, expect that at some point your cancellation primitives will disappear and be GC'ed. Most importantly: do not hold on to them in any other place that could cause them to leak.
source share