Supplying Undo Support to Designers
Designers, like editors, typically need to support undo operations by allowing users to reverse their recent changes when modifying a code element.
Most designers implemented under Visual Studio 2008 and .NET Framework can have undo support automatically provided by the environment.
Designer implementations needing to explicitly provide support for the undo feature in the .NET Framework:
Provide undo management by implementing the abstract base class UndoEngine
Supply persistence and CodeDOM support by implementing the IDesignerSerializationService and the IComponentChangeService classes.
For more information on writing designers using .NET Framework, see Extending Design-Time Support.
The Visual Studio SDK provides a default undo functionality infrastructure by:
Providing undo manage implementations through the OleUndoEngine and OleUndoEngine.UndoUnit classes.
Supplying persistence and CodeDOM support through the default CodeDomComponentSerializationService and IComponentChangeService implementations.
Obtaining Undo Support Automatically
Any designer created in Visual Studio and .NET Framework has automatic and full undo support if, the designer
Makes use of a System.Windows.Forms.Control based class for its user interface.
Employs standard CodeDOM-based code generation and parsing system for code generation and persistence.
For more information on working with Visual Studio 2008 CodeDOM support, see Dynamic Source Code Generation and Compilation
When to Use Explicit Designer Undo Support
Designers must supply their own undo management if they use a graphical user interface, referred to as a ViewAdapter, other than that supplied by System.Windows.Forms.Control.
An example of this might be creating a product with a web-based graphical design interface rather than a .NET Framework based graphical interface.
In such cases, one would need to register this ViewAdapter with Visual Studio using ProvideViewAdapterAttribute, and provide explicit undo management.
Designers need to provide CodeDOM and persistence support if they do not use the Visual Studio code generation model provided in the System.CodeDom name space.
Undo Support Features of the Designer
The Environment SDK provides default implementations of interfaces needed to provide undo support that can be used by designers not using System.Windows.Forms.Control based classes for their user interfaces or the standard CodeDOM and persistence model.
The OleUndoEngine class derives from the .NET Framework UndoEngine class using an implementation of the IOleUndoManager class to manage undo operations.
The Visual Studio SDK extensions to designer undo, allow:
Linked undo functionality across multiple designers.
Child units within a designer to interact with their parent's, by fully implementing IOleUndoUnit and IOleParentUndoUnit on OleUndoEngine.UndoUnit.
The Environment SDK provides CodeDOM and persistence support by supplying:
CodeDomComponentSerializationService as an implementations of the IDesignerSerializationService
A IComponentChangeService provided by the Visual Studio DesignHost.
Using the Environment SDK Features to Supply Undo Support
To obtain undo support, an object implementing a designer must:
Instantiate and initialize an instance of the OleUndoEngine class with a valid IServiceProvider implementation.
This IServiceProvider class must provide the following services:
-
Designers using Visual Studio CodeDOM serialization may choose to use CodeDomComponentSerializationService provided with the Visual Studio SDK as its implementation of the IDesignerSerializationService.
In this case, the IServiceProvider class provided to the OleUndoEngine constructor should return this object as an implementation of the IDesignerSerializationService class.
-
Designers using the default DesignSurface provided by the Visual Studio DesignHost are guaranteed to have a default implementation of the IComponentChangeService class.
Designers implementing a OleUndoEngine based undo mechanism automatically tracks changes if:
Property changes are made through the TypeDescriptor object.
IComponentChangeService events are manually generated when an undoable change is committed.
Modification on the designer was created within the context of a DesignerTransaction.
The designer chooses to explicitly create UndoUnits using either the standard UndoUnit provided by an implementation System.ComponentModel.Design.UndoEngine.UndoUnit or the VSIP SDK implementation Microsoft.VisualStudio.Shell.Design.OleUndoEngine.UndoUnit.
Microsoft.VisualStudio.Shell.Design.OleUndoEngine.UndoUnit derives from System.ComponentModel.Design.UndoEngine.UndoUnit and in addition provides an implementation of both IOleUndoUnit and IOleParentUndoUnit.