Example #1
0
        public static IEnumerable <Action <PadEditor> > ResolveMacro(Mode mode, string macro)
        {
            List <Action <PadEditor> > keys = new List <Action <PadEditor> >();

            macro = macro.Substring(0);

            while (macro.Length > 0)
            {
                if (Char.IsDigit(macro[0]))
                {
                    string digits = new String(macro.TakeWhile(c => Char.IsDigit(c)).ToArray());

                    macro = macro.Substring(digits.Length);
                    keys.Add(new Action <PadEditor>(pe =>
                                                    pe.AddToCount(digits)));
                }
                else
                {
                    EditGesture gesture = ResolveKeyName(ref macro);

                    if (mode.Gestures.ContainsKey(gesture))
                    {
                        keys.Add(mode.Gestures[gesture]);
                    }
                    else
                    {
                        throw new Exception("Key not found: " + gesture.ToString());
                    }
                }
            }

            return(keys);
        }
Example #2
0
        public static EditGesture ResolveKeyName(ref string keys)
        {
            EditGesture gesture = new EditGesture();
            Key keyValue;
            string key;

            if(keys.StartsWith("^")) {
                gesture.Mods = ModifierKeys.Control;
                keys = keys.Substring(1);
            }

            if(keys.Length < 1)
                throw new Exception("key string is empty");

            if(keys.StartsWith("<")){
                int end = keys.IndexOf('>');

                if(end == -1)
                    throw new Exception("Open < not closed in map");

                key = keys.Substring(1, end - 1);
                keys.Substring(key.Length + 2);
            }
            else{
                key = keys.Substring(0, 1);
                keys = keys.Substring(1);
            }

            if(!Enum.TryParse(key, true, out keyValue))
                throw new Exception("Invalid key name " + key);

            gesture.Key = keyValue;

            return gesture;
        }
Example #3
0
        public static EditGesture ResolveKeyName(ref string keys)
        {
            EditGesture gesture = new EditGesture();
            Key         keyValue;
            string      key;

            if (keys.StartsWith("^"))
            {
                gesture.Mods = ModifierKeys.Control;
                keys         = keys.Substring(1);
            }

            if (keys.Length < 1)
            {
                throw new Exception("key string is empty");
            }

            if (keys.StartsWith("<"))
            {
                int end = keys.IndexOf('>');

                if (end == -1)
                {
                    throw new Exception("Open < not closed in map");
                }

                key = keys.Substring(1, end - 1);
                keys.Substring(key.Length + 2);
            }
            else
            {
                key  = keys.Substring(0, 1);
                keys = keys.Substring(1);
            }

            if (!Enum.TryParse(key, true, out keyValue))
            {
                throw new Exception("Invalid key name " + key);
            }

            gesture.Key = keyValue;

            return(gesture);
        }