private KeyboardShortcutCollection ConfigureCommands()
        {
            var configuration = File.ReadAllLines(@"keyboard.trcfg");

            var descriptors = new BlockDescriptor[]
            {
                ParagraphBlock.Descriptor,
                HeadingBlock.Descriptor,
            };

            var addedCommands = new IContextualCommand[]
            {
                new BreakTextBlockCommand(),
                new DeleteNextCharacterCommand(),
                new DeletePreviousCharacterCommand(),
                new MergeTextBlocksCommand(),
                new MoveCaretBackwardCommand(),
                new MoveCaretForwardCommand(),
                new MoveCaretUpCommand(),
                new MoveCaretDownCommand(),
                new MoveCaretHomeCommand(),
                new MoveCaretEndCommand(),
                new MoveCaretPreviousWordCommand(),
                new MoveCaretNextWordCommand(),
                new UndoCommand(),
                new RedoCommand(),
            };

            var allCommands = addedCommands
                              .Concat(descriptors.SelectMany(d => d.GetCommands(_editor.Document)))
                              .ToDictionary(c => c.Id, c => c, StringComparer.InvariantCultureIgnoreCase);

            var converter = new KeyGestureConverter();

            var items = configuration
                        .Where(s => !string.IsNullOrWhiteSpace(s))
                        .Select(s => s.Trim())
                        .Select(s => s.Split(new[] { " => " }, StringSplitOptions.RemoveEmptyEntries))
                        .Select(p => new { StringKey = p[0], Id = p[1] })
                        .Select(i => new { Key = (KeyGesture)converter.ConvertFromString(i.StringKey), Command = allCommands[i.Id] })
                        .GroupBy(i => i.Key)
            ;
            var keyboardShortcutCollection = new KeyboardShortcutCollection();

            foreach (var aGroup in items)
            {
                keyboardShortcutCollection.Add(aGroup.Key.Modifiers, aGroup.Key.Key, aGroup.Select(it => it.Command).ToArray());
            }
            return(keyboardShortcutCollection);
        }
コード例 #2
0
        /// <summary> Adds a keyboard shortcut associated with a command. </summary>
        /// <param name="modifier"> The modifiers that must be present for the command.
        ///  If CTRL is specified and not SHIFT, the command will still be active when
        ///  SHIFT is held. </param>
        /// <param name="key"> The key to associate with the command. </param>
        /// <param name="contextualCommand"> The command. </param>
        public void Add(ModifierKeys modifier, Key key, IContextualCommand contextualCommand)
        {
            // TODO thrown an exception on duplicate
            var newShortcut = new Shortcut(modifier, key, contextualCommand);

            List <Shortcut> existingValue;

            if (_keyLookup.TryGetValue(key, out existingValue))
            {
                existingValue.Add(newShortcut);
            }
            else
            {
                _keyLookup[key] = new List <Shortcut>
                {
                    newShortcut
                };
            }
        }
コード例 #3
0
 /// <summary> Adds a keyboard shortcut associated with a command. </summary>
 /// <param name="key"> The key to associate with the command. </param>
 /// <param name="command"> The command. </param>
 public void Add(Key key, IContextualCommand command)
 {
     Add(0, key, command);
 }
コード例 #4
0
 public Shortcut(ModifierKeys modifers, Key key, IContextualCommand contextualCommand)
 {
     Modifers          = modifers;
     Key               = key;
     ContextualCommand = contextualCommand;
 }