Udostępnij za pośrednictwem


Instantiating the Core Editor By Using the Legacy API

The editor is responsible for text editing functions such as insertion, deletion, copy, and paste. It combines these functions with those provided by language services, such as text coloring, indentation, and IntelliSense statement completion.

You can instantiate an instance of the core editor 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.

The following sections discuss how to use the legacy API to instantiate the editor.

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: Register an Editor Factory Using MPF Class Attributes and Walkthrough: Creating a Core Editor and Registering an Editor File Type.

See Also

Tasks

Walkthrough: Creating a Core Editor and Registering an Editor File Type

Other Resources

Inside the Core Editor

Opening and Saving Project Items

Editor Features