次の方法で共有


Supporting Multiple Document Views

You can provide more than one view of a document by creating separate document data and document view objects for your editor. Some cases in which an additional document view would be useful are:

  • New window support — You want your editor to be equipped to provide two or more views of the same type, so that a user who already has a window open in the editor can open a new window by selecting the New Window command from the Window menu.

  • Form and code view support — You want your editor to be equipped to provide views of different types. Visual Basic, for example, provides both a form view and a code view.

    For more information about this, see the CreateEditorInstance procedure in the EditorFactory.cs file, located in the Visual C# version of the Example.XMLDesigner sample. By default, this sample is located in <Visual Studio SDK installation path>\VisualStudioIntegration\Samples\IDE\CSharp\Example.XmlDesigner\.

Synchronizing Views

When you implement multiple views, the document data object is responsible for keeping all views synchronized with the data. If you customize the Visual Studio 2008 core editor, then you can use the event handling interfaces on its document data object (VsTextBuffer) to synchronize multiple views with the data. For more information, see Text Buffer Events.

If you do not use the VsTextBuffer object to synchronize multiple views, then you must implement your own event system to handle changes made to the document data object. You can use different levels of granularity to keep multiple views up-to-date. With a setting of maximum granularity, as you type in one view the other views are updated immediately. With minimum granularity, other views are not updated until they are activated. An example of how multiple views are updated is provided in the Figures Edit sample.

Determining Whether Document Data is Already Open

The running document table (RDT) in the integrated development environment (IDE) helps track whether the data for a document is already open, as shown in the following diagram.

Multiple views
DocDataView graphic

By default in the IDE, each view (document view object) is contained in its own window frame (IVsWindowFrame). As already noted, however, a document data object can utilize multiple views. To enable this, the IDE checks the RDT to determine if the document in question is already open in an editor. When the IDE calls CreateEditorInstance to create the editor, a non-NULL value returned in the punkDocDataExisting parameter indicates that the document is already open in another editor. For more information about how the RDT functions, see Running Document Table.

In your IVsEditorFactory implementation, examine the document data object returned in punkDocDataExisting to determine if the document data object is appropriate for your editor. (For example, HTML data for an HTML editor.) If it is appropriate, then your editor factory should do the work of providing a second view for the data. If the punkDocDataExisting parameter is not NULL, it is possible either that the document data object is open in another editor, or, more likely, that the document data object is already open in one view with the editor of the editor factory. If the document data object is open in an editor that your editor factory is unable to work with, then the IDE fails to open your editor factory. For more information, see How to: Attach Views to Document Data Objects.

See Also

Concepts

Editors