Condividi tramite


IVsEditorFactory.CreateEditorInstance Method

Definition

Used by the editor factory architecture to create editors that support data/view separation.

public:
 int CreateEditorInstance(System::UInt32 grfCreateDoc, System::String ^ pszMkDocument, System::String ^ pszPhysicalView, Microsoft::VisualStudio::Shell::Interop::IVsHierarchy ^ pvHier, System::UInt32 itemid, IntPtr punkDocDataExisting, [Runtime::InteropServices::Out] IntPtr % ppunkDocView, [Runtime::InteropServices::Out] IntPtr % ppunkDocData, [Runtime::InteropServices::Out] System::String ^ % pbstrEditorCaption, [Runtime::InteropServices::Out] Guid % pguidCmdUI, [Runtime::InteropServices::Out] int % pgrfCDW);
public int CreateEditorInstance (uint grfCreateDoc, string pszMkDocument, string pszPhysicalView, Microsoft.VisualStudio.Shell.Interop.IVsHierarchy pvHier, uint itemid, IntPtr punkDocDataExisting, out IntPtr ppunkDocView, out IntPtr ppunkDocData, out string pbstrEditorCaption, out Guid pguidCmdUI, out int pgrfCDW);
abstract member CreateEditorInstance : uint32 * string * string * Microsoft.VisualStudio.Shell.Interop.IVsHierarchy * uint32 * nativeint * nativeint * nativeint * string * Guid * int -> int
Public Function CreateEditorInstance (grfCreateDoc As UInteger, pszMkDocument As String, pszPhysicalView As String, pvHier As IVsHierarchy, itemid As UInteger, punkDocDataExisting As IntPtr, ByRef ppunkDocView As IntPtr, ByRef ppunkDocData As IntPtr, ByRef pbstrEditorCaption As String, ByRef pguidCmdUI As Guid, ByRef pgrfCDW As Integer) As Integer

Parameters

grfCreateDoc
UInt32

[in] Flags whose values are taken from the __VSCREATEEDITORFLAGS enumeration that defines the conditions under which to create the editor. Only open and silent flags are valid.

pszMkDocument
String

[in] String form of the moniker identifier of the document in the project system. In the case of documents that are files, this is always the path to the file. This parameter can also be used to specify documents that are not files. For example, in a database-oriented project, this parameter could contain a string that refers to records in a table.

pszPhysicalView
String

[in] Name of the physical view. See Remarks for details.

pvHier
IVsHierarchy

[in] Pointer to the IVsHierarchy interface.

itemid
UInt32

[in] Item identifier of this editor instance.

punkDocDataExisting
IntPtr

nativeint

[in] Must be the punkDocData object that is registered in the Running Document Table (RDT). This parameter is used to determine if a document buffer (DocData object) has already been created. When an editor factory is asked to create a secondary view, then this parameter will be non-null indicating that there is no document buffer. If the file is open, return VS_E_INCOMPATIBLEDOCDATA and the environment will ask the user to close it.

ppunkDocView
IntPtr

nativeint

[out] Pointer to the IUnknown interface for the DocView object. Returns null if an external editor exists, otherwise returns the view of the document.

ppunkDocData
IntPtr

nativeint

[out] Pointer to the IUnknown interface for the DocData object. Returns the buffer for the document.

pbstrEditorCaption
String

[out] Initial caption defined by the document editor for the document window. This is typically a string enclosed in square brackets, such as "[Form]". This value is passed as an input parameter to the CreateDocumentWindow(UInt32, String, IVsUIHierarchy, UInt32, IntPtr, IntPtr, Guid, String, Guid, IServiceProvider, String, String, Int32[], IVsWindowFrame) method. If the file is [ReadOnly] the caption will be set during load of the file.

pguidCmdUI
Guid

[out] Returns the Command UI GUID. This GUID is active when this editor is activated. Any UI element that is visible in the editor has to use this GUID. This GUID is used in the .ctc file in the satellite DLL where it indicates which menus and toolbars should be displayed when the document is active.

Returns

If the document has a format that cannot be opened in the editor, VS_E_UNSUPPORTEDFORMAT is returned.If the document is open in an incompatible editor (or E_NOINTERFACE), VS_E_INCOMPATIBLEDOCDATA is returned.If the file could not be opened for any other reason, another HRESULT error code is returned.

Remarks

COM Signature

From vsshell.idl:

HRESULT IVsEditorFactory::CreateEditorInstance(  
   [in] VSCREATEEDITORFLAGS grfCreateDoc,  
   [in] LPCOLESTR pszMkDocument,  
   [in] LPCOLESTR pszPhysicalView,  
   [in] IVsHierarchy *pvHier,  
   [in] VSITEMID itemid,  
   [in] IUnknown *punkDocDataExisting,  
   [out] IUnknown **ppunkDocView,  
   [out] IUnknown **ppunkDocData,  
   [out] BSTR *pbstrEditorCaption,  
   [out] GUID *pguidCmdUI,  
   [out, retval] VSEDITORCREATEDOCWIN *pgrfCDW  
);  

IVsEditorFactory.CreateEditorInstance is called by the environment in response to a project system calling either the OpenStandardEditor or OpenSpecificEditor helper functions in its OpenItem Method implementation. In the case of OpenStandardEditor, the environment first determines the editor factory with the highest priority for opening the file and then calls IVsEditorFactory.CreateEditorInstance. If the environment is unable to instantiate the document data in that editor, it will find the editor with the next highest priority and attempt to so that same thing. You can return the following for your editor factory to support this loop:

VS_E_UNSUPPORTEDFORMAT allows the loop to continue without closing the document if it is currently open.

Return this value if the document data provided to your editor factory is not compatible with your editor factory. You can determine whether the document data is compatible by calling QueryInterface on the document data object for the set of interfaces you require. In this case, the user is not prompted to close the file.VS_E_INCOMPATIBLEDOCDATA asks if the open document should be closed. Any other return will stop the loop from continuing.

Return this value if the document data provided to your editor factory is not compatible with your editor factory. You can determine whether the document data is compatible by calling QueryInterface on the document data object for the set of interfaces you require. This value is also returned if your editor factory only supports a single view on the document data, because in this case, the document data is already open with another view. Returning this value causes the environment to prompt the user to close the file in the other editor and allow it to be opened in your editor.

Note

If your editor instantiates the document data and document view on the same object, then your editor can only support opening a single view for an instance of the document data. As a result, if you are requested to open document data that is already instantiated in another editor, or even your editor, you are unable to support providing another view and must return this value.

If the document data object referenced by ppunkDocData supports IOleCommandTarget, the object is included in the command routing chain of the environment after the command is routed to the active object referenced by ppunkDocView.

The physical view string pszPhysicalView either is supplied by MapLogicalView or is found in the registry under the appropriate editor key of the form: HKLM\SOFTWARE\Microsoft\VisualStudio\8.0\Editors\<guid of editor>\LogicalViews\<guid of logical view>.

Applies to