private void Emit(List <KeyMock> keys) { var mainKey = keys.Where(key => key.KeyModifier == KeyModifier.None).Last(); var keyModifier = keys .Where(key => key.KeyModifier != KeyModifier.None) .Select(key => key.KeyModifier) .Aggregate((k1, k2) => k1 | k2); var shortcut = new ShortcutMock(mainKey, keyModifier); var name = mainKey.Name; if (RegisteredShortcuts.ContainsKey(name)) { var registeredShortcutsForKey = RegisteredShortcuts[name]; if (registeredShortcutsForKey != null) { if (registeredShortcutsForKey.ContainsKey(keyModifier)) { var registeredShortcut = registeredShortcutsForKey[keyModifier]; if (registeredShortcut != null) { shortcut = registeredShortcut.Shortcut; if (registeredShortcut.Operation != null) { registeredShortcut.Operation.Action(); } } } } } OnEmit?.Invoke(shortcut); }
public IRegisteredShortcut RegisterShortcut(IShortcut iShortcut, IOperation operation) { if (OnRegisterShortcut == null) { if (iShortcut is ShortcutMock shortcut) { if (!RegisteredShortcuts.ContainsKey(shortcut.Key.Name)) { RegisteredShortcuts[shortcut.Key.Name] = new Dictionary <KeyModifier, RegisteredShortcutMock>(); } if (!RegisteredShortcuts[shortcut.Key.Name].ContainsKey(shortcut.KeyModifier)) { var registeredShortcut = new RegisteredShortcutMock(shortcut, operation); RegisteredShortcuts[shortcut.Key.Name][shortcut.KeyModifier] = registeredShortcut; return(registeredShortcut); } return(null); } throw new NotImplementedException(); } else { return(OnRegisterShortcut(iShortcut, operation)); } }
public void UnregisterShortcut(IRegisteredShortcut registeredShortcut) { if (OnUnregisterShortcut == null) { var shortcut = registeredShortcut.Shortcut; var key = shortcut.Key; var keyModifier = shortcut.KeyModifier; var name = key.Name; if (RegisteredShortcuts.ContainsKey(name)) { var registeredShortcutsForName = RegisteredShortcuts[name]; if (registeredShortcutsForName.ContainsKey(keyModifier)) { if (registeredShortcutsForName[keyModifier] == registeredShortcut) { registeredShortcutsForName.Remove(keyModifier); } if (registeredShortcutsForName.Count == 0) { RegisteredShortcuts.Remove(name); } } } } else { OnUnregisterShortcut(registeredShortcut); } }