private CurrentCommandsContainer GetChordCombinations(ModifierKeys modifierKeys, Key key) { // Filter command infos by specific modifier keys and key // And find in them only chord combinations Debug.Assert(modifierKeys != ModifierKeys.None, "modifierKeys != ModifierKeys.None"); var commandsSet = new CurrentCommandsContainer(this.packageSettings); foreach (var scope in this.commandScopeService.GetCurrentScopes()) { foreach (var commandInfo in this.commandInfos.Filter(modifierKeys, scope, key)) { CommandBinding commandBinding = commandInfo.CommandBinding; if (commandBinding.KeyCombinations.Length == 1) { return(null); } commandsSet.Add(commandInfo.Name, commandBinding.Scope, commandBinding.KeyCombinations[1]); } } return(commandsSet); }
private CurrentCommandsContainer GetCombinations(ModifierKeys modifierKeys) { // Get combinations for pressed modifier keys if (modifierKeys == ModifierKeys.None) { return(null); } var currentCommandsSet = new CurrentCommandsContainer(this.packageSettings); foreach (var scope in this.commandScopeService.GetCurrentScopes()) { foreach (var commandInfo in this.commandInfos.Filter(modifierKeys, scope)) { CommandBinding commandBinding = commandInfo.CommandBinding; if (commandBinding.KeyCombinations.Length == 1) { currentCommandsSet.Add(commandInfo.Name, commandBinding.Scope, commandBinding.KeyCombinations[0]); } else { currentCommandsSet.AddChordCandidate(commandBinding.KeyCombinations[0]); } } } return(currentCommandsSet); }
void ICommandsInfoWindow.SetCombinations(CurrentCommandsContainer commandsContainer) { this.Dispatcher.Invoke( DispatcherPriority.DataBind, new Action( () => { IList <KeyCombination> chordCombinations = null; IList <CommandViewModel> commands = null; if (commandsContainer != null) { chordCombinations = commandsContainer.GetChordCombinations(); commands = commandsContainer.GetCommands(); } if (chordCombinations != null && chordCombinations.Count > 0) { this.chordKeys.Text = string.Join(", ", chordCombinations); this.chordKeysPanel.Visibility = Visibility.Visible; } else { this.chordKeys.Text = null; this.chordKeysPanel.Visibility = Visibility.Collapsed; } this.commandsPanel.Commands = commands; this.IsOpen = (commands != null && commands.Count > 0) || (chordCombinations != null && chordCombinations.Count > 0); })); }
private void HandleKeyDown(RawKeyEventArgs args) { lock (this.locker) { var isModifierKeys = KeyExtensions.IsModifierKeys(args.Key); var modifierKeys = Keyboard.Modifiers; // If current key down is modifier key and if we are not in chord sequence // we need to find all chord combinations and possible commands for current modifer keys if (isModifierKeys && !this.inChordSequence) { var fNewModifiersCombination = this.modifiersCombination != modifierKeys; if (fNewModifiersCombination) { this.combinationStart = DateTime.Now; this.modifiersCombination = modifierKeys; } if ((this.window.IsOpen && fNewModifiersCombination) || (this.combinationStart.HasValue && (DateTime.Now - this.combinationStart.Value).TotalMilliseconds >= this.keyModifiersCombinationDelay)) { this.combinationStart = null; this.window.SetCombinations(this.GetCombinations(modifierKeys)); } } else if (!isModifierKeys && modifierKeys != ModifierKeys.None && !this.inChordSequence) { this.DisposeTimer(); CurrentCommandsContainer chordCommands = this.GetChordCombinations(modifierKeys, args.Key); this.inChordSequence = chordCommands != null && chordCommands.HasCommands(); if (this.inChordSequence && !this.window.IsOpen && this.chordCombinationDelay > 0) { this.showChordKeyTimer = new Timer( (state) => { lock (this.locker) { if (this.showChordKeyTimer != null) { this.DisposeTimer(); this.window.SetCombinations(chordCommands); } } }, null, this.chordCombinationDelay, Timeout.Infinite); } else { this.window.SetCombinations(chordCommands); } } else if (!isModifierKeys && (modifierKeys == ModifierKeys.None || this.inChordSequence)) { this.inChordSequence = false; this.DisposeTimer(); // If this is not a modifier keys and user doesn't press any of modifier keys now // or if this is second combination of chord key we need to hide window if it is open. if (this.window.IsOpen) { this.window.SetCombinations(null); } } } }