private static string GenerateBindingSequenceText(BindingSequence bindingSequence) { if (bindingSequence.Modifiers == System.Windows.Input.ModifierKeys.None) { return(bindingSequence.Key); } var buffer = new System.Text.StringBuilder(); if (bindingSequence.Modifiers.HasFlag(System.Windows.Input.ModifierKeys.Windows)) { buffer.Append("Windows+"); } if (bindingSequence.Modifiers.HasFlag(System.Windows.Input.ModifierKeys.Control)) { buffer.Append("Ctrl+"); } if (bindingSequence.Modifiers.HasFlag(System.Windows.Input.ModifierKeys.Shift)) { buffer.Append("Shift+"); } if (bindingSequence.Modifiers.HasFlag(System.Windows.Input.ModifierKeys.Alt)) { buffer.Append("Alt+"); } buffer.Append(bindingSequence.Key); string s = buffer.ToString(); return(s); }
internal CommandBinding(CommandId command, KeybindingScope scope, BindingSequence sequence) { this.Command = command; this.Scope = scope; this.Chords = new List<BindingSequence>() { sequence }; }
private bool SameBindingSequence(BindingSequence bindingSeq1, BindingSequence bindingSeq2) { if (bindingSeq1 == null) return bindingSeq2 == null; if (bindingSeq2 == null) return false; return bindingSeq1.Modifiers == bindingSeq2.Modifiers && bindingSeq1.Key == bindingSeq2.Key; }
private async void RefreshShortcuts() { var modifierKey = GetSelectedModifierKey(); VSShortcutQueryEngine engine = new VSShortcutQueryEngine(ServiceProvider); var selectedscope = (Scope)cmbScopeList.SelectedItem; Guid scopeGuid = Guid.Parse(selectedscope.ID); // Get Guid Scope BindingSequence bindingSequence = BindingSequence.Empty; // TODO: This is if there is a Chord, otherwise BindingSequence.EMPTY const bool includeGlobals = true; IDictionary <string, IEnumerable <Tuple <CommandBinding, Command> > > bindingsMap = await engine.GetBindingsForModifiersAsync(scopeGuid, ModifierKeys.None, bindingSequence, includeGlobals); }
private string GetLocalizedShortcutKey(BindingSequence bindingSequence) { // Localize modifiers string localizedModifiers = GetLocalizedModifiersText(bindingSequence.Modifiers); // Localize key string localizedKey = GetLocalizedKeyText(bindingSequence); // Return the combination return(localizedModifiers + localizedKey); }
private bool SameBindingSequence(BindingSequence bindingSeq1, BindingSequence bindingSeq2) { if (bindingSeq1 == null) { return(bindingSeq2 == null); } if (bindingSeq2 == null) { return(false); } return(bindingSeq1.Modifiers == bindingSeq2.Modifiers && bindingSeq1.Key == bindingSeq2.Key); }
private string GetLocalizedKeyText(BindingSequence bindingSequence) { Key keyObj = (Key)Enum.Parse(typeof(Key), bindingSequence.Key); // TODO: Handle parse errors // First, try to get the localized key from the LocalizedKeyMap // LocalizedKeyMap contains non-alphanumeric/punc chars (ie. F1-F24,Home,Ins,Period,Comma,UpArrow,NumPad0-9) if (LocalizedKeyMap.ContainsKey(keyObj)) { return(LocalizedKeyMap[keyObj]); } // Otherwise, pull it from ToUnicode // ToUniCode can return regular alphanumberic/punctuation chars (ie. [A-Z][0-9](`-=[]\;',./)) return(KeycharUtil.GetCharFromKey(keyObj).ToString()); }
public IDictionary <string, IEnumerable <Tuple <CommandBinding, Command> > > GetBindingsForModifiers(Guid scope, ModifierKeys modifiers, BindingSequence chordStart, bool includeGlobals) { IEnumerable <Command> allCommands = AllCommands; var bindingMap = new Dictionary <string, IEnumerable <Tuple <CommandBinding, Command> > >(); foreach (Command command in allCommands) { // Each command can have zero-many bindings. We'll look at each binding to see if it should be returned (matching scope and modifier) foreach (CommandBinding binding in command.Bindings) { // Ensure the binding is in the desired scope (or Global if includeGlobals is true) if (!VSShortcutQueryEngine.ScopeMatches(scope, binding.Scope.Guid) && !(VSShortcutQueryEngine.ScopeIsGlobal(binding.Scope.Guid) && includeGlobals)) { continue; } // If the user passed in a starting chord (chordStart is not empty), only return this binding if it is a chord and starts with the chordStart if (chordStart != BindingSequence.Empty && (binding.Sequences.Count < 2 || !VSShortcutQueryEngine.SameBindingSequence(binding.Sequences[0], chordStart))) { continue; } // Does the binding have the right modifiers? Two cases: chordStart is empty / chordStart is not empty BindingSequence sequenceOfInterest = (chordStart != BindingSequence.Empty) ? binding.Sequences[1] : binding.Sequences[0]; if (sequenceOfInterest.Modifiers != modifiers) { continue; } // Found a command with matching modifiers for the given scope (with matching starting chord). // Add it to the relevant entry in the dictionary. VSShortcutQueryEngine.AddCommandBindingToBindingMap(bindingMap, command, binding, sequenceOfInterest.Key); } } return(bindingMap); }
private async void RefreshShortcuts() { try { var modifierKeys = GetSelectedModifierKeys(); VSShortcutQueryEngine engine = new VSShortcutQueryEngine(ServiceProvider); var selectedscope = (Scope)cmbScopeList.SelectedItem; Guid scopeGuid = (selectedscope != null) ? Guid.Parse(selectedscope.ID) : Guid.Empty; BindingSequence bindingSequence = BindingSequence.Empty; // TODO: This is if there is a Chord, otherwise BindingSequence.EMPTY const bool includeGlobals = true; IDictionary <string, IEnumerable <Tuple <CommandBinding, Command> > > matchingShortcuts = await engine.GetBindingsForModifiersAsync(scopeGuid, modifierKeys, bindingSequence, includeGlobals); foreach (var matchingShortcut in matchingShortcuts) { var key = matchingShortcut.Key; var commandBindings = matchingShortcut.Value; var commandString = String.Join(",", commandBindings.Select(commandBinding => commandBinding.Item2.DisplayName)); UpdateShortcutValue(key, commandString); } } catch (Exception ex) { } }
private async void RefreshShortcuts() { try { //Reset the old commands to blank before assigning new commands viewModel.ResetShortCutKeystoDefaultValue(); // Get all the user parameter input from the UI Guid scopeGuid = GetSelectedScope(); ModifierKeys modifierKeys = GetSelectedModifierKeys(); BindingSequence startingChord = GetStartingChord(); bool includeGlobals = GetIsIncludedGlobals(); // Get the map of matching shortcut for this scope and modifier keys from the Query Engine IDictionary <string, IEnumerable <Tuple <CommandBinding, Command> > > matchingShortcuts = GetBindingsForModifiers(scopeGuid, modifierKeys, startingChord, includeGlobals); // Note: This method will affect the model in the view, which in turn will reflect on the UI through bindings. UpdateCommandsInViewModel(matchingShortcuts); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception occurred: " + ex.Message, ex); } }
private async void RefreshShortcuts() { try { //Reset the old commands to blank before assigning new commands viewModel.ResetShortCutKeystoDefaultValue(); var modifierKeys = GetSelectedModifierKeys(); VSShortcutQueryEngine engine = new VSShortcutQueryEngine(ServiceProvider); var selectedscope = (Scope)cmbScopeList.SelectedItem; Guid scopeGuid = (selectedscope != null) ? Guid.Parse(selectedscope.ID) : Guid.Empty; BindingSequence bindingSequence = BindingSequence.Empty; // TODO: This is if there is a Chord, otherwise BindingSequence.EMPTY const bool includeGlobals = true; IDictionary <string, IEnumerable <Tuple <CommandBinding, Command> > > matchingShortcuts = await engine.GetBindingsForModifiersAsync(scopeGuid, modifierKeys, bindingSequence, includeGlobals); foreach (var matchingShortcut in matchingShortcuts) { string key = matchingShortcut.Key; IEnumerable <Tuple <CommandBinding, Command> > commandBindings = matchingShortcut.Value; int? sequenceCountofFirstCommandBinding = commandBindings.FirstOrDefault()?.Item1.Sequences.Count; string commandString = ""; if (sequenceCountofFirstCommandBinding == 1) { commandString = commandBindings.FirstOrDefault().Item2.DisplayName; } else if (sequenceCountofFirstCommandBinding > 1) { commandString = "<Chord>"; } UpdateShortcutValue(key, commandString); } } catch (Exception ex) { } }
internal CommandBinding(CommandId command, KeybindingScope scope, BindingSequence sequence1, BindingSequence sequence2) : this(command, scope, sequence1) { ((List<BindingSequence>)this.Chords).Add(sequence2); }