コード例 #1
0
        static EditingCommandHandler()
        {
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, OnDelete(CaretMovementType.None), CanDelete));
            AddBinding(EditingCommands.Delete, ModifierKeys.None, Key.Delete, OnDelete(CaretMovementType.CharRight));
            AddBinding(EditingCommands.DeleteNextWord, ModifierKeys.Control, Key.Delete, OnDelete(CaretMovementType.WordRight));
            AddBinding(EditingCommands.Backspace, ModifierKeys.None, Key.Back, OnDelete(CaretMovementType.Backspace));
            InputBindings.Add(TextAreaDefaultInputHandler.CreateFrozenKeyBinding(EditingCommands.Backspace, ModifierKeys.Shift, Key.Back)); // make Shift-Backspace do the same as plain backspace
            AddBinding(EditingCommands.DeletePreviousWord, ModifierKeys.Control, Key.Back, OnDelete(CaretMovementType.WordLeft));
            AddBinding(EditingCommands.EnterParagraphBreak, ModifierKeys.None, Key.Enter, OnEnter);
            AddBinding(EditingCommands.EnterLineBreak, ModifierKeys.Shift, Key.Enter, OnEnter);
            AddBinding(EditingCommands.TabForward, ModifierKeys.None, Key.Tab, OnTab);
            AddBinding(EditingCommands.TabBackward, ModifierKeys.Shift, Key.Tab, OnShiftTab);

            CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, OnCopy, CanCutOrCopy));
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, OnCut, CanCutOrCopy));
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, OnPaste, CanPaste));

            CommandBindings.Add(new CommandBinding(EditorCommands.ToggleOverstrike, OnToggleOverstrike));
            CommandBindings.Add(new CommandBinding(EditorCommands.DeleteLine, OnDeleteLine));

            CommandBindings.Add(new CommandBinding(EditorCommands.RemoveLeadingWhitespace, OnRemoveLeadingWhitespace));
            CommandBindings.Add(new CommandBinding(EditorCommands.RemoveTrailingWhitespace, OnRemoveTrailingWhitespace));
            CommandBindings.Add(new CommandBinding(EditorCommands.ConvertToUppercase, OnConvertToUpperCase));
            CommandBindings.Add(new CommandBinding(EditorCommands.ConvertToLowercase, OnConvertToLowerCase));
            CommandBindings.Add(new CommandBinding(EditorCommands.ConvertToTitleCase, OnConvertToTitleCase));
            CommandBindings.Add(new CommandBinding(EditorCommands.InvertCase, OnInvertCase));
            CommandBindings.Add(new CommandBinding(EditorCommands.ConvertTabsToSpaces, OnConvertTabsToSpaces));
            CommandBindings.Add(new CommandBinding(EditorCommands.ConvertSpacesToTabs, OnConvertSpacesToTabs));
            CommandBindings.Add(new CommandBinding(EditorCommands.ConvertLeadingTabsToSpaces, OnConvertLeadingTabsToSpaces));
            CommandBindings.Add(new CommandBinding(EditorCommands.ConvertLeadingSpacesToTabs, OnConvertLeadingSpacesToTabs));
            CommandBindings.Add(new CommandBinding(EditorCommands.IndentSelection, OnIndentSelection));

            TextAreaDefaultInputHandler.WorkaroundWPFMemoryLeak(InputBindings);
        }
コード例 #2
0
 private static void AddBinding(ICommand command, ModifierKeys modifiers, Key key, ExecutedRoutedEventHandler handler)
 {
     CommandBindings.Add(new CommandBinding(command, handler));
     InputBindings.Add(TextAreaDefaultInputHandler.CreateFrozenKeyBinding(command, modifiers, key));
 }