Esempio n. 1
0
        private static string[] getSuggestions(string commandLine, IList <string> tokens)
        {
            Iterator <string> iter = new Iterator <string>(tokens);

            CCommand cmd = CRegistery.FindCommand(iter.Next());

            if (cmd == null)
            {
                return(EMPTY_SUGGESTIONS); // no command found
            }

            while (iter.HasNext())
            {
                string token   = iter.Next();
                int    iterPos = iter.Position; // store position to revert for the case if option skip fails

                // first try to parse options
                if (token.StartsWith("--")) // long option
                {
                    string optionName = token.Substring(2);
                    if (SkipOption(iter, cmd, optionName))
                    {
                        continue;
                    }

                    iter.Position = iterPos;
                    return(getSuggestedOptions(iter, cmd, optionName, "--"));
                }
                else if (token.StartsWith("-") && !StringUtils.IsNumeric(token)) // short option
                {
                    string optionName = token.Substring(1);
                    if (SkipOption(iter, cmd, optionName))
                    {
                        continue;
                    }

                    iter.Position = iterPos;
                    return(getSuggestedOptions(iter, cmd, optionName, "-"));
                }

                if (iter.HasNext())
                {
                    return(EMPTY_SUGGESTIONS); // TODO: add multiple args suggestion support
                }

                return(getSuggestedArgs(commandLine, cmd, token));
            }

            return(getSuggestedArgs(commandLine, cmd, ""));
        }
Esempio n. 2
0
        bool Execute(string command)
        {
            CCommand cmd = CRegistery.FindCommand(command);

            if (cmd == null)
            {
                PrintError("{0}: command not found \"{1}\"", this.Name, command);
                return(false);
            }

            cmd.Delegate = this.Delegate;
            cmd.PrintUsage(true);
            cmd.Delegate = null;

            return(true);
        }
Esempio n. 3
0
        bool Execute(string stroke, string command = null) // TODO: refactor me!
        {
            string name = stroke.ToLower();

            if (!string.IsNullOrEmpty(command))
            {
                CShortCut shortCut;
                if (!CShortCut.TryParse(stroke, out shortCut))
                {
                    PrintError("Invalid shortcut: {0}", name);
                    return(false);
                }

                string keyUpCommand = null;

                char keyDownOp = command[0];
                if (keyDownOp == '+' || keyDownOp == '-')
                {
                    if (command.Length == 1)
                    {
                        PrintError("Identifier expected!");
                        return(false);
                    }

                    string identifier = command.Substring(1);

                    // register operation command
                    CCommand keyDownCmd = CRegistery.FindCommand(command);
                    if (keyDownCmd == null)
                    {
                        keyDownCmd = new COperationCommand(keyDownOp, identifier);
                        CRegistery.Register(keyDownCmd);
                        keyDownCmd.SetFlag(CCommandFlags.System, true);
                    }

                    // register opposite operation command
                    char keyUpOp = OppositeOperation(keyDownOp);
                    keyUpCommand = keyUpOp + identifier;
                    CCommand keyUpCmd = CRegistery.FindCommand(keyUpCommand);
                    if (keyUpCmd == null)
                    {
                        keyUpCmd = new COperationCommand(keyUpOp, identifier);
                        CRegistery.Register(keyUpCmd);
                        keyUpCmd.SetFlag(CCommandFlags.System, true);
                    }
                }

                CBindings.Bind(shortCut, StringUtils.UnArg(command), keyUpCommand != null ? StringUtils.UnArg(keyUpCommand) : null);

                PostNotification(
                    CCommandNotifications.CBindingsChanged,
                    CCommandNotifications.KeyManualMode, this.IsManualMode
                    );

                return(true);
            }

            IList <CBinding> bindings = CBindings.List(name);

            if (bindings.Count > 0)
            {
                foreach (CBinding b in bindings)
                {
                    PrintIndent(ToString(b));
                }
            }
            else
            {
                PrintIndent("No bindings");
            }

            return(true);
        }