Skip to content

Commit

Permalink
Refactor - load tree outcome icons only once
Browse files Browse the repository at this point in the history
  • Loading branch information
rowo360 committed Dec 17, 2024
1 parent e86d46a commit 80d5ae2
Showing 1 changed file with 17 additions and 27 deletions.
44 changes: 17 additions & 27 deletions src/TestCentric/testcentric.gui/Views/TestTreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public TestTreeView()
OutcomeFilter = new MultiCheckedToolStripButtonGroup(new[] { filterOutcomePassedButton, filterOutcomeFailedButton, filterOutcomeWarningButton, filterOutcomeNotRunButton });
TreeView = treeView;

LoadOutcomeFilterImages();

// NOTE: We use MouseDown here rather than MouseUp because
// the menu strip Opening event occurs before MouseUp.
treeView.MouseDown += (s, e) =>
Expand Down Expand Up @@ -212,43 +210,35 @@ public void SetTestFilterVisibility(bool isVisible)
public void LoadAlternateImages(string imageSet)
{
string[] imageNames = { "Skipped", "Inconclusive", "Success", "Ignored", "Failure" };

string imageDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
Path.Combine("Images", Path.Combine("Tree", imageSet)));

for (int index = 0; index < imageNames.Length; index++)
LoadAlternateImage(index, imageNames[index], imageDir);
this.Invalidate();
this.Refresh();
// 1. Load all images once
IDictionary<string, Image> images = new Dictionary<string, Image>();
foreach (string imageName in imageNames)
images[imageName] = LoadAlternateImage(imageName, imageDir);

LoadOutcomeFilterImages();
}

private void LoadOutcomeFilterImages()
{
if (string.IsNullOrEmpty(AlternateImageSet))
return;
// 2. Set tree images
for (int index = 0; index < imageNames.Length; index++)
{
string imageName = imageNames[index];
treeImages.Images[index] = images[imageName];
}

string imageDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
Path.Combine("Images", Path.Combine("Tree", AlternateImageSet)));
// 3. Set filter outcome toolbar images
filterOutcomeFailedButton.Image = images["Failure"];
filterOutcomePassedButton.Image = images["Success"];
filterOutcomeWarningButton.Image = images["Ignored"];
filterOutcomeNotRunButton.Image = images["Skipped"];

filterOutcomeFailedButton.Image = LoadAlternateImage("Failure", imageDir);
filterOutcomePassedButton.Image = LoadAlternateImage("Success", imageDir);
filterOutcomeWarningButton.Image = LoadAlternateImage("Ignored", imageDir);
filterOutcomeNotRunButton.Image = LoadAlternateImage("Skipped", imageDir);
this.Invalidate();
this.Refresh();
}

#endregion

#region Helper Methods

private void LoadAlternateImage(int index, string name, string imageDir)
{
Image image = LoadAlternateImage(name, imageDir);
if (image != null)
treeImages.Images[index] = image;
}

private Image LoadAlternateImage(string name, string imageDir)
{
string[] extensions = { ".png", ".jpg" };
Expand Down

0 comments on commit 80d5ae2

Please sign in to comment.