1 // This module implements the QsciLexerBatch class.
2 //
3 // Copyright (c) 2021 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
20
21 #include "Qsci/qscilexerbatch.h"
22
23 #include <qcolor.h>
24 #include <qfont.h>
25 #include <qsettings.h>
26
27
28 // The ctor.
QsciLexerBatch(QObject * parent)29 QsciLexerBatch::QsciLexerBatch(QObject *parent)
30 : QsciLexer(parent)
31 {
32 }
33
34
35 // The dtor.
~QsciLexerBatch()36 QsciLexerBatch::~QsciLexerBatch()
37 {
38 }
39
40
41 // Returns the language name.
language() const42 const char *QsciLexerBatch::language() const
43 {
44 return "Batch";
45 }
46
47
48 // Returns the lexer name.
lexer() const49 const char *QsciLexerBatch::lexer() const
50 {
51 return "batch";
52 }
53
54
55 // Return the string of characters that comprise a word.
wordCharacters() const56 const char *QsciLexerBatch::wordCharacters() const
57 {
58 return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-";
59 }
60
61
62 // Returns the foreground colour of the text for a style.
defaultColor(int style) const63 QColor QsciLexerBatch::defaultColor(int style) const
64 {
65 switch (style)
66 {
67 case Default:
68 case Operator:
69 return QColor(0x00,0x00,0x00);
70
71 case Comment:
72 return QColor(0x00,0x7f,0x00);
73
74 case Keyword:
75 case ExternalCommand:
76 return QColor(0x00,0x00,0x7f);
77
78 case Label:
79 return QColor(0x7f,0x00,0x7f);
80
81 case HideCommandChar:
82 return QColor(0x7f,0x7f,0x00);
83
84 case Variable:
85 return QColor(0x80,0x00,0x80);
86 }
87
88 return QsciLexer::defaultColor(style);
89 }
90
91
92 // Returns the end-of-line fill for a style.
defaultEolFill(int style) const93 bool QsciLexerBatch::defaultEolFill(int style) const
94 {
95 switch (style)
96 {
97 case Label:
98 return true;
99 }
100
101 return QsciLexer::defaultEolFill(style);
102 }
103
104
105 // Returns the font of the text for a style.
defaultFont(int style) const106 QFont QsciLexerBatch::defaultFont(int style) const
107 {
108 QFont f;
109
110 switch (style)
111 {
112 case Comment:
113 #if defined(Q_OS_WIN)
114 f = QFont("Comic Sans MS",9);
115 #elif defined(Q_OS_MAC)
116 f = QFont("Comic Sans MS", 12);
117 #else
118 f = QFont("Bitstream Vera Serif",9);
119 #endif
120 break;
121
122 case Keyword:
123 f = QsciLexer::defaultFont(style);
124 f.setBold(true);
125 break;
126
127 case ExternalCommand:
128 #if defined(Q_OS_WIN)
129 f = QFont("Courier New",10);
130 #elif defined(Q_OS_MAC)
131 f = QFont("Courier", 12);
132 #else
133 f = QFont("Bitstream Vera Sans Mono",9);
134 #endif
135 f.setBold(true);
136 break;
137
138 default:
139 f = QsciLexer::defaultFont(style);
140 }
141
142 return f;
143 }
144
145
146 // Returns the set of keywords.
keywords(int set) const147 const char *QsciLexerBatch::keywords(int set) const
148 {
149 if (set == 1)
150 return
151 "rem set if exist errorlevel for in do break call "
152 "chcp cd chdir choice cls country ctty date del "
153 "erase dir echo exit goto loadfix loadhigh mkdir md "
154 "move path pause prompt rename ren rmdir rd shift "
155 "time type ver verify vol com con lpt nul";
156
157 return 0;
158 }
159
160
161 // Return the case sensitivity.
caseSensitive() const162 bool QsciLexerBatch::caseSensitive() const
163 {
164 return false;
165 }
166
167
168 // Returns the user name of a style.
description(int style) const169 QString QsciLexerBatch::description(int style) const
170 {
171 switch (style)
172 {
173 case Default:
174 return tr("Default");
175
176 case Comment:
177 return tr("Comment");
178
179 case Keyword:
180 return tr("Keyword");
181
182 case Label:
183 return tr("Label");
184
185 case HideCommandChar:
186 return tr("Hide command character");
187
188 case ExternalCommand:
189 return tr("External command");
190
191 case Variable:
192 return tr("Variable");
193
194 case Operator:
195 return tr("Operator");
196 }
197
198 return QString();
199 }
200
201
202 // Returns the background colour of the text for a style.
defaultPaper(int style) const203 QColor QsciLexerBatch::defaultPaper(int style) const
204 {
205 switch (style)
206 {
207 case Label:
208 return QColor(0x60,0x60,0x60);
209 }
210
211 return QsciLexer::defaultPaper(style);
212 }
213