public bool CanEntryBeAssignedToKey(KeyCode keyCode, EventModifiers eventModifier, ShortcutEntry entry) { if (!m_BindingValidator.IsBindingValid(keyCode)) { return(false); } var keycombination = KeyCombination.FromKeyboardInput(keyCode, eventModifier); List <ShortcutEntry> entries; if (m_KeyBindingRootToBoundEntries.TryGetValue(keycombination, out entries)) { foreach (var boundEntry in entries) { if (IsGlobalContext(entry)) { return(false); } if (boundEntry.context.IsAssignableFrom(entry.context) || entry.context.IsAssignableFrom(boundEntry.context)) { return(false); } } } return(true); }
void PopulateShortcutsBoundToSelectedKey() { m_ShortcutsBoundToSelectedKey.Clear(); var keycombination = KeyCombination.FromKeyboardInput(m_SerializedState.selectedKey, m_SerializedState.selectedModifiers); List <ShortcutEntry> entries; if (m_KeyBindingRootToBoundEntries.TryGetValue(keycombination, out entries)) { m_ShortcutsBoundToSelectedKey.AddRange(entries); } }
public IList <ShortcutEntry> GetShortcutsBoundTo(KeyCode keyCode, EventModifiers modifiers) { var keyCombination = KeyCombination.FromKeyboardInput(keyCode, modifiers); List <ShortcutEntry> entries; if (m_KeyBindingRootToBoundEntries.TryGetValue(keyCombination, out entries)) { return(entries); } return(null); }
public void DragEntryAndDropIntoKey(KeyCode keyCode, EventModifiers eventModifier, ShortcutEntry entry) { if (!CanEntryBeAssignedToKey(keyCode, eventModifier, entry)) { throw new InvalidOperationException("This would create a conflict"); } var keyCombination = new List <KeyCombination>(); keyCombination.Add(KeyCombination.FromKeyboardInput(keyCode, eventModifier)); RebindEntry(entry, keyCombination); }
public BindingState GetBindingStateForKeyWithModifiers(KeyCode keyCode, EventModifiers modifiers) { var keycombination = KeyCombination.FromKeyboardInput(keyCode, modifiers); List <ShortcutEntry> entries; if (m_KeyBindingRootToBoundEntries.TryGetValue(keycombination, out entries)) { foreach (var entry in entries) { if (IsGlobalContext(entry)) { return(BindingState.BoundGlobally); } } return(BindingState.BoundToContext); } return(BindingState.NotBound); }
public BindingState GetBindingStateForKeyWithModifiers(KeyCode keyCode, EventModifiers modifiers) { var keycombination = KeyCombination.FromKeyboardInput(keyCode, modifiers); List <ShortcutEntry> entries; bool foundEntries = m_KeyBindingRootToBoundEntries.TryGetValue(keycombination, out entries); if (Application.platform != RuntimePlatform.OSXEditor && (keycombination.modifiers & ShortcutModifiers.Action) != 0) { var altkeycombination = new KeyCombination(keycombination.keyCode, (keycombination.modifiers & ~ShortcutModifiers.Action) | ShortcutModifiers.Control); if (m_KeyBindingRootToBoundEntries.TryGetValue(altkeycombination, out List <ShortcutEntry> additionalEntries)) { foundEntries = true; if (entries == null) { entries = new List <ShortcutEntry>(); } entries.AddRange(additionalEntries); } } if (foundEntries) { var state = BindingState.NotBound; foreach (var entry in entries) { state |= IsGlobalContext(entry) ? BindingState.BoundGlobally : BindingState.BoundToContext; } return(state); } return(BindingState.NotBound); }
public void HandleKeyEvent(Event evt, IContextManager contextManager) { if (evt == null || !evt.isKey || evt.keyCode == KeyCode.None) { return; } if (evt.type == EventType.KeyUp) { KeyValuePair <ShortcutEntry, object> clutchKeyValuePair; if (m_ActiveClutches.TryGetValue(evt.keyCode, out clutchKeyValuePair)) { var clutchContext = m_ActiveClutches[evt.keyCode].Value; m_ActiveClutches.Remove(evt.keyCode); var args = new ShortcutArguments { context = clutchContext, state = ShortcutState.End }; invokingAction?.Invoke(clutchKeyValuePair.Key, args); clutchKeyValuePair.Key.action(args); } return; } // Use the event and return if the key is currently used in an active clutch if (m_ActiveClutches.ContainsKey(evt.keyCode)) { evt.Use(); return; } var keyCodeCombination = KeyCombination.FromKeyboardInput(evt); m_KeyCombinationSequence.Add(keyCodeCombination); // Ignore event if sequence is empty if (m_KeyCombinationSequence.Count == 0) { return; } m_Directory.FindShortcutEntries(m_KeyCombinationSequence, contextManager, m_Entries); IEnumerable <ShortcutEntry> entries = m_Entries; // Deal ONLY with prioritycontext if (entries.Count() > 1 && contextManager.HasAnyPriorityContext()) { m_CurrentContextManager = contextManager; entries = m_Entries.FindAll(CurrentContextManagerHasPriorityContextFor); if (!entries.Any()) { entries = m_Entries; } } switch (entries.Count()) { case 0: Reset(); break; case 1: var shortcutEntry = entries.Single(); if (ShortcutFullyMatchesKeyCombination(shortcutEntry)) { if (evt.keyCode != m_KeyCombinationSequence.Last().keyCode) { break; } var args = new ShortcutArguments(); args.context = contextManager.GetContextInstanceOfType(shortcutEntry.context); switch (shortcutEntry.type) { case ShortcutType.Action: args.state = ShortcutState.End; invokingAction?.Invoke(shortcutEntry, args); shortcutEntry.action(args); evt.Use(); Reset(); break; case ShortcutType.Clutch: if (!m_ActiveClutches.ContainsKey(evt.keyCode)) { m_ActiveClutches.Add(evt.keyCode, new KeyValuePair <ShortcutEntry, object>(shortcutEntry, args.context)); args.state = ShortcutState.Begin; invokingAction?.Invoke(shortcutEntry, args); shortcutEntry.action(args); evt.Use(); Reset(); } break; case ShortcutType.Menu: args.state = ShortcutState.End; invokingAction?.Invoke(shortcutEntry, args); shortcutEntry.action(args); evt.Use(); Reset(); break; } } break; default: if (HasConflicts(entries, m_KeyCombinationSequence)) { m_ConflictResolver.ResolveConflict(m_KeyCombinationSequence, entries); evt.Use(); Reset(); } break; } }