using System;
using System.IO;
using System.Windows.Data;
using System.Windows.Media;
using RainmeterStudio.Business;
using RainmeterStudio.Core.Model;
namespace RainmeterStudio.UI.Controller
{
///
/// Provides icons
///
public static class IconProvider
{
///
/// Gets an icon by resource name
///
/// Resource name
/// The icon
public static ImageSource GetIcon(string key)
{
return ResourceProvider.GetImage(key);
}
///
/// Gets an icon by reference
///
/// The reference
/// The icon
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;
}
}
///
/// Icon provider converter, for use in xaml
///
public class IconProviderConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var reference = value as Reference;
if (reference != null)
{
return IconProvider.GetProjectItemIcon(reference);
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
}