If undo is managed at the document level then you may have to using the RunningDocumentTable to enumerate the tables, get their undo managers, and nuke from orbit:
class NavigateListener: IVsRunningDocTableEvents3
{
private HashSet<IVsTextView> views = new HashSet<IVsTextView>();
private IVsRunningDocumentTable table;
private uint cookie;
...
Outside, call this register call -- add an unregister call that unadvises the events.
public void Register()
{
table =(IVsRunningDocumentTable) Package.GetGlobalService(typeof(SVsRunningDocumentTable));
// Listen to show/hide events of docs to register activate/deactivate cursor listeners.
table.AdviseRunningDocTableEvents(this, out cookie);
}
The running table has lots of events, like save, etc, but you can listen to when a view is registered:
public int OnAfterDocumentWindowHide(uint docCookie, IVsWindowFrame pFrame)
{
IVsTextView view = VsShellUtilities.GetTextView(pFrame);
if (view != null)
{
views.Add(view);
}
}
You may have trouble with documents that had changes saved but then were closed... remove them for now...
public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame)
{
IVsTextView view = VsShellUtilities.GetTextView(pFrame);
if (view != null)
{
views.Remove(view);
}
return VSConstants.S_OK;
}
Then you can do a super undo nuke. I haven't testing this part -- you'll have to play with it.
private void NukeFromOrbit()
{
foreach( var view in views )
{
IVsTextLines buffer;
view.GetBuffer(out buffer);
IOleUndoManager manager;
buffer.GetUndoManager(out manager);
IEnumOleUndoUnits units;
manager.EnumUndoable(out units);
uint fetched=0;
var unitArray = new IOleUndoUnit[1];
while( units.Next(1, unitArray , out fetched ) == VSConstants.S_OK)
{
unitArray[0].Do(manager);
}
}
}