Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7516329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:05:42+00:00 2026-05-30T01:05:42+00:00

I have written a Visual Studio extension and I have it keep a log

  • 0

I have written a Visual Studio extension and I have it keep a log of user actions related to my extension. I want to be able to include undo/redo information for changes that my tool makes in the log, which I expect to be able to do by having an event listener called when an undo/redo occurs and check if the undo/redo object is the one corresponding to an action that my tool generated.

Currently, I have code to get the ITextUndoHistory for the current IWpfTextView, which I get using an ITextUndoHistoryRegistry which I followed this answer to generate. Unfortunately, the ITextUndoHistory object I get does not implement enough of the functionality to be useful. Specifically, its UndoRedoHappened event gets called, but always has a transaction of null. Also, its UndoStack/RedoStack properties throw System.NotSupportedException. The only thing that does work is CreateTransaction does give me a transaction object and lets me set the name for the action displayed in Visual Studio’s undo/redo list, although I don’t need that to work.

Is there some other way to access undo information in Visual Studio? Or maybe some more creative hack with what I have access to?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:05:44+00:00Added an answer on May 30, 2026 at 1:05 am

    I’m assuming you’re wanting to log undo/redos of commands of your editor extension. If that’s not the case…this description below won’t be useful. 🙂

    What you want to do first is create a small class that derives from ITextUndoPrimitive which represents a small “operation” that’s included in a part of a undo transaction. This has two important methods: Undo() which is called when the user undoes the transaction, and Do() which is called if the user undid the transaction and then hit Redo. For the rest of the methods, just do the trivial implementation: CanUndo/CanRedo should always return true, and make Parent a simple read/write property. CanMerge should always return false, and you can leave Merge() unimplemented. You can of course hold any additional state you want in the ITextUndoPrimitive.

    As far as what you do in Do/Undo, that’s up to you. So if your extension is, say, modifying the text buffer and also writing to some other file in the user’s project, you could undo the file write. I get a sense you’re just trying to track which operations the user undid (perhaps for statistical purposes?), and so you might just update a “the user undid this” bit in your log and be done with it.

    When you are performing your action, call CreateTransaction to start a new transaction, and then on that transaction call AddUndo() passing in a new instance of your undo primitive. The editor will then call Do/Undo as described as appropriate.

    One last note: the editor will automatically get rid of undo transactions when either the transaction history is getting too long, or in some cases where the history is destroyed and it must be reset. So expect that at some point your undo primitives will go away and be GC’ed. Most importantly: don’t hold onto them in some other place that would cause them to leak.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have application written in Visual Studio 2008 which I deploy with ClickOnce to
JI have written a .NET C# Windows Form app in Visual Studio 2008 that
Visual Studio C++ 2008 / GCC 4.4.2 I have written a program to run
I have written a very simple control. C# Visual Studio 2008. Its output should
I have visual studio 2008. I have a written a small C program. I
I have a number of macros written for Visual Studio 2005, but they have
I have a problem with a Winforms application written in Visual Studio 2005 (C#).
I have a multi-threaded Windows C++ app written in Visual Studio 6. Within the
Let's say that you have a product that is written in Visual Studio and
I have a program written in VB.Net (Visual Studio 2008) that uses a DLL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.