共用方式為


編輯器工廠

編輯器工廠建立編輯器物件,並將它們置於視窗外框,稱為 「 實體檢視。 它會建立文件資料和建立編輯器和設計工具所需的文件檢視物件。 編輯器工廠,才能建立 Visual Studio 的核心編輯器和其他標準的編輯器。 自訂編輯器也可以選擇性地由編輯器工廠。

您藉由實作建立編輯器工廠IVsEditorFactory介面。 下列範例會說明如何實作IVsEditorFactory來建立編輯器工廠:

<Guid(GuidList.guidEditorFactory)> _
Public NotInheritable Class SingleViewEditorFactory
    Implements IVsEditorFactory
    Implements IDisposable

    Private MyPackage As PackageSingleViewEditor
    Private vsServiceProvider As ServiceProvider

    Public Sub New(ByVal packageEditor As PackageSingleViewEditor)
        Trace.WriteLine(String.Format(CultureInfo.CurrentCulture,
          "Entering {0} constructor", Me.ToString()))
        MyPackage = packageEditor
    End Sub

#Region "IVsEditorFactorySupport" 
    Public Function Close() As Integer Implements VisualStudio.Shell.Interop.IVsEditorFactory.Close
        Throw New NotImplementedException
    End Function 

    Public Function CreateEditorInstance(ByVal grfCreateDoc As UInteger, ByVal pszMkDocument As String, ByVal pszPhysicalView As String, ByVal pvHier As VisualStudio.Shell.Interop.IVsHierarchy, ByVal itemid As UInteger, ByVal punkDocDataExisting As System.IntPtr, ByRef ppunkDocView As System.IntPtr, ByRef ppunkDocData As System.IntPtr, ByRef pbstrEditorCaption As String, ByRef pguidCmdUI As System.Guid, ByRef pgrfCDW As Integer) As Integer Implements VisualStudio.Shell.Interop.IVsEditorFactory.CreateEditorInstance
        Throw New NotImplementedException
    End Function 

    Public Function MapLogicalView(ByRef rguidLogicalView As System.Guid, ByRef pbstrPhysicalView As String) As Integer Implements VisualStudio.Shell.Interop.IVsEditorFactory.MapLogicalView
        Throw New NotImplementedException
    End Function 

    Public Function SetSite(ByVal psp As VisualStudio.OLE.Interop.IServiceProvider) As Integer Implements VisualStudio.Shell.Interop.IVsEditorFactory.SetSite
        Throw New NotImplementedException
    End Function
#End Region

#Region "IDisposable Support" 
    Public Sub Dispose() Implements IDisposable.Dispose
        Throw New NotImplementedException
    End Sub
#End Region

End Class
[Guid(GuidList.guidEditorFactory)]
public sealed class SingleViewEditorFactory : IVsEditorFactory, IDisposable
{
    private PackageSingleViewEditor MyPackage;
    private ServiceProvider vsServiceProvider;

    public SingleViewEditorFactory(PackageSingleViewEditor packageEditor)
    {
        Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, 
            "Entering {0} constructor", this.ToString()));
        MyPackage = packageEditor;
    }

    #region "IVsEditorFactory Support" 
        public int Close()
        {
            throw new NotImplementedException();
        }

        public int CreateEditorInstance(uint grfCreateDoc, string pszMkDocument, string pszPhysicalView, IVsHierarchy pvHier, uint itemid, IntPtr punkDocDataExisting, out IntPtr ppunkDocView, out IntPtr ppunkDocData, out string pbstrEditorCaption, out System.Guid pguidCmdUI, out int pgrfCDW)
        {
            throw new NotImplementedException();
        }

        public int MapLogicalView(ref System.Guid rguidLogicalView, out string pbstrPhysicalView)
        {
            throw new NotImplementedException();
        }

        public int SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider psp)
        {
            throw new NotImplementedException();
        }
    #endregion

    #region "IDisposable Support" 
        public void Dispose()
        {
            throw new NotImplementedException();
        }
    #endregion
}

編輯器便會載入第一次您開啟該編輯器所處理的檔案類型。 您可以選擇開啟特定的編輯器] 或 [預設的編輯器。 如果您選取的預設編輯器,整合式的開發環境 (IDE) 決定正確的編輯器 」,然後再將它開啟。 如需詳細資訊,請參閱 決定哪些編輯器開啟的專案中的檔案

登錄編輯器工廠

您可以使用編輯器建立之前,首先必須登錄其資訊,包括它可以處理的附檔名。

如果您的 VSPackage 撰寫 managed 程式碼中,您可以使用管理套件架構 (MPF) 方法RegisterEditorFactory之後您 VSPackage 已載入, 登錄編輯器。 如果您的 VSPackage unmanaged 程式碼所撰寫,那麼您必須使用登錄編輯器工廠SVsRegisterEditors服務。

藉由使用登錄編輯器工廠 Managed 程式碼

您必須註冊編輯器工廠,在您的 VSPackage Initialize方法。 第一次呼叫base.Initialize,然後呼叫RegisterEditorFactory的每個編輯器工廠

在 managed 程式碼,並不需要取消註冊編輯器工廠,因為 VSPackage 會為您處理這。 此外,如果您的編輯器工廠實作IDisposable,會自動處置時,它未註冊。

登錄編輯器工廠使用 unmanaged 程式碼

SetSite實作的編輯器套件,使用QueryService方法以呼叫SVsRegisterEditors。 如此一來傳回變數的指標, IVsRegisterEditors。 呼叫RegisterEditor方法傳遞的實作IVsEditorFactory介面。 您必須 mplement IVsEditorFactory在不同的類別。

編輯器處理站註冊程序

Visual Studio 載入您使用編輯器工廠的編輯器時,就會發生下列的程序:

  1. Visual Studio專案系統呼叫OpenStandardEditor

  2. 這個方法會傳回編輯器工廠。 Visual Studio 的延遲載入編輯器的套件,不過,直到專案系統實際需要在編輯器]。

  3. 當專案系統需要編輯器] 中時,會呼叫 Visual Studio CreateEditorInstance,特定的方法會傳回文件檢視] 與 [文件的資料物件。

  4. 如果呼叫程式編輯器工廠使用 Visual Studio CreateEditorInstance傳回文件的資料物件和文件檢視物件、 Visual Studio 再建立文件視窗、 將文件中的 view 物件,以及讓項目加入文件資料的物件執行文件表格 (RDT)。

請參閱

參考

IVsEditorFactory

概念

執行文件表格