diff --git a/MPF/ComboBoxItems/CategoryComboBoxItem.cs b/MPF/ComboBoxItems/CategoryComboBoxItem.cs deleted file mode 100644 index 492d2455..00000000 --- a/MPF/ComboBoxItems/CategoryComboBoxItem.cs +++ /dev/null @@ -1,29 +0,0 @@ -using MPF.Utilities; -using MPF.Web; - -namespace MPF -{ - /// - /// Represents a single item in the Category combo box - /// - public class CategoryComboBoxItem - { - private object data; - - public CategoryComboBoxItem(DiscCategory? category) => data = category; - - public static implicit operator DiscCategory? (CategoryComboBoxItem item) => item.data as DiscCategory?; - - public string Name - { - get { return (data as DiscCategory?).LongName(); } - } - - public bool IsChecked { get; set; } - - public DiscCategory? Value - { - get { return data as DiscCategory?; } - } - } -} diff --git a/MPF/ComboBoxItems/Element.cs b/MPF/ComboBoxItems/Element.cs new file mode 100644 index 00000000..5ae6bce9 --- /dev/null +++ b/MPF/ComboBoxItems/Element.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; + +namespace MPF +{ + /// + /// A generic combo box element + /// + /// Enum type representing the possible values + public class Element : IElement where T : struct, Enum + { + private readonly T Data; + + public Element(T data) + { + Data = data; + } + + /// + /// Allow elements to be used as their internal enum type + /// + /// + public static implicit operator T? (Element item) => item.Data; + + /// + /// Display name for the combo box element + /// + public string Name => new EnumDescriptionConverter().Convert(Data, null, null, CultureInfo.CurrentCulture) as string; + + /// + /// Internal enum value + /// + public T Value => Data; + + /// + /// Determine if the item is selected or not + /// + /// Only applies to CheckBox type + public bool IsChecked { get; set; } + + + /// + /// Generate all elements assocaited with the data enum type + /// + /// + public static IEnumerable> GenerateElements() + { + return Enum.GetValues(typeof(T)) + .OfType() + .Select(e => new Element(e)); + } + } +} diff --git a/MPF/ComboBoxItems/IElement.cs b/MPF/ComboBoxItems/IElement.cs new file mode 100644 index 00000000..ce19f4b5 --- /dev/null +++ b/MPF/ComboBoxItems/IElement.cs @@ -0,0 +1,7 @@ +namespace MPF +{ + public interface IElement + { + string Name { get; } + } +} diff --git a/MPF/ComboBoxItems/InternalProgramComboBoxItem.cs b/MPF/ComboBoxItems/InternalProgramComboBoxItem.cs deleted file mode 100644 index 9998ce31..00000000 --- a/MPF/ComboBoxItems/InternalProgramComboBoxItem.cs +++ /dev/null @@ -1,30 +0,0 @@ -using MPF.Data; -using MPF.Utilities; - -namespace MPF -{ - /// - /// Represents a single item in the Internal Program combo box - /// - public class InternalProgramComboBoxItem - { - private object data; - - public InternalProgramComboBoxItem(InternalProgram? internalProgram) => data = internalProgram; - - public static implicit operator InternalProgram? (InternalProgramComboBoxItem item) => item.data as InternalProgram?; - - public string Name - { - get - { - return (data as InternalProgram?).LongName(); - } - } - - public InternalProgram? Value - { - get { return data as InternalProgram?; } - } - } -} diff --git a/MPF/ComboBoxItems/KnownSystemComboBoxItem.cs b/MPF/ComboBoxItems/KnownSystemComboBoxItem.cs index e3307ee9..1e18f063 100644 --- a/MPF/ComboBoxItems/KnownSystemComboBoxItem.cs +++ b/MPF/ComboBoxItems/KnownSystemComboBoxItem.cs @@ -7,7 +7,7 @@ namespace MPF /// /// Represents a single item in the System combo box /// - public class KnownSystemComboBoxItem + public class KnownSystemComboBoxItem : IElement { private object data; diff --git a/MPF/ComboBoxItems/LanguageComboBoxItem.cs b/MPF/ComboBoxItems/LanguageComboBoxItem.cs deleted file mode 100644 index 913e3916..00000000 --- a/MPF/ComboBoxItems/LanguageComboBoxItem.cs +++ /dev/null @@ -1,29 +0,0 @@ -using MPF.Utilities; -using MPF.Web; - -namespace MPF -{ - /// - /// Represents a single item in the Language combo box - /// - public class LanguageComboBoxItem - { - private object data; - - public LanguageComboBoxItem(Language? region) => data = region; - - public static implicit operator Language? (LanguageComboBoxItem item) => item.data as Language?; - - public string Name - { - get { return (data as Language?).LongName(); } - } - - public bool IsChecked { get; set; } - - public Language? Value - { - get { return data as Language?; } - } - } -} diff --git a/MPF/ComboBoxItems/MediaTypeComboBoxItem.cs b/MPF/ComboBoxItems/MediaTypeComboBoxItem.cs deleted file mode 100644 index b0a6cd73..00000000 --- a/MPF/ComboBoxItems/MediaTypeComboBoxItem.cs +++ /dev/null @@ -1,20 +0,0 @@ -using MPF.Data; -using MPF.Utilities; - -namespace MPF -{ - /// - /// Represents a single item in the MediaType combo box - /// - public class MediaTypeComboBoxItem - { - private MediaType? data; - - public MediaTypeComboBoxItem(MediaType? mediaType) => data = mediaType; - - public static implicit operator MediaType? (MediaTypeComboBoxItem item) => item.data; - - public string Name { get { return data.LongName(); } - } - } -} diff --git a/MPF/ComboBoxItems/RegionComboBoxItem.cs b/MPF/ComboBoxItems/RegionComboBoxItem.cs deleted file mode 100644 index 9fa78ee0..00000000 --- a/MPF/ComboBoxItems/RegionComboBoxItem.cs +++ /dev/null @@ -1,30 +0,0 @@ -using MPF.Utilities; -using MPF.Web; - -namespace MPF -{ - /// - /// Represents a single item in the Region combo box - /// - public class RegionComboBoxItem - { - private object data; - - public RegionComboBoxItem(Region? region) => data = region; - - public static implicit operator Region? (RegionComboBoxItem item) => item.data as Region?; - - public string Name - { - get - { - return (data as Region?).LongName(); - } - } - - public Region? Value - { - get { return data as Region?; } - } - } -} diff --git a/MPF/Windows/DiscInformationWindow.xaml.cs b/MPF/Windows/DiscInformationWindow.xaml.cs index 84c9963b..b7aa0e98 100644 --- a/MPF/Windows/DiscInformationWindow.xaml.cs +++ b/MPF/Windows/DiscInformationWindow.xaml.cs @@ -17,7 +17,7 @@ namespace MPF.Windows /// /// List of available disc categories /// - public List Categories { get; private set; } = GenerateComboBoxItems().ToList(); + public List> Categories { get; private set; } = Element.GenerateElements().ToList(); /// /// SubmissionInfo object to fill and save @@ -27,12 +27,12 @@ namespace MPF.Windows /// /// List of available regions /// - public List Regions { get; private set; } = GenerateComboBoxItems().ToList(); + public List> Regions { get; private set; } = Element.GenerateElements().ToList(); /// /// List of available languages /// - public List Languages { get; private set; } = GenerateComboBoxItems().ToList(); + public List> Languages { get; private set; } = Element.GenerateElements().ToList(); #endregion @@ -45,20 +45,6 @@ namespace MPF.Windows ManipulateFields(); } - /// - /// Generate a set of combo box items for a given set of types - /// - /// Base enum value to create combo box items for - /// Combo box wrapper type for the base enum value - /// IEnumerable representing the generated combo box items - private static IEnumerable GenerateComboBoxItems() - { - return Enum.GetValues(typeof(T)) - .OfType() - .Select(e => Activator.CreateInstance(typeof(K), e)) - .OfType(); - } - /// /// Manipulate fields based on the current disc /// @@ -242,8 +228,8 @@ namespace MPF.Windows SubmissionInfo.CommonDiscInfo.ForeignTitleNonLatin = ForeignTitle.Text ?? ""; SubmissionInfo.CommonDiscInfo.DiscNumberLetter = DiscNumberLetter.Text ?? ""; SubmissionInfo.CommonDiscInfo.DiscTitle = DiscTitle.Text ?? ""; - SubmissionInfo.CommonDiscInfo.Category = (CategoryComboBox.SelectedItem as CategoryComboBoxItem)?.Value ?? DiscCategory.Games; - SubmissionInfo.CommonDiscInfo.Region = (RegionComboBox.SelectedItem as RegionComboBoxItem)?.Value ?? Region.World; + SubmissionInfo.CommonDiscInfo.Category = (CategoryComboBox.SelectedItem as Element)?.Value ?? DiscCategory.Games; + SubmissionInfo.CommonDiscInfo.Region = (RegionComboBox.SelectedItem as Element)?.Value ?? Region.World; var languages = new List(); foreach (var language in Languages) { diff --git a/MPF/Windows/OptionsWindow.xaml.cs b/MPF/Windows/OptionsWindow.xaml.cs index 99a6870c..97f2b54a 100644 --- a/MPF/Windows/OptionsWindow.xaml.cs +++ b/MPF/Windows/OptionsWindow.xaml.cs @@ -26,7 +26,7 @@ namespace MPF.Windows /// /// List of available internal programs /// - public List InternalPrograms { get; private set; } + public List> InternalPrograms { get; private set; } #endregion @@ -65,10 +65,10 @@ namespace MPF.Windows { // We only support certain programs for dumping var internalPrograms = new List { InternalProgram.DiscImageCreator, InternalProgram.Aaru, InternalProgram.DD }; - InternalPrograms = new List(); + InternalPrograms = new List>(); foreach (var internalProgram in internalPrograms) { - InternalPrograms.Add(new InternalProgramComboBoxItem(internalProgram)); + InternalPrograms.Add(new Element(internalProgram)); } InternalProgramComboBox.ItemsSource = InternalPrograms; @@ -155,7 +155,7 @@ namespace MPF.Windows private void OnAcceptClick(object sender, EventArgs e) { // Handle non-bindable fields - UIOptions.Options.InternalProgram = (InternalProgramComboBox.SelectedItem as InternalProgramComboBoxItem)?.Name ?? InternalProgram.DiscImageCreator.ToString(); + UIOptions.Options.InternalProgram = (InternalProgramComboBox.SelectedItem as Element)?.Name ?? InternalProgram.DiscImageCreator.ToString(); UIOptions.Options.Password = RedumpPasswordBox.Password; UIOptions.Save();