1 /*
2 FXiTe - The Free eXtensIble Text Editor
3 Copyright (c) 2009-2011 Jeffrey Pohlmeyer <yetanothergeek@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License version 3 as
7 published by the Free Software Foundation.
8
9 This software is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <fx.h>
20 #include "prefs.h"
21 #include "desclistdlg.h"
22
23 #include "compat.h"
24 #include "intl.h"
25 #include "prefdlg_ext.h"
26
27
28 static const char*file_filter_intro=_("\
29 Edit the list of wildcard masks (File Filters) that appear in \n\
30 the drop-down box for File Open and File Save dialogs.\
31 ");
32
33
FileFiltersDlg(FXWindow * w)34 FileFiltersDlg::FileFiltersDlg(FXWindow* w):
35 DescListDlg( w, _("File dialog filters"),
36 _("File mask"),_("File masks: (separated by comma)"), file_filter_intro)
37 {
38 before=Settings::instance()->FileFilters;
39 before.substitute('\n', '|', true);
40 }
41
42
43
Verify(FXString & item)44 bool FileFiltersDlg::Verify(FXString&item)
45 {
46 for (const char*c=" \t()"; *c; c++ ) {
47 const char s[2]={*c,0};
48 item.substitute(s, "", true);
49 }
50 return true;
51 }
52
53
54
RestoreAppDefaults()55 void FileFiltersDlg::RestoreAppDefaults()
56 {
57 setText(Settings::defaultFileFilters());
58 }
59
60
61
setText(const FXString str)62 void FileFiltersDlg::setText(const FXString str)
63 {
64 items->clearItems();
65 FXString FileFilters=str;
66 FileFilters.substitute('|', '\n', true);
67 for (FXint i=0; i<FileFilters.contains('\n'); i++) {
68 FXString sect=FileFilters.section('\n',i);
69 sect.simplify();
70 FXString desc=sect.section("(", 0);
71 FXString mask=sect.section("(", 1);
72 mask.substitute(")", "");
73 items->appendItem(desc.simplify() + '\t' + mask.simplify());
74 }
75 }
76
77
78
getText()79 const FXString& FileFiltersDlg::getText()
80 {
81 after.clear();
82 for (FXint i=0; i<items->getNumItems(); i++) {
83 FXString item=items->getItemText(i);
84 FXString desc=item.section('\t',0);
85 FXString mask=item.section('\t',1);
86 item.format("%s (%s)|", desc.text(), mask.text());
87 after+=item;
88 }
89 return after;
90 }
91
92
93
execute(FXuint placement)94 FXuint FileFiltersDlg::execute(FXuint placement)
95 {
96 if (DescListDlg::execute(placement)) {
97 FXString filters=getText();
98 filters.substitute('|', '\n', true);
99 Settings::instance()->FileFilters=filters.text();
100 return true;
101 } else {
102 return false;
103 }
104 }
105
106
107
108 static const char*errpat_intro=_("\
109 A list of regular expressions used to parse file name and line number \n\
110 information from compiler output, etc. Each expression uses two pairs \n\
111 of capturing parenthesis: the first pair for the filename, and the second \n\
112 pair for the line number. The expressions are tried in the order they \n\
113 appear here, first one to match an existing file wins.\
114 ");
115
116
ErrPatDlg(FXWindow * w)117 ErrPatDlg::ErrPatDlg(FXWindow* w):
118 DescListDlg(w, _("Output pane line matching patterns"), _("Regular Expression"),
119 _("Regular Expression:\n First capture is filename, second is line number"), errpat_intro)
120 {
121 before.clear();
122 ErrorPattern*ep= Settings::ErrorPatterns();
123 for (FXint i=0; i<Settings::ErrorPatternCount(); i++) {
124 before+=ep[i].id;
125 before+='\t';
126 before+=ep[i].pat;
127 before+='\n';
128 }
129 desc_max_len=sizeof(ep->id)-1;
130 item_max_len=sizeof(ep->pat)-1;
131 items_max=Settings::MaxErrorPatterns();
132 }
133
134
135
setText(const FXString str)136 void ErrPatDlg::setText(const FXString str)
137 {
138 items->clearItems();
139 for (FXint i=0; i<str.contains('\n'); i++) {
140 items->appendItem(str.section('\n',i));
141 }
142 }
143
144
145
getText()146 const FXString& ErrPatDlg::getText()
147 {
148 after.clear();
149 for (FXint i=0; i<items->getNumItems(); i++) {
150 FXString item=items->getItemText(i)+'\n';
151 after+=item;
152 }
153 return after;
154 }
155
156
157
Verify(FXString & item)158 bool ErrPatDlg::Verify(FXString&item)
159 {
160 FXRex *rx=new FXRex();
161 FXRexError err=rx->parse(item,REX_CAPTURE|REX_SYNTAX);
162 delete rx;
163 if (err!=REGERR_OK) {
164 FXMessageBox::error(this, MBOX_OK, _("Syntax error"), "%s:\n%s",
165 _("Error parsing regular expression"), FXRex::getError(err));
166 return false;
167 } else {
168 return true;
169 }
170 }
171
172
173
RestoreAppDefaults()174 void ErrPatDlg::RestoreAppDefaults()
175 {
176 FXString txt=FXString::null;
177 ErrorPattern*ep= Settings::DefaultErrorPatterns();
178 for (FXint i=0; i<Settings::MaxErrorPatterns(); i++) {
179 txt+=ep[i].id;
180 txt+='\t';
181 txt+=ep[i].pat;
182 txt+='\n';
183 }
184 setText(txt);
185 }
186
187
188
execute(FXuint placement)189 FXuint ErrPatDlg::execute(FXuint placement)
190 {
191 ErrorPattern *ep=Settings::ErrorPatterns();
192 if (DescListDlg::execute(placement)) {
193 FXString txt=getText();
194 for (FXint i=0; (i<Settings::MaxErrorPatterns()); i++) {
195 if (i<txt.contains('\n')) {
196 FXString line=txt.section('\n',i);
197 strncpy(ep[i].id, line.section('\t',0).text(), sizeof(ep[i].id)-1);
198 strncpy(ep[i].pat, line.section('\t',1).text(), sizeof(ep[i].pat)-1);
199 } else {
200 ep[i].id[0]=0;
201 ep[i].pat[0]=0;
202 }
203 }
204 return true;
205 } else {
206 return false;
207 }
208 }
209
210
211
212 static const char*sysinc_intro=_("\
213 A list of directories where the \"Open Selected\" menu command will\n\
214 look for C/C++ header files which are enclosed in <> brackets.\
215 ");
216
217
SysIncDlg(FXWindow * w)218 SysIncDlg::SysIncDlg(FXWindow* w):
219 DescListDlg(w, _("System Include Directories"), _("Include Directories"),
220 _("Directory to search for C/C++ system headers"), sysinc_intro,-1,0,64,true)
221 {
222 before.clear();
223 before=Settings::SystemIncludePaths();
224 }
225
226
227
setText(const FXString str)228 void SysIncDlg::setText(const FXString str)
229 {
230 items->clearItems();
231 for (FXint i=0; i<str.contains('\n'); i++) {
232 FXString sect=str.section('\n',i);
233 items->appendItem('\t' + sect.simplify());
234 }
235 }
236
237
238
getText()239 const FXString& SysIncDlg::getText()
240 {
241 after.clear();
242 for (FXint i=0; i<items->getNumItems(); i++) {
243 FXString item=items->getItemText(i)+'\n';
244 item.erase(0,1);
245 after+=item;
246 }
247 return after;
248 }
249
250
251
Verify(FXString & item)252 bool SysIncDlg::Verify(FXString&item)
253 {
254 item.simplify();
255 if (item.empty()) {
256 FXMessageBox::error(this, MBOX_OK, _("Error"), _("Path must not be empty."));
257 return false;
258 } else {
259 return true;
260 }
261 }
262
263
264
RestoreAppDefaults()265 void SysIncDlg::RestoreAppDefaults()
266 {
267 setText(Settings::defaultSystemIncludePaths());
268 }
269
270
271
Browse(FXString & text)272 bool SysIncDlg::Browse(FXString &text)
273 {
274 FXDirDialog dlg(this, _("Select include path"));
275 dlg.setDirectory(text);
276 if (dlg.execute()) {
277 text=dlg.getDirectory();
278 return true;
279 } else {
280 return false;
281 }
282 }
283
284
285
execute(FXuint placement)286 FXuint SysIncDlg::execute(FXuint placement)
287 {
288 if (DescListDlg::execute(placement)) {
289 Settings::SystemIncludePaths(after);
290 return true;
291 } else {
292 return false;
293 }
294 }
295
296