qscicommandset.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  1. // This module implements the QsciCommandSet 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. #include "Qsci/qscicommandset.h"
  20. #include <QSettings>
  21. #include "Qsci/qscicommand.h"
  22. #include "Qsci/qsciscintilla.h"
  23. #include "Qsci/qsciscintillabase.h"
  24. // Starting with QScintilla v2.7 the standard OS/X keyboard shortcuts are used
  25. // where possible. In order to restore the behaviour of earlier versions then
  26. // #define DONT_USE_OSX_KEYS here or add it to the qmake project (.pro) file.
  27. #if defined(Q_OS_MAC) && !defined(DONT_USE_OSX_KEYS)
  28. #define USING_OSX_KEYS
  29. #else
  30. #undef USING_OSX_KEYS
  31. #endif
  32. // The ctor.
  33. QsciCommandSet::QsciCommandSet(QsciScintilla *qs) : qsci(qs)
  34. {
  35. struct sci_cmd {
  36. QsciCommand::Command cmd;
  37. int key;
  38. int altkey;
  39. const char *desc;
  40. };
  41. static struct sci_cmd cmd_table[] = {
  42. {
  43. QsciCommand::LineDown,
  44. Qt::Key_Down,
  45. #if defined(USING_OSX_KEYS)
  46. Qt::Key_N | Qt::META,
  47. #else
  48. 0,
  49. #endif
  50. QT_TRANSLATE_NOOP("QsciCommand", "Move down one line")
  51. },
  52. {
  53. QsciCommand::LineDownExtend,
  54. Qt::Key_Down | Qt::SHIFT,
  55. #if defined(USING_OSX_KEYS)
  56. Qt::Key_N | Qt::META | Qt::SHIFT,
  57. #else
  58. 0,
  59. #endif
  60. QT_TRANSLATE_NOOP("QsciCommand", "Extend selection down one line")
  61. },
  62. {
  63. QsciCommand::LineDownRectExtend,
  64. Qt::Key_Down | Qt::ALT | Qt::SHIFT,
  65. #if defined(USING_OSX_KEYS)
  66. Qt::Key_N | Qt::META | Qt::ALT | Qt::SHIFT,
  67. #else
  68. 0,
  69. #endif
  70. QT_TRANSLATE_NOOP("QsciCommand",
  71. "Extend rectangular selection down one line")
  72. },
  73. {
  74. QsciCommand::LineScrollDown,
  75. Qt::Key_Down | Qt::CTRL,
  76. 0,
  77. QT_TRANSLATE_NOOP("QsciCommand", "Scroll view down one line")
  78. },
  79. {
  80. QsciCommand::LineUp,
  81. Qt::Key_Up,
  82. #if defined(USING_OSX_KEYS)
  83. Qt::Key_P | Qt::META,
  84. #else
  85. 0,
  86. #endif
  87. QT_TRANSLATE_NOOP("QsciCommand", "Move up one line")
  88. },
  89. {
  90. QsciCommand::LineUpExtend,
  91. Qt::Key_Up | Qt::SHIFT,
  92. #if defined(USING_OSX_KEYS)
  93. Qt::Key_P | Qt::META | Qt::SHIFT,
  94. #else
  95. 0,
  96. #endif
  97. QT_TRANSLATE_NOOP("QsciCommand", "Extend selection up one line")
  98. },
  99. {
  100. QsciCommand::LineUpRectExtend,
  101. Qt::Key_Up | Qt::ALT | Qt::SHIFT,
  102. #if defined(USING_OSX_KEYS)
  103. Qt::Key_P | Qt::META | Qt::ALT | Qt::SHIFT,
  104. #else
  105. 0,
  106. #endif
  107. QT_TRANSLATE_NOOP("QsciCommand",
  108. "Extend rectangular selection up one line")
  109. },
  110. {
  111. QsciCommand::LineScrollUp,
  112. Qt::Key_Up | Qt::CTRL,
  113. 0,
  114. QT_TRANSLATE_NOOP("QsciCommand", "Scroll view up one line")
  115. },
  116. {
  117. QsciCommand::ScrollToStart,
  118. #if defined(USING_OSX_KEYS)
  119. Qt::Key_Home,
  120. #else
  121. 0,
  122. #endif
  123. 0,
  124. QT_TRANSLATE_NOOP("QsciCommand", "Scroll to start of document")
  125. },
  126. {
  127. QsciCommand::ScrollToEnd,
  128. #if defined(USING_OSX_KEYS)
  129. Qt::Key_End,
  130. #else
  131. 0,
  132. #endif
  133. 0,
  134. QT_TRANSLATE_NOOP("QsciCommand", "Scroll to end of document")
  135. },
  136. {
  137. QsciCommand::VerticalCentreCaret,
  138. #if defined(USING_OSX_KEYS)
  139. Qt::Key_L | Qt::META,
  140. #else
  141. 0,
  142. #endif
  143. 0,
  144. QT_TRANSLATE_NOOP("QsciCommand",
  145. "Scroll vertically to centre current line")
  146. },
  147. {
  148. QsciCommand::ParaDown,
  149. Qt::Key_BracketRight | Qt::CTRL,
  150. 0,
  151. QT_TRANSLATE_NOOP("QsciCommand", "Move down one paragraph")
  152. },
  153. {
  154. QsciCommand::ParaDownExtend,
  155. Qt::Key_BracketRight | Qt::CTRL | Qt::SHIFT,
  156. 0,
  157. QT_TRANSLATE_NOOP("QsciCommand",
  158. "Extend selection down one paragraph")
  159. },
  160. {
  161. QsciCommand::ParaUp,
  162. Qt::Key_BracketLeft | Qt::CTRL,
  163. 0,
  164. QT_TRANSLATE_NOOP("QsciCommand", "Move up one paragraph")
  165. },
  166. {
  167. QsciCommand::ParaUpExtend,
  168. Qt::Key_BracketLeft | Qt::CTRL | Qt::SHIFT,
  169. 0,
  170. QT_TRANSLATE_NOOP("QsciCommand",
  171. "Extend selection up one paragraph")
  172. },
  173. {
  174. QsciCommand::CharLeft,
  175. Qt::Key_Left,
  176. #if defined(USING_OSX_KEYS)
  177. Qt::Key_B | Qt::META,
  178. #else
  179. 0,
  180. #endif
  181. QT_TRANSLATE_NOOP("QsciCommand", "Move left one character")
  182. },
  183. {
  184. QsciCommand::CharLeftExtend,
  185. Qt::Key_Left | Qt::SHIFT,
  186. #if defined(USING_OSX_KEYS)
  187. Qt::Key_B | Qt::META | Qt::SHIFT,
  188. #else
  189. 0,
  190. #endif
  191. QT_TRANSLATE_NOOP("QsciCommand",
  192. "Extend selection left one character")
  193. },
  194. {
  195. QsciCommand::CharLeftRectExtend,
  196. Qt::Key_Left | Qt::ALT | Qt::SHIFT,
  197. #if defined(USING_OSX_KEYS)
  198. Qt::Key_B | Qt::META | Qt::ALT | Qt::SHIFT,
  199. #else
  200. 0,
  201. #endif
  202. QT_TRANSLATE_NOOP("QsciCommand",
  203. "Extend rectangular selection left one character")
  204. },
  205. {
  206. QsciCommand::CharRight,
  207. Qt::Key_Right,
  208. #if defined(USING_OSX_KEYS)
  209. Qt::Key_F | Qt::META,
  210. #else
  211. 0,
  212. #endif
  213. QT_TRANSLATE_NOOP("QsciCommand", "Move right one character")
  214. },
  215. {
  216. QsciCommand::CharRightExtend,
  217. Qt::Key_Right | Qt::SHIFT,
  218. #if defined(USING_OSX_KEYS)
  219. Qt::Key_F | Qt::META | Qt::SHIFT,
  220. #else
  221. 0,
  222. #endif
  223. QT_TRANSLATE_NOOP("QsciCommand",
  224. "Extend selection right one character")
  225. },
  226. {
  227. QsciCommand::CharRightRectExtend,
  228. Qt::Key_Right | Qt::ALT | Qt::SHIFT,
  229. #if defined(USING_OSX_KEYS)
  230. Qt::Key_F | Qt::META | Qt::ALT | Qt::SHIFT,
  231. #else
  232. 0,
  233. #endif
  234. QT_TRANSLATE_NOOP("QsciCommand",
  235. "Extend rectangular selection right one character")
  236. },
  237. {
  238. QsciCommand::WordLeft,
  239. #if defined(USING_OSX_KEYS)
  240. Qt::Key_Left | Qt::ALT,
  241. #else
  242. Qt::Key_Left | Qt::CTRL,
  243. #endif
  244. 0,
  245. QT_TRANSLATE_NOOP("QsciCommand", "Move left one word")
  246. },
  247. {
  248. QsciCommand::WordLeftExtend,
  249. #if defined(USING_OSX_KEYS)
  250. Qt::Key_Left | Qt::ALT | Qt::SHIFT,
  251. #else
  252. Qt::Key_Left | Qt::CTRL | Qt::SHIFT,
  253. #endif
  254. 0,
  255. QT_TRANSLATE_NOOP("QsciCommand", "Extend selection left one word")
  256. },
  257. {
  258. QsciCommand::WordRight,
  259. #if defined(USING_OSX_KEYS)
  260. 0,
  261. #else
  262. Qt::Key_Right | Qt::CTRL,
  263. #endif
  264. 0,
  265. QT_TRANSLATE_NOOP("QsciCommand", "Move right one word")
  266. },
  267. {
  268. QsciCommand::WordRightExtend,
  269. Qt::Key_Right | Qt::CTRL | Qt::SHIFT,
  270. 0,
  271. QT_TRANSLATE_NOOP("QsciCommand", "Extend selection right one word")
  272. },
  273. {
  274. QsciCommand::WordLeftEnd,
  275. 0,
  276. 0,
  277. QT_TRANSLATE_NOOP("QsciCommand", "Move to end of previous word")
  278. },
  279. {
  280. QsciCommand::WordLeftEndExtend,
  281. 0,
  282. 0,
  283. QT_TRANSLATE_NOOP("QsciCommand",
  284. "Extend selection to end of previous word")
  285. },
  286. {
  287. QsciCommand::WordRightEnd,
  288. #if defined(USING_OSX_KEYS)
  289. Qt::Key_Right | Qt::ALT,
  290. #else
  291. 0,
  292. #endif
  293. 0,
  294. QT_TRANSLATE_NOOP("QsciCommand", "Move to end of next word")
  295. },
  296. {
  297. QsciCommand::WordRightEndExtend,
  298. #if defined(USING_OSX_KEYS)
  299. Qt::Key_Right | Qt::ALT | Qt::SHIFT,
  300. #else
  301. 0,
  302. #endif
  303. 0,
  304. QT_TRANSLATE_NOOP("QsciCommand",
  305. "Extend selection to end of next word")
  306. },
  307. {
  308. QsciCommand::WordPartLeft,
  309. Qt::Key_Slash | Qt::CTRL,
  310. 0,
  311. QT_TRANSLATE_NOOP("QsciCommand", "Move left one word part")
  312. },
  313. {
  314. QsciCommand::WordPartLeftExtend,
  315. Qt::Key_Slash | Qt::CTRL | Qt::SHIFT,
  316. 0,
  317. QT_TRANSLATE_NOOP("QsciCommand",
  318. "Extend selection left one word part")
  319. },
  320. {
  321. QsciCommand::WordPartRight,
  322. Qt::Key_Backslash | Qt::CTRL,
  323. 0,
  324. QT_TRANSLATE_NOOP("QsciCommand", "Move right one word part")
  325. },
  326. {
  327. QsciCommand::WordPartRightExtend,
  328. Qt::Key_Backslash | Qt::CTRL | Qt::SHIFT,
  329. 0,
  330. QT_TRANSLATE_NOOP("QsciCommand",
  331. "Extend selection right one word part")
  332. },
  333. {
  334. QsciCommand::Home,
  335. #if defined(USING_OSX_KEYS)
  336. Qt::Key_A | Qt::META,
  337. #else
  338. 0,
  339. #endif
  340. 0,
  341. QT_TRANSLATE_NOOP("QsciCommand", "Move to start of document line")
  342. },
  343. {
  344. QsciCommand::HomeExtend,
  345. #if defined(USING_OSX_KEYS)
  346. Qt::Key_A | Qt::META | Qt::SHIFT,
  347. #else
  348. 0,
  349. #endif
  350. 0,
  351. QT_TRANSLATE_NOOP("QsciCommand",
  352. "Extend selection to start of document line")
  353. },
  354. {
  355. QsciCommand::HomeRectExtend,
  356. #if defined(USING_OSX_KEYS)
  357. Qt::Key_A | Qt::META | Qt::ALT | Qt::SHIFT,
  358. #else
  359. 0,
  360. #endif
  361. 0,
  362. QT_TRANSLATE_NOOP("QsciCommand",
  363. "Extend rectangular selection to start of document line")
  364. },
  365. {
  366. QsciCommand::HomeDisplay,
  367. #if defined(USING_OSX_KEYS)
  368. Qt::Key_Left | Qt::CTRL,
  369. #else
  370. Qt::Key_Home | Qt::ALT,
  371. #endif
  372. 0,
  373. QT_TRANSLATE_NOOP("QsciCommand", "Move to start of display line")
  374. },
  375. {
  376. QsciCommand::HomeDisplayExtend,
  377. #if defined(USING_OSX_KEYS)
  378. Qt::Key_Left | Qt::CTRL | Qt::SHIFT,
  379. #else
  380. 0,
  381. #endif
  382. 0,
  383. QT_TRANSLATE_NOOP("QsciCommand",
  384. "Extend selection to start of display line")
  385. },
  386. {
  387. QsciCommand::HomeWrap,
  388. 0,
  389. 0,
  390. QT_TRANSLATE_NOOP("QsciCommand",
  391. "Move to start of display or document line")
  392. },
  393. {
  394. QsciCommand::HomeWrapExtend,
  395. 0,
  396. 0,
  397. QT_TRANSLATE_NOOP("QsciCommand",
  398. "Extend selection to start of display or document line")
  399. },
  400. {
  401. QsciCommand::VCHome,
  402. #if defined(USING_OSX_KEYS)
  403. 0,
  404. #else
  405. Qt::Key_Home,
  406. #endif
  407. 0,
  408. QT_TRANSLATE_NOOP("QsciCommand",
  409. "Move to first visible character in document line")
  410. },
  411. {
  412. QsciCommand::VCHomeExtend,
  413. #if defined(USING_OSX_KEYS)
  414. 0,
  415. #else
  416. Qt::Key_Home | Qt::SHIFT,
  417. #endif
  418. 0,
  419. QT_TRANSLATE_NOOP("QsciCommand",
  420. "Extend selection to first visible character in document line")
  421. },
  422. {
  423. QsciCommand::VCHomeRectExtend,
  424. #if defined(USING_OSX_KEYS)
  425. 0,
  426. #else
  427. Qt::Key_Home | Qt::ALT | Qt::SHIFT,
  428. #endif
  429. 0,
  430. QT_TRANSLATE_NOOP("QsciCommand",
  431. "Extend rectangular selection to first visible character in document line")
  432. },
  433. {
  434. QsciCommand::VCHomeWrap,
  435. 0,
  436. 0,
  437. QT_TRANSLATE_NOOP("QsciCommand",
  438. "Move to first visible character of display in document line")
  439. },
  440. {
  441. QsciCommand::VCHomeWrapExtend,
  442. 0,
  443. 0,
  444. QT_TRANSLATE_NOOP("QsciCommand",
  445. "Extend selection to first visible character in display or document line")
  446. },
  447. {
  448. QsciCommand::LineEnd,
  449. #if defined(USING_OSX_KEYS)
  450. Qt::Key_E | Qt::META,
  451. #else
  452. Qt::Key_End,
  453. #endif
  454. 0,
  455. QT_TRANSLATE_NOOP("QsciCommand", "Move to end of document line")
  456. },
  457. {
  458. QsciCommand::LineEndExtend,
  459. #if defined(USING_OSX_KEYS)
  460. Qt::Key_E | Qt::META | Qt::SHIFT,
  461. #else
  462. Qt::Key_End | Qt::SHIFT,
  463. #endif
  464. 0,
  465. QT_TRANSLATE_NOOP("QsciCommand",
  466. "Extend selection to end of document line")
  467. },
  468. {
  469. QsciCommand::LineEndRectExtend,
  470. #if defined(USING_OSX_KEYS)
  471. Qt::Key_E | Qt::META | Qt::ALT | Qt::SHIFT,
  472. #else
  473. Qt::Key_End | Qt::ALT | Qt::SHIFT,
  474. #endif
  475. 0,
  476. QT_TRANSLATE_NOOP("QsciCommand",
  477. "Extend rectangular selection to end of document line")
  478. },
  479. {
  480. QsciCommand::LineEndDisplay,
  481. #if defined(USING_OSX_KEYS)
  482. Qt::Key_Right | Qt::CTRL,
  483. #else
  484. Qt::Key_End | Qt::ALT,
  485. #endif
  486. 0,
  487. QT_TRANSLATE_NOOP("QsciCommand", "Move to end of display line")
  488. },
  489. {
  490. QsciCommand::LineEndDisplayExtend,
  491. #if defined(USING_OSX_KEYS)
  492. Qt::Key_Right | Qt::CTRL | Qt::SHIFT,
  493. #else
  494. 0,
  495. #endif
  496. 0,
  497. QT_TRANSLATE_NOOP("QsciCommand",
  498. "Extend selection to end of display line")
  499. },
  500. {
  501. QsciCommand::LineEndWrap,
  502. 0,
  503. 0,
  504. QT_TRANSLATE_NOOP("QsciCommand",
  505. "Move to end of display or document line")
  506. },
  507. {
  508. QsciCommand::LineEndWrapExtend,
  509. 0,
  510. 0,
  511. QT_TRANSLATE_NOOP("QsciCommand",
  512. "Extend selection to end of display or document line")
  513. },
  514. {
  515. QsciCommand::DocumentStart,
  516. #if defined(USING_OSX_KEYS)
  517. Qt::Key_Up | Qt::CTRL,
  518. #else
  519. Qt::Key_Home | Qt::CTRL,
  520. #endif
  521. 0,
  522. QT_TRANSLATE_NOOP("QsciCommand", "Move to start of document")
  523. },
  524. {
  525. QsciCommand::DocumentStartExtend,
  526. #if defined(USING_OSX_KEYS)
  527. Qt::Key_Up | Qt::CTRL | Qt::SHIFT,
  528. #else
  529. Qt::Key_Home | Qt::CTRL | Qt::SHIFT,
  530. #endif
  531. 0,
  532. QT_TRANSLATE_NOOP("QsciCommand",
  533. "Extend selection to start of document")
  534. },
  535. {
  536. QsciCommand::DocumentEnd,
  537. #if defined(USING_OSX_KEYS)
  538. Qt::Key_Down | Qt::CTRL,
  539. #else
  540. Qt::Key_End | Qt::CTRL,
  541. #endif
  542. 0,
  543. QT_TRANSLATE_NOOP("QsciCommand", "Move to end of document")
  544. },
  545. {
  546. QsciCommand::DocumentEndExtend,
  547. #if defined(USING_OSX_KEYS)
  548. Qt::Key_Down | Qt::CTRL | Qt::SHIFT,
  549. #else
  550. Qt::Key_End | Qt::CTRL | Qt::SHIFT,
  551. #endif
  552. 0,
  553. QT_TRANSLATE_NOOP("QsciCommand",
  554. "Extend selection to end of document")
  555. },
  556. {
  557. QsciCommand::PageUp,
  558. Qt::Key_PageUp,
  559. 0,
  560. QT_TRANSLATE_NOOP("QsciCommand", "Move up one page")
  561. },
  562. {
  563. QsciCommand::PageUpExtend,
  564. Qt::Key_PageUp | Qt::SHIFT,
  565. 0,
  566. QT_TRANSLATE_NOOP("QsciCommand", "Extend selection up one page")
  567. },
  568. {
  569. QsciCommand::PageUpRectExtend,
  570. Qt::Key_PageUp | Qt::ALT | Qt::SHIFT,
  571. 0,
  572. QT_TRANSLATE_NOOP("QsciCommand",
  573. "Extend rectangular selection up one page")
  574. },
  575. {
  576. QsciCommand::PageDown,
  577. Qt::Key_PageDown,
  578. #if defined(USING_OSX_KEYS)
  579. Qt::Key_V | Qt::META,
  580. #else
  581. 0,
  582. #endif
  583. QT_TRANSLATE_NOOP("QsciCommand", "Move down one page")
  584. },
  585. {
  586. QsciCommand::PageDownExtend,
  587. Qt::Key_PageDown | Qt::SHIFT,
  588. #if defined(USING_OSX_KEYS)
  589. Qt::Key_V | Qt::META | Qt::SHIFT,
  590. #else
  591. 0,
  592. #endif
  593. QT_TRANSLATE_NOOP("QsciCommand", "Extend selection down one page")
  594. },
  595. {
  596. QsciCommand::PageDownRectExtend,
  597. Qt::Key_PageDown | Qt::ALT | Qt::SHIFT,
  598. #if defined(USING_OSX_KEYS)
  599. Qt::Key_V | Qt::META | Qt::ALT | Qt::SHIFT,
  600. #else
  601. 0,
  602. #endif
  603. QT_TRANSLATE_NOOP("QsciCommand",
  604. "Extend rectangular selection down one page")
  605. },
  606. {
  607. QsciCommand::StutteredPageUp,
  608. 0,
  609. 0,
  610. QT_TRANSLATE_NOOP("QsciCommand", "Stuttered move up one page")
  611. },
  612. {
  613. QsciCommand::StutteredPageUpExtend,
  614. 0,
  615. 0,
  616. QT_TRANSLATE_NOOP("QsciCommand",
  617. "Stuttered extend selection up one page")
  618. },
  619. {
  620. QsciCommand::StutteredPageDown,
  621. 0,
  622. 0,
  623. QT_TRANSLATE_NOOP("QsciCommand", "Stuttered move down one page")
  624. },
  625. {
  626. QsciCommand::StutteredPageDownExtend,
  627. 0,
  628. 0,
  629. QT_TRANSLATE_NOOP("QsciCommand",
  630. "Stuttered extend selection down one page")
  631. },
  632. {
  633. QsciCommand::Delete,
  634. Qt::Key_Delete,
  635. #if defined(USING_OSX_KEYS)
  636. Qt::Key_D | Qt::META,
  637. #else
  638. 0,
  639. #endif
  640. QT_TRANSLATE_NOOP("QsciCommand", "Delete current character")
  641. },
  642. {
  643. QsciCommand::DeleteBack,
  644. Qt::Key_Backspace,
  645. #if defined(USING_OSX_KEYS)
  646. Qt::Key_H | Qt::META,
  647. #else
  648. Qt::Key_Backspace | Qt::SHIFT,
  649. #endif
  650. QT_TRANSLATE_NOOP("QsciCommand", "Delete previous character")
  651. },
  652. {
  653. QsciCommand::DeleteBackNotLine,
  654. 0,
  655. 0,
  656. QT_TRANSLATE_NOOP("QsciCommand",
  657. "Delete previous character if not at start of line")
  658. },
  659. {
  660. QsciCommand::DeleteWordLeft,
  661. Qt::Key_Backspace | Qt::CTRL,
  662. 0,
  663. QT_TRANSLATE_NOOP("QsciCommand", "Delete word to left")
  664. },
  665. {
  666. QsciCommand::DeleteWordRight,
  667. Qt::Key_Delete | Qt::CTRL,
  668. 0,
  669. QT_TRANSLATE_NOOP("QsciCommand", "Delete word to right")
  670. },
  671. {
  672. QsciCommand::DeleteWordRightEnd,
  673. #if defined(USING_OSX_KEYS)
  674. Qt::Key_Delete | Qt::ALT,
  675. #else
  676. 0,
  677. #endif
  678. 0,
  679. QT_TRANSLATE_NOOP("QsciCommand",
  680. "Delete right to end of next word")
  681. },
  682. {
  683. QsciCommand::DeleteLineLeft,
  684. Qt::Key_Backspace | Qt::CTRL | Qt::SHIFT,
  685. 0,
  686. QT_TRANSLATE_NOOP("QsciCommand", "Delete line to left")
  687. },
  688. {
  689. QsciCommand::DeleteLineRight,
  690. #if defined(USING_OSX_KEYS)
  691. Qt::Key_K | Qt::META,
  692. #else
  693. Qt::Key_Delete | Qt::CTRL | Qt::SHIFT,
  694. #endif
  695. 0,
  696. QT_TRANSLATE_NOOP("QsciCommand", "Delete line to right")
  697. },
  698. {
  699. QsciCommand::LineDelete,
  700. Qt::Key_L | Qt::CTRL | Qt::SHIFT,
  701. 0,
  702. QT_TRANSLATE_NOOP("QsciCommand", "Delete current line")
  703. },
  704. {
  705. QsciCommand::LineCut,
  706. Qt::Key_L | Qt::CTRL,
  707. 0,
  708. QT_TRANSLATE_NOOP("QsciCommand", "Cut current line")
  709. },
  710. {
  711. QsciCommand::LineCopy,
  712. Qt::Key_T | Qt::CTRL | Qt::SHIFT,
  713. 0,
  714. QT_TRANSLATE_NOOP("QsciCommand", "Copy current line")
  715. },
  716. {
  717. QsciCommand::LineTranspose,
  718. Qt::Key_T | Qt::CTRL,
  719. 0,
  720. QT_TRANSLATE_NOOP("QsciCommand",
  721. "Transpose current and previous lines")
  722. },
  723. {
  724. QsciCommand::LineDuplicate,
  725. 0,
  726. 0,
  727. QT_TRANSLATE_NOOP("QsciCommand", "Duplicate the current line")
  728. },
  729. {
  730. QsciCommand::SelectAll,
  731. Qt::Key_A | Qt::CTRL,
  732. 0,
  733. QT_TRANSLATE_NOOP("QsciCommand", "Select all")
  734. },
  735. {
  736. QsciCommand::MoveSelectedLinesUp,
  737. 0,
  738. 0,
  739. QT_TRANSLATE_NOOP("QsciCommand", "Move selected lines up one line")
  740. },
  741. {
  742. QsciCommand::MoveSelectedLinesDown,
  743. 0,
  744. 0,
  745. QT_TRANSLATE_NOOP("QsciCommand",
  746. "Move selected lines down one line")
  747. },
  748. {
  749. QsciCommand::SelectionDuplicate,
  750. Qt::Key_D | Qt::CTRL,
  751. 0,
  752. QT_TRANSLATE_NOOP("QsciCommand", "Duplicate selection")
  753. },
  754. {
  755. QsciCommand::SelectionLowerCase,
  756. Qt::Key_U | Qt::CTRL,
  757. 0,
  758. QT_TRANSLATE_NOOP("QsciCommand", "Convert selection to lower case")
  759. },
  760. {
  761. QsciCommand::SelectionUpperCase,
  762. Qt::Key_U | Qt::CTRL | Qt::SHIFT,
  763. 0,
  764. QT_TRANSLATE_NOOP("QsciCommand", "Convert selection to upper case")
  765. },
  766. {
  767. QsciCommand::SelectionCut,
  768. Qt::Key_X | Qt::CTRL,
  769. Qt::Key_Delete | Qt::SHIFT,
  770. QT_TRANSLATE_NOOP("QsciCommand", "Cut selection")
  771. },
  772. {
  773. QsciCommand::SelectionCopy,
  774. Qt::Key_C | Qt::CTRL,
  775. Qt::Key_Insert | Qt::CTRL,
  776. QT_TRANSLATE_NOOP("QsciCommand", "Copy selection")
  777. },
  778. {
  779. QsciCommand::Paste,
  780. Qt::Key_V | Qt::CTRL,
  781. Qt::Key_Insert | Qt::SHIFT,
  782. QT_TRANSLATE_NOOP("QsciCommand", "Paste")
  783. },
  784. {
  785. QsciCommand::EditToggleOvertype,
  786. Qt::Key_Insert,
  787. 0,
  788. QT_TRANSLATE_NOOP("QsciCommand", "Toggle insert/overtype")
  789. },
  790. {
  791. QsciCommand::Newline,
  792. Qt::Key_Return,
  793. Qt::Key_Return | Qt::SHIFT,
  794. QT_TRANSLATE_NOOP("QsciCommand", "Insert newline")
  795. },
  796. {
  797. QsciCommand::Formfeed,
  798. 0,
  799. 0,
  800. QT_TRANSLATE_NOOP("QsciCommand", "Formfeed")
  801. },
  802. {
  803. QsciCommand::Tab,
  804. Qt::Key_Tab,
  805. 0,
  806. QT_TRANSLATE_NOOP("QsciCommand", "Indent one level")
  807. },
  808. {
  809. QsciCommand::Backtab,
  810. Qt::Key_Tab | Qt::SHIFT,
  811. 0,
  812. QT_TRANSLATE_NOOP("QsciCommand", "De-indent one level")
  813. },
  814. {
  815. QsciCommand::Cancel,
  816. Qt::Key_Escape,
  817. 0,
  818. QT_TRANSLATE_NOOP("QsciCommand", "Cancel")
  819. },
  820. {
  821. QsciCommand::Undo,
  822. Qt::Key_Z | Qt::CTRL,
  823. Qt::Key_Backspace | Qt::ALT,
  824. QT_TRANSLATE_NOOP("QsciCommand", "Undo last command")
  825. },
  826. {
  827. QsciCommand::Redo,
  828. #if defined(USING_OSX_KEYS)
  829. Qt::Key_Z | Qt::CTRL | Qt::SHIFT,
  830. #else
  831. Qt::Key_Y | Qt::CTRL,
  832. #endif
  833. 0,
  834. QT_TRANSLATE_NOOP("QsciCommand", "Redo last command")
  835. },
  836. {
  837. QsciCommand::ZoomIn,
  838. Qt::Key_Plus | Qt::CTRL,
  839. 0,
  840. QT_TRANSLATE_NOOP("QsciCommand", "Zoom in")
  841. },
  842. {
  843. QsciCommand::ZoomOut,
  844. Qt::Key_Minus | Qt::CTRL,
  845. 0,
  846. QT_TRANSLATE_NOOP("QsciCommand", "Zoom out")
  847. },
  848. };
  849. // Clear the default map.
  850. qsci->SendScintilla(QsciScintillaBase::SCI_CLEARALLCMDKEYS);
  851. // By default control characters don't do anything (rather than insert the
  852. // control character into the text).
  853. for (int k = 'A'; k <= 'Z'; ++k)
  854. qsci->SendScintilla(QsciScintillaBase::SCI_ASSIGNCMDKEY,
  855. k + (QsciScintillaBase::SCMOD_CTRL << 16),
  856. QsciScintillaBase::SCI_NULL);
  857. for (int i = 0; i < sizeof (cmd_table) / sizeof (cmd_table[0]); ++i)
  858. cmds.append(
  859. new QsciCommand(qsci, cmd_table[i].cmd, cmd_table[i].key,
  860. cmd_table[i].altkey, cmd_table[i].desc));
  861. }
  862. // The dtor.
  863. QsciCommandSet::~QsciCommandSet()
  864. {
  865. for (int i = 0; i < cmds.count(); ++i)
  866. delete cmds.at(i);
  867. }
  868. // Read the command set from settings.
  869. bool QsciCommandSet::readSettings(QSettings &qs, const char *prefix)
  870. {
  871. bool rc = true;
  872. QString skey;
  873. for (int i = 0; i < cmds.count(); ++i)
  874. {
  875. QsciCommand *cmd = cmds.at(i);
  876. skey.sprintf("%s/keymap/c%d/", prefix,
  877. static_cast<int>(cmd->command()));
  878. int key;
  879. bool ok;
  880. // Read the key.
  881. ok = qs.contains(skey + "key");
  882. key = qs.value(skey + "key", 0).toInt();
  883. if (ok)
  884. cmd->setKey(key);
  885. else
  886. rc = false;
  887. // Read the alternate key.
  888. ok = qs.contains(skey + "alt");
  889. key = qs.value(skey + "alt", 0).toInt();
  890. if (ok)
  891. cmd->setAlternateKey(key);
  892. else
  893. rc = false;
  894. }
  895. return rc;
  896. }
  897. // Write the command set to settings.
  898. bool QsciCommandSet::writeSettings(QSettings &qs, const char *prefix)
  899. {
  900. bool rc = true;
  901. QString skey;
  902. for (int i = 0; i < cmds.count(); ++i)
  903. {
  904. QsciCommand *cmd = cmds.at(i);
  905. skey.sprintf("%s/keymap/c%d/", prefix,
  906. static_cast<int>(cmd->command()));
  907. // Write the key.
  908. qs.setValue(skey + "key", cmd->key());
  909. // Write the alternate key.
  910. qs.setValue(skey + "alt", cmd->key());
  911. }
  912. return rc;
  913. }
  914. // Clear the key bindings.
  915. void QsciCommandSet::clearKeys()
  916. {
  917. for (int i = 0; i < cmds.count(); ++i)
  918. cmds.at(i)->setKey(0);
  919. }
  920. // Clear the alternate key bindings.
  921. void QsciCommandSet::clearAlternateKeys()
  922. {
  923. for (int i = 0; i < cmds.count(); ++i)
  924. cmds.at(i)->setAlternateKey(0);
  925. }
  926. // Find the command bound to a key.
  927. QsciCommand *QsciCommandSet::boundTo(int key) const
  928. {
  929. for (int i = 0; i < cmds.count(); ++i)
  930. {
  931. QsciCommand *cmd = cmds.at(i);
  932. if (cmd->key() == key || cmd->alternateKey() == key)
  933. return cmd;
  934. }
  935. return 0;
  936. }
  937. // Find a command.
  938. QsciCommand *QsciCommandSet::find(QsciCommand::Command command) const
  939. {
  940. for (int i = 0; i < cmds.count(); ++i)
  941. {
  942. QsciCommand *cmd = cmds.at(i);
  943. if (cmd->command() == command)
  944. return cmd;
  945. }
  946. // This should never happen.
  947. return 0;
  948. }