public CommandMethod SelectCommand(string str, ICommandTable commandTable, out object[] extra)
        {
            var tokens = Tokenizer.Tokenize(str).ToArray();
            var index  = tokens.Length;

            while (index > -1)
            {
                //get the command string
                string cmd;
                if (index == 0)
                {
                    //check the root/default route
                    cmd = "";
                }
                else
                {
                    cmd = string.Join(" ", tokens.Take(index));
                }

                if (commandTable.TryGetValue(cmd, out var method))
                {
                    extra = tokens.Skip(index).ToArray();
                    return(method);
                }

                --index;
            }

            extra = null;
            return(null);
        }
Example #2
0
        protected override async Task <object> InitializeToolWindowAsync(Type toolWindowType, int id, CancellationToken cancellationToken)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync();

            var dte = await GetServiceAsync(typeof(DTE)) as DTE2;

            Assumes.Present(dte);

            var dto         = new CommandTableExplorerDTO();
            var dteCommands = new List <EnvDTE.Command>();

            foreach (EnvDTE.Command command in dte.Commands)
            {
                if (!string.IsNullOrEmpty(command.Name))
                {
                    dteCommands.Add(command);
                }
            }

            dto.DTE         = dte;
            dto.DteCommands = dteCommands.OrderBy(c => c.Name).ToList();

            var           factory = new CommandTableFactory();
            ICommandTable table   = factory.CreateCommandTableFromHost(this, HostLoadType.FromRegisteredMenuDlls);

            dto.CommandTable = await table.GetCommands();

            return(dto);
        }
Example #3
0
        private async Task PopulateCTMCommandsAsync()
        {
            CommandTableFactory factory = new CommandTableFactory();
            ICommandTable commandTable = factory.CreateCommandTableFromHost(serviceProvider, CommandTable.HostLoadType.FromCTM);

            IEnumerable<CommandTable.Command> commands = await commandTable.GetCommands();
            foreach (var command in commands)
            {
                commandIdToCTMCommandMap[new CommandId(command.ItemId.Guid, (int)command.ItemId.DWord)] = command;
            }
        }
Example #4
0
 public CommandRunner(ICommandTable commandTable, ICommandSelector commandSelector, ParameterBinder parameterBinder)
 {
     _commandTable    = commandTable;
     _commandSelector = commandSelector;
     _parameterBinder = parameterBinder;
 }