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:
Obtain a IVsTextBuffer to hold the document data object being edited.
Create a line oriented representation of the document data object by creating an IVsTextLines interface from the IVsTextBuffer interface.
Set IVsTextLines as the document data object for an instance of the default implementation of the IVsCodeWindow interface, using the SetBuffer method.
Host the IVsCodeWindow instance in a IVsWindowFrame interface by using the CreateToolWindow method.
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:
Use the SetLanguageServiceID method to associate a language service and the document data object that the editor uses.
Either create your own shortcut keys, or use the system default by setting the IVsWindowFrame objects display properties. To do this, call the SetGuidProperty method with the VSFPROPID_InheritKeyBindings property.
To obtain and use non-standard shortcut keys, generate them using the .vsct file. For more information, see Visual Studio Command Table (.Vsct) Files.
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 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