public TextViewFilter(IVsTextView vsTextView) { if (_vsEditorAdaptersFactoryService == null) { _vsEditorAdaptersFactoryService = BabePackage.ComponentModel.GetService <IVsEditorAdaptersFactoryService>(); } if (_debugger == null) { _debugger = (IVsDebugger)BabePackage.GetGlobalService(typeof(IVsDebugger)); } vsTextView.GetBuffer(out _vsTextLines); _wpfTextView = _vsEditorAdaptersFactoryService.GetWpfTextView(vsTextView); ErrorHandler.ThrowOnFailure(vsTextView.AddCommandFilter(this, out _next)); }
/// <summary> /// Get a IVsTextView interface that the ActiveDocument use /// </summary> /// <returns></returns> public static IVsTextView GetCurrentTextView() { var monitorSelection = (IVsMonitorSelection)BabePackage.GetGlobalService(typeof(SVsShellMonitorSelection)); if (monitorSelection == null) { return(null); } object curDocument; if (ErrorHandler.Failed(monitorSelection.GetCurrentElementValue((uint)VSConstants.VSSELELEMID.SEID_DocumentFrame, out curDocument))) { // TODO: Report error return(null); } IVsWindowFrame frame = curDocument as IVsWindowFrame; if (frame == null) { // TODO: Report error return(null); } object docView = null; if (ErrorHandler.Failed(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView))) { // TODO: Report error return(null); } if (docView is IVsCodeWindow) { IVsTextView textView; if (ErrorHandler.Failed(((IVsCodeWindow)docView).GetPrimaryView(out textView))) { // TODO: Report error return(null); } return(textView); } return(null); }