Skip to content

Commit

Permalink
add discard to menu action
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jul 14, 2021
1 parent ab1d7e4 commit 4d83691
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/DiffEngineTray/MenuBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ static IEnumerable<ToolStripItem> BuildMovesAndDeletes(string? name, Tracker tra
yield return new MenuButton($"Pending Moves ({moves.Count}):", () => tracker.Accept(moves), Images.Accept);
foreach (var move in moves)
{
yield return BuildMove(move, () => tracker.Accept(move));
yield return BuildMove(
move,
() => tracker.Accept(move),
() => tracker.Discard(move));
}
}

Expand All @@ -159,6 +162,7 @@ static ToolStripItem BuildMove(TrackedMove move, Action accept)
var menu = new ToolStripDropDownButton($"{move.Name} ({move.Extension})");
menu.DropDownDirection = ToolStripDropDownDirection.Left;
menu.DropDownItems.Add(new MenuButton("Accept move", accept));
menu.DropDownItems.Add(new MenuButton("Discard", discard));
if (move.Exe != null)
{
menu.DropDownItems.Add(new MenuButton("Open diff tool", () => DiffToolLauncher.Launch(move)));
Expand Down
27 changes: 27 additions & 0 deletions src/DiffEngineTray/Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,18 @@ public void Accept(TrackedMove move)
}
}

public void Discard(TrackedMove move)
{
if (moves.Remove(move.Target, out var removed))
{
InnerDiscard(removed);
}
}

static void InnerMove(TrackedMove move)
{
KillProcesses(move);

if (File.Exists(move.Temp))
{
try
Expand All @@ -210,8 +220,25 @@ static void InnerMove(TrackedMove move)
//writing to the files, and the result will re-add the tracked item
}
}
}

static void InnerDiscard(TrackedMove move)
{
KillProcesses(move);

if (File.Exists(move.Temp))
{
try
{
File.Delete(move.Temp);
}
catch (IOException exception)
{
Log.Error(exception, $"Filed to delete '{move.Temp}'.");
//Swallow this since it is likely that a running test it reading or
//writing to the files, and the result will re-add the tracked item
}
}
}

static void KillProcesses(TrackedMove move)
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;CS0649</NoWarn>
<Version>6.9.1</Version>
<Version>6.9.2</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<PackageTags>Testing, Snapshot, Diff, Compare</PackageTags>
<Description>Launches diff tools based on file extensions. Designed to be consumed by snapshot testing libraries.</Description>
Expand Down

0 comments on commit 4d83691

Please sign in to comment.