Udostępnij za pośrednictwem


How to: Open Editors for Open Documents

Note

This article applies to Visual Studio 2015. 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

Before a project opens a document window, the project first must determine whether the file is already open in the document window for another editor. The file can be either open in a project-specific editor, or one of the standard editors registered with Visual Studio.

Opening a Project-Specific Editor

Use the following procedure to open a project-specific editor for a file that is already open.

To open a project-specific editor for an open file

  1. Call the IsDocumentOpen method.

    This call returns pointers to the document's hierarchy, hierarchy item, and window frame, if appropriate.

  2. If the document is open, the project must check to see whether only a document data object exists, or if a document view object is also present.

    • If a document view object exists, and this view is for a different hierarchy or hierarchy item, the project uses the pointer to the view's window frame to resurface the existing window.

    • If a document view object exists, and this view is for the same hierarchy and hierarchy item, the project can open a second view if it can attach to the underlying document data object. Otherwise, the project should use the pointer to the view's window frame to resurface the existing window.

    • If only the document data object exists, the project should determine whether it can use the document data object for its view. If the document data object is compatible, complete the steps discussed in Opening a Project-Specific Editor.

      If the document data object is not compatible, an error should be displayed to the user that indicates that the file is currently in use. This error should only be displayed in transient cases, such as when a file is being compiled at the same time the user is trying to open the file by using an editor other than the Visual Studio core text editor. The core text editor can share document data object with the compiler.

  3. If the document is not open because there is no document data object or document view object, complete the steps in Opening a Project-Specific Editor.

Opening a Standard Editor

Use the following procedure to open a standard editor for a file that is already open.

To open a standard editor for an open file

  1. Call OpenStandardEditor.

    This method first verifies that the document is not already open by calling IsDocumentOpen. If the document is already open, then its editor window is resurfaced.

  2. If the document is not open, then complete the steps in How to: Open Standard Editors.

See Also

Opening and Saving Project Items
How to: Open Project-Specific Editors
How to: Open Standard Editors