public void SetUp()
        {
            base.RunSetUp();

            CRegistery.Register(new Cmd_playmode(delegate {
                AddResult("executed");
            }));
        }
Ejemplo n.º 2
0
        protected void RegisterCommand(Type type, bool hidden = true)
        {
            CCommand command = CClassUtils.CreateInstance <CCommand>(type);

            if (command == null)
            {
                throw new ArgumentException("Can't create class instance: " + type.FullName);
            }

            String commandName = type.Name;

            if (commandName.StartsWith("Cmd_"))
            {
                commandName = commandName.Substring("Cmd_".Length);
            }

            command.Name     = commandName;
            command.IsHidden = hidden;
            CRuntimeResolver.ResolveOptions(command);

            CRegistery.Register(command);
        }
Ejemplo n.º 3
0
 private static void Register(CVar cvar)
 {
     CRegistery.Register(cvar);
 }
Ejemplo n.º 4
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);
        }