How to: Open standard editors
Applies to: Visual Studio Visual Studio for Mac
Note
This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
When you open a standard editor, you let the IDE determine a standard editor for a designated file type, instead of specifying a project-specific editor for the file.
Complete the following procedure to implement the OpenItem method. This will open a project file in a standard editor.
To implement the OpenItem method with a standard editor
Call IVsRunningDocumentTable (
RDT_EditLock
) to determine whether the document data object file is already open.If the file is already open, resurface the file by calling the IsDocumentOpen method, specifying a value of
IDO_ActivateIfOpen
for thegrfIDO
parameter.If the file is open and the document is owned by a different project than the calling project, your project receives a warning that the editor being opened is from another project. The file window is then surfaced.
If the document is not open or not in the running document table, call the OpenStandardEditor method (
OSE_ChooseBestStdEditor
) to open a standard editor for the file.When you call the method, the IDE performs the following tasks:
The IDE scans the Editors/{guidEditorType}/Extensions subkey in the registry to determine which editor can open the file and has the highest priority for doing this.
After the IDE has determined which editor can open the file, the IDE calls CreateEditorInstance. The editor's implementation of this method returns information that is required for the IDE to call CreateDocumentWindow and site the newly opened document.
Finally, the IDE loads the document by using the usual persistence interface, such as IVsPersistDocData2.
If the IDE has previously determined that the hierarchy or hierarchy item is available, the IDE calls GetItemContext method on the project to get a project-level context IServiceProvider pointer to pass back in with the CreateDocumentWindow method call.
Return an IServiceProvider pointer to the IDE when the IDE calls GetItemContext on your project if you want to let the editor get context from your project.
Performing this step lets the project offer additional services to the editor.
If the document view or document view object was successfully sited in a window frame, the object is initialized with its data by calling LoadDocData.