Command.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. // These classes use a keybinding system based on the design implemented in Scintilla.Net which is an
  2. // MIT licensed open source project https://github.com/jacobslusser/ScintillaNET/blob/master/src/ScintillaNET/Command.cs
  3. namespace Terminal.Gui.Input;
  4. /// <summary>
  5. /// Actions which can be performed by a <see cref="View"/>.
  6. /// </summary>
  7. /// <seealso cref="View.KeyBindings"/>
  8. /// <seealso cref="View.MouseBindings"/>
  9. /// <seealso cref="Application.KeyBindings"/>
  10. /// <remarks>
  11. /// <para>
  12. /// <see cref="Application"/> supports a subset of these commands by default, which can be overriden via <see cref="Application.KeyBindings"/>.
  13. /// </para>
  14. /// <para>
  15. /// See the Commands Deep Dive for more information: <see href="https://gui-cs.github.io/Terminal.Gui/docs/command.html"/>.
  16. /// </para>
  17. /// </remarks>
  18. public enum Command
  19. {
  20. /// <summary>
  21. /// Indicates the command is not bound or invalid. Will call <see cref="View.RaiseCommandNotBound"/>.
  22. /// </summary>
  23. NotBound = 0,
  24. #region Base View Commands
  25. /// <summary>
  26. /// Accepts the current state of the View (e.g. list selection, button press, checkbox state, etc.).
  27. /// <para>
  28. /// The default implementation in <see cref="View"/> calls <see cref="View.RaiseAccepting"/>. If the event is not handled,
  29. /// the command is invoked on:
  30. /// - Any peer-view that is a <see cref="Button"/> with <see cref="Button.IsDefault"/> set to <see langword="true"/>.
  31. /// - The <see cref="View.SuperView"/>. This enables default Accept behavior.
  32. /// </para>
  33. /// </summary>
  34. Accept,
  35. /// <summary>
  36. /// Performs a hot key action (e.g. setting focus, accepting, and/or moving focus to the next View).
  37. /// <para>
  38. /// The default implementation in <see cref="View"/> calls <see cref="View.SetFocus"/> and then
  39. /// <see cref="View.RaiseHandlingHotKey"/>.
  40. /// </para>
  41. /// </summary>
  42. HotKey,
  43. /// <summary>
  44. /// Activates the View or an item in the View, changing its state or preparing it for interaction
  45. /// (e.g. toggling a checkbox, selecting a list item, focusing a button, navigating a menu item) without necessarily accepting it.
  46. /// <para>
  47. /// The default implementation in <see cref="View"/> calls <see cref="View.RaiseActivating"/>.
  48. /// </para>
  49. /// </summary>
  50. Activate,
  51. #endregion
  52. #region Movement Commands
  53. /// <summary>Moves up one (cell, line, etc...).</summary>
  54. Up,
  55. /// <summary>Moves down one item (cell, line, etc...).</summary>
  56. Down,
  57. /// <summary>
  58. /// Moves left one (cell, line, etc...).
  59. /// </summary>
  60. Left,
  61. /// <summary>
  62. /// Moves right one (cell, line, etc...).
  63. /// </summary>
  64. Right,
  65. /// <summary>Move one page up.</summary>
  66. PageUp,
  67. /// <summary>Move one page down.</summary>
  68. PageDown,
  69. /// <summary>Moves to the left page.</summary>
  70. PageLeft,
  71. /// <summary>Moves to the right page.</summary>
  72. PageRight,
  73. /// <summary>Moves to the top of page.</summary>
  74. StartOfPage,
  75. /// <summary>Moves to the bottom of page.</summary>
  76. EndOfPage,
  77. /// <summary>Moves to the start (e.g. the top or home).</summary>
  78. Start,
  79. /// <summary>Moves to the end (e.g. the bottom).</summary>
  80. End,
  81. /// <summary>Moves left to the start on the current row/line.</summary>
  82. LeftStart,
  83. /// <summary>Moves right to the end on the current row/line.</summary>
  84. RightEnd,
  85. /// <summary>Moves to the start of the previous word.</summary>
  86. WordLeft,
  87. /// <summary>Moves the start of the next word.</summary>
  88. WordRight,
  89. #endregion
  90. #region Movement With Extension Commands
  91. /// <summary>Extends the selection up one item (cell, line, etc...).</summary>
  92. UpExtend,
  93. /// <summary>Extends the selection down one (cell, line, etc...).</summary>
  94. DownExtend,
  95. /// <summary>
  96. /// Extends the selection left one item (cell, line, etc...)
  97. /// </summary>
  98. LeftExtend,
  99. /// <summary>
  100. /// Extends the selection right one item (cell, line, etc...)
  101. /// </summary>
  102. RightExtend,
  103. /// <summary>Extends the selection to the start of the previous word.</summary>
  104. WordLeftExtend,
  105. /// <summary>Extends the selection to the start of the next word.</summary>
  106. WordRightExtend,
  107. /// <summary>Move one page down extending the selection to cover revealed objects/characters.</summary>
  108. PageDownExtend,
  109. /// <summary>Move one page up extending the selection to cover revealed objects/characters.</summary>
  110. PageUpExtend,
  111. /// <summary>Extends the selection to start (e.g. home or top).</summary>
  112. StartExtend,
  113. /// <summary>Extends the selection to end (e.g. bottom).</summary>
  114. EndExtend,
  115. /// <summary>Extends the selection to the start on the current row/line.</summary>
  116. LeftStartExtend,
  117. /// <summary>Extends the selection to the right on the current row/line.</summary>
  118. RightEndExtend,
  119. /// <summary>Toggles the selection.</summary>
  120. ToggleExtend,
  121. #endregion
  122. #region Editing Commands
  123. /// <summary>Deletes the characters forwards.</summary>
  124. KillWordForwards,
  125. /// <summary>Deletes the characters backwards.</summary>
  126. KillWordBackwards,
  127. /// <summary>
  128. /// Toggles overwrite mode such that newly typed text overwrites the text that is already there (typically
  129. /// associated with the Insert key).
  130. /// </summary>
  131. ToggleOverwrite,
  132. // QUESTION: What is the difference between EnableOverwrite and ToggleOverwrite?
  133. /// <summary>
  134. /// Enables overwrite mode such that newly typed text overwrites the text that is already there (typically
  135. /// associated with the Insert key).
  136. /// </summary>
  137. EnableOverwrite,
  138. /// <summary>
  139. /// Inserts a character.
  140. /// </summary>
  141. Insert,
  142. /// <summary>Disables overwrite mode (<see cref="EnableOverwrite"/>)</summary>
  143. DisableOverwrite,
  144. /// <summary>Deletes the character on the right.</summary>
  145. DeleteCharRight,
  146. /// <summary>Deletes the character on the left.</summary>
  147. DeleteCharLeft,
  148. /// <summary>Selects all objects.</summary>
  149. SelectAll,
  150. /// <summary>Deletes all objects.</summary>
  151. DeleteAll,
  152. /// <summary>Inserts a new item.</summary>
  153. NewLine,
  154. /// <summary>Unix emulation.</summary>
  155. UnixEmulation,
  156. #endregion
  157. #region Tree Commands
  158. /// <summary>Moves down to the last child node of the branch that holds the current selection.</summary>
  159. LineDownToLastBranch,
  160. /// <summary>Moves up to the first child node of the branch that holds the current selection.</summary>
  161. LineUpToFirstBranch,
  162. #endregion
  163. #region Scroll Commands
  164. /// <summary>Scrolls down one (cell, line, etc...).</summary>
  165. ScrollDown,
  166. /// <summary>Scrolls up one item (cell, line, etc...).</summary>
  167. ScrollUp,
  168. /// <summary>Scrolls one item (cell, character, etc...) to the left.</summary>
  169. ScrollLeft,
  170. /// <summary>Scrolls one item (cell, character, etc...) to the right.</summary>
  171. ScrollRight,
  172. #endregion
  173. #region Clipboard Commands
  174. /// <summary>Undo changes.</summary>
  175. Undo,
  176. /// <summary>Redo changes.</summary>
  177. Redo,
  178. /// <summary>Copies the current selection.</summary>
  179. Copy,
  180. /// <summary>Cuts the current selection.</summary>
  181. Cut,
  182. /// <summary>Pastes the current selection.</summary>
  183. Paste,
  184. /// <summary>Cuts to the clipboard the characters from the current position to the end of the line.</summary>
  185. CutToEndLine,
  186. /// <summary>Cuts to the clipboard the characters from the current position to the start of the line.</summary>
  187. CutToStartLine,
  188. #endregion
  189. #region Navigation Commands
  190. /// <summary>Moves focus to the next <see cref="TabBehavior.TabStop"/>.</summary>
  191. NextTabStop,
  192. /// <summary>Moves focus to the previous <see cref="TabBehavior.TabStop"/>.</summary>
  193. PreviousTabStop,
  194. /// <summary>Moves focus to the next <see cref="TabBehavior.TabGroup"/>.</summary>
  195. NextTabGroup,
  196. /// <summary>Moves focus to the next<see cref="TabBehavior.TabGroup"/>.</summary>
  197. PreviousTabGroup,
  198. /// <summary>Tabs to the next item.</summary>
  199. Tab,
  200. /// <summary>Tabs back to the previous item.</summary>
  201. BackTab,
  202. /// <summary>Enables arrange mode.</summary>
  203. Arrange,
  204. #endregion
  205. #region Action Commands
  206. /// <summary>Toggles something (e.g. the expanded or collapsed state of a list).</summary>
  207. Toggle,
  208. /// <summary>Expands a list or item (with subitems).</summary>
  209. Expand,
  210. /// <summary>Recursively Expands all child items and their child items (if any).</summary>
  211. ExpandAll,
  212. /// <summary>Collapses a list or item (with subitems).</summary>
  213. Collapse,
  214. /// <summary>Recursively collapses a list items of their children (if any).</summary>
  215. CollapseAll,
  216. /// <summary>Cancels an action or any temporary states on the control e.g. expanding a combo list.</summary>
  217. Cancel,
  218. /// <summary>Quit.</summary>
  219. Quit,
  220. /// <summary>Refresh.</summary>
  221. Refresh,
  222. /// <summary>Suspend an application (Only implemented in UnixDriver).</summary>
  223. Suspend,
  224. /// <summary>Open the selected item or invoke a UI for opening something.</summary>
  225. Open,
  226. /// <summary>Saves the current document.</summary>
  227. Save,
  228. /// <summary>Saves the current document with a new name.</summary>
  229. SaveAs,
  230. /// <summary>Creates a new document.</summary>
  231. New,
  232. /// <summary>Shows context about the item (e.g. a context menu).</summary>
  233. Context,
  234. /// <summary>
  235. /// Invokes a user interface for editing or configuring something.
  236. /// </summary>
  237. Edit,
  238. #endregion
  239. }