UndoContext.SetAborted 方法

放弃自打开 UndoContext 对象以来对参与的打开文档所做的一切更改。

命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.dll 中)

语法

声明
Sub SetAborted
void SetAborted()
void SetAborted()
abstract SetAborted : unit -> unit 
function SetAborted()

备注

SetAborted 将打开的 UndoContext 对象的 IsAborted 属性设置为 true。在这种情况下,自打开 UndoContext 对象到关闭 UndoContext 对象为止,对参与的文档所做的一切更改都将被放弃。

示例

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

   ' Check to see if UndoContext object is already open.
   If DTE.UndoContext.IsOpen = True Then
      bIsOpen = True
   Else
      ' Open the UndoContext object to track changes.
      DTE.UndoContext.Open("RemoveNewLines", False)
   End If
   MsgBox("Current IsAborted value: " & DTE.UndoContext.IsAborted)

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

   ' Check to see if you want to discard changes.
   strAnswer = MsgBox("Do you want to discard all changes made?", vbYesNo & vbQuestion)
   If strAnswer = True Then
      DTE.UndoContext.SetAborted()
      MsgBox("Current IsAborted value: " & DTE.UndoContext.IsAborted)
   End If

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

.NET Framework 安全性

请参见

参考

UndoContext 接口

EnvDTE 命名空间