using System; namespace Terminal.Gui.Views; /// /// Provides a user interface for displaying and selecting non-mutually-exclusive flags in a type-safe way. /// provides a non-type-safe version. TFlagsEnum must be a valid enum type with /// the '[Flags]' attribute. /// public sealed class FlagSelector : FlagSelector where TFlagsEnum : struct, Enum { /// /// Initializes a new instance of the class. /// public FlagSelector () { SetValuesAndLabels (); } /// /// Gets or sets the value of the selected flags. /// public new TFlagsEnum? Value { get => base.Value.HasValue ? (TFlagsEnum)Enum.ToObject (typeof (TFlagsEnum), base.Value.Value) : (TFlagsEnum?)null; set => base.Value = value.HasValue ? Convert.ToInt32 (value.Value) : (int?)null; } /// /// Raised when has changed. Provides the new value as ?. /// public new event EventHandler>? ValueChanged; /// /// Called when has changed. Raises the generic event. /// protected override void OnValueChanged (int? value, int? previousValue) { base.OnValueChanged (value, previousValue); TFlagsEnum? newValue = value.HasValue ? (TFlagsEnum)Enum.ToObject (typeof (TFlagsEnum), value.Value) : null; ValueChanged?.Invoke (this, new EventArgs (newValue)); } }