qscilexertcl.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. // This module implements the QsciLexerTCL 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/qscilexertcl.h"
  20. #include <qcolor.h>
  21. #include <qfont.h>
  22. #include <qsettings.h>
  23. // The ctor.
  24. QsciLexerTCL::QsciLexerTCL(QObject *parent)
  25. : QsciLexer(parent), fold_comments(false)
  26. {
  27. }
  28. // The dtor.
  29. QsciLexerTCL::~QsciLexerTCL()
  30. {
  31. }
  32. // Returns the language name.
  33. const char *QsciLexerTCL::language() const
  34. {
  35. return "TCL";
  36. }
  37. // Returns the lexer name.
  38. const char *QsciLexerTCL::lexer() const
  39. {
  40. return "tcl";
  41. }
  42. // Return the style used for braces.
  43. int QsciLexerTCL::braceStyle() const
  44. {
  45. return Operator;
  46. }
  47. // Returns the foreground colour of the text for a style.
  48. QColor QsciLexerTCL::defaultColor(int style) const
  49. {
  50. switch (style)
  51. {
  52. case Default:
  53. return QColor(0x80,0x80,0x80);
  54. case Comment:
  55. case CommentLine:
  56. case CommentBox:
  57. return QColor(0x00,0x7f,0x00);
  58. case Number:
  59. return QColor(0x00,0x7f,0x7f);
  60. case QuotedKeyword:
  61. case QuotedString:
  62. case Modifier:
  63. return QColor(0x7f,0x00,0x7f);
  64. case Operator:
  65. return QColor(0x00,0x00,0x00);
  66. case Identifier:
  67. case ExpandKeyword:
  68. case TCLKeyword:
  69. case TkKeyword:
  70. case ITCLKeyword:
  71. case TkCommand:
  72. case KeywordSet6:
  73. case KeywordSet7:
  74. case KeywordSet8:
  75. case KeywordSet9:
  76. return QColor(0x00,0x00,0x7f);
  77. case Substitution:
  78. case SubstitutionBrace:
  79. return QColor(0x7f,0x7f,0x00);
  80. }
  81. return QsciLexer::defaultColor(style);
  82. }
  83. // Returns the end-of-line fill for a style.
  84. bool QsciLexerTCL::defaultEolFill(int style) const
  85. {
  86. switch (style)
  87. {
  88. case QuotedString:
  89. case CommentBox:
  90. return true;
  91. }
  92. return QsciLexer::defaultEolFill(style);
  93. }
  94. // Returns the font of the text for a style.
  95. QFont QsciLexerTCL::defaultFont(int style) const
  96. {
  97. QFont f;
  98. switch (style)
  99. {
  100. case Comment:
  101. case CommentLine:
  102. case CommentBox:
  103. #if defined(Q_OS_WIN)
  104. f = QFont("Comic Sans MS", 9);
  105. #elif defined(Q_OS_MAC)
  106. f = QFont("Comic Sans MS", 12);
  107. #else
  108. f = QFont("Bitstream Vera Serif", 9);
  109. #endif
  110. break;
  111. case QuotedKeyword:
  112. case Operator:
  113. case ExpandKeyword:
  114. case TCLKeyword:
  115. case TkKeyword:
  116. case ITCLKeyword:
  117. case TkCommand:
  118. f = QsciLexer::defaultFont(style);
  119. f.setBold(true);
  120. break;
  121. case CommentBlock:
  122. #if defined(Q_OS_WIN)
  123. f = QFont("Comic Sans MS", 8);
  124. #elif defined(Q_OS_MAC)
  125. f = QFont("Comic Sans MS", 11);
  126. #else
  127. f = QFont("Serif", 9);
  128. #endif
  129. break;
  130. default:
  131. f = QsciLexer::defaultFont(style);
  132. }
  133. return f;
  134. }
  135. // Returns the set of keywords.
  136. const char *QsciLexerTCL::keywords(int set) const
  137. {
  138. if (set == 1)
  139. return
  140. "after append array auto_execok auto_import auto_load "
  141. "auto_load_index auto_qualify beep bgerror binary break case "
  142. "catch cd clock close concat continue dde default echo else "
  143. "elseif encoding eof error eval exec exit expr fblocked "
  144. "fconfigure fcopy file fileevent flush for foreach format gets "
  145. "glob global history http if incr info interp join lappend lindex "
  146. "linsert list llength load loadTk lrange lreplace lsearch lset "
  147. "lsort memory msgcat namespace open package pid pkg::create "
  148. "pkg_mkIndex Platform-specific proc puts pwd re_syntax read "
  149. "regexp registry regsub rename resource return scan seek set "
  150. "socket source split string subst switch tclLog tclMacPkgSearch "
  151. "tclPkgSetup tclPkgUnknown tell time trace unknown unset update "
  152. "uplevel upvar variable vwait while";
  153. if (set == 2)
  154. return
  155. "bell bind bindtags bitmap button canvas checkbutton clipboard "
  156. "colors console cursors destroy entry event focus font frame grab "
  157. "grid image Inter-client keysyms label labelframe listbox lower "
  158. "menu menubutton message option options pack panedwindow photo "
  159. "place radiobutton raise scale scrollbar selection send spinbox "
  160. "text tk tk_chooseColor tk_chooseDirectory tk_dialog tk_focusNext "
  161. "tk_getOpenFile tk_messageBox tk_optionMenu tk_popup "
  162. "tk_setPalette tkerror tkvars tkwait toplevel winfo wish wm";
  163. if (set == 3)
  164. return
  165. "@scope body class code common component configbody constructor "
  166. "define destructor hull import inherit itcl itk itk_component "
  167. "itk_initialize itk_interior itk_option iwidgets keep method "
  168. "private protected public";
  169. if (set == 4)
  170. return
  171. "tk_bisque tk_chooseColor tk_dialog tk_focusFollowsMouse "
  172. "tk_focusNext tk_focusPrev tk_getOpenFile tk_getSaveFile "
  173. "tk_messageBox tk_optionMenu tk_popup tk_setPalette tk_textCopy "
  174. "tk_textCut tk_textPaste tkButtonAutoInvoke tkButtonDown "
  175. "tkButtonEnter tkButtonInvoke tkButtonLeave tkButtonUp "
  176. "tkCancelRepeat tkCheckRadioDown tkCheckRadioEnter "
  177. "tkCheckRadioInvoke tkColorDialog tkColorDialog_BuildDialog "
  178. "tkColorDialog_CancelCmd tkColorDialog_Config "
  179. "tkColorDialog_CreateSelector tkColorDialog_DrawColorScale "
  180. "tkColorDialog_EnterColorBar tkColorDialog_HandleRGB Entry "
  181. "tkColorDialog_HandleSelEntry tkColorDialog_InitValues "
  182. "tkColorDialog_LeaveColorBar tkColorDialog_MoveSelector "
  183. "tkColorDialog_OkCmd tkColorDialog_RedrawColorBars "
  184. "tkColorDialog_RedrawFinalColor tkColorDialog_ReleaseMouse "
  185. "tkColorDialog_ResizeColorBars tkColorDialog_RgbToX "
  186. "tkColorDialog_SetRGBValue tkColorDialog_StartMove "
  187. "tkColorDialog_XToRgb tkConsoleAbout tkConsoleBind tkConsoleExit "
  188. "tkConsoleHistory tkConsoleInit tkConsoleInsert tkConsoleInvoke "
  189. "tkConsoleOutput tkConsolePrompt tkConsoleSource tkDarken "
  190. "tkEntryAutoScan tkEntryBackspace tkEntryButton1 "
  191. "tkEntryClosestGap tkEntryGetSelection tkEntryInsert "
  192. "tkEntryKeySelect tkEntryMouseSelect tkEntryNextWord tkEntryPaste "
  193. "tkEntryPreviousWord tkEntrySeeInsert tkEntrySetCursor "
  194. "tkEntryTranspose tkEventMotifBindings tkFDGetFileTypes "
  195. "tkFirstMenu tkFocusGroup_BindIn tkFocusGroup_BindOut "
  196. "tkFocusGroup_Create tkFocusGroup_Destroy tkFocusGroup_In "
  197. "tkFocusGroup_Out tkFocusOK tkGenerateMenuSelect tkIconList "
  198. "tkIconList_Add tkIconList_Arrange tkIconList_AutoScan "
  199. "tkIconList_Btn1 tkIconList_Config tkIconList_Create "
  200. "tkIconList_CtrlBtn1 tkIconList_Curselection tkIconList_DeleteAll "
  201. "tkIconList_Double1 tkIconList_DrawSelection tkIconList_FocusIn "
  202. "tkIconList_FocusOut tkIconList_Get tkIconList_Goto "
  203. "tkIconList_Index tkIconList_Invoke tkIconList_KeyPress "
  204. "tkIconList_Leave1 tkIconList_LeftRight tkIconList_Motion1 "
  205. "tkIconList_Reset tkIconList_ReturnKey tkIconList_See "
  206. "tkIconList_Select tkIconList_Selection tkIconList_ShiftBtn1 "
  207. "tkIconList_UpDown tkListbox tkListboxAutoScan "
  208. "tkListboxBeginExtend tkListboxBeginSelect tkListboxBeginToggle "
  209. "tkListboxCancel tkListboxDataExtend tkListboxExtendUpDown "
  210. "tkListboxKeyAccel_Goto tkListboxKeyAccel_Key "
  211. "tkListboxKeyAccel_Reset tkListboxKeyAccel_Set "
  212. "tkListboxKeyAccel_Unset tkListboxMotion tkListboxSelectAll "
  213. "tkListboxUpDown tkMbButtonUp tkMbEnter tkMbLeave tkMbMotion "
  214. "tkMbPost tkMenuButtonDown tkMenuDownArrow tkMenuDup tkMenuEscape "
  215. "tkMenuFind tkMenuFindName tkMenuFirstEntry tkMenuInvoke "
  216. "tkMenuLeave tkMenuLeftArrow tkMenuMotion tkMenuNextEntry "
  217. "tkMenuNextMenu tkMenuRightArrow tkMenuUnpost tkMenuUpArrow "
  218. "tkMessageBox tkMotifFDialog tkMotifFDialog_ActivateDList "
  219. "tkMotifFDialog_ActivateFEnt tkMotifFDialog_ActivateFList "
  220. "tkMotifFDialog_ActivateSEnt tkMotifFDialog_BrowseDList "
  221. "tkMotifFDialog_BrowseFList tkMotifFDialog_BuildUI "
  222. "tkMotifFDialog_CancelCmd tkMotifFDialog_Config "
  223. "tkMotifFDialog_Create tkMotifFDialog_FileTypes "
  224. "tkMotifFDialog_FilterCmd tkMotifFDialog_InterpFilter "
  225. "tkMotifFDialog_LoadFiles tkMotifFDialog_MakeSList "
  226. "tkMotifFDialog_OkCmd tkMotifFDialog_SetFilter "
  227. "tkMotifFDialog_SetListMode tkMotifFDialog_Update tkPostOverPoint "
  228. "tkRecolorTree tkRestoreOldGrab tkSaveGrabInfo tkScaleActivate "
  229. "tkScaleButton2Down tkScaleButtonDown tkScaleControlPress "
  230. "tkScaleDrag tkScaleEndDrag tkScaleIncrement tkScreenChanged "
  231. "tkScrollButton2Down tkScrollButtonDown tkScrollButtonDrag "
  232. "tkScrollButtonUp tkScrollByPages tkScrollByUnits tkScrollDrag "
  233. "tkScrollEndDrag tkScrollSelect tkScrollStartDrag "
  234. "tkScrollTopBottom tkScrollToPos tkTabToWindow tkTearOffMenu "
  235. "tkTextAutoScan tkTextButton1 tkTextClosestGap tkTextInsert "
  236. "tkTextKeyExtend tkTextKeySelect tkTextNextPara tkTextNextPos "
  237. "tkTextNextWord tkTextPaste tkTextPrevPara tkTextPrevPos "
  238. "tkTextPrevWord tkTextResetAnchor tkTextScrollPages "
  239. "tkTextSelectTo tkTextSetCursor tkTextTranspose tkTextUpDownLine "
  240. "tkTraverseToMenu tkTraverseWithinMenu";
  241. if (set == 5)
  242. return "expand";
  243. return 0;
  244. }
  245. // Returns the user name of a style.
  246. QString QsciLexerTCL::description(int style) const
  247. {
  248. switch (style)
  249. {
  250. case Default:
  251. return tr("Default");
  252. case Comment:
  253. return tr("Comment");
  254. case CommentLine:
  255. return tr("Comment line");
  256. case Number:
  257. return tr("Number");
  258. case QuotedKeyword:
  259. return tr("Quoted keyword");
  260. case QuotedString:
  261. return tr("Quoted string");
  262. case Operator:
  263. return tr("Operator");
  264. case Identifier:
  265. return tr("Identifier");
  266. case Substitution:
  267. return tr("Substitution");
  268. case SubstitutionBrace:
  269. return tr("Brace substitution");
  270. case Modifier:
  271. return tr("Modifier");
  272. case ExpandKeyword:
  273. return tr("Expand keyword");
  274. case TCLKeyword:
  275. return tr("TCL keyword");
  276. case TkKeyword:
  277. return tr("Tk keyword");
  278. case ITCLKeyword:
  279. return tr("iTCL keyword");
  280. case TkCommand:
  281. return tr("Tk command");
  282. case KeywordSet6:
  283. return tr("User defined 1");
  284. case KeywordSet7:
  285. return tr("User defined 2");
  286. case KeywordSet8:
  287. return tr("User defined 3");
  288. case KeywordSet9:
  289. return tr("User defined 4");
  290. case CommentBox:
  291. return tr("Comment box");
  292. case CommentBlock:
  293. return tr("Comment block");
  294. }
  295. return QString();
  296. }
  297. // Returns the background colour of the text for a style.
  298. QColor QsciLexerTCL::defaultPaper(int style) const
  299. {
  300. switch (style)
  301. {
  302. case Comment:
  303. return QColor(0xf0,0xff,0xe0);
  304. case QuotedKeyword:
  305. case QuotedString:
  306. case ITCLKeyword:
  307. return QColor(0xff,0xf0,0xf0);
  308. case Substitution:
  309. return QColor(0xef,0xff,0xf0);
  310. case ExpandKeyword:
  311. return QColor(0xff,0xff,0x80);
  312. case TkKeyword:
  313. return QColor(0xe0,0xff,0xf0);
  314. case TkCommand:
  315. return QColor(0xff,0xd0,0xd0);
  316. case CommentBox:
  317. case CommentBlock:
  318. return QColor(0xf0,0xff,0xf0);
  319. }
  320. return QsciLexer::defaultPaper(style);
  321. }
  322. // Refresh all properties.
  323. void QsciLexerTCL::refreshProperties()
  324. {
  325. setCommentProp();
  326. }
  327. // Read properties from the settings.
  328. bool QsciLexerTCL::readProperties(QSettings &qs, const QString &prefix)
  329. {
  330. int rc = true;
  331. fold_comments = qs.value(prefix + "foldcomments", false).toBool();
  332. return rc;
  333. }
  334. // Write properties to the settings.
  335. bool QsciLexerTCL::writeProperties(QSettings &qs, const QString &prefix) const
  336. {
  337. int rc = true;
  338. qs.setValue(prefix + "foldcomments", fold_comments);
  339. return rc;
  340. }
  341. // Set if comments can be folded.
  342. void QsciLexerTCL::setFoldComments(bool fold)
  343. {
  344. fold_comments = fold;
  345. setCommentProp();
  346. }
  347. // Set the "fold.comment" property.
  348. void QsciLexerTCL::setCommentProp()
  349. {
  350. emit propertyChanged("fold.comment", (fold_comments ? "1" : "0"));
  351. }