public int CompareTo(object obj) { ChordModifier chordModifier = obj as ChordModifier; if (chordModifier == null && obj is Keys) { chordModifier = ChordModifier.GetModifiers(new ChordModifier(), (Keys)obj); } if (chordModifier == null) { return(1); } if (this.AltModifier == chordModifier.AltModifier) { if (this.ControlModifier == chordModifier.ControlModifier) { if (this.ShiftModifier == chordModifier.ShiftModifier) { return(0); } return(this.ShiftModifier ? 1 : -1); } return(this.ControlModifier ? 1 : -1); } return(this.AltModifier ? 1 : -1); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, System.Type destinationType) { if (destinationType == null) { throw new ArgumentNullException("Destination Type is not defined."); } if (destinationType != typeof(string)) { return(base.ConvertTo(context, culture, value, destinationType)); } if (value == null) { return(null); } if ((value is ChordModifier) || (value is Keys)) { ChordModifier valueToConvert = null; if (value is Keys) { valueToConvert = ChordModifier.GetModifiers((Keys)value); } else { valueToConvert = value as ChordModifier; } if (valueToConvert.IsEmpty) { return(null); } //string[] keys = null; List <string> keysList = new List <string>(1); foreach (string key in ChordConverter.KeyMaps.Keys) { if ((valueToConvert.AltModifier && Keys.Menu == (Keys)ChordConverter.KeyMaps[key]) || (valueToConvert.ControlModifier && Keys.ControlKey == (Keys)ChordConverter.KeyMaps[key]) || (valueToConvert.ShiftModifier && Keys.ShiftKey == (Keys)ChordConverter.KeyMaps[key])) { keysList.Add(key.ToString()); } } if (keysList.Count > 0) { return(string.Join(ChordConverter.separator, keysList.ToArray())); } return(null); } return(base.ConvertTo(context, culture, value, destinationType)); }
public override object ConvertTo( ITypeDescriptorContext context, CultureInfo culture, object value, System.Type destinationType) { if ((object)destinationType == null) { throw new ArgumentNullException("Destination Type is not defined."); } if ((object)destinationType != (object)typeof(string)) { return(base.ConvertTo(context, culture, value, destinationType)); } if (value == null) { return((object)null); } if (!(value is ChordModifier) && !(value is Keys)) { return(base.ConvertTo(context, culture, value, destinationType)); } ChordModifier chordModifier = !(value is Keys) ? value as ChordModifier : ChordModifier.GetModifiers((Keys)value); if (chordModifier.IsEmpty) { return((object)null); } List <string> stringList = new List <string>(1); foreach (string key in (IEnumerable)ChordConverter.KeyMaps.Keys) { if (chordModifier.AltModifier && Keys.Menu == (Keys)ChordConverter.KeyMaps[(object)key] || chordModifier.ControlModifier && Keys.ControlKey == (Keys)ChordConverter.KeyMaps[(object)key] || chordModifier.ShiftModifier && Keys.ShiftKey == (Keys)ChordConverter.KeyMaps[(object)key]) { stringList.Add(key.ToString()); } } if (stringList.Count > 0) { return((object)string.Join(ChordConverter.separator, stringList.ToArray())); } return((object)null); }
public ChordModifier(Keys pressedKey) { ChordModifier.GetModifiers(this, pressedKey); }
public static ChordModifier GetModifiers(Keys pressedKey) { return(ChordModifier.GetModifiers(new ChordModifier(), pressedKey)); }