/// <summary> /// Constructor that calls the Microsoft.VisualStudio.Shell.WindowPane constructor then /// our initialization functions. /// </summary> /// <param name="package">Our Package instance.</param> public EtoPreviewPane(EtoAddinPackage package, string fileName, IVsTextLines textBuffer, string mainAssembly, IEnumerable <string> references, CodeEditorHost codeEditor) : base(package) { this.editor = codeEditor; this.package = package; this.textBuffer = textBuffer; FileName = fileName; editorControl = new Panel(); editorControl.Content = editor.wpfElement.ToEto(); previewSplitter = new PreviewEditorViewSplitter(editorControl, mainAssembly, references, () => textBuffer?.GetText()); previewSplitter.GotFocus += (sender, e) => { WpfTextView?.VisualElement?.Focus(); }; preview = previewSplitter.Preview; var content = previewSplitter.ToNative(true); if (!preview.SetBuilder(fileName)) { throw new InvalidOperationException(string.Format("Could not find builder for file {0}", fileName)); } Content = content; }
public int CreateEditorInstance( uint grfCreateDoc, string pszMkDocument, string pszPhysicalView, IVsHierarchy pvHier, uint itemid, System.IntPtr punkDocDataExisting, out System.IntPtr ppunkDocView, out System.IntPtr ppunkDocData, out string pbstrEditorCaption, out Guid pguidCmdUI, out int pgrfCDW) { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering {0} CreateEditorInstace()", this.ToString())); // Initialize to null ppunkDocView = IntPtr.Zero; ppunkDocData = IntPtr.Zero; pguidCmdUI = Constants.EtoPreviewEditorFactory_guid; pgrfCDW = 0; pbstrEditorCaption = null; if (!BuilderInfo.Supports(pszMkDocument)) { return(VSConstants.VS_E_UNSUPPORTEDFORMAT); } // Validate inputs if ((grfCreateDoc & (VSConstants.CEF_OPENFILE | VSConstants.CEF_SILENT)) == 0) { return(VSConstants.E_INVALIDARG); } object prjItemObject; var projectItemId = VSConstants.VSITEMID_ROOT; pvHier.GetProperty(projectItemId, (int)__VSHPROPID.VSHPROPID_ExtObject, out prjItemObject); var proj = prjItemObject as EnvDTE.Project; // Get or open text buffer var textBuffer = GetTextBuffer(punkDocDataExisting, pszMkDocument, ToVsProject(proj)); if (textBuffer == null) { return(VSConstants.VS_E_INCOMPATIBLEDOCDATA); } if (punkDocDataExisting != IntPtr.Zero) { ppunkDocData = punkDocDataExisting; Marshal.AddRef(ppunkDocData); } else { ppunkDocData = Marshal.GetIUnknownForObject(textBuffer); } var codeEditor = new CodeEditorHost(textBuffer); try { var outputFile = GetAssemblyPath(proj); var references = GetReferences(proj).ToList(); //var outputDir = Path.GetDirectoryName(outputFile); // Create the Document (editor) var editor = new EtoPreviewPane(editorPackage, pszMkDocument, textBuffer, outputFile, references, codeEditor); ppunkDocView = Marshal.GetIUnknownForObject(editor); } catch (Exception ex) { MessageBox.Show($"Error creating preview pane: {ex.Message}"); Debug.WriteLine($"Error creating preview pane: {ex}"); throw; } //pbstrEditorCaption = " [Preview]"; return(VSConstants.S_OK); }