Share via


Instantiating the Core Editor

The Visual Studio core editor is the default editor of Visual Studio. The editor supports text-editing functions such as insert, delete, copy, and paste. Its functionality combines with that provided by the language that it is currently editing, such as text colorization, indentation, and IntelliSense statement completion.

You provide an instance of the core editor to your VSPackage in one of three ways:

  • Explicitly create an instance of the core editor in a window.

  • Provide an editor factory which returns an instance of the core editor

  • Open a file from the project hierarchy using a utility function.

For an example implementation of this, see the EditorFactory class in the EditorFactory.cs file, located in the Visual C# version of the Example.XMLDesigner sample. By default, this sample is located in: C:\Program Files\Visual Studio 2008 SDK\<version number>\VisualStudioIntegration\Samples\ IDE\CSharp\Example.XmlDesigner.

Explicitly Opening a Core Editor Instance

When explicitly obtaining an instance of the core editor:

At this point, displaying the IVsWindowFrame interface provides a window that contains an instance of the core editor.

However, this is not a very useful instance, because it does not have shortcut keys, or access to advanced features. To obtain access to shortcut keys and advanced features:

How to Use an Editor factory to Obtain the Core Editor

When implementing a core editor with an editor factory using the CreateEditorInstance method, follow all the steps outlined in the previous section to explicitly host an IVsCodeWindow using an IVsTextBuffer document data object, in an IVsWindowFrame object.

To display the text, obtain a IVsTextView interface from the IVsCodeWindow object and call the CreateEditorInstance method.

To provide a language service to the editor, call the SetLanguageServiceID method within the CreateEditorInstance method.

To obtain default shortcut keys, unlike the previous section, you use the command context returned by the CreateEditorInstance method when obtaining the core editor from the CreateEditorInstance method.

If the CreateEditorInstance method returns the same command GUID as the text editor, the instance of the core editor automatically obtains the default shortcut keys.

For general information, see How to: Use the Managed Package Framework Classes to Register Editor Factories and Walkthrough: Invoking the Core Editor.

See Also

Tasks

Walkthrough: Invoking the Core Editor

Other Resources

Core Editor

Opening and Saving Project Items

Editor Features