qscicommand.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. // This defines the interface to the QsciCommand class.
  2. //
  3. // Copyright (c) 2017 Riverbank Computing Limited <info@riverbankcomputing.com>
  4. //
  5. // This file is part of QScintilla.
  6. //
  7. // This file may be used under the terms of the GNU General Public License
  8. // version 3.0 as published by the Free Software Foundation and appearing in
  9. // the file LICENSE included in the packaging of this file. Please review the
  10. // following information to ensure the GNU General Public License version 3.0
  11. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  12. //
  13. // If you do not wish to use this file under the terms of the GPL version 3.0
  14. // then you may purchase a commercial license. For more information contact
  15. // info@riverbankcomputing.com.
  16. //
  17. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  18. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19. #ifndef QSCICOMMAND_H
  20. #define QSCICOMMAND_H
  21. #include <qstring.h>
  22. #include <Qsci/qsciglobal.h>
  23. #include <Qsci/qsciscintillabase.h>
  24. class QsciScintilla;
  25. //! \brief The QsciCommand class represents an internal editor command that may
  26. //! have one or two keys bound to it.
  27. //!
  28. //! Methods are provided to change the keys bound to the command and to remove
  29. //! a key binding. Each command has a user friendly description of the command
  30. //! for use in key mapping dialogs.
  31. class QSCINTILLA_EXPORT QsciCommand
  32. {
  33. public:
  34. //! This enum defines the different commands that can be assigned to a key.
  35. enum Command {
  36. //! Move down one line.
  37. LineDown = QsciScintillaBase::SCI_LINEDOWN,
  38. //! Extend the selection down one line.
  39. LineDownExtend = QsciScintillaBase::SCI_LINEDOWNEXTEND,
  40. //! Extend the rectangular selection down one line.
  41. LineDownRectExtend = QsciScintillaBase::SCI_LINEDOWNRECTEXTEND,
  42. //! Scroll the view down one line.
  43. LineScrollDown = QsciScintillaBase::SCI_LINESCROLLDOWN,
  44. //! Move up one line.
  45. LineUp = QsciScintillaBase::SCI_LINEUP,
  46. //! Extend the selection up one line.
  47. LineUpExtend = QsciScintillaBase::SCI_LINEUPEXTEND,
  48. //! Extend the rectangular selection up one line.
  49. LineUpRectExtend = QsciScintillaBase::SCI_LINEUPRECTEXTEND,
  50. //! Scroll the view up one line.
  51. LineScrollUp = QsciScintillaBase::SCI_LINESCROLLUP,
  52. //! Scroll to the start of the document.
  53. ScrollToStart = QsciScintillaBase::SCI_SCROLLTOSTART,
  54. //! Scroll to the end of the document.
  55. ScrollToEnd = QsciScintillaBase::SCI_SCROLLTOEND,
  56. //! Scroll vertically to centre the current line.
  57. VerticalCentreCaret = QsciScintillaBase::SCI_VERTICALCENTRECARET,
  58. //! Move down one paragraph.
  59. ParaDown = QsciScintillaBase::SCI_PARADOWN,
  60. //! Extend the selection down one paragraph.
  61. ParaDownExtend = QsciScintillaBase::SCI_PARADOWNEXTEND,
  62. //! Move up one paragraph.
  63. ParaUp = QsciScintillaBase::SCI_PARAUP,
  64. //! Extend the selection up one paragraph.
  65. ParaUpExtend = QsciScintillaBase::SCI_PARAUPEXTEND,
  66. //! Move left one character.
  67. CharLeft = QsciScintillaBase::SCI_CHARLEFT,
  68. //! Extend the selection left one character.
  69. CharLeftExtend = QsciScintillaBase::SCI_CHARLEFTEXTEND,
  70. //! Extend the rectangular selection left one character.
  71. CharLeftRectExtend = QsciScintillaBase::SCI_CHARLEFTRECTEXTEND,
  72. //! Move right one character.
  73. CharRight = QsciScintillaBase::SCI_CHARRIGHT,
  74. //! Extend the selection right one character.
  75. CharRightExtend = QsciScintillaBase::SCI_CHARRIGHTEXTEND,
  76. //! Extend the rectangular selection right one character.
  77. CharRightRectExtend = QsciScintillaBase::SCI_CHARRIGHTRECTEXTEND,
  78. //! Move left one word.
  79. WordLeft = QsciScintillaBase::SCI_WORDLEFT,
  80. //! Extend the selection left one word.
  81. WordLeftExtend = QsciScintillaBase::SCI_WORDLEFTEXTEND,
  82. //! Move right one word.
  83. WordRight = QsciScintillaBase::SCI_WORDRIGHT,
  84. //! Extend the selection right one word.
  85. WordRightExtend = QsciScintillaBase::SCI_WORDRIGHTEXTEND,
  86. //! Move to the end of the previous word.
  87. WordLeftEnd = QsciScintillaBase::SCI_WORDLEFTEND,
  88. //! Extend the selection to the end of the previous word.
  89. WordLeftEndExtend = QsciScintillaBase::SCI_WORDLEFTENDEXTEND,
  90. //! Move to the end of the next word.
  91. WordRightEnd = QsciScintillaBase::SCI_WORDRIGHTEND,
  92. //! Extend the selection to the end of the next word.
  93. WordRightEndExtend = QsciScintillaBase::SCI_WORDRIGHTENDEXTEND,
  94. //! Move left one word part.
  95. WordPartLeft = QsciScintillaBase::SCI_WORDPARTLEFT,
  96. //! Extend the selection left one word part.
  97. WordPartLeftExtend = QsciScintillaBase::SCI_WORDPARTLEFTEXTEND,
  98. //! Move right one word part.
  99. WordPartRight = QsciScintillaBase::SCI_WORDPARTRIGHT,
  100. //! Extend the selection right one word part.
  101. WordPartRightExtend = QsciScintillaBase::SCI_WORDPARTRIGHTEXTEND,
  102. //! Move to the start of the document line.
  103. Home = QsciScintillaBase::SCI_HOME,
  104. //! Extend the selection to the start of the document line.
  105. HomeExtend = QsciScintillaBase::SCI_HOMEEXTEND,
  106. //! Extend the rectangular selection to the start of the document line.
  107. HomeRectExtend = QsciScintillaBase::SCI_HOMERECTEXTEND,
  108. //! Move to the start of the displayed line.
  109. HomeDisplay = QsciScintillaBase::SCI_HOMEDISPLAY,
  110. //! Extend the selection to the start of the displayed line.
  111. HomeDisplayExtend = QsciScintillaBase::SCI_HOMEDISPLAYEXTEND,
  112. //! Move to the start of the displayed or document line.
  113. HomeWrap = QsciScintillaBase::SCI_HOMEWRAP,
  114. //! Extend the selection to the start of the displayed or document
  115. //! line.
  116. HomeWrapExtend = QsciScintillaBase::SCI_HOMEWRAPEXTEND,
  117. //! Move to the first visible character in the document line.
  118. VCHome = QsciScintillaBase::SCI_VCHOME,
  119. //! Extend the selection to the first visible character in the document
  120. //! line.
  121. VCHomeExtend = QsciScintillaBase::SCI_VCHOMEEXTEND,
  122. //! Extend the rectangular selection to the first visible character in
  123. //! the document line.
  124. VCHomeRectExtend = QsciScintillaBase::SCI_VCHOMERECTEXTEND,
  125. //! Move to the first visible character of the displayed or document
  126. //! line.
  127. VCHomeWrap = QsciScintillaBase::SCI_VCHOMEWRAP,
  128. //! Extend the selection to the first visible character of the
  129. //! displayed or document line.
  130. VCHomeWrapExtend = QsciScintillaBase::SCI_VCHOMEWRAPEXTEND,
  131. //! Move to the end of the document line.
  132. LineEnd = QsciScintillaBase::SCI_LINEEND,
  133. //! Extend the selection to the end of the document line.
  134. LineEndExtend = QsciScintillaBase::SCI_LINEENDEXTEND,
  135. //! Extend the rectangular selection to the end of the document line.
  136. LineEndRectExtend = QsciScintillaBase::SCI_LINEENDRECTEXTEND,
  137. //! Move to the end of the displayed line.
  138. LineEndDisplay = QsciScintillaBase::SCI_LINEENDDISPLAY,
  139. //! Extend the selection to the end of the displayed line.
  140. LineEndDisplayExtend = QsciScintillaBase::SCI_LINEENDDISPLAYEXTEND,
  141. //! Move to the end of the displayed or document line.
  142. LineEndWrap = QsciScintillaBase::SCI_LINEENDWRAP,
  143. //! Extend the selection to the end of the displayed or document line.
  144. LineEndWrapExtend = QsciScintillaBase::SCI_LINEENDWRAPEXTEND,
  145. //! Move to the start of the document.
  146. DocumentStart = QsciScintillaBase::SCI_DOCUMENTSTART,
  147. //! Extend the selection to the start of the document.
  148. DocumentStartExtend = QsciScintillaBase::SCI_DOCUMENTSTARTEXTEND,
  149. //! Move to the end of the document.
  150. DocumentEnd = QsciScintillaBase::SCI_DOCUMENTEND,
  151. //! Extend the selection to the end of the document.
  152. DocumentEndExtend = QsciScintillaBase::SCI_DOCUMENTENDEXTEND,
  153. //! Move up one page.
  154. PageUp = QsciScintillaBase::SCI_PAGEUP,
  155. //! Extend the selection up one page.
  156. PageUpExtend = QsciScintillaBase::SCI_PAGEUPEXTEND,
  157. //! Extend the rectangular selection up one page.
  158. PageUpRectExtend = QsciScintillaBase::SCI_PAGEUPRECTEXTEND,
  159. //! Move down one page.
  160. PageDown = QsciScintillaBase::SCI_PAGEDOWN,
  161. //! Extend the selection down one page.
  162. PageDownExtend = QsciScintillaBase::SCI_PAGEDOWNEXTEND,
  163. //! Extend the rectangular selection down one page.
  164. PageDownRectExtend = QsciScintillaBase::SCI_PAGEDOWNRECTEXTEND,
  165. //! Stuttered move up one page.
  166. StutteredPageUp = QsciScintillaBase::SCI_STUTTEREDPAGEUP,
  167. //! Stuttered extend the selection up one page.
  168. StutteredPageUpExtend = QsciScintillaBase::SCI_STUTTEREDPAGEUPEXTEND,
  169. //! Stuttered move down one page.
  170. StutteredPageDown = QsciScintillaBase::SCI_STUTTEREDPAGEDOWN,
  171. //! Stuttered extend the selection down one page.
  172. StutteredPageDownExtend = QsciScintillaBase::SCI_STUTTEREDPAGEDOWNEXTEND,
  173. //! Delete the current character.
  174. Delete = QsciScintillaBase::SCI_CLEAR,
  175. //! Delete the previous character.
  176. DeleteBack = QsciScintillaBase::SCI_DELETEBACK,
  177. //! Delete the previous character if not at start of line.
  178. DeleteBackNotLine = QsciScintillaBase::SCI_DELETEBACKNOTLINE,
  179. //! Delete the word to the left.
  180. DeleteWordLeft = QsciScintillaBase::SCI_DELWORDLEFT,
  181. //! Delete the word to the right.
  182. DeleteWordRight = QsciScintillaBase::SCI_DELWORDRIGHT,
  183. //! Delete right to the end of the next word.
  184. DeleteWordRightEnd = QsciScintillaBase::SCI_DELWORDRIGHTEND,
  185. //! Delete the line to the left.
  186. DeleteLineLeft = QsciScintillaBase::SCI_DELLINELEFT,
  187. //! Delete the line to the right.
  188. DeleteLineRight = QsciScintillaBase::SCI_DELLINERIGHT,
  189. //! Delete the current line.
  190. LineDelete = QsciScintillaBase::SCI_LINEDELETE,
  191. //! Cut the current line to the clipboard.
  192. LineCut = QsciScintillaBase::SCI_LINECUT,
  193. //! Copy the current line to the clipboard.
  194. LineCopy = QsciScintillaBase::SCI_LINECOPY,
  195. //! Transpose the current and previous lines.
  196. LineTranspose = QsciScintillaBase::SCI_LINETRANSPOSE,
  197. //! Duplicate the current line.
  198. LineDuplicate = QsciScintillaBase::SCI_LINEDUPLICATE,
  199. //! Select the whole document.
  200. SelectAll = QsciScintillaBase::SCI_SELECTALL,
  201. //! Move the selected lines up one line.
  202. MoveSelectedLinesUp = QsciScintillaBase::SCI_MOVESELECTEDLINESUP,
  203. //! Move the selected lines down one line.
  204. MoveSelectedLinesDown = QsciScintillaBase::SCI_MOVESELECTEDLINESDOWN,
  205. //! Duplicate the selection.
  206. SelectionDuplicate = QsciScintillaBase::SCI_SELECTIONDUPLICATE,
  207. //! Convert the selection to lower case.
  208. SelectionLowerCase = QsciScintillaBase::SCI_LOWERCASE,
  209. //! Convert the selection to upper case.
  210. SelectionUpperCase = QsciScintillaBase::SCI_UPPERCASE,
  211. //! Cut the selection to the clipboard.
  212. SelectionCut = QsciScintillaBase::SCI_CUT,
  213. //! Copy the selection to the clipboard.
  214. SelectionCopy = QsciScintillaBase::SCI_COPY,
  215. //! Paste from the clipboard.
  216. Paste = QsciScintillaBase::SCI_PASTE,
  217. //! Toggle insert/overtype.
  218. EditToggleOvertype = QsciScintillaBase::SCI_EDITTOGGLEOVERTYPE,
  219. //! Insert a platform dependent newline.
  220. Newline = QsciScintillaBase::SCI_NEWLINE,
  221. //! Insert a formfeed.
  222. Formfeed = QsciScintillaBase::SCI_FORMFEED,
  223. //! Indent one level.
  224. Tab = QsciScintillaBase::SCI_TAB,
  225. //! De-indent one level.
  226. Backtab = QsciScintillaBase::SCI_BACKTAB,
  227. //! Cancel any current operation.
  228. Cancel = QsciScintillaBase::SCI_CANCEL,
  229. //! Undo the last command.
  230. Undo = QsciScintillaBase::SCI_UNDO,
  231. //! Redo the last command.
  232. Redo = QsciScintillaBase::SCI_REDO,
  233. //! Zoom in.
  234. ZoomIn = QsciScintillaBase::SCI_ZOOMIN,
  235. //! Zoom out.
  236. ZoomOut = QsciScintillaBase::SCI_ZOOMOUT,
  237. };
  238. //! Return the command that will be executed by this instance.
  239. Command command() const {return scicmd;}
  240. //! Execute the command.
  241. void execute();
  242. //! Binds the key \a key to the command. If \a key is 0 then the key
  243. //! binding is removed. If \a key is invalid then the key binding is
  244. //! unchanged. Valid keys are any visible or control character or any
  245. //! of \c Qt::Key_Down, \c Qt::Key_Up, \c Qt::Key_Left, \c Qt::Key_Right,
  246. //! \c Qt::Key_Home, \c Qt::Key_End, \c Qt::Key_PageUp,
  247. //! \c Qt::Key_PageDown, \c Qt::Key_Delete, \c Qt::Key_Insert,
  248. //! \c Qt::Key_Escape, \c Qt::Key_Backspace, \c Qt::Key_Tab,
  249. //! \c Qt::Key_Backtab, \c Qt::Key_Return, \c Qt::Key_Enter,
  250. //! \c Qt::Key_Super_L, \c Qt::Key_Super_R or \c Qt::Key_Menu. Keys may be
  251. //! modified with any combination of \c Qt::ShiftModifier,
  252. //! \c Qt::ControlModifier, \c Qt::AltModifier and \c Qt::MetaModifier.
  253. //!
  254. //! \sa key(), setAlternateKey(), validKey()
  255. void setKey(int key);
  256. //! Binds the alternate key \a altkey to the command. If \a key is 0
  257. //! then the alternate key binding is removed.
  258. //!
  259. //! \sa alternateKey(), setKey(), validKey()
  260. void setAlternateKey(int altkey);
  261. //! The key that is currently bound to the command is returned.
  262. //!
  263. //! \sa setKey(), alternateKey()
  264. int key() const {return qkey;}
  265. //! The alternate key that is currently bound to the command is
  266. //! returned.
  267. //!
  268. //! \sa setAlternateKey(), key()
  269. int alternateKey() const {return qaltkey;}
  270. //! If the key \a key is valid then true is returned.
  271. static bool validKey(int key);
  272. //! The user friendly description of the command is returned.
  273. QString description() const;
  274. private:
  275. friend class QsciCommandSet;
  276. QsciCommand(QsciScintilla *qs, Command cmd, int key, int altkey,
  277. const char *desc);
  278. void bindKey(int key,int &qk,int &scik);
  279. QsciScintilla *qsCmd;
  280. Command scicmd;
  281. int qkey, scikey, qaltkey, scialtkey;
  282. const char *descCmd;
  283. QsciCommand(const QsciCommand &);
  284. QsciCommand &operator=(const QsciCommand &);
  285. };
  286. #endif