UndoContext.Open(String, Boolean) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
开始一个新的撤消操作。
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)
参数
- Name
- String
必需。 表示为其提供撤消上下文的过程名称。
- Strict
- Boolean
可选。 指示撤消堆栈链接是否严格。 默认值为 False。
- 属性
示例
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
注解
如果在 UndoContext 执行方法时该对象已打开 Open ,则会生成一个错误。
如果撤消堆栈链接是严格的,则必须将所有链接的撤消同级堆栈一起撤消或全部撤消。 严格链接的撤消操作通常是对多个文件(如标头文件和 Visual C++ 文件)中的文本更改所必需的。 这实际上是 Visual Studio 中使用的模型。 有关撤消堆栈链接的详细信息,请参阅 OpenLinkedUndo 方法。