コード例 #1
0
ファイル: CBindings.cs プロジェクト: tonymtz/super-unity-bros
        public override string ToString()
        {
            StringBuilder result = new StringBuilder();

            if (this.IsCommand)
            {
                result.Append("cmd+");
            }
            if (this.IsControl)
            {
                result.Append("ctrl+");
            }
            if (this.IsAlt)
            {
                result.Append("alt+");
            }
            if (this.IsShift)
            {
                result.Append("shift+");
            }

            result.Append(CBindings.KeyName(this.key));

            return(result.ToString());
        }
コード例 #2
0
 void Execute()
 {
     if (CBindings.Count > 0)
     {
         CBindings.Clear();
         PostNotification();
     }
 }
コード例 #3
0
        void Execute(string prefix = null)
        {
            IList <CBinding> bindings = CBindings.List(prefix);

            foreach (CBinding b in bindings)
            {
                PrintIndent("bind {0} {1}", b.shortCut.ToString(), StringUtils.Arg(b.cmdKeyDown));
            }
        }
コード例 #4
0
        private static IList <string> ListBindings()
        {
            IList <CBinding> bindings = CBindings.List();

            IList <string> entries = new List <string>(bindings.Count);

            foreach (CBinding binding in bindings)
            {
                entries.Add(string.Format("bind {0} {1}", binding.shortCut.ToString(), StringUtils.Arg(binding.cmdKeyDown)));
            }

            return(entries);
        }
コード例 #5
0
ファイル: CBindings.cs プロジェクト: tonymtz/super-unity-bros
        public static IList <string> ListShortCuts(string prefix = null) // TODO: unit tests
        {
            IList <CBinding> bindings = CBindings.List(prefix);

            string[] shortcuts = new string[bindings.Count];

            int index = 0;

            foreach (CBinding b in bindings)
            {
                shortcuts[index++] = b.shortCut.ToString();
            }

            return(shortcuts);
        }
コード例 #6
0
        void Execute(string prefix)
        {
            if (CBindings.Count > 0)
            {
                IList <CBinding> bindings = CBindings.List(prefix);
                if (bindings.Count > 0)
                {
                    foreach (CBinding binding in bindings)
                    {
                        CBindings.Unbind(binding.shortCut);
                    }

                    PostNotification();
                }
            }
        }
コード例 #7
0
ファイル: CBindings.cs プロジェクト: tonymtz/super-unity-bros
        public static bool TryParse(string token, out CShortCut shortCut)
        {
            string[] tokens = token.Split('+');

            CModifiers modifiers = 0;

            if (tokens.Length > 1)
            {
                for (int i = 0; i < tokens.Length - 1; ++i)
                {
                    string name = tokens[i].ToLower();
                    if (name == "ctrl")
                    {
                        modifiers |= CModifiers.Control;
                    }
                    else if (name == "shift")
                    {
                        modifiers |= CModifiers.Shift;
                    }
                    else if (name == "alt")
                    {
                        modifiers |= CModifiers.Alt;
                    }
                    else if (name == "cmd" || name == "command")
                    {
                        modifiers |= CModifiers.Command;
                    }
                    else
                    {
                        shortCut = default(CShortCut);
                        return(false);
                    }
                }
            }

            string  keyName = tokens[tokens.Length - 1].ToLower();
            KeyCode key;

            if (!CBindings.TryParse(keyName, out key))
            {
                shortCut = default(CShortCut);
                return(false);
            }

            shortCut = new CShortCut(key, modifiers);
            return(true);
        }
コード例 #8
0
        bool Execute(string key)
        {
            string token = key.ToLower();

            CShortCut shortCut;

            if (!CShortCut.TryParse(token, out shortCut))
            {
                PrintError("Invalid shortcut: {0}", token);
                return(false);
            }

            CBindings.Unbind(shortCut); // TODO: unbind 'operation' commands

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

            return(true);
        }
コード例 #9
0
 internal static IList <string> AutoCompleteArgs(string token)
 {
     return(CBindings.ListShortCuts(token));
 }
コード例 #10
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);
        }