|
| 1 | +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team |
| 2 | +// |
| 3 | +// Permission is hereby granted, free of charge, to any person obtaining a copy of this |
| 4 | +// software and associated documentation files (the "Software"), to deal in the Software |
| 5 | +// without restriction, including without limitation the rights to use, copy, modify, merge, |
| 6 | +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons |
| 7 | +// to whom the Software is furnished to do so, subject to the following conditions: |
| 8 | +// |
| 9 | +// The above copyright notice and this permission notice shall be included in all copies or |
| 10 | +// substantial portions of the Software. |
| 11 | +// |
| 12 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
| 13 | +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
| 14 | +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE |
| 15 | +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 16 | +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 17 | +// DEALINGS IN THE SOFTWARE. |
| 18 | + |
| 19 | +using System.Diagnostics.CodeAnalysis; |
| 20 | +using Avalonia; |
| 21 | +using Avalonia.Input; |
| 22 | +using Avalonia.Platform; |
| 23 | + |
| 24 | +namespace AvaloniaEdit |
| 25 | +{ |
| 26 | + /// <summary> |
| 27 | + /// Custom commands for AvalonEdit. |
| 28 | + /// </summary> |
| 29 | + public static class AvaloniaEditCommands |
| 30 | + { |
| 31 | + /// <summary> |
| 32 | + /// Toggles Overstrike mode |
| 33 | + /// The default shortcut is Ins. |
| 34 | + /// </summary> |
| 35 | + public static RoutedCommand ToggleOverstrike { get; } = new RoutedCommand(nameof(ToggleOverstrike), new KeyGesture(Key.Insert)); |
| 36 | + |
| 37 | + /// <summary> |
| 38 | + /// Deletes the current line. |
| 39 | + /// The default shortcut is Ctrl+D. |
| 40 | + /// </summary> |
| 41 | + public static RoutedCommand DeleteLine { get; } = new RoutedCommand(nameof(DeleteLine), new KeyGesture(Key.D, KeyModifiers.Control)); |
| 42 | + |
| 43 | + /// <summary> |
| 44 | + /// Removes leading whitespace from the selected lines (or the whole document if the selection is empty). |
| 45 | + /// </summary> |
| 46 | + [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "Whitespace")] |
| 47 | + public static RoutedCommand RemoveLeadingWhitespace { get; } = new RoutedCommand(nameof(RemoveLeadingWhitespace)); |
| 48 | + |
| 49 | + /// <summary> |
| 50 | + /// Removes trailing whitespace from the selected lines (or the whole document if the selection is empty). |
| 51 | + /// </summary> |
| 52 | + [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "Whitespace")] |
| 53 | + public static RoutedCommand RemoveTrailingWhitespace { get; } = new RoutedCommand(nameof(RemoveTrailingWhitespace)); |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// Converts the selected text to upper case. |
| 57 | + /// </summary> |
| 58 | + public static RoutedCommand ConvertToUppercase { get; } = new RoutedCommand(nameof(ConvertToUppercase)); |
| 59 | + |
| 60 | + /// <summary> |
| 61 | + /// Converts the selected text to lower case. |
| 62 | + /// </summary> |
| 63 | + public static RoutedCommand ConvertToLowercase { get; } = new RoutedCommand(nameof(ConvertToLowercase)); |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// Converts the selected text to title case. |
| 67 | + /// </summary> |
| 68 | + public static RoutedCommand ConvertToTitleCase { get; } = new RoutedCommand(nameof(ConvertToTitleCase)); |
| 69 | + |
| 70 | + /// <summary> |
| 71 | + /// Inverts the case of the selected text. |
| 72 | + /// </summary> |
| 73 | + public static RoutedCommand InvertCase { get; } = new RoutedCommand(nameof(InvertCase)); |
| 74 | + |
| 75 | + /// <summary> |
| 76 | + /// Converts tabs to spaces in the selected text. |
| 77 | + /// </summary> |
| 78 | + public static RoutedCommand ConvertTabsToSpaces { get; } = new RoutedCommand(nameof(ConvertTabsToSpaces)); |
| 79 | + |
| 80 | + /// <summary> |
| 81 | + /// Converts spaces to tabs in the selected text. |
| 82 | + /// </summary> |
| 83 | + public static RoutedCommand ConvertSpacesToTabs { get; } = new RoutedCommand(nameof(ConvertSpacesToTabs)); |
| 84 | + |
| 85 | + /// <summary> |
| 86 | + /// Converts leading tabs to spaces in the selected lines (or the whole document if the selection is empty). |
| 87 | + /// </summary> |
| 88 | + public static RoutedCommand ConvertLeadingTabsToSpaces { get; } = new RoutedCommand(nameof(ConvertLeadingTabsToSpaces)); |
| 89 | + |
| 90 | + /// <summary> |
| 91 | + /// Converts leading spaces to tabs in the selected lines (or the whole document if the selection is empty). |
| 92 | + /// </summary> |
| 93 | + public static RoutedCommand ConvertLeadingSpacesToTabs { get; } = new RoutedCommand(nameof(ConvertLeadingSpacesToTabs)); |
| 94 | + |
| 95 | + /// <summary>InputModifiers |
| 96 | + /// Runs the IIndentationStrategy on the selected lines (or the whole document if the selection is empty). |
| 97 | + /// </summary> |
| 98 | + public static RoutedCommand IndentSelection { get; } = new RoutedCommand(nameof(IndentSelection), new KeyGesture(Key.I, KeyModifiers.Control)); |
| 99 | + } |
| 100 | + |
| 101 | + |
| 102 | + public static class ApplicationCommands |
| 103 | + { |
| 104 | + private static readonly KeyModifiers PlatformCommandKey = GetPlatformCommandKey(); |
| 105 | + |
| 106 | + public static RoutedCommand Delete { get; } = new RoutedCommand(nameof(Delete), new KeyGesture(Key.Delete)); |
| 107 | + public static RoutedCommand Copy { get; } = new RoutedCommand(nameof(Copy), new KeyGesture(Key.C, PlatformCommandKey)); |
| 108 | + public static RoutedCommand Cut { get; } = new RoutedCommand(nameof(Cut), new KeyGesture(Key.X, PlatformCommandKey)); |
| 109 | + public static RoutedCommand Paste { get; } = new RoutedCommand(nameof(Paste), new KeyGesture(Key.V, PlatformCommandKey)); |
| 110 | + public static RoutedCommand SelectAll { get; } = new RoutedCommand(nameof(SelectAll), new KeyGesture(Key.A, PlatformCommandKey)); |
| 111 | + public static RoutedCommand Undo { get; } = new RoutedCommand(nameof(Undo), new KeyGesture(Key.Z, PlatformCommandKey)); |
| 112 | + public static RoutedCommand Redo { get; } = new RoutedCommand(nameof(Redo), new KeyGesture(Key.Y, PlatformCommandKey)); |
| 113 | + public static RoutedCommand Find { get; } = new RoutedCommand(nameof(Find), new KeyGesture(Key.F, PlatformCommandKey)); |
| 114 | + public static RoutedCommand Replace { get; } = new RoutedCommand(nameof(Replace), GetReplaceKeyGesture()); |
| 115 | + |
| 116 | + private static OperatingSystemType GetOperatingSystemType() |
| 117 | + { |
| 118 | + return AvaloniaLocator.Current.GetService<IRuntimePlatform>().GetRuntimeInfo().OperatingSystem; |
| 119 | + } |
| 120 | + |
| 121 | + private static KeyModifiers GetPlatformCommandKey() |
| 122 | + { |
| 123 | + var os = GetOperatingSystemType(); |
| 124 | + |
| 125 | + if (os == OperatingSystemType.OSX) |
| 126 | + { |
| 127 | + return KeyModifiers.Meta; |
| 128 | + } |
| 129 | + |
| 130 | + return KeyModifiers.Control; |
| 131 | + } |
| 132 | + |
| 133 | + private static KeyGesture GetReplaceKeyGesture() |
| 134 | + { |
| 135 | + var os = GetOperatingSystemType(); |
| 136 | + |
| 137 | + if (os == OperatingSystemType.OSX) |
| 138 | + { |
| 139 | + return new KeyGesture(Key.F, KeyModifiers.Meta | KeyModifiers.Alt); |
| 140 | + } |
| 141 | + |
| 142 | + return new KeyGesture(Key.H, PlatformCommandKey); |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + public static class EditingCommands |
| 147 | + { |
| 148 | + public static RoutedCommand Delete { get; } = new RoutedCommand(nameof(Delete)); |
| 149 | + public static RoutedCommand DeleteNextWord { get; } = new RoutedCommand(nameof(DeleteNextWord)); |
| 150 | + public static RoutedCommand Backspace { get; } = new RoutedCommand(nameof(Backspace)); |
| 151 | + public static RoutedCommand DeletePreviousWord { get; } = new RoutedCommand(nameof(DeletePreviousWord)); |
| 152 | + public static RoutedCommand EnterParagraphBreak { get; } = new RoutedCommand(nameof(EnterParagraphBreak)); |
| 153 | + public static RoutedCommand EnterLineBreak { get; } = new RoutedCommand(nameof(EnterLineBreak)); |
| 154 | + public static RoutedCommand TabForward { get; } = new RoutedCommand(nameof(TabForward)); |
| 155 | + public static RoutedCommand TabBackward { get; } = new RoutedCommand(nameof(TabBackward)); |
| 156 | + public static RoutedCommand MoveLeftByCharacter { get; } = new RoutedCommand(nameof(MoveLeftByCharacter)); |
| 157 | + public static RoutedCommand SelectLeftByCharacter { get; } = new RoutedCommand(nameof(SelectLeftByCharacter)); |
| 158 | + public static RoutedCommand MoveRightByCharacter { get; } = new RoutedCommand(nameof(MoveRightByCharacter)); |
| 159 | + public static RoutedCommand SelectRightByCharacter { get; } = new RoutedCommand(nameof(SelectRightByCharacter)); |
| 160 | + public static RoutedCommand MoveLeftByWord { get; } = new RoutedCommand(nameof(MoveLeftByWord)); |
| 161 | + public static RoutedCommand SelectLeftByWord { get; } = new RoutedCommand(nameof(SelectLeftByWord)); |
| 162 | + public static RoutedCommand MoveRightByWord { get; } = new RoutedCommand(nameof(MoveRightByWord)); |
| 163 | + public static RoutedCommand SelectRightByWord { get; } = new RoutedCommand(nameof(SelectRightByWord)); |
| 164 | + public static RoutedCommand MoveUpByLine { get; } = new RoutedCommand(nameof(MoveUpByLine)); |
| 165 | + public static RoutedCommand SelectUpByLine { get; } = new RoutedCommand(nameof(SelectUpByLine)); |
| 166 | + public static RoutedCommand MoveDownByLine { get; } = new RoutedCommand(nameof(MoveDownByLine)); |
| 167 | + public static RoutedCommand SelectDownByLine { get; } = new RoutedCommand(nameof(SelectDownByLine)); |
| 168 | + public static RoutedCommand MoveDownByPage { get; } = new RoutedCommand(nameof(MoveDownByPage)); |
| 169 | + public static RoutedCommand SelectDownByPage { get; } = new RoutedCommand(nameof(SelectDownByPage)); |
| 170 | + public static RoutedCommand MoveUpByPage { get; } = new RoutedCommand(nameof(MoveUpByPage)); |
| 171 | + public static RoutedCommand SelectUpByPage { get; } = new RoutedCommand(nameof(SelectUpByPage)); |
| 172 | + public static RoutedCommand MoveToLineStart { get; } = new RoutedCommand(nameof(MoveToLineStart)); |
| 173 | + public static RoutedCommand SelectToLineStart { get; } = new RoutedCommand(nameof(SelectToLineStart)); |
| 174 | + public static RoutedCommand MoveToLineEnd { get; } = new RoutedCommand(nameof(MoveToLineEnd)); |
| 175 | + public static RoutedCommand SelectToLineEnd { get; } = new RoutedCommand(nameof(SelectToLineEnd)); |
| 176 | + public static RoutedCommand MoveToDocumentStart { get; } = new RoutedCommand(nameof(MoveToDocumentStart)); |
| 177 | + public static RoutedCommand SelectToDocumentStart { get; } = new RoutedCommand(nameof(SelectToDocumentStart)); |
| 178 | + public static RoutedCommand MoveToDocumentEnd { get; } = new RoutedCommand(nameof(MoveToDocumentEnd)); |
| 179 | + public static RoutedCommand SelectToDocumentEnd { get; } = new RoutedCommand(nameof(SelectToDocumentEnd)); |
| 180 | + } |
| 181 | +} |
0 commit comments