為設計工具提供復原支援Supply undo support to designers

設計工具(例如編輯器)通常需要支援復原作業,以便使用者在修改程式碼專案時,可以反轉其最近的變更。Designers, like editors, typically need to support undo operations so that users can reverse their recent changes when modifying a code element.

在 Visual Studio 中執行的大部分設計工具都有環境自動提供的「復原」支援。Most designers implemented in Visual Studio have "undo" support automatically provided by the environment.

需要提供復原功能支援的設計工具:Designer implementations that need to provide support for the undo feature:

如需使用 .NET Framework 撰寫設計工具的詳細資訊,請參閱 擴充 Design-Time 支援For more information on writing designers using .NET Framework, see Extend Design-Time Support.

Visual Studio SDKVisual Studio SDK提供預設的復原基礎結構,方式如下:The Visual Studio SDKVisual Studio SDK provides a default undo infrastructure by:

自動取得復原支援Obtain Undo Support Automatically

在 Visual Studio 中建立的任何設計工具,在設計工具時都具有自動和完整復原支援:Any designer created in Visual Studio has automatic and full undo support if, the designer:

  • 使用型類別做 Control 為其使用者介面。Makes use of a Control based class for its user interface.

  • 採用標準的 CodeDOM 型程式碼產生和剖析系統,以產生程式碼和持續性。Employs standard CodeDOM-based code generation and parsing system for code generation and persistence.

    如需有關使用 Visual Studio CodeDOM 支援的詳細資訊,請參閱 動態原始程式碼產生和編譯For more information about working with Visual Studio CodeDOM support, see Dynamic Source Code Generation and Compilation.

使用明確設計工具復原支援的時機When to Use Explicit Designer Undo Support

如果設計人員使用圖形化使用者介面(稱為 view adapter)(而非提供者),則必須提供自己的復原管理 ControlDesigners must supply their own undo management if they use a graphical user interface, referred to as a view adapter, other than the one supplied by Control.

其中一個範例可能是以 web 為基礎的圖形設計介面來建立產品,而不是以 .NET Framework 為基礎的圖形化介面。An example of this might be creating a product with a web-based graphical design interface rather than a .NET Framework-based graphical interface.

在這種情況下,您需要使用 Visual Studio 註冊此 view adapter ProvideViewAdapterAttribute ,並提供明確的復原管理。In such cases, one would need to register this view adapter with Visual Studio using ProvideViewAdapterAttribute, and provide explicit undo management.

如果設計工具未使用命名空間中提供的 Visual Studio 程式碼產生模型,則需要提供 CodeDOM 和持續性支援 System.CodeDomDesigners 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

環境 SDK 提供所需的預設介面介面,以提供復原支援,而設計工具可使用 Control 其使用者介面或標準 CodeDOM 和持續性模型,而不使用型類別。The Environment SDK provides default implementations of interfaces needed to provide undo support that can be used by designers not using Control based classes for their user interfaces or the standard CodeDOM and persistence model.

OleUndoEngine類別衍生自 .NET Framework 類別,其 UndoEngine 使用類別的實 IOleUndoManager 來管理復原作業。The OleUndoEngine class derives from the .NET Framework UndoEngine class using an implementation of the IOleUndoManager class to manage undo operations.

Visual Studio 提供下列功能給設計工具復原:Visual Studio provides the following feature to designer undo:

環境 SDK 提供 CodeDOM 和持續性支援,方法是提供:The Environment SDK provides CodeDOM and persistence support by supplying:

使用環境 SDK 功能來提供復原支援Use the Environment SDK Features to Supply Undo Support

若要取得復原支援,執行設計工具的物件必須具現化,並 OleUndoEngine 使用有效的實初始化類別的實例 IServiceProviderTo obtain undo support, an object implementing a designer must instantiate and initialize an instance of the OleUndoEngine class with a valid IServiceProvider implementation. IServiceProvider 類別必須提供下列服務:This IServiceProvider class must provide the following services:

執行以復原機制為基礎的設計工具 OleUndoEngine 會在下列情況自動追蹤變更:Designers implementing a OleUndoEngine based undo mechanism automatically tracks changes if:

請參閱See also