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";
|
|
|
|
|
|
2014-08-31 11:41:24 +00:00
|
|
|
|
// Is a file?
|
|
|
|
|
if (File.Exists(item.StoragePath))
|
|
|
|
|
{
|
|
|
|
|
if (String.IsNullOrEmpty(Path.GetExtension(item.StoragePath)))
|
|
|
|
|
key += "Unknown";
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
key += "_" + Path.GetExtension(item.StoragePath).Substring(1);
|
|
|
|
|
}
|
2014-07-27 13:21:06 +00:00
|
|
|
|
|
2014-08-31 11:41:24 +00:00
|
|
|
|
// Not a file, try to figure out if a directory
|
|
|
|
|
else if (item.Count > 0 || Directory.Exists(item.StoragePath))
|
|
|
|
|
{
|
|
|
|
|
key += "Directory";
|
|
|
|
|
}
|
2014-07-27 13:21:06 +00:00
|
|
|
|
|
2014-08-31 11:41:24 +00:00
|
|
|
|
// None
|
2014-07-27 13:21:06 +00:00
|
|
|
|
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-08-30 07:24:01 +00:00
|
|
|
|
if (value is Reference)
|
2014-07-27 13:21:06 +00:00
|
|
|
|
{
|
2014-08-30 07:24:01 +00:00
|
|
|
|
return IconProvider.GetProjectItemIcon((Reference)value);
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|