]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiListings.cpp
Skip paint event when in the middle of a buffer operation
[lyx.git] / src / frontends / qt4 / GuiListings.cpp
1 /**
2  * \file GuiListings.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Bo Peng
7  * \author Jürgen Spitzmüller
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiListings.h"
15
16 #include "qt_helpers.h"
17
18 #include "Buffer.h"
19 #include "BufferParams.h"
20 #include "FuncRequest.h"
21
22 #include "insets/InsetListings.h"
23 #include "insets/InsetListingsParams.h"
24
25 #include "support/convert.h"
26 #include "support/debug.h"
27 #include "support/gettext.h"
28 #include "support/lstrings.h"
29
30 #include <QLineEdit>
31 #include <QPushButton>
32 #include <QValidator>
33 #include <QRegExpValidator>
34
35 using namespace std;
36 using namespace lyx::support;
37
38 namespace lyx {
39 namespace frontend {
40
41
42 /////////////////////////////////////////////////////////////////////
43 //
44 // GuiListings
45 //
46 /////////////////////////////////////////////////////////////////////
47
48
49 char const * languages_supported[] =
50 { "no language", "ABAP", "ACSL", "Ada", "ALGOL", "Assembler", "Awk", "bash", "Basic", "C",
51   "C++", "Caml", "Clean", "Cobol", "Comal 80", "command.com", "Comsol", "csh", "Delphi",
52   "Eiffel", "Elan", "erlang", "Euphoria", "Fortran", "Gnuplot", "Haskell", "HTML", "IDL", "inform",
53   "Java", "JVMIS", "ksh", "Lingo", "Lisp", "Logo", "make", "Mathematica", "Matlab", "Mercury",
54   "MetaPost", "Miranda", "ML", "Modula-2", "MuPAD", "NASTRAN", "Oberon-2", "OCL", "Octave",
55   "Oz", "Pascal", "Perl", "PHP", "PL/I", "Plasm", "PostScript", "POV", "Prolog", "Promela",
56   "PSTricks", "Python", "R", "Reduce", "Rexx", "RSL", "Ruby", "S", "SAS", "Scilab", "sh",
57   "SHELXL", "Simula", "tcl", "SPARQL", "SQL", "tcl", "TeX", "VBScript", "Verilog", "VHDL",
58   "VRML", "XML", "XSLT", "" };
59
60
61 char const * languages_gui[] =
62 { N_("No language"), "ABAP", "ACSL", "Ada", "ALGOL", "Assembler", "Awk", "bash", "Basic",
63   "C", "C++", "Caml", "Clean", "Cobol", "Comal 80", "command.com", "Comsol", "csh", "Delphi",
64   "Eiffel", "Elan", "Erlang", "Euphoria", "Fortran", "Gnuplot", "Haskell", "HTML", "IDL", "inform",
65   "Java", "JVMIS", "ksh", "Lingo", "Lisp", "Logo", "make", "Mathematica", "Matlab", "Mercury",
66   "MetaPost", "Miranda", "ML", "Modula-2", "MuPAD", "NASTRAN", "Oberon-2", "OCL", "Octave",
67   "Oz", "Pascal", "Perl", "PHP", "PL/I", "Plasm", "PostScript", "POV", "Prolog", "Promela",
68   "PSTricks", "Python", "R", "Reduce", "Rexx", "RSL", "Ruby", "S", "SAS", "Scilab", "sh",
69   "SHELXL", "Simula", "tcl", "SPARQL", "SQL", "tcl", "TeX", "VBScript", "Verilog", "VHDL",
70   "VRML", "XML", "XSLT", "" };
71
72
73 struct dialect_info {
74         /// the dialect
75         char const * dialect;
76         /// the associated language
77         char const * language;
78         /// representation of the dialect in the gui
79         char const * gui;
80         /// is this the default dialect?
81         bool is_default;
82 };
83
84
85 dialect_info const dialects[] = {
86         { "R/2 4.3", "ABAP", "R/2 4.3", false },
87         { "R/2 5.0", "ABAP", "R/2 5.0", false },
88         { "R/3 3.1", "ABAP", "R/3 3.1", false },
89         { "R/3 4.6C", "ABAP", "R/3 4.6C", false },
90         { "R/3 6.10", "ABAP", "R/3 6.10", true },
91         { "2005", "Ada", "2005", true },
92         { "83", "Ada", "83", false },
93         { "95", "Ada", "95", false },
94         { "60", "Algol", "60", false },
95         { "68", "Algol", "68", true },
96         { "Motorola68k", "Assembler", "Motorola 68xxx", false },
97         { "x86masm", "Assembler", "x86 (MASM)", false },
98         { "gnu", "Awk", "gnu", true },
99         { "POSIX", "Awk", "POSIX", false },
100         { "Visual", "Basic", "Visual", false },
101         { "ANSI", "C", "ANSI", true },
102         { "Handel", "C", "Handel", false },
103         { "Objective", "C", "Objective", false },
104         { "Sharp", "C", "Sharp", false },
105         { "ANSI", "C++", "ANSI", false },
106         { "GNU", "C++", "GNU", false },
107         { "ISO", "C++", "ISO", true },
108         { "Visual", "C++", "Visual", false },
109         { "light", "Caml", "light", true },
110         { "Objective", "Caml", "Objective", false },
111         { "1974", "Cobol", "1974", false },
112         { "1985", "Cobol", "1985", true },
113         { "ibm", "Cobol", "IBM", false },
114         { "WinXP", "command.com", "Windows XP", true },
115         { "77", "Fortran", "77", false },
116         { "90", "Fortran", "90", false },
117         { "95", "Fortran", "95", true },
118         { "CORBA", "IDL", "CORBA", false },
119         { "AspectJ", "Java", "Aspect J", false },
120         { "Auto", "Lisp", "Auto", false },
121         { "gnu", "make", "gnu", false },
122         { "1.0", "Mathematica", "1.0", false },
123         { "3.0", "Mathematica", "3.0", false },
124         { "5.2", "Mathematica", "5.2", true },
125         { "decorative", "OCL", "decorative", false },
126         { "OMG", "OCL", "OMG", true },
127         { "Borland6", "Pascal", "Borland 6", false },
128         { "Standard", "Pascal", "Standard", true },
129         { "XSC", "Pascal", "XSC", false },
130         { "PLUS", "S", "PLUS", false },
131         { "67", "Simula", "67", true },
132         { "CII", "Simula", "CII", false },
133         { "DEC", "Simula", "DEC", false },
134         { "IBM", "Simula", "IBM", false },
135         { "tk", "tcl", "tk", false },
136         { "AlLaTeX", "TeX", "AlLaTeX", false },
137         { "common", "TeX", "common", false },
138         { "LaTeX", "TeX", "LaTeX", false },
139         { "plain", "TeX", "plain", true },
140         { "primitive", "TeX", "primitive", false },
141         { "AMS", "VHDL", "AMS", false },
142         { "97", "VRML", "97", true }
143 };
144
145
146 size_t const nr_dialects = sizeof(dialects) / sizeof(dialect_info);
147
148
149 char const * font_sizes[] =
150 { "default", "tiny", "scriptsize", "footnotesize", "small", "normalsize", "large",
151   "Large", "" };
152
153 char const * font_sizes_gui[] =
154 { N_("Default"), N_("Tiny"), N_("Smallest"), N_("Smaller"), N_("Small"), N_("Normal"),
155   N_("Large"), N_("Larger"), "" };
156
157 char const * font_styles[] =
158 { "default", "rmfamily", "ttfamily", "sffamily", "" };
159
160 char const * font_styles_gui[] =
161 { N_("Default"), N_("Roman"), N_("Typewriter"), N_("Sans Serif"), "" };
162
163
164
165 GuiListings::GuiListings(GuiView & lv)
166         : GuiDialog(lv, "listings", qt_("Program Listing Settings"))
167 {
168         setupUi(this);
169
170         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
171         connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
172         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
173
174         connect(languageCO, SIGNAL(currentIndexChanged(int)),
175                 this, SLOT(change_adaptor()));
176         connect(dialectCO, SIGNAL(currentIndexChanged(int)),
177                 this, SLOT(change_adaptor()));
178         connect(inlineCB, SIGNAL(clicked()),
179                 this, SLOT(change_adaptor()));
180         connect(floatCB, SIGNAL(clicked()),
181                 this, SLOT(change_adaptor()));
182         connect(placementLE, SIGNAL(textChanged(QString)),
183                 this, SLOT(change_adaptor()));
184         connect(numberSideCO, SIGNAL(currentIndexChanged(int)),
185                 this, SLOT(change_adaptor()));
186         connect(numberStepLE, SIGNAL(textChanged(QString)),
187                 this, SLOT(change_adaptor()));
188         connect(numberFontSizeCO, SIGNAL(currentIndexChanged(int)),
189                 this, SLOT(change_adaptor()));
190         connect(firstlineLE, SIGNAL(textChanged(QString)),
191                 this, SLOT(change_adaptor()));
192         connect(lastlineLE, SIGNAL(textChanged(QString)),
193                 this, SLOT(change_adaptor()));
194         connect(fontsizeCO, SIGNAL(currentIndexChanged(int)),
195                 this, SLOT(change_adaptor()));
196         connect(fontstyleCO, SIGNAL(currentIndexChanged(int)),
197                 this, SLOT(change_adaptor()));
198         connect(breaklinesCB, SIGNAL(clicked()),
199                 this, SLOT(change_adaptor()));
200         connect(spaceCB, SIGNAL(clicked()),
201                 this, SLOT(change_adaptor()));
202         connect(spaceInStringCB, SIGNAL(clicked()),
203                 this, SLOT(change_adaptor()));
204         connect(tabsizeSB, SIGNAL(valueChanged(int)),
205                 this, SLOT(change_adaptor()));
206         connect(extendedcharsCB, SIGNAL(clicked()),
207                 this, SLOT(change_adaptor()));
208
209         connect(listingsED,  SIGNAL(textChanged()),
210                 this, SLOT(change_adaptor()));
211         connect(listingsED,  SIGNAL(textChanged()),
212                 this, SLOT(setListingsMsg()));
213         connect(bypassCB, SIGNAL(clicked()),
214                 this, SLOT(change_adaptor()));
215         connect(bypassCB, SIGNAL(clicked()),
216                 this, SLOT(setListingsMsg()));
217
218         for (int n = 0; languages_supported[n][0]; ++n)
219                 languageCO->addItem(qt_(languages_gui[n]));
220
221         for (int n = 0; font_styles[n][0]; ++n)
222                 fontstyleCO->addItem(qt_(font_styles_gui[n]));
223
224         for (int n = 0; font_sizes[n][0]; ++n) {
225                 QString font = qt_(font_sizes_gui[n]);
226                 fontsizeCO->addItem(font);
227                 numberFontSizeCO->addItem(font);
228         }
229
230         // set validators
231         numberStepLE->setValidator(new QIntValidator(0, 1000000, this));
232         firstlineLE->setValidator(new QIntValidator(0, 1000000, this));
233         lastlineLE->setValidator(new QIntValidator(0, 1000000, this));
234         placementLE->setValidator(new QRegExpValidator(QRegExp("[\\*tbph]*"), this));
235
236         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
237         bc().setOK(okPB);
238         bc().setApply(applyPB);
239         bc().setCancel(closePB);
240         listingsTB->setPlainText(
241                 qt_("Input listing parameters on the right. Enter ? for a list of parameters."));
242
243         updateContents();
244
245 }
246
247
248 void GuiListings::change_adaptor()
249 {
250         changed();
251 }
252
253
254 string GuiListings::construct_params()
255 {
256         string language = languages_supported[qMax(0, languageCO->currentIndex())];
257         string dialect;
258         string const dialect_gui = fromqstr(dialectCO->currentText());
259         if (dialectCO->currentIndex() > 0) {
260                 for (size_t i = 0; i != nr_dialects; ++i) {
261                         if (dialect_gui == dialects[i].gui
262                         && dialects[i].language == language
263                         && !dialects[i].is_default) {
264                                 dialect = dialects[i].dialect;
265                                 break;
266                         }
267                 }
268         }
269
270         bool float_ = floatCB->isChecked();
271         string placement;
272         if (placementLE->isEnabled())
273                 placement = fromqstr(placementLE->text());
274
275         string numberSide;
276         switch (qMax(0, numberSideCO->currentIndex())) {
277         case 0:
278                 numberSide = "none";
279                 break;
280         case 1:
281                 numberSide = "left";
282                 break;
283         case 2:
284                 numberSide = "right";
285                 break;
286         default:
287                 numberSide = "none";
288                 break;
289         }
290         string stepnumber = fromqstr(numberStepLE->text());
291         string numberfontsize = font_sizes[qMax(0, numberFontSizeCO->currentIndex())];
292         string firstline = fromqstr(firstlineLE->text());
293         string lastline = fromqstr(lastlineLE->text());
294
295         string fontsize = font_sizes[qMax(0, fontsizeCO->currentIndex())];
296         string fontstyle = font_styles[qMax(0, fontstyleCO->currentIndex())];
297         string basicstyle;
298         string mintedsize;
299         bool const use_minted = buffer().params().use_minted;
300         if (fontsize != "default") {
301                 if (use_minted)
302                         mintedsize = "\\" + fontsize;
303                 else
304                         basicstyle = "\\" + fontsize;
305         }
306         if (fontstyle != "default") {
307                 if (use_minted)
308                         basicstyle = fontstyle.substr(0, 2);
309                 else
310                         basicstyle += "\\" + fontstyle;
311         }
312         bool breakline = breaklinesCB->isChecked();
313         bool space = spaceCB->isChecked();
314         int tabsize = tabsizeSB->value();
315         bool spaceInString = spaceInStringCB->isChecked();
316         bool extendedchars = extendedcharsCB->isChecked();
317         string extra = fromqstr(listingsED->toPlainText());
318
319         // compose a string
320         InsetListingsParams par;
321         par.setMinted(use_minted);
322         if (use_minted) {
323                 if (language == "no language" && !contains(extra, "language="))
324                         par.addParam("language", "TeX");
325                 else
326                         par.addParam("language", language);
327         } else if (language != "no language" && !contains(extra, "language=")) {
328                 if (dialect.empty())
329                         par.addParam("language", language);
330                 else
331                         par.addParam("language", "{[" + dialect + "]" + language + "}");
332         }
333         // this dialog uses float=placement instead of float,floatplacement=placement
334         // because float accepts *tbph and floatplacement accepts bph.
335         // our placement textedit is actually for the float parameter
336         if (float_)
337                 par.addParam("float", placement);
338         if (numberSide != "none")
339                 par.addParam("numbers", numberSide);
340         if (numberfontsize != "default" && numberSide != "none" && !use_minted)
341                 par.addParam("numberstyle", "\\" + numberfontsize);
342         if (!stepnumber.empty() && numberSide != "none")
343                 par.addParam("stepnumber", stepnumber);
344         if (!firstline.empty())
345                 par.addParam("firstline", firstline);
346         if (!lastline.empty())
347                 par.addParam("lastline", lastline);
348         if (!basicstyle.empty())
349                 par.addParam(use_minted ? "fontfamily" : "basicstyle", basicstyle);
350         if (!mintedsize.empty())
351                 par.addParam("fontsize", mintedsize);
352         if (breakline)
353                 par.addParam("breaklines", "true");
354         if (space)
355                 par.addParam("showspaces", "true");
356         if (!spaceInString && !use_minted)
357                 par.addParam("showstringspaces", "false");
358         if (tabsize != 8)
359                 par.addParam("tabsize", convert<string>(tabsize));
360         if (extendedchars && !use_minted)
361                 par.addParam("extendedchars", "true");
362         par.addParams(extra);
363         return par.params();
364 }
365
366
367 docstring GuiListings::validate_listings_params()
368 {
369         if (bypassCB->isChecked())
370                 return docstring();
371         return InsetListingsParams(construct_params()).validate();
372 }
373
374
375 void GuiListings::setListingsMsg()
376 {
377         // FIXME THREAD
378         static bool isOK = true;
379         docstring msg = validate_listings_params();
380         if (msg.empty()) {
381                 if (isOK)
382                         return;
383                 isOK = true;
384                 listingsTB->setPlainText(
385                         qt_("Input listing parameters on the right. Enter ? for a list of parameters."));
386         } else {
387                 isOK = false;
388                 listingsTB->setPlainText(toqstr(msg));
389         }
390 }
391
392
393 void GuiListings::on_floatCB_stateChanged(int state)
394 {
395         if (state == Qt::Checked) {
396                 inlineCB->setChecked(false);
397                 placementLE->setEnabled(true);
398         } else
399                 placementLE->setEnabled(false);
400 }
401
402
403 void GuiListings::on_inlineCB_stateChanged(int state)
404 {
405         if (state == Qt::Checked) {
406                 floatCB->setChecked(false);
407                 placementLE->setEnabled(false);
408         }
409 }
410
411
412 void GuiListings::on_numberSideCO_currentIndexChanged(int index)
413 {
414         numberStepLE->setEnabled(index > 0);
415         numberFontSizeCO->setEnabled(index > 0);
416 }
417
418
419 void GuiListings::on_languageCO_currentIndexChanged(int index)
420 {
421         dialectCO->clear();
422         // 0 is "no dialect"
423         int default_dialect = 0;
424         dialectCO->addItem(qt_("No dialect"));
425         string const language = languages_supported[index];
426
427         for (size_t i = 0; i != nr_dialects; ++i) {
428                 if (language == dialects[i].language) {
429                         dialectCO->addItem(qt_(dialects[i].gui));
430                         if (dialects[i].is_default)
431                                 default_dialect =
432                                         dialectCO->findText(qt_(dialects[i].gui));
433                 }
434         }
435         dialectCO->setCurrentIndex(default_dialect);
436         dialectCO->setEnabled(dialectCO->count() > 1
437                               && !buffer().params().use_minted);
438 }
439
440
441 void GuiListings::applyView()
442 {
443         params_.setMinted(buffer().params().use_minted);
444         params_.setInline(inlineCB->isChecked());
445         params_.setParams(construct_params());
446 }
447
448
449 static string plainParam(string const & par)
450 {
451         // remove enclosing braces
452         if (prefixIs(par, "{") && suffixIs(par, "}"))
453                 return par.substr(1, par.size() - 2);
454         return par;
455 }
456
457
458 void GuiListings::updateContents()
459 {
460         bool const use_minted = buffer().params().use_minted;
461         // set default values
462         listingsTB->setPlainText(
463                 qt_("Input listing parameters on the right. Enter ? for a list of parameters."));
464         languageCO->setCurrentIndex(findToken(languages_supported, "no language"));
465         dialectCO->setCurrentIndex(0);
466         floatCB->setChecked(false);
467         placementLE->clear();
468         numberSideCO->setCurrentIndex(0);
469         numberStepLE->clear();
470         numberFontSizeCO->setCurrentIndex(findToken(font_sizes, "default"));
471         firstlineLE->clear();
472         lastlineLE->clear();
473         fontstyleCO->setCurrentIndex(findToken(font_styles, "default"));
474         fontsizeCO->setCurrentIndex(findToken(font_sizes, "default"));
475         breaklinesCB->setChecked(false);
476         spaceCB->setChecked(false);
477         spaceInStringCB->setChecked(true);
478         tabsizeSB->setValue(8);
479         extendedcharsCB->setChecked(false);
480
481         // set values from param string
482         inlineCB->setChecked(params_.isInline());
483         if (params_.isInline()) {
484                 floatCB->setChecked(false);
485                 placementLE->setEnabled(false);
486         }
487         // break other parameters and set values
488         vector<string> pars = getVectorFromString(params_.separatedParams(), "\n");
489         // process each of them
490         for (vector<string>::iterator it = pars.begin();
491             it != pars.end(); ++it) {
492                 if (prefixIs(*it, "language=")) {
493                         string arg = plainParam(it->substr(9));
494                         // has dialect?
495                         string language;
496                         string dialect;
497                         bool in_gui = false;
498                         if (prefixIs(arg, "[") && contains(arg, "]")) {
499                                 size_t end_dialect = arg.find("]");
500                                 dialect = arg.substr(1, end_dialect - 1);
501                                 language = arg.substr(end_dialect + 1);
502                         } else {
503                                 language = arg;
504                         }
505                         int n = findToken(languages_supported, language);
506                         if (n >= 0) {
507                                 languageCO->setCurrentIndex(n);
508                                 in_gui = true;
509                         }
510                         // on_languageCO_currentIndexChanged should have set dialects
511                         if (!dialect.empty()) {
512                                 string dialect_gui;
513                                 for (size_t i = 0; i != nr_dialects; ++i) {
514                                         if (dialect == dialects[i].dialect
515                                             && dialects[i].language == language) {
516                                                 dialect_gui = dialects[i].gui;
517                                                 break;
518                                         }
519                                 }
520                                 n = dialectCO->findText(qt_(dialect_gui));
521                                 if (n >= 0)
522                                         dialectCO->setCurrentIndex(n);
523                                 else
524                                         in_gui = false;
525                         }
526                         if (in_gui)
527                                 *it = "";
528                         languageCO->setEnabled(in_gui);
529                         dialectCO->setEnabled(!use_minted &&
530                                 in_gui && dialectCO->count() > 1);
531                 } else if (prefixIs(*it, "float")) {
532                         floatCB->setChecked(true);
533                         inlineCB->setChecked(false);
534                         placementLE->setEnabled(true);
535                         if (prefixIs(*it, "float="))
536                                 placementLE->setText(
537                                         toqstr(plainParam(it->substr(6))));
538                         *it = "";
539                 } else if (prefixIs(*it, "numbers=")) {
540                         string s = plainParam(it->substr(8));
541                         int n = 0;
542                         if (s == "left")
543                                 n = 1;
544                         else if (s == "right")
545                                 n = 2;
546                         numberSideCO->setCurrentIndex(n);
547                         *it = "";
548                 } else if (prefixIs(*it, "stepnumber=")) {
549                         numberStepLE->setText(
550                                 toqstr(plainParam(it->substr(11))));
551                         *it = "";
552                 } else if (prefixIs(*it, "numberstyle=")) {
553                         string par = plainParam(it->substr(12));
554                         int n = findToken(font_sizes, par.substr(1));
555                         if (n >= 0)
556                                 numberFontSizeCO->setCurrentIndex(n);
557                         *it = "";
558                 } else if (prefixIs(*it, "firstline=")) {
559                         firstlineLE->setText(
560                                 toqstr(plainParam(it->substr(10))));
561                         *it = "";
562                 } else if (prefixIs(*it, "lastline=")) {
563                         lastlineLE->setText(
564                                 toqstr(plainParam(it->substr(9))));
565                         *it = "";
566                 } else if (prefixIs(*it, "basicstyle=")) {
567                         string style;
568                         string size;
569                         for (int n = 0; font_styles[n][0]; ++n) {
570                                 string const s = font_styles[n];
571                                 if (contains(*it, "\\" + s)) {
572                                         style = "\\" + s;
573                                         break;
574                                 }
575                         }
576                         for (int n = 0; font_sizes[n][0]; ++n) {
577                                 string const s = font_sizes[n];
578                                 if (contains(*it, "\\" + s)) {
579                                         size = "\\" + s;
580                                         break;
581                                 }
582                         }
583                         if (plainParam(it->substr(11)) == style + size
584                             || plainParam(it->substr(11)) == size + style) {
585                                 if (!style.empty()) {
586                                         int n = findToken(font_styles, style.substr(1));
587                                         if (n >= 0)
588                                                 fontstyleCO->setCurrentIndex(n);
589                                 }
590                                 if (!size.empty()) {
591                                         int n = findToken(font_sizes, size.substr(1));
592                                         if (n >= 0)
593                                                 fontsizeCO->setCurrentIndex(n);
594                                 }
595                                 *it = "";
596                         }
597                 } else if (prefixIs(*it, "fontsize=")) {
598                         string size;
599                         for (int n = 0; font_sizes[n][0]; ++n) {
600                                 string const s = font_sizes[n];
601                                 if (contains(*it, "\\" + s)) {
602                                         size = "\\" + s;
603                                         break;
604                                 }
605                         }
606                         if (!size.empty()) {
607                                 int n = findToken(font_sizes, size.substr(1));
608                                 if (n >= 0)
609                                         fontsizeCO->setCurrentIndex(n);
610                         }
611                         *it = "";
612                 } else if (prefixIs(*it, "fontfamily=")) {
613                         string style;
614                         for (int n = 0; font_styles[n][0]; ++n) {
615                                 string const s = font_styles[n];
616                                 if (contains(*it, "=" + s.substr(0,2))) {
617                                         style = "\\" + s;
618                                         break;
619                                 }
620                         }
621                         if (!style.empty()) {
622                                 int n = findToken(font_styles, style.substr(1));
623                                 if (n >= 0)
624                                         fontstyleCO->setCurrentIndex(n);
625                         }
626                         *it = "";
627                 } else if (prefixIs(*it, "breaklines=")) {
628                         breaklinesCB->setChecked(contains(*it, "true"));
629                         *it = "";
630                 } else if (prefixIs(*it, "showspaces=")) {
631                         spaceCB->setChecked(contains(*it, "true"));
632                         *it = "";
633                 } else if (prefixIs(*it, "showstringspaces=")) {
634                         spaceInStringCB->setChecked(contains(*it, "true"));
635                         *it = "";
636                 } else if (prefixIs(*it, "tabsize=")) {
637                         tabsizeSB->setValue(convert<int>(plainParam(it->substr(8))));
638                         *it = "";
639                 } else if (prefixIs(*it, "extendedchars=")) {
640                         extendedcharsCB->setChecked(contains(*it, "true"));
641                         *it = "";
642                 }
643         }
644
645         numberStepLE->setEnabled(numberSideCO->currentIndex() > 0);
646         numberFontSizeCO->setEnabled(numberSideCO->currentIndex() > 0
647                                      && !use_minted);
648         spaceInStringCB->setEnabled(!use_minted);
649         extendedcharsCB->setEnabled(!use_minted);
650         // parameters that can be handled by widgets are cleared
651         // the rest is put to the extra edit box.
652         string extra = getStringFromVector(pars);
653         listingsED->setPlainText(toqstr(InsetListingsParams(extra).separatedParams()));
654         params_.setMinted(use_minted);
655 }
656
657
658 bool GuiListings::isValid()
659 {
660         return validate_listings_params().empty();
661 }
662
663
664 bool GuiListings::initialiseParams(string const & sdata)
665 {
666         InsetListings::string2params(sdata, params_);
667         return true;
668 }
669
670
671 void GuiListings::clearParams()
672 {
673         params_.clear();
674         params_.setMinted(buffer().params().use_minted);
675 }
676
677
678 void GuiListings::dispatchParams()
679 {
680         string const lfun = InsetListings::params2string(params_);
681         dispatch(FuncRequest(getLfun(), lfun));
682 }
683
684
685 void GuiListings::setParams(InsetListingsParams const & params)
686 {
687         params_ = params;
688         params_.setMinted(buffer().params().use_minted);
689 }
690
691
692 Dialog * createGuiListings(GuiView & lv) { return new GuiListings(lv); }
693
694
695 } // namespace frontend
696 } // namespace lyx
697
698
699 #include "moc_GuiListings.cpp"