private void GetCurrentSource() { try { IVsMonitorSelection selection = (IVsMonitorSelection)Package.GetGlobalService(typeof(SVsShellMonitorSelection)); object pvar = null; if (!ErrorHandler.Succeeded(selection.GetCurrentElementValue((uint)VSConstants.VSSELELEMID.SEID_DocumentFrame, out pvar))) { this.currentDocument = null; return; } IVsWindowFrame frame = pvar as IVsWindowFrame; if (frame == null) { this.currentDocument = null; return; } object docData = null; if (!ErrorHandler.Succeeded(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData))) { this.currentDocument = null; return; } object docViewServiceObject; if (!ErrorHandler.Succeeded(frame.GetProperty((int)Microsoft.VisualStudio.Shell.Interop.__VSFPROPID.VSFPROPID_SPFrame, out docViewServiceObject))) { this.currentDocument = null; return; } IVsTextLines buffer = docData as IVsTextLines; if (buffer == null) { IVsTextBufferProvider tb = docData as IVsTextBufferProvider; if (tb != null) { tb.GetTextBuffer(out buffer); } } if (buffer == null) { this.currentDocument = null; return; } IOleServiceProvider docViewService = (IOleServiceProvider)docViewServiceObject; if (this.currentDocument == null || buffer != this.currentDocument.TextEditorBuffer) { this.currentDocument = new VisualStudioDocument(frame, buffer, docViewService); this.changeCount = this.currentDocument.Source.ChangeCount; } else { if (this.changeCount != this.currentDocument.Source.ChangeCount) { this.currentDocument.Reload(); this.changeCount = this.currentDocument.Source.ChangeCount; } } return; } catch (Exception e) { ReportError(e); } }
private void GetCurrentSource() { try { IVsMonitorSelection selection = (IVsMonitorSelection)Package.GetGlobalService(typeof(SVsShellMonitorSelection)); object pvar = null; if (!ErrorHandler.Succeeded(selection.GetCurrentElementValue((uint)VSConstants.VSSELELEMID.SEID_DocumentFrame, out pvar))) { this.currentDocument = null; return; } IVsWindowFrame frame = pvar as IVsWindowFrame; if (frame == null) { this.currentDocument = null; return; } object docData = null; if (!ErrorHandler.Succeeded(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData))) { this.currentDocument = null; return; } object docViewServiceObject; if (!ErrorHandler.Succeeded(frame.GetProperty((int)Microsoft.VisualStudio.Shell.Interop.__VSFPROPID.VSFPROPID_SPFrame, out docViewServiceObject))) { this.currentDocument = null; return; } IVsTextLines buffer = docData as IVsTextLines; if (buffer == null) { IVsTextBufferProvider tb = docData as IVsTextBufferProvider; if (tb != null) { tb.GetTextBuffer(out buffer); } } if (buffer == null) { this.currentDocument = null; return; } IOleServiceProvider docViewService = (IOleServiceProvider)docViewServiceObject; if (this.currentDocument == null || buffer != this.currentDocument.TextEditorBuffer) { this.currentDocument = new VisualStudioDocument(frame,buffer, docViewService); this.changeCount = this.currentDocument.Source.ChangeCount; } else { if (this.changeCount != this.currentDocument.Source.ChangeCount) { this.currentDocument.Reload(); this.changeCount = this.currentDocument.Source.ChangeCount; } } return; } catch (Exception e) { ReportError(e); } }