次の方法で共有


UndoContext.IsOpen プロパティ

元に戻す操作が現在有効かどうか、またはソリューションが開かれているかどうかを示す値を取得します。

名前空間:  EnvDTE
アセンブリ:  EnvDTE (EnvDTE.dll 内)

構文

'宣言
ReadOnly Property IsOpen As Boolean
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 名前空間

その他の技術情報

方法 : オートメーション オブジェクト モデルのコード例をコンパイルおよび実行する