private Window OpenDocument(string filePath, string key) { var window = ShellUtils.Open(filePath); window.Document.ReadOnly = true; _fileRevisionWindowMap[key] = window; _documentWindows[window] = key; return(window); }
/// <summary> /// Navigate from a parsed stack frame to source code line. /// </summary> /// <param name="errorGroupItem">The error group item that will be shown in the source code tooltip.</param> /// <param name="stackFrame">The stack frame that contains the source file and source line number.</param> public static void ErrorFrameToSourceLine( ErrorGroupItem errorGroupItem, ErrorReporting.StackFrame stackFrame) { if (errorGroupItem == null || stackFrame == null || !stackFrame.IsWellParsed) { throw new ArgumentException("Invalid argument"); } ProjectSourceFile projectFile = null; SolutionHelper solution = SolutionHelper.CurrentSolution; if (solution != null) { var items = solution.FindMatchingSourceFile(stackFrame.SourceFile); if (items.Count > 1) { var index = PickFileDialog.PickFileWindow.PromptUser(items.Select(x => x.FullName)); if (index < 0) { return; } projectFile = items.ElementAt(index); } else { projectFile = items.FirstOrDefault(); } } if (projectFile == null) { SourceVersionUtils.FileItemNotFoundPrompt(stackFrame.SourceFile); return; } var window = ShellUtils.Open(projectFile.FullName); if (window == null) { FailedToOpenFilePrompt(stackFrame.SourceFile); return; } ShowToolTip(errorGroupItem, stackFrame, window); }
/// <summary> /// Open the source file, move to the source line and show tooltip. /// If git sha is present at the log entry, try to open the revision of the file. /// If the log item does not contain revision id, /// fallback to using the assembly version information. /// </summary> /// <param name="logItem">The log item to search for source file.</param> public static async Task NavigateToSourceLineCommandAsync(LogItem logItem) { EnvDTE.Window window = null; try { if (logItem.Entry.Labels?.ContainsKey(SourceContextIdLabel) == true) { string sha = logItem.Entry.Labels[SourceContextIdLabel]; if (!ValidateGitDependencyHelper.ValidateGitForWindowsInstalled()) { return; } window = await ProgressDialogWindow.PromptUser( SearchGitRepoAndOpenFileAsync(sha, logItem.SourceFilePath), s_gitOperationOption); } else { // If the log item does not contain revision id, // fallback to using assembly version information. var project = FindOrOpenProject(logItem); if (project == null) { Debug.WriteLine($"Failed to find project of {logItem.AssemblyName}"); return; } var locatedFilePath = project.FindSourceFile(logItem.SourceFilePath)?.FullName; if (locatedFilePath != null) { window = ShellUtils.Open(locatedFilePath); } } } catch (FileNotFoundException ex) { FileItemNotFoundPrompt(ex.FilePath); return; } if (window == null) { FailedToOpenFilePrompt(logItem.SourceFilePath); return; } logItem.ShowToolTip(window); }