编辑工厂

编辑工厂。窗架创建编辑对象并将它们放置,也称为的一个物理视图。 它创建文档数据和文档需要创建编辑器和设计器的视图对象。 需要编辑工厂创建 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) (ide) 确定正确的编辑器中打开然后将其打开。 有关更多信息,请参见 确定要编辑器中打开项目中的文件

注册表编辑器工厂

在将您创建的编辑之前,必须先有关它可以处理的方式注册信息,包括文件扩展名。

如果 VSPackage 用托管代码编写,可以使用托管包 framework (MPF) 方法 RegisterEditorFactory 注册编辑器工厂,在 VSPackage 加载之后。 如果 VSPackage 在非托管代码编写的,使用 SVsRegisterEditors 服务,则必须注册编辑器工厂。

注册使用托管代码的一个版本工厂

必须注册 VSPackage 中 Initialize 方法的编辑工厂。 第一次调用 base.Initialize,然后调用每个编辑工厂的 RegisterEditorFactory

在托管代码中,因为 VSPackage,将会处理您的,不需要注销每编辑工厂。 此外,,如果编辑工厂实现 IDisposable,它将自动进行配置,以便中注销时。

注册使用非托管代码的一个版本工厂

在编辑器软件包的 SetSite 实现中,使用 QueryService 方法调用 SVsRegisterEditors。 执行此操作返回指向 IVsRegisterEditors。 通过将 IVsEditorFactory 接口的实现调用 RegisterEditor 方法。 必须在单独的类的 mplement IVsEditorFactory

编辑工厂注册过程

使用编辑器工厂,,那么,当 Visual Studio 加载编辑器以下过程发生:

  1. Visual Studio 项目系统调用 OpenStandardEditor

  2. 此方法返回编辑工厂。 ,但是, Visual Studio 延迟加载编辑的包,直到项目系统确实需要编辑器。

  3. 当项目系统需要编辑器时, Visual Studio 会调用 CreateEditorInstance,返回文档视图和文档数据对象的专用方法。

  4. 如果由 Visual Studio 调入编辑工厂使用 CreateEditorInstance 返回文档数据对象并记录视图对象,然后 Visual Studio 在创建文档窗口中,将文档视图对象,并提交项转换为文档文档 (RDT)数据对象的表的运行。

请参见

参考

IVsEditorFactory

概念

运行文档表