/// <summary> /// Fetch all shortcut bindings from DTE Commands /// </summary> /// <returns></returns> public async Task <IEnumerable <Command> > GetAllCommandsAsync() { List <Command> result = new List <Command>(); // Initialize the commandIdToCTMCommandMap if (this.commandIdToCTMCommandMap.Count == 0) { await this.PopulateCTMCommandsAsync(); } // Initialize the foreach (EnvDTE.Command c in this.DTECommands) { List <CommandBinding> bindings = new List <CommandBinding>(); if (c.Bindings != null && c.Bindings is object[] && ((object[])c.Bindings).Length > 0) { object[] bindingsObj = (object[])c.Bindings; foreach (string s in bindingsObj) { CommandBinding commandBinding = ParseBindingFromString(new Guid(c.Guid), c.ID, s); if (commandBinding == null) { // Something went wrong with parsing (ie. Scope = "Unknown Editor") Skip this command. continue; } bindings.Add(commandBinding); } } CommandId commandId = new CommandId(Guid.Parse(c.Guid), c.ID); string displayName = GetDisplayTextFromCTMCommand(commandId); string canonicalName = c.Name; result.Add(new Command(commandId, displayName, canonicalName, bindings)); } return(result); }
private static void AddCommandBindingToBindingMap(Dictionary <string, IEnumerable <Tuple <CommandBinding, Command> > > bindingMap, Command command, CommandBinding binding, string key) { // Add the command/binding tuple to the relevant key in the binding map. IEnumerable <Tuple <CommandBinding, Command> > commandsForKey; if (!bindingMap.TryGetValue(key, out commandsForKey)) { // Create new entry for the key if none exists. commandsForKey = new List <Tuple <CommandBinding, Command> >(); bindingMap[key] = commandsForKey; } ((List <Tuple <CommandBinding, Command> >)commandsForKey).Add(new Tuple <CommandBinding, Command>(binding, command)); }