UndoContext.Open 方法

啟動新的復原作業。

命名空間:  EnvDTE
組件:  EnvDTE (在 EnvDTE.dll 中)

語法

'宣告
Sub Open ( _
    Name As String, _
    Strict As Boolean _
)
void Open(
    string Name,
    bool Strict
)
void Open(
    [InAttribute] String^ Name, 
    [InAttribute] bool Strict
)
abstract Open : 
        Name:string * 
        Strict:bool -> unit 
function Open(
    Name : String, 
    Strict : boolean
)

參數

  • Name
    型別:System.String
    必要項。代表提供復原內容之程序的名稱。
  • Strict
    型別:System.Boolean
    選擇項。指示復原堆疊連結性是否嚴格。預設值為 False。

備註

在執行 Open 方法時,如果 UndoContext 物件已經開啟,它會產生一個錯誤。

如果復原堆疊連結非常嚴格,必須同時復原所有連結的復原同層級堆疊,或者全部不復原。 跨多個檔案 (例如標頭檔和 Visual C++ 檔案) 同時變更文字通常需要嚴格的連結復原作業。 事實上,這就是 Visual Studio 中使用的模型。 如需復原堆疊連結的詳細資訊,請參閱 OpenLinkedUndo 方法。

範例

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

.NET Framework 安全性

請參閱

參考

UndoContext 介面

EnvDTE 命名空間