public void Bind(IKeyMap <T> keyMap) { if (_idToInfos == null) { return; } foreach (var pair in _keyToId) { var prefix = pair.Key.Prefix; var shortcut = pair.Key.Key; if (shortcut == Keys.None) { continue; } var targetKeyMap = keyMap; if (prefix != Keys.None) { if (keyMap.IsPrefixDefined(prefix)) { targetKeyMap = keyMap.GetPrefixKeyMap(prefix); } else { targetKeyMap = keyMap.SetPrefix(prefix); } } var actionId = pair.Value; var handled = false; if (_idToBindAction.IsValueCreated) { if (_idToBindAction.Value.ContainsKey(actionId)) { var bindAction = _idToBindAction.Value[actionId]; bindAction(shortcut, targetKeyMap); handled = true; } } if (!handled && _idToInfos.ContainsKey(actionId)) { var info = _idToInfos[actionId]; targetKeyMap.SetAction(shortcut, info.Action); } } }
// ------------------------------ // private // ------------------------------ private void BindKillLine(Keys shortcutKey, IKeyMap <IFocus> keyMap) { var killLinePrefix = keyMap.SetPrefix( shortcutKey, (key, focus) => ((StyledTextFocus)focus).KillLineFirst(), (key, focus) => { if (keyMap.IsDefined(key)) { var action = keyMap.GetAction(key); if (action != null) { action(focus); } } }, (key, focus) => key != shortcutKey, false ); killLinePrefix.SetAction(shortcutKey, (focus) => ((StyledTextFocus)focus).KillLine()); }