private bool OpenItem(ProjectItem item, ViewCodeArgs e) { Dte.Application.MainWindow.Activate(); Log("Code item found [{0}] in project [{1}]", item.Name, item.ContainingProject.Name); var window = item.Open(); if (null != window) { if (!window.Visible) { window.Activate(); } var selection = (TextSelection)window.Document.Selection; if (e.LineNumber > 0) { selection.GotoLine(e.LineNumber, Select: true); } } return(true); }
public string ViewCode(ViewCodeArgs e) { var found = false; var errMsg = string.Empty; try { if (Dte != null) { var solution = (Solution2)Dte.Solution; var prjItem = solution.FindProjectItem(e.ClassName); if (prjItem != null) { found = OpenItem(prjItem, e); } } else { errMsg = "Visual Studio Instance " + e.ProgId + " is not available!"; } } catch (Exception ex) { errMsg = ex.Message + " ProgId [" + e.ProgId + "] " + ex.StackTrace; } if (!found) { errMsg = string.Format("Class {0} not found in namespace {1}.", e.ClassName, e.NameSpace); } if (errMsg.Length > 0) { Log(errMsg); } return(errMsg); }