UndoContext 接口

定义

表示为单个事务,在 Visual Studio 中所有参与打开的文档上执行的所有操作。 如果调用了其 SetAborted() 方法,则从打开该对象以来所做的所有更改都将被丢弃。

public interface class UndoContext
public interface class UndoContext
__interface UndoContext
[System.Runtime.InteropServices.Guid("D8DEC44D-CAF2-4B39-A539-B91AE921BA92")]
[System.Runtime.InteropServices.TypeLibType(4160)]
public interface UndoContext
[<System.Runtime.InteropServices.Guid("D8DEC44D-CAF2-4B39-A539-B91AE921BA92")>]
[<System.Runtime.InteropServices.TypeLibType(4160)>]
type UndoContext = interface
Public Interface UndoContext
属性

示例

Sub UndoContextExample()  
   ' 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, do not close it.  
   If boolWasOpen = False Then  
      ' Close the UndoContext object to commit the changes.  
      DTE.UndoContext.Close()  
   End If  
End Sub  

注解

对象 UndoContext 由对象的属性返回 UndoContext _DTE 。 只有一个全局撤消服务处于 Visual Studio 打开或关闭状态。 UndoContext对象打开后,在中对文档所做的所有更新都 Visual Studio 可以通过单个撤消操作(方法)撤消) (, SetAborted 直到关闭该对象。 如果 SetAborted 调用了方法,则将放弃打开对象以来所做的所有更改。

若要使用该对象,请 UndoContext 打开它,进行文档更改,然后关闭该对象以完成更改。

若要放弃这些更改,请 SetAborted 在关闭该对象之前调用方法 UndoContext 。 关闭对象后 UndoContext ,将无法再撤消所做的更改。

备注

使用对象之前 UndoContext ,请检查以确定它是否已从上一个操作打开。 如果它已打开,则将在所有参与的文档中撤消所做的更改,以及在首次打开该对象之后完成的所有更改。 如果在 UndoContext 您选中该对象时该对象已打开,请不要将其关闭,因为前一个调用方仍需要它进行撤消操作。 因此,你不应调用 SetAborted 然后关闭对象, UndoContext 除非你最初打开了它。 完成更改文档中的文本后,请关闭它。

属性

DTE

获取顶级扩展性对象。

IsAborted

获取 UndoContext 对象操作是否已由 SetAborted() 方法终止。

IsOpen

获取指示撤消操作当前是否生效,或是否打开了解决方案的值。

IsStrict

获取指示撤消堆栈链接是否严格的值。

Parent

获取对象的直接父对象 UndoContext

方法

Close()

结束撤消操作。

Open(String, Boolean)

开始一个新的撤消操作。

SetAborted()

从打开对象后放弃对参与打开的文档所做的所有更改 UndoContext

适用于