diff options
author | Vsevolod Kukol <sevoku@microsoft.com> | 2020-01-23 22:28:35 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-23 22:28:35 +0300 |
commit | 7642846e9d9e93deca1efb59de9ae868f98f0e82 (patch) | |
tree | 148c1df4b6503a26109c1ccf463e617ae0cb6c30 | |
parent | 96f5a04f086a00f8e789cbc3c57c785d77f45d1b (diff) | |
parent | f5db8837d0a1edaa84d7915e3745266482990b3f (diff) |
Merge pull request #9590 from mono/fix-hc-dark-sel-icon-loader
[Ide] Dynamically add ~contrast~dark~sel resource mappings
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ImageService.cs | 41 |
1 files changed, 39 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..88f9c7d9ce 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ImageService.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ImageService.cs @@ -929,12 +929,49 @@ 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; + + // to avoid duplicate resource entries in project files, add virtual file mappings for + // high contrast icons in selected state. + // note: we include the "." to ensure that we match "~dark~sel" exactly and not "~dark~sel~xyz". + int start = baseName.Length; + int length = name.Length - baseName.Length - ext.Length + 1; + if (name.IndexOf ("~dark~sel.", start, length, StringComparison.Ordinal) == start || + name.IndexOf ("~dark~sel@2x.", start, length, StringComparison.Ordinal) == start) + { + 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); } } } |