How to: Use the Managed Package Framework Classes to Register Editor Factories

The RegisterEditorFactory method is used to register an editor factory with Visual Studio. For examples of implementations of this method, see the Managed Basic Editor sample or generate a basic embedded editor using the Visual Studio Integration Package Wizard. For more information, see How to: Create VSPackages (C# and Visual Basic).

To register an editor factory

  1. Add a RegisterEditorExtensionAttribute to your class that inherits from Package class.

    This is demonstrated in the example below.

  2. Override the Initialize method.

    To do this, call the RegisterEditorFactory method in your implementation of the Initialize method, passing the instance of your editor factory.

    This is demonstrated in the example below.

  3. Unregister the editor factories.

    Editor factories are automatically unregistered when the VSPackage is disposed. If the editor factory object implements the IDisposable interface, its Dispose method is called after the factory has been unregistered with Visual Studio.

Example

The following code sample demonstrates the registration of an editor factory.

using System;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Shell;

using MSVSIP = Microsoft.VisualStudio.Shell;

namespace Microsoft.VisualStudio.VSIP.Samples.BasicEditor
{
    // BasicEditor
[MSVSIP.DefaultRegistryRoot("Software\\Microsoft\\VisualStudio\\8.0Exp"
  )]
[MSVSIP.InstalledProductRegistration(false, "#100", "#102", "8.0", 
  IconResourceID = 400)]
[MSVSIP.ProvideLoadKey("Standard", "8.0", "Basic Managed Editor (C#)", 
  "Microsoft", 1)]
[MSVSIP.ProvideMenuResource(1000, 1)]
[MSVSIP.ProvideEditorExtensionAttribute(typeof(EditorFactory),  
  ".Sample", 32,  
ProjectGuid = "{A2FE74E1-B743-11d0-AE1A-00A0C90FFFC3}",  
TemplateDir = "..\\..\\Templates",  
NameResourceID = 106)]
[MSVSIP.ProvideEditorLogicalView(typeof(EditorFactory), "{7651a703-
  06e5-11d1-8ebd-00a0c90f26ea}")]
[Guid("a4635212-1cf4-4f5d-92ed-74dc17f6f5c8")]
public sealed class BasicEditor : MSVSIP.Package
{
    private EditorFactory editorFactory;

    public BasicEditor()
    {
        Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, 
          "Entering constructor for: {0}", this.ToString()));
    }
    // CBscPkgPackage Package Implementation
    #region Package Members
    protected override void Initialize()
    {
        Trace.WriteLine (string.Format(CultureInfo.CurrentCulture, 
          "Entering Initialize() of: {0}", this.ToString()));
        base.Initialize();
        //Create Editor Factory 
        editorFactory = new EditorFactory(this); 
        base.RegisterEditorFactory(editorFactory); 
    }

See Also

Tasks

How to: Register Editor File Types

Other Resources

Editors

Associating Editors with Projects and File Types