public HotLinesToolWindow() : base(null) { this.Caption = "ProjBufferToolWindow"; var componentModel = (IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel)); _invisibleEditorManager = (IVsInvisibleEditorManager)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsInvisibleEditorManager)); _editorAdapter = componentModel.GetService <IVsEditorAdaptersFactoryService>(); _windowControl = new HotLinesToolWindowControl(); }
public EditorControl(string filePath) { InitializeComponent(); this.filePath = filePath; componentModel = (IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel)); textEditorFactory = componentModel.GetService <ITextEditorFactoryService>(); invisibleEditorManager = (IVsInvisibleEditorManager)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsInvisibleEditorManager)); editorAdapter = componentModel.GetService <IVsEditorAdaptersFactoryService>(); this.Content = CreateEditor(filePath); }
public ProjBufferToolWindow() : base(null) { this.Caption = "ProjBufferToolWindow"; this.BitmapResourceID = 301; this.BitmapIndex = 1; _componentModel = (IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel)); _invisibleEditorManager = (IVsInvisibleEditorManager)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsInvisibleEditorManager)); _editorAdapter = _componentModel.GetService <IVsEditorAdaptersFactoryService>(); _editorFactoryService = _componentModel.GetService <ITextEditorFactoryService>(); }
public MyToolWindow() : base(null) { this.Caption = Resources.ToolWindowTitle; this.BitmapResourceID = 301; this.BitmapIndex = 1; _componentModel = (IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel)); _invisibleEditorManager = (IVsInvisibleEditorManager)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsInvisibleEditorManager)); _editorAdapter = _componentModel.GetService<IVsEditorAdaptersFactoryService>(); _editorFactoryService = _componentModel.GetService<ITextEditorFactoryService>(); }
/// <summary> /// Method to call to cause us to place the file at the given path into our hosted editor. /// </summary> public void SetDisplayedFile(string filePath) { ClearOldEditor(); //Get an invisible editor over the file, this makes it much easier than having to manually figure out the right content type, //language service, and it will automatically associate the document with its owning project, meaning we will get intellisense //in our editor with no extra work. IVsInvisibleEditorManager invisibleEditorManager = (IVsInvisibleEditorManager)GetService(typeof(SVsInvisibleEditorManager)); ErrorHandler.ThrowOnFailure(invisibleEditorManager.RegisterInvisibleEditor(filePath, pProject: null, dwFlags: (uint)_EDITORREGFLAGS.RIEF_ENABLECACHING, pFactory: null, ppEditor: out this.invisibleEditor)); //The doc data is the IVsTextLines that represents the in-memory version of the file we opened in our invisibe editor, we need //to extract that so that we can create our real (visible) editor. IntPtr docDataPointer = IntPtr.Zero; Guid guidIVSTextLines = typeof(IVsTextLines).GUID; ErrorHandler.ThrowOnFailure(this.invisibleEditor.GetDocData(fEnsureWritable: 1, riid: ref guidIVSTextLines, ppDocData: out docDataPointer)); try { IVsTextLines docData = (IVsTextLines)Marshal.GetObjectForIUnknown(docDataPointer); //Get the component model so we can request the editor adapter factory which we can use to spin up an editor instance. IComponentModel componentModel = (IComponentModel)GetService(typeof(SComponentModel)); IVsEditorAdaptersFactoryService editorAdapterFactoryService = componentModel.GetService <IVsEditorAdaptersFactoryService>(); //Create a code window adapter. this.codeWindow = editorAdapterFactoryService.CreateVsCodeWindowAdapter(OleServiceProvider); //Disable the splitter control on the editor as leaving it enabled causes a crash if the user //tries to use it here :( IVsCodeWindowEx codeWindowEx = (IVsCodeWindowEx)this.codeWindow; INITVIEW[] initView = new INITVIEW[1]; codeWindowEx.Initialize((uint)_codewindowbehaviorflags.CWB_DISABLESPLITTER, VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter, szNameAuxUserContext: "", szValueAuxUserContext: "", InitViewFlags: 0, pInitView: initView); //Associate our IVsTextLines with our new code window. ErrorHandler.ThrowOnFailure(this.codeWindow.SetBuffer((IVsTextLines)docData)); //Get our text view for our editor which we will use to get the WPF control that hosts said editor. ErrorHandler.ThrowOnFailure(this.codeWindow.GetPrimaryView(out this.textView)); //Get our WPF host from our text view (from our code window). IWpfTextViewHost textViewHost = editorAdapterFactoryService.GetWpfTextViewHost(this.textView); Debug.Assert(this.control != null); //We already have an open window, so just insert this editor in place of the old one. this.control.InsertNewEditor(textViewHost.HostControl); } finally { if (docDataPointer != IntPtr.Zero) { //Release the doc data from the invisible editor since it gave us a ref-counted copy. Marshal.Release(docDataPointer); } } }