67 lines
2.1 KiB
C#
67 lines
2.1 KiB
C#
|
using ANX.Framework.Content.Pipeline.Tasks;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel;
|
|||
|
using System.Globalization;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
|
|||
|
namespace ANX.ContentCompiler.GUI.Converters
|
|||
|
{
|
|||
|
class ImporterConverter : StringConverter
|
|||
|
{
|
|||
|
private ImporterManager importerManager = new ImporterManager();
|
|||
|
|
|||
|
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
|||
|
{
|
|||
|
if (sourceType == typeof(string))
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
return base.CanConvertFrom(context, sourceType);
|
|||
|
}
|
|||
|
|
|||
|
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
|
|||
|
{
|
|||
|
return base.CanConvertTo(context, destinationType);
|
|||
|
}
|
|||
|
|
|||
|
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
|||
|
{
|
|||
|
//From real name to display name.
|
|||
|
if (value is string)
|
|||
|
{
|
|||
|
return importerManager.GetImporterDisplayName((string)value);
|
|||
|
}
|
|||
|
|
|||
|
return base.ConvertTo(context, culture, value, destinationType);
|
|||
|
}
|
|||
|
|
|||
|
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
|||
|
{
|
|||
|
//From display name to real name.
|
|||
|
if (value is string)
|
|||
|
{
|
|||
|
return importerManager.GetImporterName((string)value);
|
|||
|
}
|
|||
|
|
|||
|
return base.ConvertFrom(context, culture, value);
|
|||
|
}
|
|||
|
|
|||
|
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
|
|||
|
{
|
|||
|
return new StandardValuesCollection(importerManager.AvailableImporters.Select((x) => x.Key).ToArray());
|
|||
|
}
|
|||
|
}
|
|||
|
}
|