using System; using System.Globalization; using System.Windows.Data; using MPF.Frontend; using MPF.Frontend.ComboBoxItems; using SabreTools.RedumpLib.Data; using RedumperReadMethod = MPF.ExecutionContexts.Redumper.ReadMethod; using RedumperSectorOrder = MPF.ExecutionContexts.Redumper.SectorOrder; namespace MPF.UI { internal class ElementConverter: IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return value switch { DiscCategory discCategory => new Element(discCategory), InternalProgram internalProgram => new Element(internalProgram), MediaType mediaType => new Element(mediaType), RedumperReadMethod readMethod => new Element(readMethod), RedumperSectorOrder sectorOrder => new Element(sectorOrder), RedumpSystem redumpSystem => new RedumpSystemComboBoxItem(redumpSystem), Region region => new Element(region), // Null values are treated as a system value _ => new RedumpSystemComboBoxItem((RedumpSystem?)null), }; } public object? ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { // If it's an IElement but ends up null if (value is not IElement element) return null; return element switch { Element dcElement => dcElement.Value, Element ipElement => ipElement.Value, Element mtElement => mtElement.Value, Element rmElement => rmElement.Value, Element soElement => soElement.Value, RedumpSystemComboBoxItem rsElement => rsElement.Value, Element reValue => reValue.Value, _ => null, }; } } }