示例#1
0
文件: Mode.cs 项目: hww/VARP2
 public Mode(Mode parentMode, string name, string help = null, KeyMap keyMap = null)
 {
     this.parentMode = parentMode;
     this.name       = name;
     this.help       = help;
     this.keyMap     = keyMap;
 }
示例#2
0
文件: KeyMap.cs 项目: hww/VARP2
        public virtual bool Define([NotNull] int[] sequence, object value)
        {
            if (sequence == null)
            {
                throw new ArgumentNullException("sequence");
            }

            var curentMap = this;
            var lastIndex = sequence.Length - 1;

            for (var i = 0; i < sequence.Length; i++)
            {
                var key = sequence[i];
                var tmp = curentMap.GetLocal(key); // do not alow defaults
                if (tmp == null)
                {
                    // there is no this binding
                    // N.B. Do not look at the parent one!
                    if (i == lastIndex)
                    {
                        // the curentMap is the target map and it does not have definition
                        curentMap.SetLocal(key, value);
                        return(true);
                    }
                    else
                    {
                        // the curentMap is the map in the sequence and it does not have definition
                        var newMap = new KeyMap();
                        curentMap.SetLocal(key, newMap);
                        curentMap = newMap;
                    }
                }
                else
                {
                    // we found binding in curentMap
                    if (i == lastIndex)
                    {
                        // curentMap is target map, it has binding but we have to redefine it
                        curentMap.SetLocal(key, value);
                    }
                    else
                    {
                        // the curentMap is the map in the sequence and it has definition
                        var map = tmp.value as KeyMap;
                        if (map != null)
                        {
                            curentMap = map;
                        }
                        else
                        {
                            throw new Exception(string.Format("Expect KeyMap at '{0}' found: '{1}' in: '{2}'", sequence[i], tmp, sequence));
                        }
                    }
                }
            }
            throw new Exception("We can\'t be here");
        }
示例#3
0
文件: KeyMap.cs 项目: hww/VARP2
 /// <summary>
 /// Create empty keymap based on parent keymap
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="title"></param>
 public KeyMap([NotNull] KeyMap parent, string title = null)
 {
     if (parent == null)
     {
         throw new ArgumentNullException("parent");
     }
     this.title  = title;
     this.parent = parent;
     items       = new List <KeyMapItem>();
 }
示例#4
0
文件: KeyMap.cs 项目: hww/VARP2
 public virtual void CopyTo(KeyMap other)
 {
     other.title  = title;
     other.title  = help;
     other.parent = parent;
     foreach (var item in items)
     {
         other.SetLocal(item.key, item.value);
     }
 }
示例#5
0
文件: KeyMap.cs 项目: hww/VARP2
 /// <summary>
 /// Create empty keymap based on parent keymap
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="title"></param>
 public FullKeymap([NotNull] KeyMap parent, string title = null) : base(parent, title)
 {
 }
示例#6
0
文件: KeyMap.cs 项目: hww/VARP2
 public KeyMap(KeyMap parent, string title, string help = null) : this(parent, title)
 {
     this.title = help;
 }
示例#7
0
文件: Mode.cs 项目: hww/VARP2
 public Mode(string name, string help = null, KeyMap keyMap = null)
 {
     this.name   = name;
     this.help   = help;
     this.keyMap = keyMap;
 }
示例#8
0
 private ReadLine(Mode parentMode, string name, string help = null, KeyMap keyMap = null)
     : base(parentMode, name, help, keyMap)
 {
     Initialize();
 }
示例#9
0
 private ReadLine(string name, string help = null, KeyMap keyMap = null) : base(name, help, keyMap)
 {
     Initialize();
 }