/// <summary> /// View the changes between the revisions, if possible as a diff /// </summary> /// <param name="fileViewer">Current FileViewer</param> /// <param name="item">The FileStatusItem to present changes for</param> /// <param name="defaultText">default text if no diff is possible</param> /// <param name="openWithDiffTool">The difftool command to open with</param> /// <returns>Task to view</returns> public static Task ViewChangesAsync(this FileViewer fileViewer, [CanBeNull] FileStatusItem item, [NotNull] string defaultText = "", [CanBeNull] Action openWithDiffTool = null) { if (item?.Item?.IsStatusOnly ?? false) { // Present error (e.g. parsing Git) return(fileViewer.ViewTextAsync(item.Item.Name, item.Item.ErrorMessage)); } if (item?.Item == null || item.SecondRevision?.ObjectId == null) { if (!string.IsNullOrWhiteSpace(defaultText)) { return(fileViewer.ViewTextAsync(item?.Item?.Name, defaultText)); } fileViewer.Clear(); return(Task.CompletedTask); } var firstId = item.FirstRevision?.ObjectId ?? item.SecondRevision.FirstParentId; openWithDiffTool ??= OpenWithDiffTool; if (item.Item.IsNew || firstId == null || FileHelper.IsImage(item.Item.Name)) { // View blob guid from revision, or file for worktree return(fileViewer.ViewGitItemRevisionAsync(item.Item, item.SecondRevision.ObjectId, openWithDiffTool)); } string selectedPatch = GetSelectedPatch(fileViewer, firstId, item.SecondRevision.ObjectId, item.Item) ?? defaultText; return(item.Item.IsSubmodule ? fileViewer.ViewTextAsync(item.Item.Name, text: selectedPatch, openWithDifftool: openWithDiffTool) : fileViewer.ViewPatchAsync(item.Item.Name, text: selectedPatch, openWithDifftool: openWithDiffTool)); void OpenWithDiffTool() { fileViewer.Module.OpenWithDifftool( item.Item.Name, item.Item.OldName, firstId?.ToString(), item.SecondRevision.ToString(), isTracked: item.Item.IsTracked); }
public static Task ViewChangesAsync( this FileViewer diffViewer, [CanBeNull] ObjectId firstRevision, ObjectId secondRevision, [NotNull] GitItemStatus file, [NotNull] string defaultText, [CanBeNull] Action openWithDifftool) { if (firstRevision == null || FileHelper.IsImage(file.Name)) { // The previous commit does not exist, nothing to compare with if (file.TreeGuid != null) { // blob guid exists return(diffViewer.ViewGitItemAsync(file, openWithDifftool)); } if (secondRevision == null) { throw new ArgumentNullException(nameof(secondRevision)); } // Get blob guid from revision return(diffViewer.ViewGitItemRevisionAsync(file, secondRevision, openWithDifftool)); } string selectedPatch = diffViewer.GetSelectedPatch(firstRevision, secondRevision, file); if (selectedPatch == null) { return(diffViewer.ViewPatchAsync(file.Name, text: defaultText, openWithDifftool: null /* not applicable */, isText: true)); } return(diffViewer.ViewPatchAsync(file.Name, text: selectedPatch, openWithDifftool: openWithDifftool ?? OpenWithDifftool, isText: file.IsSubmodule)); void OpenWithDifftool() { diffViewer.Module.OpenWithDifftool( file.Name, null, firstRevision.ToString(), firstRevision.ToString(), "", file.IsTracked); } }
public void OnOpenWithUpdate(CommandArrayInfo info) { ProjectFile finfo = (ProjectFile)CurrentNode.DataItem; FileViewer prev = null; foreach (FileViewer fv in IdeApp.Workbench.GetFileViewers(finfo.Name)) { if (prev != null && fv.IsExternal != prev.IsExternal) { info.AddSeparator(); } CommandInfo ci = info.Add(fv.Title, fv); ci.Description = GettextCatalog.GetString("Open with '{0}'", fv.Title); prev = fv; } }
private static Panel CreateViewRules([NotNull] FormSparseWorkingCopyViewModel sparse, [NotNull] ToolTip tooltip, [NotNull] IGitUICommandsSource cmdsource) { // Label var label1 = new Label() { AutoSize = true, Text = Globalized.Strings.SpecifyTheRulesForIncludingOrExcludingFilesAndDirectories.Text, Dock = DockStyle.Top, Padding = new Padding(10, 5, 10, 0) }; var label2 = new Label() { AutoSize = true, Text = Globalized.Strings.SpecifyTheRulesForIncludingOrExcludingFilesAndDirectoriesLine2.Text, Dock = DockStyle.Top, Padding = new Padding(25, 3, 10, 3), ForeColor = SystemColors.GrayText }; sparse.PropertyChanged += delegate { label1.Visible = label2.Visible = sparse.IsSparseCheckoutEnabled; }; // Text editor var editor = new FileViewer() { Dock = DockStyle.Fill, UICommandsSource = cmdsource, IsReadOnly = false }; editor.TextLoaded += (sender, args) => sparse.SetRulesTextAsOnDisk(editor.GetText()); try { FileInfo sparsefile = sparse.GetPathToSparseCheckoutFile(); if (sparsefile.Exists) { editor.ViewFile(sparsefile.FullName); } } catch (Exception ex) { MessageBox.Show(ActiveForm, Globalized.Strings.CannotLoadTheTextOfTheSparseFile.Text + "\n\n" + ex.Message, Globalized.Strings.SparseWorkingCopy.Text + " – " + Globalized.Strings.LoadFile.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } editor.TextChanged += (sender, args) => sparse.RulesText = editor.GetText() ?? ""; tooltip.SetToolTip(editor, Globalized.Strings.EditsTheContentsOfTheGitInfoSparseCheckoutFile.Text); Control separator = CreateViewSeparator(DockStyle.Top); sparse.PropertyChanged += delegate { editor.Visible = separator.Visible = sparse.IsSparseCheckoutEnabled; }; var panel = new Panel() { Margin = Padding.Empty, Padding = Padding.Empty, Controls = { editor, separator, label2, label1 }, AutoSize = true, Dock = DockStyle.Fill }; return(panel); }
public static void ViewPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file, string defaultText) { IList <GitRevision> revisions = grid.GetSelectedRevisions(); if (revisions.Count == 1 && (revisions[0].ParentGuids == null || revisions[0].ParentGuids.Length == 0)) { diffViewer.ViewGitItem(file.Name, file.TreeGuid); } else { diffViewer.ViewPatch(() => { string selectedPatch = diffViewer.GetSelectedPatch(grid, file); return(selectedPatch ?? defaultText); }); } }
private void DoResize() { Control[] fileViewers = pnlImages.Controls.Find("ucFile", false); int top = -pnlImages.VerticalScroll.Value; foreach (Control ucf in fileViewers) { FileViewer fv = (FileViewer)ucf; fv.Top = top; fv.SizeContent(); top += fv.Height + 10; } }
public static Task ViewChangesAsync(this FileViewer diffViewer, IReadOnlyList<GitRevision> revisions, GitItemStatus file, string defaultText) { if (revisions.Count == 0) { return Task.CompletedTask; } var selectedRevision = revisions[0]; var secondRevision = selectedRevision?.ObjectId; var firstRevision = revisions.Count >= 2 ? revisions[1].ObjectId : null; if (firstRevision == null && selectedRevision != null) { firstRevision = selectedRevision.FirstParentGuid; } return ViewChangesAsync(diffViewer, firstRevision, secondRevision, file, defaultText, openWithDifftool: null /* use default */); }
public static Task ViewChanges(this FileViewer diffViewer, IList <GitRevision> revisions, GitItemStatus file, string defaultText) { if (revisions.Count == 0) { return(Task.FromResult(string.Empty)); } var selectedRevision = revisions[0]; string secondRevision = selectedRevision?.Guid; string firstRevision = revisions.Count >= 2 ? revisions[1].Guid : null; if (firstRevision == null && selectedRevision != null) { firstRevision = selectedRevision.FirstParentGuid; } return(ViewChanges(diffViewer, firstRevision, secondRevision, file, defaultText)); }
public static string GetSelectedPatch(this FileViewer diffViewer, string firstRevision, string secondRevision, GitItemStatus file) { if (firstRevision == null) { return(null); } //to simplify if-ology if (GitRevision.IsArtificial(secondRevision) && firstRevision != GitRevision.UnstagedGuid) { string temp = firstRevision; firstRevision = secondRevision; secondRevision = temp; } if (IsItemUntracked(file, firstRevision, secondRevision)) { var fullPath = Path.Combine(diffViewer.Module.WorkingDir, file.Name); if (Directory.Exists(fullPath) && GitModule.IsValidGitWorkingDir(fullPath)) { return(LocalizationHelpers.GetSubmoduleText(diffViewer.Module, file.Name.TrimEnd('/'), "")); } return(FileReader.ReadFileContent(fullPath, diffViewer.Encoding)); } if (file.IsSubmodule && file.SubmoduleStatus != null) { return(LocalizationHelpers.ProcessSubmoduleStatus(diffViewer.Module, file.SubmoduleStatus.Result)); } PatchApply.Patch patch = GetItemPatch(diffViewer.Module, file, firstRevision, secondRevision, diffViewer.GetExtraDiffArguments(), diffViewer.Encoding); if (patch == null) { return(string.Empty); } if (file.IsSubmodule) { return(LocalizationHelpers.ProcessSubmodulePatch(diffViewer.Module, file.Name, patch)); } return(patch.Text); }
/// <summary> /// View the changes between the revisions, if possible as a diff /// </summary> /// <param name="fileViewer">Current FileViewer</param> /// <param name="firstId">The first (A) commit</param> /// <param name="selectedRev">The selected (B) commit</param> /// <param name="file">The git item to view</param> /// <param name="defaultText">default text if no diff is possible</param> /// <param name="openWithDiffTool">The difftool command to open with</param> /// <returns>Task to view</returns> public static Task ViewChangesAsync(this FileViewer fileViewer, [CanBeNull] ObjectId firstId, [CanBeNull] GitRevision selectedRev, [CanBeNull] GitItemStatus file, [NotNull] string defaultText = "", [CanBeNull] Action openWithDiffTool = null) { if (file == null || selectedRev?.ObjectId == null) { if (!string.IsNullOrWhiteSpace(defaultText)) { return(fileViewer.ViewTextAsync(file?.Name, defaultText, openWithDiffTool)); } fileViewer.Clear(); return(Task.CompletedTask); } firstId ??= selectedRev.FirstParentGuid; openWithDiffTool ??= OpenWithDiffTool; if (file.IsNew || firstId == null || FileHelper.IsImage(file.Name)) { // View blob guid from revision, or file for worktree return(fileViewer.ViewGitItemRevisionAsync(file, selectedRev.ObjectId, openWithDiffTool)); } string selectedPatch = GetSelectedPatch(fileViewer, firstId, selectedRev.ObjectId, file); return(file.IsSubmodule || selectedPatch == null ? fileViewer.ViewTextAsync(file.Name, text : selectedPatch ?? defaultText, openWithDifftool : openWithDiffTool) : fileViewer.ViewPatchAsync(file.Name, text: selectedPatch, openWithDifftool: openWithDiffTool)); void OpenWithDiffTool() { fileViewer.Module.OpenWithDifftool( file.Name, file.OldName, firstId?.ToString(), selectedRev?.ToString(), "", file.IsTracked); }
public static Task ViewChangesAsync(this FileViewer diffViewer, [CanBeNull] ObjectId firstId, [CanBeNull] GitRevision selectedRevision, [NotNull] GitItemStatus file, [NotNull] string defaultText, [CanBeNull] Action openWithDifftool = null) { if (firstId == null && selectedRevision != null) { firstId = selectedRevision.FirstParentGuid; } openWithDifftool ??= OpenWithDifftool; if (file.IsNew || firstId == null || FileHelper.IsImage(file.Name)) { // The previous commit does not exist, nothing to compare with if (selectedRevision == null) { throw new ArgumentNullException(nameof(selectedRevision)); } // View blob guid from revision, or file for worktree return(diffViewer.ViewGitItemRevisionAsync(file, selectedRevision.ObjectId, openWithDifftool)); } string selectedPatch = diffViewer.GetSelectedPatch(firstId, selectedRevision.ObjectId, file); return(diffViewer.ViewPatchAsync(file.Name, text: selectedPatch ?? defaultText, openWithDifftool: openWithDifftool, isText: file.IsSubmodule || selectedPatch == null)); void OpenWithDifftool() { diffViewer.Module.OpenWithDifftool( file.Name, file.OldName, firstId?.ToString(), selectedRevision?.ToString(), "", file.IsTracked); } }
public static Task ViewChangesAsync( this FileViewer diffViewer, [CanBeNull] string firstRevision, string secondRevision, [NotNull] GitItemStatus file, [NotNull] string defaultText, [CanBeNull] Action openWithDifftool) { if (firstRevision == null) { // The previous commit does not exist, nothing to compare with if (file.TreeGuid.IsNullOrEmpty()) { if (secondRevision.IsNullOrWhiteSpace()) { throw new ArgumentException(nameof(secondRevision)); } return(diffViewer.ViewGitItemRevisionAsync(file.Name, secondRevision)); } else { return(diffViewer.ViewGitItemAsync(file.Name, file.TreeGuid)); } } else { return(diffViewer.ViewPatchAsync(() => { string selectedPatch = diffViewer.GetSelectedPatch(firstRevision, secondRevision, file); if (selectedPatch == null) { return (text: defaultText, openWithDifftool: null /* not applicable */); } return (text: selectedPatch, openWithDifftool: openWithDifftool ?? (() => { diffViewer.Module.OpenWithDifftool(file.Name, null, firstRevision, secondRevision, "", file.IsTracked); })); })); } }
static async Task <string?> GetSelectedPatchAsync( FileViewer fileViewer, ObjectId firstId, ObjectId selectedId, GitItemStatus file, CancellationToken cancellationToken) { if (firstId == ObjectId.CombinedDiffId) { var diffOfConflict = fileViewer.Module.GetCombinedDiffContent(selectedId, file.Name, fileViewer.GetExtraDiffArguments(), fileViewer.Encoding); cancellationToken.ThrowIfCancellationRequested(); return(string.IsNullOrWhiteSpace(diffOfConflict) ? TranslatedStrings.UninterestingDiffOmitted : diffOfConflict); } var task = file.GetSubmoduleStatusAsync(); if (file.IsSubmodule && task is not null) { // Patch already evaluated var status = await task; cancellationToken.ThrowIfCancellationRequested(); return(status is not null ? LocalizationHelpers.ProcessSubmoduleStatus(fileViewer.Module, status) : $"Failed to get status for submodule \"{file.Name}\""); } var patch = await GetItemPatchAsync(fileViewer.Module, file, firstId, selectedId, fileViewer.GetExtraDiffArguments(), fileViewer.Encoding); cancellationToken.ThrowIfCancellationRequested(); return(file.IsSubmodule ? LocalizationHelpers.ProcessSubmodulePatch(fileViewer.Module, file.Name, patch) : patch?.Text);
private void SetViewer(FileViewer viewer) { if (viewer == currentViewer) { return; } if (currentViewer != null) { RevertMerge(menuStrip, currentViewer.Menu); RevertMerge(mainToolStrip, currentViewer.MainToolStrip); RevertMerge(statusStrip, currentViewer.StatusStrip); currentViewer.Visible = false; } currentViewer = viewer; if (viewer != null) { Merge(currentViewer.Menu, menuStrip); Merge(currentViewer.MainToolStrip, mainToolStrip); Merge(currentViewer.StatusStrip, statusStrip); currentViewer.Visible = true; } }
internal static void PopulateOpenWithViewers(CommandArrayInfo info, Project project, string filePath) { var viewers = DisplayBindingService.GetFileViewers(filePath, project).ToList(); //show the default viewer first var def = viewers.FirstOrDefault(v => v.CanUseAsDefault) ?? viewers.FirstOrDefault(v => v.IsExternal); if (def != null) { CommandInfo ci = info.Add(def.Title, def); ci.Description = GettextCatalog.GetString("Open with '{0}'", def.Title); if (viewers.Count > 1) { info.AddSeparator(); } } //then the builtins, followed by externals FileViewer prev = null; foreach (FileViewer fv in viewers) { if (def != null && fv.Equals(def)) { continue; } if (prev != null && fv.IsExternal != prev.IsExternal) { info.AddSeparator(); } CommandInfo ci = info.Add(fv.Title, fv); ci.Description = GettextCatalog.GetString("Open with '{0}'", fv.Title); prev = fv; } }
private static string GetSelectedPatch( [NotNull] this FileViewer diffViewer, [CanBeNull] ObjectId firstRevision, [CanBeNull] ObjectId secondRevision, [NotNull] GitItemStatus file) { if (!file.IsTracked) { var fullPath = Path.Combine(diffViewer.Module.WorkingDir, file.Name); if (Directory.Exists(fullPath) && GitModule.IsValidGitWorkingDir(fullPath)) { // git-status does not detect details for untracked and git-diff --no-index will not give info return(LocalizationHelpers.GetSubmoduleText(diffViewer.Module, file.Name.TrimEnd('/'), "")); } } if (file.IsSubmodule && file.GetSubmoduleStatusAsync() != null) { return(LocalizationHelpers.ProcessSubmoduleStatus(diffViewer.Module, ThreadHelper.JoinableTaskFactory.Run(() => file.GetSubmoduleStatusAsync()))); } Patch patch = GetItemPatch(diffViewer.Module, file, firstRevision, secondRevision, diffViewer.GetExtraDiffArguments(), diffViewer.Encoding); if (patch == null) { return(string.Empty); } if (file.IsSubmodule) { return(LocalizationHelpers.ProcessSubmodulePatch(diffViewer.Module, file.Name, patch)); } return(patch.Text); }
public ViewerComboItem(FileViewer viewer, string label) : base(label) { Viewer = viewer; }
public IActionResult GetFile([FromRoute] string fn) { var obj = new FileViewer(this); return(obj.GetFile(fn)); }
public async Task <IActionResult> GetFile([FromRoute] string table, [FromRoute] string field, [FromRoute] string key) { var obj = new FileViewer(this); return(await obj.GetFile(table, field, key)); }
/// <summary> /// View the changes between the revisions, if possible as a diff /// </summary> /// <param name="fileViewer">Current FileViewer</param> /// <param name="item">The FileStatusItem to present changes for</param> /// <param name="defaultText">default text if no diff is possible</param> /// <param name="openWithDiffTool">The difftool command to open with</param> /// <returns>Task to view</returns> public static Task ViewChangesAsync(this FileViewer fileViewer, [CanBeNull] FileStatusItem item, [NotNull] string defaultText = "", [CanBeNull] Action openWithDiffTool = null) { if (item?.Item?.IsStatusOnly ?? false) { // Present error (e.g. parsing Git) return(fileViewer.ViewTextAsync(item.Item.Name, item.Item.ErrorMessage)); } if (item?.Item is null || item.SecondRevision?.ObjectId is null) { if (!string.IsNullOrWhiteSpace(defaultText)) { return(fileViewer.ViewTextAsync(item?.Item?.Name, defaultText)); } fileViewer.Clear(); return(Task.CompletedTask); } var firstId = item.FirstRevision?.ObjectId ?? item.SecondRevision.FirstParentId; openWithDiffTool ??= OpenWithDiffTool; if (item.Item.IsNew || firstId is null || FileHelper.IsImage(item.Item.Name)) { // View blob guid from revision, or file for worktree return(fileViewer.ViewGitItemRevisionAsync(item.Item, item.SecondRevision.ObjectId, openWithDiffTool)); } if (item.Item.IsRangeDiff) { // This command may take time, give an indication of what is going on // The sha are incorrect if baseA/baseB is set, to simplify the presentation fileViewer.ViewText("range-diff.sh", $"git range-diff {firstId}...{item.SecondRevision.ObjectId}"); string output = fileViewer.Module.GetRangeDiff( firstId, item.SecondRevision.ObjectId, item.BaseA, item.BaseB, fileViewer.GetExtraDiffArguments(isRangeDiff: true)); // Try set highlighting from first found filename var match = new Regex(@"\n\s*(@@|##)\s+(?<file>[^#:\n]+)").Match(output ?? ""); var filename = match.Groups["file"].Success ? match.Groups["file"].Value : item.Item.Name; return(fileViewer.ViewRangeDiffAsync(filename, output ?? defaultText)); } string selectedPatch = GetSelectedPatch(fileViewer, firstId, item.SecondRevision.ObjectId, item.Item) ?? defaultText; return(item.Item.IsSubmodule ? fileViewer.ViewTextAsync(item.Item.Name, text: selectedPatch, openWithDifftool: openWithDiffTool) : fileViewer.ViewPatchAsync(item, text: selectedPatch, openWithDifftool: openWithDiffTool)); void OpenWithDiffTool() { fileViewer.Module.OpenWithDifftool( item.Item.Name, item.Item.OldName, firstId?.ToString(), item.SecondRevision.ToString(), isTracked: item.Item.IsTracked); }
private void tvwDuplicates_AfterSelect(object sender, TreeViewEventArgs e) { FileViewer fv; Control[] fileViewers = pnlImages.Controls.Find("ucFile", false); int ipIdx = 0; if (e.Node != null) { List <TreeNode> nodes = new List <TreeNode>(); TreeNode pNode = e.Node; if (pNode.Parent != null) { pNode = pNode.Parent; } nodes.Add(pNode); if (pNode.Nodes != null) { foreach (TreeNode n in pNode.Nodes) { nodes.Add(n); } } foreach (TreeNode n in nodes) { if (ipIdx >= fileViewers.Length) { fv = new FileViewer() { Name = "ucFile", Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right, Width = pnlImages.Width, Left = 0 }; fv.DeleteFile += Fv_DeleteFile; pnlImages.Controls.Add(fv); ++ipIdx; } else { fv = (FileViewer)fileViewers[ipIdx++]; } fv.Set((DataRow)n.Tag); fv.Visible = true; } DoResize(); } while (ipIdx < fileViewers.Length) { fv = (FileViewer)fileViewers[ipIdx++]; fv.ClearImage(); fv.Visible = false; } }
public static string GetSelectedPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file) { IList <GitRevision> revisions = grid.GetSelectedRevisions(); if (revisions.Count == 0) { return(null); } string firstRevision = revisions[0].Guid; var secondRevision = revisions.Count == 2 ? revisions[1].Guid : null; //to simplify if-ology if (GitRevision.IsArtificial(secondRevision) && firstRevision != GitRevision.UncommittedWorkingDirGuid) { firstRevision = secondRevision; secondRevision = revisions[0].Guid; } string extraDiffArgs = null; if (firstRevision == GitRevision.UncommittedWorkingDirGuid) //working dir changes { if (secondRevision == null || secondRevision == GitRevision.IndexGuid) { if (file.IsTracked) { return(ProcessDiffText(GitModule.Current.GetCurrentChanges(file.Name, file.OldName, false, diffViewer.GetExtraDiffArguments(), diffViewer.Encoding), file.IsSubmodule)); } return(FileReader.ReadFileContent(GitModule.CurrentWorkingDir + file.Name, diffViewer.Encoding)); } else { firstRevision = secondRevision; secondRevision = string.Empty; } } if (firstRevision == GitRevision.IndexGuid) //index { if (secondRevision == null) { return(ProcessDiffText(GitModule.Current.GetCurrentChanges(file.Name, file.OldName, true, diffViewer.GetExtraDiffArguments(), diffViewer.Encoding), file.IsSubmodule)); } //rev1 vs index firstRevision = secondRevision; secondRevision = string.Empty; extraDiffArgs = string.Join(" ", extraDiffArgs, "--cached"); } Debug.Assert(!GitRevision.IsArtificial(firstRevision), string.Join(" ", firstRevision, secondRevision)); if (secondRevision == null) { secondRevision = firstRevision + "^"; } PatchApply.Patch patch = GitModule.Current.GetSingleDiff(firstRevision, secondRevision, file.Name, file.OldName, string.Join(" ", diffViewer.GetExtraDiffArguments(), extraDiffArgs), diffViewer.Encoding); if (patch == null) { return(string.Empty); } return(ProcessDiffText(patch.Text, file.IsSubmodule)); }
public void SetUp() { _fileViewer = new FileViewer(); }
public override void Execute() { FileViewer.Collapse(); }
/// <summary> /// View the changes between the revisions, if possible as a diff. /// </summary> /// <param name="fileViewer">Current FileViewer.</param> /// <param name="item">The FileStatusItem to present changes for.</param> /// <param name="defaultText">default text if no diff is possible.</param> /// <param name="openWithDiffTool">The difftool command to open with.</param> /// <returns>Task to view.</returns> public static async Task ViewChangesAsync(this FileViewer fileViewer, FileStatusItem?item, CancellationToken cancellationToken, string defaultText = "", Action?openWithDiffTool = null) { if (item?.Item.IsStatusOnly ?? false) { // Present error (e.g. parsing Git) await fileViewer.ViewTextAsync(item.Item.Name, item.Item.ErrorMessage ?? ""); return; } if (item?.Item is null || item.SecondRevision?.ObjectId is null) { if (!string.IsNullOrWhiteSpace(defaultText)) { await fileViewer.ViewTextAsync(item?.Item?.Name, defaultText); return; } fileViewer.Clear(); return; } var firstId = item.FirstRevision?.ObjectId ?? item.SecondRevision.FirstParentId; openWithDiffTool ??= OpenWithDiffTool; if (item.Item.IsNew || firstId is null || (!item.Item.IsDeleted && FileHelper.IsImage(item.Item.Name))) { // View blob guid from revision, or file for worktree await fileViewer.ViewGitItemAsync(item, openWithDiffTool); return; } if (item.Item.IsRangeDiff) { // Git range-diff has cubic runtime complexity and can be slow and memory consuming, // give an indication of what is going on string range = item.BaseA is null || item.BaseB is null ? $"{firstId}...{item.SecondRevision.ObjectId}" : $"{item.BaseA}..{firstId} {item.BaseB}..{item.SecondRevision.ObjectId}"; await fileViewer.ViewTextAsync("range-diff.sh", $"git range-diff {range}"); string output = fileViewer.Module.GetRangeDiff( firstId, item.SecondRevision.ObjectId, item.BaseA, item.BaseB, fileViewer.GetExtraDiffArguments(isRangeDiff: true)); // Try set highlighting from first found filename Match match = new Regex(@"\n\s*(@@|##)\s+(?<file>[^#:\n]+)").Match(output ?? ""); string filename = match.Groups["file"].Success ? match.Groups["file"].Value : item.Item.Name; cancellationToken.ThrowIfCancellationRequested(); await fileViewer.ViewRangeDiffAsync(filename, output ?? defaultText); return; } string selectedPatch = (await GetSelectedPatchAsync(fileViewer, firstId, item.SecondRevision.ObjectId, item.Item)) ?? defaultText; cancellationToken.ThrowIfCancellationRequested(); if (item.Item.IsSubmodule) { await fileViewer.ViewTextAsync(item.Item.Name, text : selectedPatch, openWithDifftool : openWithDiffTool); } else { await fileViewer.ViewPatchAsync(item, text : selectedPatch, openWithDifftool : openWithDiffTool); } return; void OpenWithDiffTool() { fileViewer.Module.OpenWithDifftool( item.Item.Name, item.Item.OldName, firstId?.ToString(), item.SecondRevision.ToString(), isTracked: item.Item.IsTracked); }
public static string GetSelectedPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file) { IList <GitRevision> revisions = grid.GetSelectedRevisions(); return(GetSelectedPatch(diffViewer, revisions, file)); }
public async Task <IActionResult> GetFile([FromRoute] string fn) { var obj = new FileViewer(this); return(await obj.GetFile(fn)); }
public void SetUp() { _uiCommandsSource = Substitute.For <IGitUICommandsSource>(); _fileViewer = new FileViewer(); }
public override void Execute() { FileViewer.Expand(); }