views:

18

answers:

1

Everytime the IWpfTextView's TextBuffer changes I am trying to get the history's redostack and undostack and simply checking the count. When doing this I am encountering a "Method not supported exception" when trying to access the two stacks.

Am I retrieving the history incorrectly or does VS not want me seeing/editing the contents of the stacks?

I can post the code if necessary...

Thanks, Nick

+1  A: 

It's probably because the editor's undo history implementation in VS is a thin wrapper on top of the general VS undo history. I'd guess that Count isn't implemented on the editor's text undo history because there isn't an implementation on the VS undo history (IOleUndoManager only supports enumeration, so implementing Count would be expensive).

In general, though, it doesn't want you editing the contents of the stacks. If the undo stack gets out of sync with the text buffer, it'll essentially break undo and make small, cute animals cry.

It may help if you describe what you are trying to do, and then I can give better answers for how to accomplish that.

Noah Richards
ok, I am basically trying to write an extension that can serialize the Undo/Redo stacks to an external file when a TextView is closed, and when opening the file, can restore the UndoHistory. Am I going to have to implement my own ITextUndoHistory and ITextUndoTransaction and create transactions to my custom stacks as the view's TextBuffer is changed?Thanks, Nick
Nick U
I'm not sure how possible that is; for the most part, the innards of undo transactions are opaque. If it were somehow possible to know the context of every undo unit, you could do it with just the `IOleUndoManager`: on close, enumerate and save all the undo units; on open, `Add` them all to the (new) undo manager. However, you'd still run into issues with multi-buffer undo transactions (like refactor->rename). I guess I'm saying that I don't think this is really feasible to be added on as an extension, sorry.
Noah Richards
*sigh* That's not the answer I wanted...but you *would* know the limitations of the VS Editor better than I would. Thanks for your help on this. Time to find another vs editor project to work on!p.s. could you explain the *multi-buffer undo transactions (like refactor->rename)* part? What is that? Where can I find more info on it? I am just trying to learn as much of the terminology and SDK as I possibly can. I find all of this stuff incredibly fascinating, but not as well documented as most other things I work on.
Nick U