protected virtual object CreateDocumentView(string documentMoniker, string physicalView, IVsHierarchy hierarchy, uint itemid, IVsTextLines textLines, bool createdDocData, out string editorCaption, out Guid cmdUI) { //Init out params editorCaption = string.Empty; cmdUI = Guid.Empty; if (string.IsNullOrEmpty(physicalView)) { // create code window as default physical view return(CreateCodeView(documentMoniker, textLines, createdDocData, ref editorCaption, ref cmdUI)); } // We couldn't create the view // Return special error code so VS can try another editor factory. throw Marshal.GetExceptionForHR(VSConstants.VS_E_UNSUPPORTEDFORMAT); }
protected virtual IVsTextLines GetTextBuffer(System.IntPtr docDataExisting, string filename) { IVsTextLines textLines; if (docDataExisting == IntPtr.Zero) { // Create a new IVsTextLines buffer. Type textLinesType = typeof(IVsTextLines); Guid riid = textLinesType.GUID; Guid clsid = typeof(VsTextBufferClass).GUID; textLines = _package.CreateInstance(ref clsid, ref riid, textLinesType) as IVsTextLines; // set the buffer's site ((IObjectWithSite)textLines).SetSite(_serviceProvider.GetService(typeof(IOleServiceProvider))); } else { // Use the existing text buffer Object dataObject = Marshal.GetObjectForIUnknown(docDataExisting); textLines = dataObject as IVsTextLines; if (textLines == null) { // Try get the text buffer from textbuffer provider IVsTextBufferProvider textBufferProvider = dataObject as IVsTextBufferProvider; if (textBufferProvider != null) { textBufferProvider.GetTextBuffer(out textLines); } } if (textLines == null) { // Unknown docData type then, so we have to force VS to close the other editor. throw Marshal.GetExceptionForHR(VSConstants.VS_E_INCOMPATIBLEDOCDATA); } } return(textLines); }