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.StoragePath)) key += "Directory"; else if (File.Exists(item.StoragePath)) key += "_" + Path.GetExtension(item.StoragePath).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) { if (value is Reference) { return IconProvider.GetProjectItemIcon((Reference)value); } return null; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotSupportedException(); } } }