From 80d5ae293eae83f257329f4f9cab864b5a7123d1 Mon Sep 17 00:00:00 2001 From: rowo360 <59574371+rowo360@users.noreply.github.com> Date: Tue, 17 Dec 2024 08:38:00 +0100 Subject: [PATCH] Refactor - load tree outcome icons only once --- .../testcentric.gui/Views/TestTreeView.cs | 44 +++++++------------ 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/src/TestCentric/testcentric.gui/Views/TestTreeView.cs b/src/TestCentric/testcentric.gui/Views/TestTreeView.cs index ceeb1d27..c0012c5b 100644 --- a/src/TestCentric/testcentric.gui/Views/TestTreeView.cs +++ b/src/TestCentric/testcentric.gui/Views/TestTreeView.cs @@ -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) => @@ -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 images = new Dictionary(); + 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" };