|
| 1 | +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) |
| 2 | +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) |
| 3 | + |
| 4 | +using ICSharpCode.Core; |
| 5 | +using System; |
| 6 | +using System.Collections.Generic; |
| 7 | +using System.Drawing; |
| 8 | + |
| 9 | +namespace ICSharpCode.SharpDevelop |
| 10 | +{ |
| 11 | + /// <summary> |
| 12 | + /// This Class contains a ResourceManager, which handles bitmap resources |
| 13 | + /// for the application which were loaded from the filesystem. |
| 14 | + /// </summary> |
| 15 | + public static class FileIconService |
| 16 | + { |
| 17 | + static Dictionary<string, Bitmap> bitmapCache = new Dictionary<string, Bitmap>(); |
| 18 | + |
| 19 | + static FileIconService() |
| 20 | + { |
| 21 | + ResourceService.ClearCaches += ResourceService_ClearCaches; |
| 22 | + } |
| 23 | + |
| 24 | + static void ResourceService_ClearCaches(object sender, EventArgs e) |
| 25 | + { |
| 26 | + lock (bitmapCache) { |
| 27 | + bitmapCache.Clear(); |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// Returns a bitmap from the file system. Paceholders like ${SharpDevelopBinPath} |
| 33 | + /// and AddinPath (e. g. ${AddInPath:ICSharpCode.FiletypeRegisterer}) are resolved |
| 34 | + /// through the StringParser. |
| 35 | + /// The bitmaps are reused, you must not dispose the Bitmap! |
| 36 | + /// </summary> |
| 37 | + /// <returns> |
| 38 | + /// The bitmap loaded from the file system. |
| 39 | + /// </returns> |
| 40 | + /// <param name="name"> |
| 41 | + /// The name of the requested bitmap (prefix, path and filename). |
| 42 | + /// </param> |
| 43 | + /// <exception cref="FileNotFoundException"> |
| 44 | + /// Is thrown when the bitmap was not found in the file system. |
| 45 | + /// </exception> |
| 46 | + public static Bitmap GetBitmap(string name) |
| 47 | + { |
| 48 | + Bitmap bmp = null; |
| 49 | + if (name.ToUpper().StartsWith("FILE:")) { |
| 50 | + lock (bitmapCache) { |
| 51 | + if (bitmapCache.TryGetValue(name, out bmp)) |
| 52 | + return bmp; |
| 53 | + bmp = (Bitmap)Image.FromFile(StringParser.Parse(name.Substring(5,name.Length-5))); |
| 54 | + bitmapCache[name] = bmp; |
| 55 | + } |
| 56 | + } |
| 57 | + return bmp; |
| 58 | + } |
| 59 | + } |
| 60 | +} |
| 61 | + |
0 commit comments