Export (0) Print
Expand All

UndoContext.Open Method

Starts a new undo operation.

Namespace: EnvDTE
Assembly: EnvDTE (in envdte.dll)

void Open (
	[InAttribute] string Name,
	[OptionalAttribute] [InAttribute] bool Strict
)
void Open (
	/** @attribute InAttribute() */ String Name, 
	/** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ boolean Strict
)
function Open (
	Name : String, 
	Strict : boolean
)

Parameters

Name

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

Strict

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

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

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

Community Additions

ADD
Show:
© 2014 Microsoft