次の方法で共有


UndoContext.Open(String, Boolean) Method

Definition

Starts a new undo operation.

void Open(std::wstring const & Name, bool Strict = false);
[System.Runtime.InteropServices.DispId(3)]
public void Open (string Name, bool Strict = false);
[<System.Runtime.InteropServices.DispId(3)>]
abstract member Open : string * bool -> unit
Public Sub Open (Name As String, Optional Strict As Boolean = false)

Parameters

Name
String

Required. Represents the name of the procedure for which to provide an undo context.

Strict
Boolean

Optional. Indicates whether the undo stack linkage is strict. Default value is False.

Attributes

Examples

Sub OpenExample()  
   ' Before running, select text in an open document.  
   Dim txtSel As TextSelection  
   Dim strTS As String, boolWasOpen As Boolean  
   txtSel = DTE.ActiveDocument.Selection  
   strTS = txtSel.Text  

   ' Check to see if UndoContext object is already open.  
   If DTE.UndoContext.IsOpen = True Then  
      boolWasOpen = True  
   Else  
      ' Open the UndoContext object to track changes.  
      DTE.UndoContext.Open("RemoveNewLines", False)  
   End If  

   ' Perform search for newline characters and remove them.  
   If strTS <> "" Then  
      txtSel.Delete()  
      strTS = Replace(strTS, vbNewLine, "", Compare:=vbTextCompare)  
      txtSel.Insert(strTS)  
   End If  

   ' If UndoContext was already open, don't close it.  
   If boolWasOpen = False Then  
      ' Close the UndoContext object to commit the changes.  
      DTE.UndoContext.Close()  
   End If  
End Sub  

Remarks

If the UndoContext object is already open when the Open method is performed, it produces an error.

If undo stack linkage is strict, all the linked undo sibling stacks must be undone together or not at all. A strict linked undo operation is usually necessary for simultaneous text changes across multiple files, such as a header file and a Visual C++ file. This is, in fact, the model used in Visual Studio. For more information about undo stack linking, see the OpenLinkedUndo method.

Applies to