Bagikan melalui


How to: Open Standard Editors

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

  1. Call IVsRunningDocumentTable (RDT_EditLock) to determine whether the document data object file is already open.

  2. If the file is already open, resurface the file by calling the IsDocumentOpen method, specifying a value of IDO_ActivateIfOpen for the grfIDO 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.

  3. 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:

    1. 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.

    2. 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.

    3. Finally, the IDE loads the document by using the usual persistence interface, such as IVsPersistDocData2.

    4. 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.

  4. 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.

See Also

Tasks

How to: Open Project-Specific Editors

How to: Open Editors for Open Documents

Reference

IServiceProvider

Concepts

Displaying Files By Using the Open File Command

Other Resources

Opening and Saving Project Items