| | 1 | | using PropertyGridHelpers.Attributes; |
| | 2 | | using PropertyGridHelpers.Converters; |
| | 3 | | using System; |
| | 4 | | using System.ComponentModel; |
| | 5 | | using System.Drawing.Design; |
| | 6 | |
|
| | 7 | | namespace PropertyGridHelpers.UIEditors |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// A generic <see cref="UITypeEditor" /> that displays an enumeration with both images and localized text in a drop |
| | 11 | | /// </summary> |
| | 12 | | /// <typeparam name="TEnum">The enumeration type to be edited. This must be a value type constrained to an <see cref |
| | 13 | | /// <remarks> |
| | 14 | | /// This class extends <see cref="ImageTextUIEditor" /> and uses the specified generic enum type <typeparamref name= |
| | 15 | | /// to simplify application and enforce type safety. It supports localized display names |
| | 16 | | /// via <see cref="LocalizedEnumTextAttribute" /> and image rendering via <see cref="EnumImageAttribute" />. |
| | 17 | | /// <para> |
| | 18 | | /// This editor is useful for properties where both textual meaning and visual context help the user choose the corr |
| | 19 | | /// </para> |
| | 20 | | /// </remarks> |
| | 21 | | /// <example> |
| | 22 | | /// To use this editor for an enum named <c>ButtonStyle</c>, define your enum with attributes: |
| | 23 | | /// <code> |
| | 24 | | /// public enum ButtonStyle |
| | 25 | | /// { |
| | 26 | | /// [EnumText("Flat"), EnumImage("FlatIcon")] |
| | 27 | | /// Flat, |
| | 28 | | /// [EnumText("Raised"), EnumImage("RaisedIcon")] |
| | 29 | | /// Raised, |
| | 30 | | /// [EnumText("3D"), EnumImage("ThreeDIcon")] |
| | 31 | | /// ThreeD |
| | 32 | | /// } |
| | 33 | | /// </code> |
| | 34 | | /// Then apply the editor to your property: |
| | 35 | | /// <code> |
| | 36 | | /// [Editor(typeof(ImageTextUIEditor<ButtonStyle>), typeof(UITypeEditor))] |
| | 37 | | /// public ButtonStyle Style { get; set; } |
| | 38 | | /// </code></example> |
| | 39 | | /// <seealso cref="ImageTextUIEditor" /> |
| | 40 | | /// <seealso cref="EnumImageAttribute" /> |
| | 41 | | /// <seealso cref="LocalizedEnumTextAttribute" /> |
| | 42 | | /// <seealso cref="EnumTextConverter" /> |
| | 43 | | #if NET35 |
| | 44 | | public partial class ImageTextUIEditor<TEnum> : |
| | 45 | | ImageTextUIEditor |
| | 46 | | where TEnum : struct |
| | 47 | | { |
| | 48 | | /// <summary> |
| | 49 | | /// Initializes the <see cref="ImageTextUIEditor{TEnum}"/> class. |
| | 50 | | /// </summary> |
| | 51 | | /// <exception cref="ArgumentException">T must be an enumerated type</exception> |
| | 52 | | static ImageTextUIEditor() |
| | 53 | | { |
| | 54 | | if (!typeof(TEnum).IsEnum) |
| | 55 | | throw new ArgumentException("TEnum must be an enumerated type"); |
| | 56 | | } |
| | 57 | |
|
| | 58 | | /// <summary> |
| | 59 | | /// Initializes a new instance of the <see cref="ImageTextUIEditor" /> class. |
| | 60 | | /// </summary> |
| | 61 | | public ImageTextUIEditor() : base(typeof(TEnum)) { } |
| | 62 | |
|
| | 63 | | /// <summary> |
| | 64 | | /// Initializes a new instance of the <see cref="ImageTextUIEditor" /> class. |
| | 65 | | /// </summary> |
| | 66 | | /// <param name="ResourcePath">The path to the resources where the images are stored</param> |
| | 67 | | public ImageTextUIEditor(string ResourcePath) : base(typeof(TEnum), ResourcePath) {} |
| | 68 | | } |
| | 69 | | #else |
| | 70 | | public partial class ImageTextUIEditor<TEnum> |
| | 71 | | : ImageTextUIEditor |
| | 72 | | where TEnum : struct, Enum |
| | 73 | | { |
| | 74 | | /// <summary> |
| | 75 | | /// Initializes a new instance of the <see cref="ImageTextUIEditor" /> class. |
| | 76 | | /// </summary> |
| 12 | 77 | | public ImageTextUIEditor() : base(typeof(TEnum)) { } |
| | 78 | |
|
| | 79 | | /// <summary> |
| | 80 | | /// Initializes a new instance of the <see cref="ImageTextUIEditor" /> class. |
| | 81 | | /// </summary> |
| | 82 | | /// <param name="ResourcePath">The path to the resources where the images are stored</param> |
| 12 | 83 | | public ImageTextUIEditor(string ResourcePath) : base(typeof(TEnum), ResourcePath) { } |
| | 84 | | } |
| | 85 | | #endif |
| | 86 | | } |