Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 60e9787

Browse files
committed
Support templates that use icons from files.
1 parent dcbfca2 commit 60e9787

5 files changed

Lines changed: 75 additions & 3 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@
305305
<Compile Include="Templates\ProjectTemplateResult.cs" />
306306
<Compile Include="Templates\TemplateBase.cs" />
307307
<Compile Include="Templates\TemplateCategory.cs" />
308+
<Compile Include="Templates\TemplateIconLoader.cs" />
308309
<Compile Include="Templates\TemplateLoadException.cs" />
309310
<Compile Include="Templates\TextTemplate.cs" />
310311
<Compile Include="Util\AtomicBoolean.cs" />

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static class FileIconService
4949
public static Bitmap GetBitmap(string name)
5050
{
5151
Bitmap bmp = null;
52-
if (name.ToUpper().StartsWith("FILE:")) {
52+
if (IsFileImage(name)) {
5353
lock (bitmapCache) {
5454
if (bitmapCache.TryGetValue(name, out bmp))
5555
return bmp;
@@ -60,5 +60,10 @@ public static Bitmap GetBitmap(string name)
6060
}
6161
return bmp;
6262
}
63+
64+
public static bool IsFileImage(string name)
65+
{
66+
return name.StartsWith("file:", StringComparison.OrdinalIgnoreCase);
67+
}
6368
}
6469
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
// software and associated documentation files (the "Software"), to deal in the Software
5+
// without restriction, including without limitation the rights to use, copy, modify, merge,
6+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7+
// to whom the Software is furnished to do so, subject to the following conditions:
8+
//
9+
// The above copyright notice and this permission notice shall be included in all copies or
10+
// substantial portions of the Software.
11+
//
12+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17+
// DEALINGS IN THE SOFTWARE.
18+
19+
using System;
20+
using System.Drawing;
21+
using System.Windows.Media;
22+
23+
namespace ICSharpCode.SharpDevelop.Templates
24+
{
25+
public static class TemplateIconLoader
26+
{
27+
public static IImage GetImage(string iconName)
28+
{
29+
IImage image = GetFileImage(iconName);
30+
if (image != null) {
31+
return image;
32+
}
33+
return SD.ResourceService.GetImage(iconName);
34+
}
35+
36+
static IImage GetFileImage(string iconName)
37+
{
38+
if (FileIconService.IsFileImage(iconName)) {
39+
return new FileImage(iconName);
40+
}
41+
return null;
42+
}
43+
}
44+
45+
public class FileImage : IImage
46+
{
47+
string name;
48+
49+
public FileImage(string name)
50+
{
51+
this.name = name;
52+
}
53+
54+
public ImageSource ImageSource {
55+
get { return null; }
56+
}
57+
58+
public Bitmap Bitmap {
59+
get { return FileIconService.GetBitmap(name); }
60+
}
61+
62+
public Icon Icon {
63+
get { return null; }
64+
}
65+
}
66+
}

src/Main/SharpDevelop/Templates/File/FileTemplateImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public FileTemplateImpl(XmlDocument doc, IReadOnlyFileSystem fileSystem)
240240

241241
XmlElement config = doc.DocumentElement["Config"];
242242
name = config.GetAttribute("name");
243-
icon = SD.ResourceService.GetImage(config.GetAttribute("icon"));
243+
icon = TemplateIconLoader.GetImage(config.GetAttribute("icon"));
244244
category = config.GetAttribute("category");
245245
defaultName = config.GetAttribute("defaultname");
246246
languagename = config.GetAttribute("language");

src/Main/SharpDevelop/Templates/Project/ProjectTemplateImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public ProjectTemplateImpl(XmlDocument doc, IReadOnlyFileSystem fileSystem)
174174
}
175175

176176
if (config["Icon"] != null) {
177-
icon = SD.ResourceService.GetImage(config["Icon"].InnerText);
177+
icon = TemplateIconLoader.GetImage(config["Icon"].InnerText);
178178
}
179179

180180
if (config["SupportedTargetFrameworks"] != null) {

0 commit comments

Comments
 (0)