UndoContext.IsOpen 屬性

取得復原作業目前是否生效,或者是否開啟了方案。

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

語法

'宣告
ReadOnly Property IsOpen As Boolean
    Get
bool IsOpen { get; }
property bool IsOpen {
    bool get ();
}
abstract IsOpen : bool
function get IsOpen () : boolean

屬性值

型別:System.Boolean
如果復原作業為作用中,或是開啟了方案,布林值會指示 true,否則會指示 false。

備註

若是開啟了 UndoContext 物件,復原作業就會生效。

開啟的方案可能尚未儲存,因此不一定要有方案 (.sln) 檔。

範例

Sub IsOpenExample(ByVal dte As DTE2)

    ' Create a new text file.
    dte.ItemOperations.NewFile()

    Dim doc As TextDocument = _
        CType(dte.ActiveDocument.Object("TextDocument"), TextDocument)
    Dim done As Boolean = False

    Do While Not done
        If dte.UndoContext.IsOpen = False Then
            Try
                dte.UndoContext.Open("Insert 10 Lines")

                ' Insert 10 lines of text into the new document.
                Dim point As EditPoint = doc.StartPoint.CreateEditPoint
                Dim i As Integer

                For i = 1 To 10
                    point.Insert("This is a test." & vbCrLf)
                Next

                done = True
            Catch
            Finally
                If done Then dte.UndoContext.Close()
            End Try
        End If
    Loop

End Sub
public void IsOpenExample(DTE2 dte)
{
    // Create a new text file.
    dte.ItemOperations.NewFile(@"General\Text File", "", 
        Constants.vsViewKindPrimary);

    TextDocument doc = 
        (TextDocument)dte.ActiveDocument.Object("TextDocument");
    bool done = false;

    while (!done)
    {
        if (!dte.UndoContext.IsOpen)
        {
            try
            {
                dte.UndoContext.Open("Insert 10 Lines", false);

                // Insert 10 lines of text into the new document.
                EditPoint point = doc.StartPoint.CreateEditPoint();

                for (int i = 0; i < 10; ++i)
                    point.Insert("This is a test.\n");

                done = true;
            }
            catch
            {
            }
            finally
            {
                if (done) dte.UndoContext.Close();
            }
        }
    }
}

.NET Framework 安全性

請參閱

參考

UndoContext 介面

EnvDTE 命名空間

其他資源

HOW TO:編譯和執行 Automation 物件模型程式碼範例