Browse Source

FileIconService added to allow custom template icons to be loaded from the file system.

pull/64/head
Michael Seeger 12 years ago
parent
commit
1cb4e87fdb
  1. 1
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  2. 61
      src/Main/Base/Project/Src/Services/FileIconService.cs
  3. 27
      src/Main/Base/Project/Src/Services/IconService.cs

1
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -474,6 +474,7 @@ @@ -474,6 +474,7 @@
<Compile Include="Src\Services\DisplayBinding\ExternalProcessDisplayBinding.cs" />
<Compile Include="Src\Services\DisplayBinding\ISecondaryDisplayBinding.cs" />
<Compile Include="Src\Services\DisplayBinding\ShellExecuteDisplayBinding.cs" />
<Compile Include="Src\Services\FileIconService.cs" />
<Compile Include="Src\Services\File\FileChangeWatcher.cs" />
<Compile Include="Src\Services\File\OpenedFile.cs" />
<Compile Include="Src\Services\File\RecentOpen.cs" />

61
src/Main/Base/Project/Src/Services/FileIconService.cs

@ -0,0 +1,61 @@ @@ -0,0 +1,61 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using ICSharpCode.Core;
using System;
using System.Collections.Generic;
using System.Drawing;
namespace ICSharpCode.SharpDevelop
{
/// <summary>
/// This Class contains a ResourceManager, which handles bitmap resources
/// for the application which were loaded from the filesystem.
/// </summary>
public static class FileIconService
{
static Dictionary<string, Bitmap> bitmapCache = new Dictionary<string, Bitmap>();
static FileIconService()
{
ResourceService.ClearCaches += ResourceService_ClearCaches;
}
static void ResourceService_ClearCaches(object sender, EventArgs e)
{
lock (bitmapCache) {
bitmapCache.Clear();
}
}
/// <summary>
/// Returns a bitmap from the file system. Paceholders like ${SharpDevelopBinPath}
/// and AddinPath (e. g. ${AddInPath:ICSharpCode.FiletypeRegisterer}) are resolved
/// through the StringParser.
/// The bitmaps are reused, you must not dispose the Bitmap!
/// </summary>
/// <returns>
/// The bitmap loaded from the file system.
/// </returns>
/// <param name="name">
/// The name of the requested bitmap (prefix, path and filename).
/// </param>
/// <exception cref="FileNotFoundException">
/// Is thrown when the bitmap was not found in the file system.
/// </exception>
public static Bitmap GetBitmap(string name)
{
Bitmap bmp = null;
if (name.ToUpper().StartsWith("FILE:")) {
lock (bitmapCache) {
if (bitmapCache.TryGetValue(name, out bmp))
return bmp;
bmp = (Bitmap)Image.FromFile(StringParser.Parse(name.Substring(5,name.Length-5)));
bitmapCache[name] = bmp;
}
}
return bmp;
}
}
}

27
src/Main/Base/Project/Src/Services/IconService.cs

@ -60,18 +60,21 @@ namespace ICSharpCode.SharpDevelop @@ -60,18 +60,21 @@ namespace ICSharpCode.SharpDevelop
public static Bitmap GetBitmap(string name)
{
Bitmap bmp;
try {
bmp = WinFormsResourceService.GetBitmap(name);
} catch (ResourceNotFoundException ex) {
LoggingService.Warn(ex);
bmp = null;
}
if (bmp != null) {
return bmp;
}
return WinFormsResourceService.GetBitmap("Icons.16x16.MiscFiles");
Bitmap bmp = null;
try {
bmp = FileIconService.GetBitmap(name);
if (bmp == null) {
bmp = WinFormsResourceService.GetBitmap(name);
}
} catch (ResourceNotFoundException ex) {
LoggingService.Warn(ex);
} catch (FileNotFoundException ex) {
LoggingService.Warn(ex);
}
if (bmp != null) {
return bmp;
}
return WinFormsResourceService.GetBitmap("Icons.16x16.MiscFiles");
}
public static Icon GetIcon(string name)

Loading…
Cancel
Save