private void VerifyHotkeysValidityAgainst(GenericHotkeyProxy hotkeyProxy, ModifierKeys?previousModifiers, HotkeyType?previousType, object previousActivator) { var hotkeys = this.settingsViewModel.Hotkeys; foreach (var hp in hotkeys) { if (hp == hotkeyProxy) { continue; } if (hp.IsAlreadyInUseBy(previousModifiers ?? hotkeyProxy.Hotkey.Modifiers, previousType ?? hotkeyProxy.Type, previousActivator ?? hotkeyProxy.GetActivator())) { if (!this.settingsViewModel.CheckIfHotkeyIsAlreadyInUse(hp)) { hp.Hotkey.SetIsValid(true, null); } } } }
private void UpdateHotkeyActivator(GenericHotkeyProxy hotkeyProxy, HotkeyType newHotkeyType, object newActivator, string text) { this.TxtSingleKey.Text = text; // This should be called before changing the hotkey type; otherwise, it will return the Key/MouseAction // used by the previous *keyboard/mouse hotkey* instead of the activator used by the previous *generic hotkey*. // This doesn't make any difference if we are not changing hotkey type. object previousActivator = hotkeyProxy.GetActivator(); HotkeyType previousType = hotkeyProxy.Type; hotkeyProxy.Type = newHotkeyType; hotkeyProxy.SetActivator(newActivator); if (!previousActivator.Equals(hotkeyProxy.GetActivator())) { // Check every hotkey's validity again in case one of them has been set to use // the same activator this hotkey was previously using. this.VerifyHotkeysValidityAgainst(hotkeyProxy, null, previousType, previousActivator); } }
public bool CheckIfHotkeyIsAlreadyInUse(GenericHotkeyProxy hotkeyProxy) { int i = 0; bool alreadyInUse = false; while (i < this.Hotkeys.Count && !alreadyInUse) { GenericHotkeyProxy genericHotkeyProxy = this.Hotkeys[i++]; if (genericHotkeyProxy == hotkeyProxy) { continue; } if (hotkeyProxy.IsAlreadyInUseBy(genericHotkeyProxy)) { hotkeyProxy.Hotkey.SetIsValid(false, $"Hotkey already in use by \"{genericHotkeyProxy.Hotkey.HumanReadableAction}\""); alreadyInUse = true; } } return(alreadyInUse); }