diff options
author | Vsevolod Kukol <sevoku@microsoft.com> | 2020-01-23 16:40:10 +0300 |
---|---|---|
committer | Vsevolod Kukol <sevoku@microsoft.com> | 2020-01-23 17:50:32 +0300 |
commit | 11fd096a3d2c6db5e2a6e88526cf135b6ce5080e (patch) | |
tree | a89bfedcea41fc4bcbd2064bf566c9cd9530e835 | |
parent | b6246867e382026f5b17cc3658b2dfdb51916eac (diff) |
[Ide] Dynamically add ~contrast~dark~sel resource mappings
to avoid adding duplicate EmbeddedResource entries to project files.
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ImageService.cs | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ImageService.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ImageService.cs index cd1b75f497..7bdc877de1 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ImageService.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ImageService.cs @@ -929,12 +929,45 @@ namespace MonoDevelop.Ide resourceList.Sort (); // sort resources by name } - return resourceList.Where (r => r.StartsWith (baseName) && r.EndsWith (ext)); + return GetFinalFilelist (resourceList, baseName, ext); } + IEnumerable<string> GetFinalFilelist (IEnumerable<string> source, string baseName, string ext) + { + foreach (var name in source) { + if (name.StartsWith (baseName) && name.EndsWith (ext)) { + yield return name; + + var tagPortion = name.Substring (baseName.Length, name.Length - baseName.Length - ext.Length); + // to avoid duplicate resource entries in project files, add virtual file mappings for + // high contrast icons in selected state + if (tagPortion == "~dark~sel" || tagPortion == "~dark~sel@2x") { + var map = name.Replace ("~dark~sel", "~contrast~dark~sel"); + if (virtualMappings == null) { + virtualMappings = new Dictionary<string, string> (); + } + if (!virtualMappings.ContainsKey (map)) { + virtualMappings.Add (map, name); + } + yield return map; + } else { + // remove existing mapping if a resource with the same name exists. + // note: we know that the source is sorted + virtualMappings?.Remove (name); + } + } + } + } + + Dictionary<string, string> virtualMappings; + public Stream LoadImage (string fileName) { - return addin.GetResource (fileName, true); + // load original resource if a mapping exists + if (virtualMappings != null && virtualMappings.TryGetValue (fileName, out var mapsTo)) + return addin.GetResource (mapsTo, true); + else + return addin.GetResource (fileName, true); } } } |