2014-07-27 13:21:06 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
using System.Windows.Media;
|
2014-08-15 12:31:33 +00:00
|
|
|
|
using RainmeterStudio.Business;
|
2014-08-12 13:33:13 +00:00
|
|
|
|
using RainmeterStudio.Core.Model;
|
2014-07-27 13:21:06 +00:00
|
|
|
|
|
|
|
|
|
namespace RainmeterStudio.UI.Controller
|
|
|
|
|
{
|
2014-08-14 07:06:20 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides icons
|
|
|
|
|
/// </summary>
|
2014-07-27 13:21:06 +00:00
|
|
|
|
public static class IconProvider
|
|
|
|
|
{
|
2014-08-14 07:06:20 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets an icon by resource name
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="key">Resource name</param>
|
|
|
|
|
/// <returns>The icon</returns>
|
2014-07-27 13:21:06 +00:00
|
|
|
|
public static ImageSource GetIcon(string key)
|
|
|
|
|
{
|
2014-08-14 07:06:20 +00:00
|
|
|
|
return ResourceProvider.GetImage(key);
|
2014-07-27 13:21:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-14 07:06:20 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets an icon by reference
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The reference</param>
|
|
|
|
|
/// <returns>The icon</returns>
|
2014-07-27 13:21:06 +00:00
|
|
|
|
public static ImageSource GetProjectItemIcon(Reference item)
|
|
|
|
|
{
|
|
|
|
|
// Resource name
|
|
|
|
|
string key = "ProjectItem";
|
|
|
|
|
|
|
|
|
|
if (Directory.Exists(item.Path))
|
|
|
|
|
key += "Directory";
|
|
|
|
|
|
|
|
|
|
else if (File.Exists(item.Path))
|
|
|
|
|
key += "_" + Path.GetExtension(item.Path).Substring(1);
|
|
|
|
|
|
|
|
|
|
else key += "None";
|
|
|
|
|
|
|
|
|
|
// Get icon
|
|
|
|
|
var icon = GetIcon(key);
|
|
|
|
|
if (icon == null)
|
|
|
|
|
return GetIcon("ProjectItemUnknown");
|
|
|
|
|
return icon;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-14 07:06:20 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Icon provider converter, for use in xaml
|
|
|
|
|
/// </summary>
|
2014-07-27 13:21:06 +00:00
|
|
|
|
public class IconProviderConverter : IValueConverter
|
|
|
|
|
{
|
|
|
|
|
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|
|
|
|
{
|
2014-07-28 17:18:18 +00:00
|
|
|
|
var reference = value as Reference;
|
|
|
|
|
if (reference != null)
|
2014-07-27 13:21:06 +00:00
|
|
|
|
{
|
2014-07-28 17:18:18 +00:00
|
|
|
|
return IconProvider.GetProjectItemIcon(reference);
|
2014-07-27 13:21:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|