Exemple #1
0
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            var str = value as string;

            if (String.IsNullOrEmpty(str))
            {
                return(NotValid(Tobi_Plugin_Settings_Lang.ValueNotEmpty));
            }

            KeyGesture val = KeyGestureStringConverter.Convert(str);

            if (val == null)
            {
                return(NotValid(Tobi_Plugin_Settings_Lang.InvalidKeyboardShortcut));
            }

            var currentSetting = (SettingWrapper)DataContextSpy.DataContext;

            string strSettingsAlreadyUsingKeyG = "";

            foreach (var aggregatedSetting in ((SettingsView)DataContextBridge.DataContext).AggregatedSettings)
            {
                if (currentSetting == aggregatedSetting)
                {
                    continue;
                }

                if (aggregatedSetting.ValueType == typeof(KeyGestureString))
                {
                    var keyG = (KeyGesture)aggregatedSetting.Value;

                    if (keyG != null && val.Key == keyG.Key)
                    {
                        if (val.Modifiers.Equals(keyG.Modifiers))
                        {
                            strSettingsAlreadyUsingKeyG += aggregatedSetting.Name;
                            strSettingsAlreadyUsingKeyG += " ";
                        }
                    }
                }
            }
            if (!string.IsNullOrEmpty(strSettingsAlreadyUsingKeyG))
            {
                return(NotValid(String.Format(Tobi_Plugin_Settings_Lang.ShortcutAlreadyUsed, strSettingsAlreadyUsingKeyG)));
            }

            return(Valid());
        }
Exemple #2
0
 public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(KeyGestureStringConverter.Convert((string)value));
 }