示例#1
0
        /// <summary>
        /// Private constructor that does the real work.
        /// </summary>
        /// <param name="key">Key</param>
        /// <param name="modifiers">Modifiers</param>
        /// <param name="displayString">display string</param>
        /// <param name="validateGesture">If true, throws an exception if the key and modifier are not valid</param>
        private KeyGesture(Key key, ModifierKeys modifiers, string displayString, bool validateGesture)
        {
            if (!ModifierKeysConverter.IsDefinedModifierKeys(modifiers))
            {
                throw new InvalidEnumArgumentException("modifiers", (int)modifiers, typeof(ModifierKeys));
            }

            if (!IsDefinedKey(key))
            {
                throw new InvalidEnumArgumentException("key", (int)key, typeof(Key));
            }

            if (displayString == null)
            {
                throw new ArgumentNullException("displayString");
            }

            if (validateGesture && !IsValid(key, modifiers))
            {
                throw new NotSupportedException(SR.Get(SRID.KeyGesture_Invalid, modifiers, key));
            }

            _modifiers     = modifiers;
            _key           = key;
            _displayString = displayString;
        }
示例#2
0
        /// <summary>
        /// CanConvertToString()
        /// </summary>
        /// <param name="value"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        /// <ExternalAPI/>
        public override bool CanConvertToString(object value, IValueSerializerContext context)
        {
            KeyGesture keyGesture = value as KeyGesture;

            #pragma warning disable 6506
            return((keyGesture != null) &&
                   ModifierKeysConverter.IsDefinedModifierKeys(keyGesture.Modifiers) &&
                   KeyGestureConverter.IsDefinedKey(keyGesture.Key));

            #pragma warning restore 6506
        }
        /// <summary>
        /// CanConvertToString()
        /// </summary>
        /// <param name="value"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        /// <ExternalAPI/>
        public override bool CanConvertToString(object value, IValueSerializerContext context)
        {
            bool         result       = false;
            MouseGesture mouseGesture = value as MouseGesture;

            if (mouseGesture != null)
            {
                if (ModifierKeysConverter.IsDefinedModifierKeys(mouseGesture.Modifiers) &&
                    MouseActionConverter.IsDefinedMouseAction(mouseGesture.MouseAction))
                {
                    result = true;
                }
            }

            return(result);
        }
示例#4
0
        /// <summary>
        ///  Constructor
        /// </summary>
        /// <param name="mouseAction">Mouse Action</param>
        /// <param name="modifiers">Modifiers</param>
        public MouseGesture(MouseAction mouseAction, ModifierKeys modifiers)   // acclerator action
        {
            if (!MouseGesture.IsDefinedMouseAction(mouseAction))
            {
                throw new InvalidEnumArgumentException("mouseAction", (int)mouseAction, typeof(MouseAction));
            }

            if (!ModifierKeysConverter.IsDefinedModifierKeys(modifiers))
            {
                throw new InvalidEnumArgumentException("modifiers", (int)modifiers, typeof(ModifierKeys));
            }

            _modifiers   = modifiers;
            _mouseAction = mouseAction;

            //AttachClassListeners();
        }
示例#5
0
 ///<summary>
 ///TypeConverter method override.
 ///</summary>
 ///<param name="context">ITypeDescriptorContext</param>
 ///<param name="destinationType">Type to convert to</param>
 ///<returns>true if conversion	is possible</returns>
 public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
 {
     // We can convert to an InstanceDescriptor or to a string.
     if (destinationType == typeof(string))
     {
         // When invoked by the serialization engine we can convert to string only for known type
         if (context != null && context.Instance != null)
         {
             KeyGesture keyGesture = context.Instance as KeyGesture;
             if (keyGesture != null)
             {
                 return(ModifierKeysConverter.IsDefinedModifierKeys(keyGesture.Modifiers) &&
                        IsDefinedKey(keyGesture.Key));
             }
         }
     }
     return(false);
 }
 /// <summary>
 /// CanConvertToString()
 /// </summary>
 /// <param name="value"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 /// <ExternalAPI/>
 public override bool CanConvertToString(object value, IValueSerializerContext context)
 {
     return((value is ModifierKeys) && ModifierKeysConverter.IsDefinedModifierKeys((ModifierKeys)value));
 }