private EventHandler(DTE2 app, AddIn addin) { this._applicationObject = app; this._addInInstance = addin; e = (TaskListEventsClass)app.Events.get_TaskListEvents(null); e.TaskNavigated += new _dispTaskListEvents_TaskNavigatedEventHandler(e_TaskNavigated); Window winPre = app.ActiveWindow; Window win = app.Windows.Item(Constants.vsWindowKindTaskList); win.Activate(); winPre.Activate(); frm = null; } if (this.win == null) { string guid = "{87907470-2841-11de-8c30-0800200c9a66}"; object obj = new object(); Windows2 windows = (Windows2)this._applicationObject.Windows; string asm = Assembly.GetCallingAssembly().Location; this.win = (Window2)windows.CreateToolWindow2(this._addInInstance, asm, "EasyAddin.StackTree", "调用关系树", guid, ref obj); this.st = (StackTree)obj; } TextSelection ts = (TextSelection)this._applicationObject.ActiveWindow.Selection; EditPoint ep = ts.ActivePoint.CreateEditPoint(); CodeElement ce = GetCodeElement(ts); int startLine = 0; if (null != ce) { strFuncName = ce.FullName; strShortName = ce.Name; startLine = ce.StartPoint.Line; } this.st.AddNode(strFuncName, strTxt, _applicationObject.ActiveDocument.FullName, ts.TopPoint.Line, strShortName); strFuncName = string.Format("{0}[{1}] [{2}]", subCat, strFuncName, strTxt);CodeElement GetCodeElement(object tsORpoint) { CodeElement ce = null; TextSelection ts = tsORpoint as TextSelection; EditPoint ep ; if (null != ts) { ep = ts.ActivePoint.CreateEditPoint(); } else { ep = tsORpoint as EditPoint; } ep.EndOfLine(); int[] eleKind = new int[] { (int)vsCMElement.vsCMElementFunction, (int)vsCMElement.vsCMElementClass }; foreach (int a in eleKind) { vsCMElement eTmp = (vsCMElement)a; ce = ep.get_CodeElement(eTmp); if (null != ce) { break; } } if (null == ce) { for (int i = (int)vsCMElement.vsCMElementOther; i <= (int)vsCMElement.vsCMElementModule; i++) { vsCMElement eTmp = (vsCMElement)i; ce = ep.get_CodeElement(eTmp); if (null != ce) { break; } } } ep.StartOfLine(); return ce; } public void Navigate2File(string path, int line, string txt) { _applicationObject.ItemOperations.OpenFile(path, Constants.vsViewKindTextView); TextSelection ts = (TextSelection)_applicationObject.ActiveDocument.Selection; ts.MoveTo(line, 1, false); ts.SelectLine(); string strTxt = ts.Text.Trim(); if (!string.IsNullOrEmpty(strTxt) && txt.IndexOf(strTxt) >= 0) { return; } string[] lst = SplitTaskText(txt); if (lst == null) { return; } string filetype = "*" + path.Substring(path.LastIndexOf(".")); strTxt = lst[1]; TextDocument objTD = (TextDocument)_applicationObject.ActiveDocument.Object("TextDocument"); EditPoint objEditPt = objTD.StartPoint.CreateEditPoint(); int opt = (int)(vsFindOptions.vsFindOptionsFromStart | vsFindOptions.vsFindOptionsKeepModifiedDocumentsOpen); EditPoint EndPoint = null; bool a = objEditPt.FindPattern(strTxt, opt, ref EndPoint); if (EndPoint != null) { ts.MoveTo(EndPoint.Line, 1, false); ts.SelectLine(); } }