]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDocument.cpp
Fix bug 11099.
[lyx.git] / src / frontends / qt4 / GuiDocument.cpp
1 /**
2  * \file GuiDocument.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  * \author Richard Heck (modules)
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiDocument.h"
15
16 #include "CategorizedCombo.h"
17 #include "GuiApplication.h"
18 #include "GuiBranches.h"
19 #include "GuiIndices.h"
20 #include "GuiSelectionManager.h"
21 #include "LaTeXHighlighter.h"
22 #include "LengthCombo.h"
23 #include "PanelStack.h"
24 #include "Validator.h"
25
26 #include "LayoutFile.h"
27 #include "BranchList.h"
28 #include "buffer_funcs.h"
29 #include "Buffer.h"
30 #include "BufferParams.h"
31 #include "BufferView.h"
32 #include "CiteEnginesList.h"
33 #include "Color.h"
34 #include "ColorCache.h"
35 #include "Converter.h"
36 #include "Cursor.h"
37 #include "Encoding.h"
38 #include "FloatPlacement.h"
39 #include "Format.h"
40 #include "FuncRequest.h"
41 #include "IndicesList.h"
42 #include "Language.h"
43 #include "LaTeXFeatures.h"
44 #include "LaTeXFonts.h"
45 #include "Layout.h"
46 #include "LayoutEnums.h"
47 #include "LayoutModuleList.h"
48 #include "LyXRC.h"
49 #include "ModuleList.h"
50 #include "OutputParams.h"
51 #include "PDFOptions.h"
52 #include "qt_helpers.h"
53 #include "Session.h"
54 #include "Spacing.h"
55 #include "TextClass.h"
56 #include "Undo.h"
57 #include "VSpace.h"
58
59 #include "insets/InsetListingsParams.h"
60
61 #include "support/debug.h"
62 #include "support/FileName.h"
63 #include "support/filetools.h"
64 #include "support/gettext.h"
65 #include "support/lassert.h"
66 #include "support/lstrings.h"
67
68 #include "frontends/alert.h"
69
70 #include <QAbstractItemModel>
71 #include <QHeaderView>
72 #include <QColor>
73 #include <QColorDialog>
74 #include <QCloseEvent>
75 #include <QFontDatabase>
76 #include <QScrollBar>
77 #include <QTextBoundaryFinder>
78 #include <QTextCursor>
79
80 #include <sstream>
81 #include <vector>
82
83 #ifdef IN
84 #undef IN
85 #endif
86
87
88 // a style sheet for buttons
89 // this is for example used for the background color setting button
90 static inline QString colorButtonStyleSheet(QColor const & bgColor)
91 {
92         if (bgColor.isValid()) {
93                 QString rc = QLatin1String("background-color:");
94                 rc += bgColor.name();
95                 return rc;
96         }
97         return QString();
98 }
99
100
101 using namespace std;
102 using namespace lyx::support;
103
104
105 namespace {
106
107 char const * const tex_graphics[] =
108 {
109         "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
110         "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
111         "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
112         "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
113         "xetex", "none", ""
114 };
115
116
117 char const * const tex_graphics_gui[] =
118 {
119         N_("Default"), "dvialw", "DviLaser", "dvipdf", "DVIPDFM", "DVIPDFMx",
120         "Dvips", "DVIPSONE", "DVItoPS", "DVIWIN", "DVIWindo", "dvi2ps", "EmTeX",
121         "LN", "OzTeX", "pctexhp", "pctexps", "pctexwin", "PCTeX32", "pdfTeX",
122         "psprint", "pubps", "tcidvi", "Textures", "TrueTeX", "VTeX", "xdvi",
123         "XeTeX", N_("None"), ""
124 };
125
126
127 char const * backref_opts[] =
128 {
129         "false", "section", "slide", "page", ""
130 };
131
132
133 char const * backref_opts_gui[] =
134 {
135         N_("Off"), N_("Section"), N_("Slide"), N_("Page"), ""
136 };
137
138
139 char const * lst_packages[] =
140 {
141         "Listings", "Minted", ""
142 };
143
144
145 vector<string> engine_types_;
146 vector<pair<string, QString> > pagestyles;
147
148 QMap<QString, QString> rmfonts_;
149 QMap<QString, QString> sffonts_;
150 QMap<QString, QString> ttfonts_;
151 QMap<QString, QString> mathfonts_;
152
153
154 } // anonymous namespace
155
156 namespace lyx {
157
158 RGBColor set_backgroundcolor;
159 bool is_backgroundcolor;
160 RGBColor set_fontcolor;
161 bool is_fontcolor;
162 RGBColor set_notefontcolor;
163 RGBColor set_boxbgcolor;
164 bool forced_fontspec_activation;
165
166 namespace {
167 // used when sorting the textclass list.
168 class less_textclass_avail_desc
169         : public binary_function<string, string, int>
170 {
171 public:
172         bool operator()(string const & lhs, string const & rhs) const
173         {
174                 // Ordering criteria:
175                 //   1. Availability of text class
176                 //   2. Description (lexicographic)
177                 LayoutFile const & tc1 = LayoutFileList::get()[lhs];
178                 LayoutFile const & tc2 = LayoutFileList::get()[rhs];
179                 int const order = compare_no_case(
180                         translateIfPossible(from_utf8(tc1.description())),
181                         translateIfPossible(from_utf8(tc2.description())));
182                 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
183                         (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() && order < 0);
184         }
185 };
186
187 } // namespace
188
189 namespace frontend {
190 namespace {
191
192 vector<string> getRequiredList(string const & modName)
193 {
194         LyXModule const * const mod = theModuleList[modName];
195         if (!mod)
196                 return vector<string>(); //empty such thing
197         return mod->getRequiredModules();
198 }
199
200
201 vector<string> getExcludedList(string const & modName)
202 {
203         LyXModule const * const mod = theModuleList[modName];
204         if (!mod)
205                 return vector<string>(); //empty such thing
206         return mod->getExcludedModules();
207 }
208
209
210 docstring getModuleCategory(string const & modName)
211 {
212         LyXModule const * const mod = theModuleList[modName];
213         if (!mod)
214                 return docstring();
215         return from_utf8(mod->category());
216 }
217
218
219 docstring getModuleDescription(string const & modName)
220 {
221         LyXModule const * const mod = theModuleList[modName];
222         if (!mod)
223                 return _("Module not found!");
224         // FIXME Unicode
225         return translateIfPossible(from_utf8(mod->getDescription()));
226 }
227
228
229 vector<string> getPackageList(string const & modName)
230 {
231         LyXModule const * const mod = theModuleList[modName];
232         if (!mod)
233                 return vector<string>(); //empty such thing
234         return mod->getPackageList();
235 }
236
237
238 bool isModuleAvailable(string const & modName)
239 {
240         LyXModule const * const mod = theModuleList[modName];
241         if (!mod)
242                 return false;
243         return mod->isAvailable();
244 }
245
246 } // anonymous namespace
247
248
249 /////////////////////////////////////////////////////////////////////
250 //
251 // ModuleSelectionManager
252 //
253 /////////////////////////////////////////////////////////////////////
254
255 /// SelectionManager for use with modules
256 class ModuleSelectionManager : public GuiSelectionManager
257 {
258 public:
259         ///
260         ModuleSelectionManager(QObject * parent,
261                                QTreeView * availableLV,
262                                QListView * selectedLV,
263                                QPushButton * addPB,
264                                QPushButton * delPB,
265                                QPushButton * upPB,
266                                QPushButton * downPB,
267                                GuiIdListModel * availableModel,
268                                GuiIdListModel * selectedModel,
269                                GuiDocument const * container)
270                 : GuiSelectionManager(parent, availableLV, selectedLV, addPB, delPB,
271                                       upPB, downPB, availableModel, selectedModel),
272                   container_(container)
273                 {}
274         ///
275         void updateProvidedModules(LayoutModuleList const & pm)
276                         { provided_modules_ = pm.list(); }
277         ///
278         void updateExcludedModules(LayoutModuleList const & em)
279                         { excluded_modules_ = em.list(); }
280 private:
281         ///
282         virtual void updateAddPB();
283         ///
284         virtual void updateUpPB();
285         ///
286         virtual void updateDownPB();
287         ///
288         virtual void updateDelPB();
289         /// returns availableModel as a GuiIdListModel
290         GuiIdListModel * getAvailableModel()
291         {
292                 return dynamic_cast<GuiIdListModel *>(availableModel);
293         }
294         /// returns selectedModel as a GuiIdListModel
295         GuiIdListModel * getSelectedModel()
296         {
297                 return dynamic_cast<GuiIdListModel *>(selectedModel);
298         }
299         /// keeps a list of the modules the text class provides
300         list<string> provided_modules_;
301         /// similarly...
302         list<string> excluded_modules_;
303         ///
304         GuiDocument const * container_;
305 };
306
307 void ModuleSelectionManager::updateAddPB()
308 {
309         int const arows = availableModel->rowCount();
310         QModelIndexList const avail_sels =
311                         availableLV->selectionModel()->selectedIndexes();
312
313         // disable if there aren't any modules (?), if none of them is chosen
314         // in the dialog, or if the chosen one is already selected for use.
315         if (arows == 0 || avail_sels.isEmpty() || isSelected(avail_sels.first())) {
316                 addPB->setEnabled(false);
317                 return;
318         }
319
320         QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
321         string const modname = getAvailableModel()->getIDString(idx.row());
322
323         bool const enable =
324                 container_->params().layoutModuleCanBeAdded(modname);
325         addPB->setEnabled(enable);
326 }
327
328
329 void ModuleSelectionManager::updateDownPB()
330 {
331         int const srows = selectedModel->rowCount();
332         if (srows == 0) {
333                 downPB->setEnabled(false);
334                 return;
335         }
336         QModelIndex const & curidx = selectedLV->selectionModel()->currentIndex();
337         int const curRow = curidx.row();
338         if (curRow < 0 || curRow >= srows - 1) { // invalid or last item
339                 downPB->setEnabled(false);
340                 return;
341         }
342
343         // determine whether immediately succeding element requires this one
344         string const curmodname = getSelectedModel()->getIDString(curRow);
345         string const nextmodname = getSelectedModel()->getIDString(curRow + 1);
346
347         vector<string> reqs = getRequiredList(nextmodname);
348
349         // if it doesn't require anything....
350         if (reqs.empty()) {
351                 downPB->setEnabled(true);
352                 return;
353         }
354
355         // Enable it if this module isn't required.
356         // FIXME This should perhaps be more flexible and check whether, even
357         // if the next one is required, there is also an earlier one that will do.
358         downPB->setEnabled(
359                         find(reqs.begin(), reqs.end(), curmodname) == reqs.end());
360 }
361
362 void ModuleSelectionManager::updateUpPB()
363 {
364         int const srows = selectedModel->rowCount();
365         if (srows == 0) {
366                 upPB->setEnabled(false);
367                 return;
368         }
369
370         QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
371         int curRow = curIdx.row();
372         if (curRow <= 0 || curRow > srows - 1) { // first item or invalid
373                 upPB->setEnabled(false);
374                 return;
375         }
376         string const curmodname = getSelectedModel()->getIDString(curRow);
377
378         // determine whether immediately preceding element is required by this one
379         vector<string> reqs = getRequiredList(curmodname);
380
381         // if this one doesn't require anything....
382         if (reqs.empty()) {
383                 upPB->setEnabled(true);
384                 return;
385         }
386
387
388         // Enable it if the preceding module isn't required.
389         // NOTE This is less flexible than it might be. We could check whether, even
390         // if the previous one is required, there is an earlier one that would do.
391         string const premod = getSelectedModel()->getIDString(curRow - 1);
392         upPB->setEnabled(find(reqs.begin(), reqs.end(), premod) == reqs.end());
393 }
394
395 void ModuleSelectionManager::updateDelPB()
396 {
397         int const srows = selectedModel->rowCount();
398         if (srows == 0) {
399                 deletePB->setEnabled(false);
400                 return;
401         }
402
403         QModelIndex const & curidx =
404                 selectedLV->selectionModel()->currentIndex();
405         int const curRow = curidx.row();
406         if (curRow < 0 || curRow >= srows) { // invalid index?
407                 deletePB->setEnabled(false);
408                 return;
409         }
410
411         string const curmodname = getSelectedModel()->getIDString(curRow);
412
413         // We're looking here for a reason NOT to enable the button. If we
414         // find one, we disable it and return. If we don't, we'll end up at
415         // the end of the function, and then we enable it.
416         for (int i = curRow + 1; i < srows; ++i) {
417                 string const thisMod = getSelectedModel()->getIDString(i);
418                 vector<string> reqs = getRequiredList(thisMod);
419                 //does this one require us?
420                 if (find(reqs.begin(), reqs.end(), curmodname) == reqs.end())
421                         //no...
422                         continue;
423
424                 // OK, so this module requires us
425                 // is there an EARLIER module that also satisfies the require?
426                 // NOTE We demand that it be earlier to keep the list of modules
427                 // consistent with the rule that a module must be proceeded by a
428                 // required module. There would be more flexible ways to proceed,
429                 // but that would be a lot more complicated, and the logic here is
430                 // already complicated. (That's why I've left the debugging code.)
431                 // lyxerr << "Testing " << thisMod << endl;
432                 bool foundone = false;
433                 for (int j = 0; j < curRow; ++j) {
434                         string const mod = getSelectedModel()->getIDString(j);
435                         // lyxerr << "In loop: Testing " << mod << endl;
436                         // do we satisfy the require?
437                         if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
438                                 // lyxerr << mod << " does the trick." << endl;
439                                 foundone = true;
440                                 break;
441                         }
442                 }
443                 // did we find a module to satisfy the require?
444                 if (!foundone) {
445                         // lyxerr << "No matching module found." << endl;
446                         deletePB->setEnabled(false);
447                         return;
448                 }
449         }
450         // lyxerr << "All's well that ends well." << endl;
451         deletePB->setEnabled(true);
452 }
453
454
455 /////////////////////////////////////////////////////////////////////
456 //
457 // PreambleModule
458 //
459 /////////////////////////////////////////////////////////////////////
460
461 PreambleModule::PreambleModule(QWidget * parent)
462         : UiWidget<Ui::PreambleUi>(parent), current_id_(0)
463 {
464         // This is not a memory leak. The object will be destroyed
465         // with this.
466         // @ is letter in the LyX user preamble
467         (void) new LaTeXHighlighter(preambleTE->document(), true);
468         preambleTE->setFont(guiApp->typewriterSystemFont());
469         preambleTE->setWordWrapMode(QTextOption::NoWrap);
470         setFocusProxy(preambleTE);
471         connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
472         connect(findLE, SIGNAL(textEdited(const QString &)), this, SLOT(checkFindButton()));
473         connect(findButtonPB, SIGNAL(clicked()), this, SLOT(findText()));
474         connect(findLE, SIGNAL(returnPressed()), this, SLOT(findText()));
475         checkFindButton();
476 }
477
478
479 void PreambleModule::checkFindButton()
480 {
481         findButtonPB->setEnabled(!findLE->text().isEmpty());
482 }
483
484
485 void PreambleModule::findText()
486 {
487         bool const found = preambleTE->find(findLE->text());
488         if (!found) {
489                 // wrap
490                 QTextCursor qtcur = preambleTE->textCursor();
491                 qtcur.movePosition(QTextCursor::Start);
492                 preambleTE->setTextCursor(qtcur);
493                 preambleTE->find(findLE->text());
494         }
495 }
496
497
498 void PreambleModule::update(BufferParams const & params, BufferId id)
499 {
500         QString preamble = toqstr(params.preamble);
501         // Nothing to do if the params and preamble are unchanged.
502         if (id == current_id_
503                 && preamble == preambleTE->document()->toPlainText())
504                 return;
505
506         QTextCursor cur = preambleTE->textCursor();
507         // Save the coords before switching to the new one.
508         preamble_coords_[current_id_] =
509                 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
510
511         // Save the params address for further use.
512         current_id_ = id;
513         preambleTE->document()->setPlainText(preamble);
514         Coords::const_iterator it = preamble_coords_.find(current_id_);
515         if (it == preamble_coords_.end())
516                 // First time we open this one.
517                 preamble_coords_[current_id_] = make_pair(0, 0);
518         else {
519                 // Restore saved coords.
520                 cur = preambleTE->textCursor();
521                 cur.setPosition(it->second.first);
522                 preambleTE->setTextCursor(cur);
523                 preambleTE->verticalScrollBar()->setValue(it->second.second);
524         }
525 }
526
527
528 void PreambleModule::apply(BufferParams & params)
529 {
530         params.preamble = qstring_to_ucs4(preambleTE->document()->toPlainText());
531 }
532
533
534 void PreambleModule::closeEvent(QCloseEvent * e)
535 {
536         // Save the coords before closing.
537         QTextCursor cur = preambleTE->textCursor();
538         preamble_coords_[current_id_] =
539                 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
540         e->accept();
541 }
542
543
544 /////////////////////////////////////////////////////////////////////
545 //
546 // LocalLayout
547 //
548 /////////////////////////////////////////////////////////////////////
549
550
551 LocalLayout::LocalLayout(QWidget * parent)
552         : UiWidget<Ui::LocalLayoutUi>(parent), current_id_(0), validated_(false)
553 {
554         connect(locallayoutTE, SIGNAL(textChanged()), this, SLOT(textChanged()));
555         connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
556         connect(convertPB, SIGNAL(clicked()), this, SLOT(convertPressed()));
557 }
558
559
560 void LocalLayout::update(BufferParams const & params, BufferId id)
561 {
562         QString layout = toqstr(params.getLocalLayout(false));
563         // Nothing to do if the params and preamble are unchanged.
564         if (id == current_id_
565                 && layout == locallayoutTE->document()->toPlainText())
566                 return;
567
568         // Save the params address for further use.
569         current_id_ = id;
570         locallayoutTE->document()->setPlainText(layout);
571         validate();
572 }
573
574
575 void LocalLayout::apply(BufferParams & params)
576 {
577         docstring const layout =
578                 qstring_to_ucs4(locallayoutTE->document()->toPlainText());
579         params.setLocalLayout(layout, false);
580 }
581
582
583 void LocalLayout::hideConvert()
584 {
585         convertPB->setEnabled(false);
586         convertLB->setText("");
587         convertPB->hide();
588         convertLB->hide();
589 }
590
591
592 void LocalLayout::textChanged()
593 {
594         static const QString message =
595                 qt_("Press button to check validity...");
596         string const layout =
597                 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
598
599         if (layout.empty()) {
600                 validated_ = true;
601                 validatePB->setEnabled(false);
602                 validLB->setText("");
603                 hideConvert();
604                 changed();
605         } else if (!validatePB->isEnabled()) {
606                 // if that's already enabled, we shouldn't need to do anything.
607                 validated_ = false;
608                 validLB->setText(message);
609                 validatePB->setEnabled(true);
610                 hideConvert();
611                 changed();
612         }
613 }
614
615
616 void LocalLayout::convert() {
617         string const layout =
618                 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
619         string const newlayout = TextClass::convert(layout);
620         if (!newlayout.empty())
621                 locallayoutTE->setPlainText(toqstr(newlayout));
622         validate();
623 }
624
625
626 void LocalLayout::convertPressed() {
627         convert();
628         hideConvert();
629         changed();
630 }
631
632
633 void LocalLayout::validate() {
634         // Bold text
635         static const QString vpar("<p style=\"font-weight: bold;\">%1</p>");
636         // Flashy red bold text
637         static const QString ivpar("<p style=\"color: #c00000; font-weight: bold; \">"
638                                    "%1</p>");
639         string const layout =
640                 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
641         if (!layout.empty()) {
642                 TextClass::ReturnValues const ret = TextClass::validate(layout);
643                 validated_ = (ret == TextClass::OK) || (ret == TextClass::OK_OLDFORMAT);
644                 validatePB->setEnabled(false);
645                 validLB->setText(validated_ ? vpar.arg(qt_("Layout is valid!"))
646                                             : ivpar.arg(qt_("Layout is invalid!")));
647                 if (ret == TextClass::OK_OLDFORMAT) {
648                         convertPB->show();
649                         // Testing conversion to LYXFILE_LAYOUT_FORMAT at this point
650                         // already.
651                         if (TextClass::convert(layout).empty()) {
652                                 // Conversion failed. If LAYOUT_FORMAT > LYXFILE_LAYOUT_FORMAT,
653                                 // then maybe the layout is still valid, but its format is more
654                                 // recent than LYXFILE_LAYOUT_FORMAT. However, if LAYOUT_FORMAT
655                                 // == LYXFILE_LAYOUT_FORMAT then something is definitely wrong.
656                                 convertPB->setEnabled(false);
657                                 const QString text = (LAYOUT_FORMAT == LYXFILE_LAYOUT_FORMAT)
658                                         ? ivpar.arg(qt_("Conversion to current format impossible!"))
659                                         : vpar.arg(qt_("Conversion to current stable format "
660                                                        "impossible."));
661                                 convertLB->setText(text);
662                         } else {
663                                 convertPB->setEnabled(true);
664                                 convertLB->setText(qt_("Convert to current format"));
665                         }
666                         convertLB->show();
667                 } else {
668                         convertPB->hide();
669                         convertLB->hide();
670                 }
671         }
672 }
673
674
675 void LocalLayout::validatePressed() {
676         validate();
677         changed();
678 }
679
680
681 /////////////////////////////////////////////////////////////////////
682 //
683 // DocumentDialog
684 //
685 /////////////////////////////////////////////////////////////////////
686
687
688 GuiDocument::GuiDocument(GuiView & lv)
689         : GuiDialog(lv, "document", qt_("Document Settings")),
690           biblioChanged_(false), nonModuleChanged_(false),
691           modulesChanged_(false), shellescapeChanged_(false)
692 {
693         setupUi(this);
694
695         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
696         connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
697         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
698         connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
699
700         connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
701         connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
702
703         // Manage the restore, ok, apply, restore and cancel/close buttons
704         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
705         bc().setOK(okPB);
706         bc().setApply(applyPB);
707         bc().setCancel(closePB);
708         bc().setRestore(restorePB);
709
710
711         // text layout
712         textLayoutModule = new UiWidget<Ui::TextLayoutUi>(this);
713         connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
714                 this, SLOT(change_adaptor()));
715         connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
716                 this, SLOT(setLSpacing(int)));
717         connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
718                 this, SLOT(change_adaptor()));
719
720         connect(textLayoutModule->indentRB, SIGNAL(clicked()),
721                 this, SLOT(change_adaptor()));
722         connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
723                 textLayoutModule->indentCO, SLOT(setEnabled(bool)));
724         connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
725                 this, SLOT(change_adaptor()));
726         connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
727                 this, SLOT(setIndent(int)));
728         connect(textLayoutModule->indentLE, SIGNAL(textChanged(const QString &)),
729                 this, SLOT(change_adaptor()));
730         connect(textLayoutModule->indentLengthCO, SIGNAL(activated(int)),
731                 this, SLOT(change_adaptor()));
732
733         connect(textLayoutModule->skipRB, SIGNAL(clicked()),
734                 this, SLOT(change_adaptor()));
735         connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
736                 textLayoutModule->skipCO, SLOT(setEnabled(bool)));
737         connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
738                 this, SLOT(change_adaptor()));
739         connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
740                 this, SLOT(setSkip(int)));
741         connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
742                 this, SLOT(change_adaptor()));
743         connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
744                 this, SLOT(change_adaptor()));
745
746         connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
747                 this, SLOT(enableIndent(bool)));
748         connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
749                 this, SLOT(enableSkip(bool)));
750
751         connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
752                 this, SLOT(change_adaptor()));
753         connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
754                 this, SLOT(setColSep()));
755         connect(textLayoutModule->justCB, SIGNAL(clicked()),
756                 this, SLOT(change_adaptor()));
757
758         textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
759                 textLayoutModule->lspacingLE));
760         textLayoutModule->indentLE->setValidator(new LengthValidator(
761                 textLayoutModule->indentLE));
762         textLayoutModule->skipLE->setValidator(new LengthValidator(
763                 textLayoutModule->skipLE));
764
765         textLayoutModule->indentCO->addItem(qt_("Default"));
766         textLayoutModule->indentCO->addItem(qt_("Custom"));
767         textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
768         textLayoutModule->skipCO->addItem(qt_("MedSkip"));
769         textLayoutModule->skipCO->addItem(qt_("BigSkip"));
770         textLayoutModule->skipCO->addItem(qt_("Custom"));
771         textLayoutModule->lspacingCO->insertItem(
772                 Spacing::Single, qt_("Single"));
773         textLayoutModule->lspacingCO->insertItem(
774                 Spacing::Onehalf, qt_("OneHalf"));
775         textLayoutModule->lspacingCO->insertItem(
776                 Spacing::Double, qt_("Double"));
777         textLayoutModule->lspacingCO->insertItem(
778                 Spacing::Other, qt_("Custom"));
779         // initialize the length validator
780         bc().addCheckedLineEdit(textLayoutModule->indentLE);
781         bc().addCheckedLineEdit(textLayoutModule->skipLE);
782
783
784         // master/child handling
785         masterChildModule = new UiWidget<Ui::MasterChildUi>(this);
786
787         connect(masterChildModule->childrenTW, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
788                 this, SLOT(includeonlyClicked(QTreeWidgetItem *, int)));
789         connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
790                 masterChildModule->childrenTW, SLOT(setEnabled(bool)));
791         connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
792                 masterChildModule->maintainAuxCB, SLOT(setEnabled(bool)));
793         connect(masterChildModule->includeallRB, SIGNAL(clicked()),
794                 this, SLOT(change_adaptor()));
795         connect(masterChildModule->includeonlyRB, SIGNAL(clicked()),
796                 this, SLOT(change_adaptor()));
797         connect(masterChildModule->maintainAuxCB, SIGNAL(clicked()),
798                 this, SLOT(change_adaptor()));
799         masterChildModule->childrenTW->setColumnCount(2);
800         masterChildModule->childrenTW->headerItem()->setText(0, qt_("Child Document"));
801         masterChildModule->childrenTW->headerItem()->setText(1, qt_("Include to Output"));
802         masterChildModule->childrenTW->resizeColumnToContents(1);
803         masterChildModule->childrenTW->resizeColumnToContents(2);
804
805
806         // Formats
807         outputModule = new UiWidget<Ui::OutputUi>(this);
808
809         connect(outputModule->defaultFormatCO, SIGNAL(activated(int)),
810                 this, SLOT(change_adaptor()));
811         connect(outputModule->mathimgSB, SIGNAL(valueChanged(double)),
812                 this, SLOT(change_adaptor()));
813         connect(outputModule->strictCB, SIGNAL(stateChanged(int)),
814                 this, SLOT(change_adaptor()));
815         connect(outputModule->cssCB, SIGNAL(stateChanged(int)),
816                 this, SLOT(change_adaptor()));
817         connect(outputModule->mathoutCB, SIGNAL(currentIndexChanged(int)),
818                 this, SLOT(change_adaptor()));
819
820         connect(outputModule->shellescapeCB, SIGNAL(stateChanged(int)),
821                 this, SLOT(shellescapeChanged()));
822         connect(outputModule->outputsyncCB, SIGNAL(clicked()),
823                 this, SLOT(change_adaptor()));
824         connect(outputModule->synccustomCB, SIGNAL(editTextChanged(QString)),
825                 this, SLOT(change_adaptor()));
826         outputModule->synccustomCB->addItem("");
827         outputModule->synccustomCB->addItem("\\synctex=1");
828         outputModule->synccustomCB->addItem("\\synctex=-1");
829         outputModule->synccustomCB->addItem("\\usepackage[active]{srcltx}");
830
831         outputModule->synccustomCB->setValidator(new NoNewLineValidator(
832                 outputModule->synccustomCB));
833
834         connect(outputModule->saveTransientPropertiesCB, SIGNAL(clicked()),
835                 this, SLOT(change_adaptor()));
836
837         // fonts
838         fontModule = new FontModule(this);
839         connect(fontModule->osFontsCB, SIGNAL(clicked()),
840                 this, SLOT(change_adaptor()));
841         connect(fontModule->osFontsCB, SIGNAL(toggled(bool)),
842                 this, SLOT(osFontsChanged(bool)));
843         connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
844                 this, SLOT(change_adaptor()));
845         connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
846                 this, SLOT(romanChanged(int)));
847         connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
848                 this, SLOT(change_adaptor()));
849         connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
850                 this, SLOT(sansChanged(int)));
851         connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
852                 this, SLOT(change_adaptor()));
853         connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
854                 this, SLOT(ttChanged(int)));
855         connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
856                 this, SLOT(change_adaptor()));
857         connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
858                 this, SLOT(mathFontChanged(int)));
859         connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
860                 this, SLOT(change_adaptor()));
861         connect(fontModule->fontencCO, SIGNAL(activated(int)),
862                 this, SLOT(change_adaptor()));
863         connect(fontModule->fontencCO, SIGNAL(activated(int)),
864                 this, SLOT(fontencChanged(int)));
865         connect(fontModule->fontencLE, SIGNAL(textChanged(const QString &)),
866                 this, SLOT(change_adaptor()));
867         connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
868                 this, SLOT(change_adaptor()));
869         connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
870                 this, SLOT(change_adaptor()));
871         connect(fontModule->microtypeCB, SIGNAL(clicked()),
872                 this, SLOT(change_adaptor()));
873         connect(fontModule->dashesCB, SIGNAL(clicked()),
874                 this, SLOT(change_adaptor()));
875         connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
876                 this, SLOT(change_adaptor()));
877         connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
878                 this, SLOT(change_adaptor()));
879         connect(fontModule->fontScCB, SIGNAL(clicked()),
880                 this, SLOT(change_adaptor()));
881         connect(fontModule->fontScCB, SIGNAL(toggled(bool)),
882                 this, SLOT(fontScToggled(bool)));
883         connect(fontModule->fontOsfCB, SIGNAL(clicked()),
884                 this, SLOT(change_adaptor()));
885         connect(fontModule->fontOsfCB, SIGNAL(toggled(bool)),
886                 this, SLOT(fontOsfToggled(bool)));
887
888         fontModule->fontencLE->setValidator(new NoNewLineValidator(
889                 fontModule->fontencLE));
890         fontModule->cjkFontLE->setValidator(new NoNewLineValidator(
891                 fontModule->cjkFontLE));
892
893         updateFontlist();
894
895         fontModule->fontsizeCO->addItem(qt_("Default"));
896         fontModule->fontsizeCO->addItem(qt_("10"));
897         fontModule->fontsizeCO->addItem(qt_("11"));
898         fontModule->fontsizeCO->addItem(qt_("12"));
899
900         fontModule->fontencCO->addItem(qt_("Default"), QString("global"));
901         fontModule->fontencCO->addItem(qt_("Custom"), QString("custom"));
902         fontModule->fontencCO->addItem(qt_("None (no fontenc)"), QString("default"));
903
904         for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
905                 fontModule->fontsDefaultCO->addItem(
906                         qt_(GuiDocument::fontfamilies_gui[n]));
907
908         if (!LaTeXFeatures::isAvailable("fontspec"))
909                 fontModule->osFontsCB->setToolTip(
910                         qt_("Use OpenType and TrueType fonts directly (requires XeTeX or LuaTeX)\n"
911                             "You need to install the package \"fontspec\" to use this feature"));
912
913
914         // page layout
915         pageLayoutModule = new UiWidget<Ui::PageLayoutUi>(this);
916         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
917                 this, SLOT(papersizeChanged(int)));
918         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
919                 this, SLOT(papersizeChanged(int)));
920         connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
921                 this, SLOT(change_adaptor()));
922         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
923                 this, SLOT(change_adaptor()));
924         connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
925                 this, SLOT(change_adaptor()));
926         connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
927                 this, SLOT(change_adaptor()));
928         connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
929                 this, SLOT(change_adaptor()));
930         connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
931                 this, SLOT(change_adaptor()));
932         connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
933                 this, SLOT(change_adaptor()));
934         connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
935                 this, SLOT(change_adaptor()));
936         connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
937                 this, SLOT(change_adaptor()));
938         connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
939                 this, SLOT(change_adaptor()));
940
941         pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
942         pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
943         pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
944         pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
945         pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
946         bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
947                 pageLayoutModule->paperheightL);
948         bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
949                 pageLayoutModule->paperwidthL);
950
951         QComboBox * cb = pageLayoutModule->papersizeCO;
952         cb->addItem(qt_("Default"));
953         cb->addItem(qt_("Custom"));
954         cb->addItem(qt_("US letter"));
955         cb->addItem(qt_("US legal"));
956         cb->addItem(qt_("US executive"));
957         cb->addItem(qt_("A0"));
958         cb->addItem(qt_("A1"));
959         cb->addItem(qt_("A2"));
960         cb->addItem(qt_("A3"));
961         cb->addItem(qt_("A4"));
962         cb->addItem(qt_("A5"));
963         cb->addItem(qt_("A6"));
964         cb->addItem(qt_("B0"));
965         cb->addItem(qt_("B1"));
966         cb->addItem(qt_("B2"));
967         cb->addItem(qt_("B3"));
968         cb->addItem(qt_("B4"));
969         cb->addItem(qt_("B5"));
970         cb->addItem(qt_("B6"));
971         cb->addItem(qt_("C0"));
972         cb->addItem(qt_("C1"));
973         cb->addItem(qt_("C2"));
974         cb->addItem(qt_("C3"));
975         cb->addItem(qt_("C4"));
976         cb->addItem(qt_("C5"));
977         cb->addItem(qt_("C6"));
978         cb->addItem(qt_("JIS B0"));
979         cb->addItem(qt_("JIS B1"));
980         cb->addItem(qt_("JIS B2"));
981         cb->addItem(qt_("JIS B3"));
982         cb->addItem(qt_("JIS B4"));
983         cb->addItem(qt_("JIS B5"));
984         cb->addItem(qt_("JIS B6"));
985         // remove the %-items from the unit choice
986         pageLayoutModule->paperwidthUnitCO->noPercents();
987         pageLayoutModule->paperheightUnitCO->noPercents();
988         pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
989                 pageLayoutModule->paperheightLE));
990         pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
991                 pageLayoutModule->paperwidthLE));
992
993
994         // margins
995         marginsModule = new UiWidget<Ui::MarginsUi>(this);
996         connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
997                 this, SLOT(setCustomMargins(bool)));
998         connect(marginsModule->marginCB, SIGNAL(clicked()),
999                 this, SLOT(change_adaptor()));
1000         connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
1001                 this, SLOT(change_adaptor()));
1002         connect(marginsModule->topUnit, SIGNAL(activated(int)),
1003                 this, SLOT(change_adaptor()));
1004         connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
1005                 this, SLOT(change_adaptor()));
1006         connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
1007                 this, SLOT(change_adaptor()));
1008         connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
1009                 this, SLOT(change_adaptor()));
1010         connect(marginsModule->innerUnit, SIGNAL(activated(int)),
1011                 this, SLOT(change_adaptor()));
1012         connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
1013                 this, SLOT(change_adaptor()));
1014         connect(marginsModule->outerUnit, SIGNAL(activated(int)),
1015                 this, SLOT(change_adaptor()));
1016         connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
1017                 this, SLOT(change_adaptor()));
1018         connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
1019                 this, SLOT(change_adaptor()));
1020         connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
1021                 this, SLOT(change_adaptor()));
1022         connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
1023                 this, SLOT(change_adaptor()));
1024         connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
1025                 this, SLOT(change_adaptor()));
1026         connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
1027                 this, SLOT(change_adaptor()));
1028         connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
1029                 this, SLOT(change_adaptor()));
1030         connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
1031                 this, SLOT(change_adaptor()));
1032         marginsModule->topLE->setValidator(new LengthValidator(
1033                 marginsModule->topLE));
1034         marginsModule->bottomLE->setValidator(new LengthValidator(
1035                 marginsModule->bottomLE));
1036         marginsModule->innerLE->setValidator(new LengthValidator(
1037                 marginsModule->innerLE));
1038         marginsModule->outerLE->setValidator(new LengthValidator(
1039                 marginsModule->outerLE));
1040         marginsModule->headsepLE->setValidator(new LengthValidator(
1041                 marginsModule->headsepLE));
1042         marginsModule->headheightLE->setValidator(new LengthValidator(
1043                 marginsModule->headheightLE));
1044         marginsModule->footskipLE->setValidator(new LengthValidator(
1045                 marginsModule->footskipLE));
1046         marginsModule->columnsepLE->setValidator(new LengthValidator(
1047                 marginsModule->columnsepLE));
1048
1049         bc().addCheckedLineEdit(marginsModule->topLE,
1050                 marginsModule->topL);
1051         bc().addCheckedLineEdit(marginsModule->bottomLE,
1052                 marginsModule->bottomL);
1053         bc().addCheckedLineEdit(marginsModule->innerLE,
1054                 marginsModule->innerL);
1055         bc().addCheckedLineEdit(marginsModule->outerLE,
1056                 marginsModule->outerL);
1057         bc().addCheckedLineEdit(marginsModule->headsepLE,
1058                 marginsModule->headsepL);
1059         bc().addCheckedLineEdit(marginsModule->headheightLE,
1060                 marginsModule->headheightL);
1061         bc().addCheckedLineEdit(marginsModule->footskipLE,
1062                 marginsModule->footskipL);
1063         bc().addCheckedLineEdit(marginsModule->columnsepLE,
1064                 marginsModule->columnsepL);
1065
1066
1067         // language & quote
1068         langModule = new UiWidget<Ui::LanguageUi>(this);
1069         connect(langModule->languageCO, SIGNAL(activated(int)),
1070                 this, SLOT(change_adaptor()));
1071         connect(langModule->languageCO, SIGNAL(activated(int)),
1072                 this, SLOT(languageChanged(int)));
1073         connect(langModule->defaultencodingRB, SIGNAL(clicked()),
1074                 this, SLOT(change_adaptor()));
1075         connect(langModule->otherencodingRB, SIGNAL(clicked()),
1076                 this, SLOT(change_adaptor()));
1077         connect(langModule->encodingCO, SIGNAL(activated(int)),
1078                 this, SLOT(change_adaptor()));
1079         connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
1080                 this, SLOT(change_adaptor()));
1081         connect(langModule->languagePackageCO, SIGNAL(activated(int)),
1082                 this, SLOT(change_adaptor()));
1083         connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
1084                 this, SLOT(change_adaptor()));
1085         connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
1086                 this, SLOT(languagePackageChanged(int)));
1087         connect(langModule->dynamicQuotesCB, SIGNAL(clicked()),
1088                 this, SLOT(change_adaptor()));
1089
1090         langModule->languagePackageLE->setValidator(new NoNewLineValidator(
1091                 langModule->languagePackageLE));
1092
1093         QAbstractItemModel * language_model = guiApp->languageModel();
1094         // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1095         language_model->sort(0);
1096         langModule->languageCO->setModel(language_model);
1097         langModule->languageCO->setModelColumn(0);
1098
1099         // Always put the default encoding in the first position.
1100         langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
1101         QStringList encodinglist;
1102         for (auto const & encvar : encodings) {
1103                 if (!encvar.unsafe() && !encvar.guiName().empty())
1104                         encodinglist.append(qt_(encvar.guiName()));
1105         }
1106         encodinglist.sort();
1107         langModule->encodingCO->addItems(encodinglist);
1108
1109         langModule->languagePackageCO->addItem(
1110                 qt_("Default"), toqstr("default"));
1111         langModule->languagePackageCO->addItem(
1112                 qt_("Automatic"), toqstr("auto"));
1113         langModule->languagePackageCO->addItem(
1114                 qt_("Always Babel"), toqstr("babel"));
1115         langModule->languagePackageCO->addItem(
1116                 qt_("Custom"), toqstr("custom"));
1117         langModule->languagePackageCO->addItem(
1118                 qt_("None[[language package]]"), toqstr("none"));
1119
1120
1121         // color
1122         colorModule = new UiWidget<Ui::ColorUi>(this);
1123         connect(colorModule->fontColorPB, SIGNAL(clicked()),
1124                 this, SLOT(changeFontColor()));
1125         connect(colorModule->delFontColorTB, SIGNAL(clicked()),
1126                 this, SLOT(deleteFontColor()));
1127         connect(colorModule->noteFontColorPB, SIGNAL(clicked()),
1128                 this, SLOT(changeNoteFontColor()));
1129         connect(colorModule->delNoteFontColorTB, SIGNAL(clicked()),
1130                 this, SLOT(deleteNoteFontColor()));
1131         connect(colorModule->backgroundPB, SIGNAL(clicked()),
1132                 this, SLOT(changeBackgroundColor()));
1133         connect(colorModule->delBackgroundTB, SIGNAL(clicked()),
1134                 this, SLOT(deleteBackgroundColor()));
1135         connect(colorModule->boxBackgroundPB, SIGNAL(clicked()),
1136                 this, SLOT(changeBoxBackgroundColor()));
1137         connect(colorModule->delBoxBackgroundTB, SIGNAL(clicked()),
1138                 this, SLOT(deleteBoxBackgroundColor()));
1139
1140
1141         // numbering
1142         numberingModule = new UiWidget<Ui::NumberingUi>(this);
1143         connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1144                 this, SLOT(change_adaptor()));
1145         connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1146                 this, SLOT(change_adaptor()));
1147         connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1148                 this, SLOT(updateNumbering()));
1149         connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1150                 this, SLOT(updateNumbering()));
1151         numberingModule->tocTW->setColumnCount(3);
1152         numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
1153         numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
1154         numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
1155         setSectionResizeMode(numberingModule->tocTW->header(), QHeaderView::ResizeToContents);
1156
1157         // biblio
1158         biblioModule = new UiWidget<Ui::BiblioUi>(this);
1159         connect(biblioModule->citeEngineCO, SIGNAL(activated(int)),
1160                 this, SLOT(citeEngineChanged(int)));
1161         connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
1162                 this, SLOT(citeStyleChanged()));
1163         connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
1164                 this, SLOT(biblioChanged()));
1165         connect(biblioModule->bibunitsCO, SIGNAL(activated(int)),
1166                 this, SLOT(biblioChanged()));
1167         connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
1168                 this, SLOT(bibtexChanged(int)));
1169         connect(biblioModule->bibtexOptionsLE, SIGNAL(textChanged(QString)),
1170                 this, SLOT(biblioChanged()));
1171         connect(biblioModule->citePackageOptionsLE, SIGNAL(textChanged(QString)),
1172                 this, SLOT(biblioChanged()));
1173         connect(biblioModule->defaultBiblioCO, SIGNAL(activated(int)),
1174                 this, SLOT(biblioChanged()));
1175         connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
1176                 this, SLOT(biblioChanged()));
1177         connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
1178                 this, SLOT(updateResetDefaultBiblio()));
1179         connect(biblioModule->biblatexBbxCO, SIGNAL(activated(int)),
1180                 this, SLOT(biblioChanged()));
1181         connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
1182                 this, SLOT(biblioChanged()));
1183         connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
1184                 this, SLOT(updateResetDefaultBiblio()));
1185         connect(biblioModule->biblatexCbxCO, SIGNAL(activated(int)),
1186                 this, SLOT(biblioChanged()));
1187         connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
1188                 this, SLOT(biblioChanged()));
1189         connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
1190                 this, SLOT(updateResetDefaultBiblio()));
1191         connect(biblioModule->rescanBibliosPB, SIGNAL(clicked()),
1192                 this, SLOT(rescanBibFiles()));
1193         connect(biblioModule->resetDefaultBiblioPB, SIGNAL(clicked()),
1194                 this, SLOT(resetDefaultBibfile()));
1195         connect(biblioModule->resetCbxPB, SIGNAL(clicked()),
1196                 this, SLOT(resetDefaultCbxBibfile()));
1197         connect(biblioModule->resetBbxPB, SIGNAL(clicked()),
1198                 this, SLOT(resetDefaultBbxBibfile()));
1199         connect(biblioModule->matchBbxPB, SIGNAL(clicked()),
1200                 this, SLOT(matchBiblatexStyles()));
1201
1202         biblioModule->citeEngineCO->clear();
1203         for (LyXCiteEngine const & cet : theCiteEnginesList) {
1204                 biblioModule->citeEngineCO->addItem(qt_(cet.getName()), toqstr(cet.getID()));
1205                 int const i = biblioModule->citeEngineCO->findData(toqstr(cet.getID()));
1206                 biblioModule->citeEngineCO->setItemData(i, qt_(cet.getDescription()),
1207                                                         Qt::ToolTipRole);
1208         }
1209
1210         biblioModule->bibtexOptionsLE->setValidator(new NoNewLineValidator(
1211                 biblioModule->bibtexOptionsLE));
1212         biblioModule->defaultBiblioCO->lineEdit()->setValidator(new NoNewLineValidator(
1213                 biblioModule->defaultBiblioCO->lineEdit()));
1214         biblioModule->citePackageOptionsLE->setValidator(new NoNewLineValidator(
1215                 biblioModule->citePackageOptionsLE));
1216
1217         // NOTE: we do not provide "custom" here for security reasons!
1218         biblioModule->bibtexCO->clear();
1219         biblioModule->bibtexCO->addItem(qt_("Default"), QString("default"));
1220         for (auto const & alts : lyxrc.bibtex_alternatives) {
1221                 QString const command = toqstr(alts).left(toqstr(alts).indexOf(" "));
1222                 biblioModule->bibtexCO->addItem(command, command);
1223         }
1224
1225
1226         // indices
1227         indicesModule = new GuiIndices;
1228         connect(indicesModule, SIGNAL(changed()),
1229                 this, SLOT(change_adaptor()));
1230
1231
1232         // maths
1233         mathsModule = new UiWidget<Ui::MathsUi>(this);
1234         QStringList headers;
1235         headers << qt_("Package") << qt_("Load automatically")
1236                 << qt_("Load always") << qt_("Do not load");
1237         mathsModule->packagesTW->setHorizontalHeaderLabels(headers);
1238         setSectionResizeMode(mathsModule->packagesTW->horizontalHeader(), QHeaderView::Stretch);
1239         map<string, string> const & packages = BufferParams::auto_packages();
1240         mathsModule->packagesTW->setRowCount(packages.size());
1241         int packnum = 0;
1242         for (auto const & pkgvar : packages) {
1243                 docstring const package = from_ascii(pkgvar.first);
1244                 QString autoTooltip = qt_(pkgvar.second);
1245                 QString alwaysTooltip;
1246                 if (package == "amsmath")
1247                         alwaysTooltip =
1248                                 qt_("The AMS LaTeX packages are always used");
1249                 else
1250                         alwaysTooltip = toqstr(bformat(
1251                                 _("The LaTeX package %1$s is always used"),
1252                                 package));
1253                 QString neverTooltip;
1254                 if (package == "amsmath")
1255                         neverTooltip =
1256                                 qt_("The AMS LaTeX packages are never used");
1257                 else
1258                         neverTooltip = toqstr(bformat(
1259                                 _("The LaTeX package %1$s is never used"),
1260                                 package));
1261                 QRadioButton * autoRB = new QRadioButton(mathsModule);
1262                 QRadioButton * alwaysRB = new QRadioButton(mathsModule);
1263                 QRadioButton * neverRB = new QRadioButton(mathsModule);
1264                 QButtonGroup * packageGroup = new QButtonGroup(mathsModule);
1265                 packageGroup->addButton(autoRB);
1266                 packageGroup->addButton(alwaysRB);
1267                 packageGroup->addButton(neverRB);
1268                 autoRB->setToolTip(autoTooltip);
1269                 alwaysRB->setToolTip(alwaysTooltip);
1270                 neverRB->setToolTip(neverTooltip);
1271
1272                 // Pack the buttons in a layout in order to get proper alignment
1273                 QWidget * autoRBWidget = new QWidget();
1274                 QHBoxLayout * autoRBLayout = new QHBoxLayout(autoRBWidget);
1275                 autoRBLayout->addWidget(autoRB);
1276                 autoRBLayout->setAlignment(Qt::AlignCenter);
1277                 autoRBLayout->setContentsMargins(0, 0, 0, 0);
1278                 autoRBWidget->setLayout(autoRBLayout);
1279
1280                 QWidget * alwaysRBWidget = new QWidget();
1281                 QHBoxLayout * alwaysRBLayout = new QHBoxLayout(alwaysRBWidget);
1282                 alwaysRBLayout->addWidget(alwaysRB);
1283                 alwaysRBLayout->setAlignment(Qt::AlignCenter);
1284                 alwaysRBLayout->setContentsMargins(0, 0, 0, 0);
1285                 alwaysRBWidget->setLayout(alwaysRBLayout);
1286
1287                 QWidget * neverRBWidget = new QWidget();
1288                 QHBoxLayout * neverRBLayout = new QHBoxLayout(neverRBWidget);
1289                 neverRBLayout->addWidget(neverRB);
1290                 neverRBLayout->setAlignment(Qt::AlignCenter);
1291                 neverRBLayout->setContentsMargins(0, 0, 0, 0);
1292                 neverRBWidget->setLayout(neverRBLayout);
1293
1294                 QTableWidgetItem * pack = new QTableWidgetItem(toqstr(package));
1295                 mathsModule->packagesTW->setItem(packnum, 0, pack);
1296                 mathsModule->packagesTW->setCellWidget(packnum, 1, autoRBWidget);
1297                 mathsModule->packagesTW->setCellWidget(packnum, 2, alwaysRBWidget);
1298                 mathsModule->packagesTW->setCellWidget(packnum, 3, neverRBWidget);
1299
1300                 connect(autoRB, SIGNAL(clicked()),
1301                         this, SLOT(change_adaptor()));
1302                 connect(alwaysRB, SIGNAL(clicked()),
1303                         this, SLOT(change_adaptor()));
1304                 connect(neverRB, SIGNAL(clicked()),
1305                         this, SLOT(change_adaptor()));
1306                 ++packnum;
1307         }
1308         connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1309                 this, SLOT(allPackagesAuto()));
1310         connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1311                 this, SLOT(allPackagesAlways()));
1312         connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1313                 this, SLOT(allPackagesNot()));
1314         connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1315                 this, SLOT(change_adaptor()));
1316         connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1317                 this, SLOT(change_adaptor()));
1318         connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1319                 this, SLOT(change_adaptor()));
1320         connect(mathsModule->MathNumberingPosCO, SIGNAL(activated(int)),
1321                 this, SLOT(change_adaptor()));
1322
1323         connect(mathsModule->MathIndentCB, SIGNAL(toggled(bool)),
1324                 this, SLOT(change_adaptor()));
1325         connect(mathsModule->MathIndentCB, SIGNAL(toggled(bool)),
1326                 this, SLOT(allowMathIndent()));
1327         connect(mathsModule->MathIndentCO, SIGNAL(activated(int)),
1328                 this, SLOT(change_adaptor()));
1329         connect(mathsModule->MathIndentCO, SIGNAL(activated(int)),
1330                 this, SLOT(enableMathIndent(int)));
1331         connect(mathsModule->MathIndentLE, SIGNAL(textChanged(const QString &)),
1332                 this, SLOT(change_adaptor()));
1333         connect(mathsModule->MathIndentLengthCO, SIGNAL(activated(int)),
1334                 this, SLOT(change_adaptor()));
1335
1336
1337         mathsModule->MathIndentCO->addItem(qt_("Default"));
1338         mathsModule->MathIndentCO->addItem(qt_("Custom"));
1339         mathsModule->MathIndentLE->setValidator(new LengthValidator(
1340                 mathsModule->MathIndentLE));
1341         // initialize the length validator
1342         bc().addCheckedLineEdit(mathsModule->MathIndentLE);
1343         mathsModule->MathNumberingPosCO->addItem(qt_("Left"));
1344         mathsModule->MathNumberingPosCO->addItem(qt_("Default"));
1345         mathsModule->MathNumberingPosCO->addItem(qt_("Right"));
1346         mathsModule->MathNumberingPosCO->setCurrentIndex(1);
1347
1348
1349         // latex class
1350         latexModule = new UiWidget<Ui::LaTeXUi>(this);
1351         connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
1352                 this, SLOT(change_adaptor()));
1353         connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
1354                 this, SLOT(change_adaptor()));
1355         connect(latexModule->psdriverCO, SIGNAL(activated(int)),
1356                 this, SLOT(change_adaptor()));
1357         connect(latexModule->classCO, SIGNAL(activated(int)),
1358                 this, SLOT(classChanged_adaptor()));
1359         connect(latexModule->classCO, SIGNAL(activated(int)),
1360                 this, SLOT(change_adaptor()));
1361         connect(latexModule->layoutPB, SIGNAL(clicked()),
1362                 this, SLOT(browseLayout()));
1363         connect(latexModule->layoutPB, SIGNAL(clicked()),
1364                 this, SLOT(change_adaptor()));
1365         connect(latexModule->childDocGB, SIGNAL(clicked()),
1366                 this, SLOT(change_adaptor()));
1367         connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
1368                 this, SLOT(change_adaptor()));
1369         connect(latexModule->childDocPB, SIGNAL(clicked()),
1370                 this, SLOT(browseMaster()));
1371         connect(latexModule->suppressDateCB, SIGNAL(clicked()),
1372                 this, SLOT(change_adaptor()));
1373         connect(latexModule->refstyleCB, SIGNAL(clicked()),
1374                 this, SLOT(change_adaptor()));
1375
1376         latexModule->optionsLE->setValidator(new NoNewLineValidator(
1377                 latexModule->optionsLE));
1378         latexModule->childDocLE->setValidator(new NoNewLineValidator(
1379                 latexModule->childDocLE));
1380
1381         // postscript drivers
1382         for (int n = 0; tex_graphics[n][0]; ++n) {
1383                 QString enc = qt_(tex_graphics_gui[n]);
1384                 latexModule->psdriverCO->addItem(enc);
1385         }
1386         // latex classes
1387         LayoutFileList const & bcl = LayoutFileList::get();
1388         vector<LayoutFileIndex> classList = bcl.classList();
1389         sort(classList.begin(), classList.end(), less_textclass_avail_desc());
1390
1391         for (auto const & cvar : classList) {
1392                 LayoutFile const & tc = bcl[cvar];
1393                 bool const available = tc.isTeXClassAvailable();
1394                 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
1395                 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
1396                 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
1397                 if (!available) {
1398                         docstring const output_type = (tc.outputType() == lyx::DOCBOOK) ? _("DocBook") : _("LaTeX");
1399                         tooltip += '\n' + toqstr(bformat(_("Class not found by LyX. "
1400                                                            "Please check if you have the matching %1$s class "
1401                                                            "and all required packages (%2$s) installed."),
1402                                                          output_type, from_utf8(tc.prerequisites(", "))));
1403                 }
1404                 latexModule->classCO->addItemSort(toqstr(tc.name()),
1405                                                   toqstr(guiname),
1406                                                   toqstr(translateIfPossible(from_utf8(tc.category()))),
1407                                                   tooltip,
1408                                                   true, true, true, available);
1409         }
1410
1411
1412         // branches
1413         branchesModule = new GuiBranches(this);
1414         connect(branchesModule, SIGNAL(changed()),
1415                 this, SLOT(change_adaptor()));
1416         connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
1417                 this, SLOT(branchesRename(docstring const &, docstring const &)));
1418         connect(branchesModule, SIGNAL(okPressed()), this, SLOT(slotOK()));
1419         updateUnknownBranches();
1420
1421
1422         // preamble
1423         preambleModule = new PreambleModule(this);
1424         connect(preambleModule, SIGNAL(changed()),
1425                 this, SLOT(change_adaptor()));
1426
1427         localLayout = new LocalLayout(this);
1428         connect(localLayout, SIGNAL(changed()),
1429                 this, SLOT(change_adaptor()));
1430
1431
1432         // bullets
1433         bulletsModule = new BulletsModule(this);
1434         connect(bulletsModule, SIGNAL(changed()),
1435                 this, SLOT(change_adaptor()));
1436
1437
1438         // Modules
1439         modulesModule = new UiWidget<Ui::ModulesUi>(this);
1440         modulesModule->availableLV->header()->setVisible(false);
1441         setSectionResizeMode(modulesModule->availableLV->header(), QHeaderView::ResizeToContents);
1442         modulesModule->availableLV->header()->setStretchLastSection(false);
1443         selectionManager =
1444                 new ModuleSelectionManager(this, modulesModule->availableLV,
1445                                            modulesModule->selectedLV,
1446                                            modulesModule->addPB,
1447                                            modulesModule->deletePB,
1448                                            modulesModule->upPB,
1449                                            modulesModule->downPB,
1450                                            availableModel(), selectedModel(), this);
1451         connect(selectionManager, SIGNAL(updateHook()),
1452                 this, SLOT(updateModuleInfo()));
1453         connect(selectionManager, SIGNAL(selectionChanged()),
1454                 this, SLOT(modulesChanged()));
1455
1456
1457         // PDF support
1458         pdfSupportModule = new UiWidget<Ui::PDFSupportUi>(this);
1459         connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
1460                 this, SLOT(change_adaptor()));
1461         connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
1462                 this, SLOT(change_adaptor()));
1463         connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
1464                 this, SLOT(change_adaptor()));
1465         connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
1466                 this, SLOT(change_adaptor()));
1467         connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
1468                 this, SLOT(change_adaptor()));
1469         connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
1470                 this, SLOT(change_adaptor()));
1471         connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
1472                 this, SLOT(change_adaptor()));
1473         connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
1474                 this, SLOT(change_adaptor()));
1475         connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
1476                 this, SLOT(change_adaptor()));
1477         connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
1478                 this, SLOT(change_adaptor()));
1479         connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
1480                 this, SLOT(change_adaptor()));
1481         connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
1482                 this, SLOT(change_adaptor()));
1483         connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
1484                 this, SLOT(change_adaptor()));
1485         connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
1486                 this, SLOT(change_adaptor()));
1487         connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
1488                 this, SLOT(change_adaptor()));
1489         connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
1490                 this, SLOT(change_adaptor()));
1491
1492         pdfSupportModule->titleLE->setValidator(new NoNewLineValidator(
1493                 pdfSupportModule->titleLE));
1494         pdfSupportModule->authorLE->setValidator(new NoNewLineValidator(
1495                 pdfSupportModule->authorLE));
1496         pdfSupportModule->subjectLE->setValidator(new NoNewLineValidator(
1497                 pdfSupportModule->subjectLE));
1498         pdfSupportModule->keywordsLE->setValidator(new NoNewLineValidator(
1499                 pdfSupportModule->keywordsLE));
1500         pdfSupportModule->optionsLE->setValidator(new NoNewLineValidator(
1501                 pdfSupportModule->optionsLE));
1502
1503         for (int i = 0; backref_opts[i][0]; ++i)
1504                 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
1505
1506
1507         // float
1508         floatModule = new FloatPlacement;
1509         connect(floatModule, SIGNAL(changed()),
1510                 this, SLOT(change_adaptor()));
1511
1512
1513         // listings
1514         listingsModule = new UiWidget<Ui::ListingsSettingsUi>(this);
1515         connect(listingsModule->listingsED, SIGNAL(textChanged()),
1516                 this, SLOT(change_adaptor()));
1517         connect(listingsModule->bypassCB, SIGNAL(clicked()),
1518                 this, SLOT(change_adaptor()));
1519         connect(listingsModule->bypassCB, SIGNAL(clicked()),
1520                 this, SLOT(setListingsMessage()));
1521         connect(listingsModule->packageCO, SIGNAL(activated(int)),
1522                 this, SLOT(change_adaptor()));
1523         connect(listingsModule->packageCO, SIGNAL(activated(int)),
1524                 this, SLOT(listingsPackageChanged(int)));
1525         connect(listingsModule->listingsED, SIGNAL(textChanged()),
1526                 this, SLOT(setListingsMessage()));
1527         listingsModule->listingsTB->setPlainText(
1528                 qt_("Input listings parameters below. Enter ? for a list of parameters."));
1529
1530         for (int i = 0; lst_packages[i][0]; ++i)
1531             listingsModule->packageCO->addItem(lst_packages[i]);
1532
1533
1534         // add the panels
1535         docPS->addPanel(latexModule, N_("Document Class"));
1536         docPS->addPanel(masterChildModule, N_("Child Documents"));
1537         docPS->addPanel(modulesModule, N_("Modules"));
1538         docPS->addPanel(localLayout, N_("Local Layout"));
1539         docPS->addPanel(fontModule, N_("Fonts"));
1540         docPS->addPanel(textLayoutModule, N_("Text Layout"));
1541         docPS->addPanel(pageLayoutModule, N_("Page Layout"));
1542         docPS->addPanel(marginsModule, N_("Page Margins"));
1543         docPS->addPanel(langModule, N_("Language"));
1544         docPS->addPanel(colorModule, N_("Colors"));
1545         docPS->addPanel(numberingModule, N_("Numbering & TOC"));
1546         docPS->addPanel(biblioModule, N_("Bibliography"));
1547         docPS->addPanel(indicesModule, N_("Indexes"));
1548         docPS->addPanel(pdfSupportModule, N_("PDF Properties"));
1549         docPS->addPanel(mathsModule, N_("Math Options"));
1550         docPS->addPanel(floatModule, N_("Float Placement"));
1551         docPS->addPanel(listingsModule, N_("Listings[[inset]]"));
1552         docPS->addPanel(bulletsModule, N_("Bullets"));
1553         docPS->addPanel(branchesModule, N_("Branches"));
1554         docPS->addPanel(outputModule, N_("Formats[[output]]"));
1555         docPS->addPanel(preambleModule, N_("LaTeX Preamble"));
1556         docPS->setCurrentPanel("Document Class");
1557 // FIXME: hack to work around resizing bug in Qt >= 4.2
1558 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1559 #if QT_VERSION >= 0x040200
1560         docPS->updateGeometry();
1561 #endif
1562 }
1563
1564
1565 void GuiDocument::onBufferViewChanged()
1566 {
1567         if (isVisibleView())
1568                 initialiseParams("");
1569 }
1570
1571
1572 void GuiDocument::saveDefaultClicked()
1573 {
1574         saveDocDefault();
1575 }
1576
1577
1578 void GuiDocument::useDefaultsClicked()
1579 {
1580         useClassDefaults();
1581 }
1582
1583
1584 void GuiDocument::change_adaptor()
1585 {
1586         nonModuleChanged_ = true;
1587         changed();
1588 }
1589
1590
1591 void GuiDocument::shellescapeChanged()
1592 {
1593         shellescapeChanged_ = true;
1594         changed();
1595 }
1596
1597
1598 void GuiDocument::slotApply()
1599 {
1600         bool only_shellescape_changed = !nonModuleChanged_ && !modulesChanged_;
1601         bool wasclean = buffer().isClean();
1602         GuiDialog::slotApply();
1603         if (wasclean && only_shellescape_changed)
1604                 buffer().markClean();
1605         modulesChanged_ = false;
1606 }
1607
1608
1609 void GuiDocument::slotOK()
1610 {
1611         bool only_shellescape_changed = !nonModuleChanged_ && !modulesChanged_;
1612         bool wasclean = buffer().isClean();
1613         GuiDialog::slotOK();
1614         if (wasclean && only_shellescape_changed)
1615                 buffer().markClean();
1616         modulesChanged_ = false;
1617 }
1618
1619
1620 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
1621 {
1622         if (item == 0)
1623                 return;
1624
1625         string child = fromqstr(item->text(0));
1626         if (child.empty())
1627                 return;
1628
1629         if (std::find(includeonlys_.begin(),
1630                       includeonlys_.end(), child) != includeonlys_.end())
1631                 includeonlys_.remove(child);
1632         else
1633                 includeonlys_.push_back(child);
1634
1635         updateIncludeonlys();
1636         change_adaptor();
1637 }
1638
1639
1640 QString GuiDocument::validateListingsParameters()
1641 {
1642         if (listingsModule->bypassCB->isChecked())
1643                 return QString();
1644         string const package =
1645             lst_packages[listingsModule->packageCO->currentIndex()];
1646         string params = fromqstr(listingsModule->listingsED->toPlainText());
1647         InsetListingsParams lstparams(params);
1648         lstparams.setMinted(package == "Minted");
1649         return toqstr(lstparams.validate());
1650 }
1651
1652
1653 void GuiDocument::setListingsMessage()
1654 {
1655         // FIXME THREAD
1656         static bool isOK = true;
1657         QString msg = validateListingsParameters();
1658         if (msg.isEmpty()) {
1659                 if (isOK)
1660                         return;
1661                 isOK = true;
1662                 // listingsTB->setTextColor("black");
1663                 listingsModule->listingsTB->setPlainText(
1664                         qt_("Input listings parameters below. "
1665                             "Enter ? for a list of parameters."));
1666         } else {
1667                 isOK = false;
1668                 // listingsTB->setTextColor("red");
1669                 listingsModule->listingsTB->setPlainText(msg);
1670         }
1671 }
1672
1673
1674 void GuiDocument::listingsPackageChanged(int index)
1675 {
1676         string const package = lst_packages[index];
1677         if (package == "Minted" && lyxrc.pygmentize_command.empty()) {
1678                 Alert::warning(_("Pygments driver command not found!"),
1679                     _("The driver command necessary to use the minted package\n"
1680                       "(pygmentize) has not been found. Make sure you have\n"
1681                       "the python-pygments module installed or, if the driver\n"
1682                       "is named differently, to add the following line to the\n"
1683                       "document preamble:\n\n"
1684                       "\\AtBeginDocument{\\renewcommand{\\MintedPygmentize}{driver}}\n\n"
1685                       "where 'driver' is name of the driver command."));
1686         }
1687 }
1688
1689
1690 void GuiDocument::setLSpacing(int item)
1691 {
1692         textLayoutModule->lspacingLE->setEnabled(item == 3);
1693 }
1694
1695
1696 void GuiDocument::setIndent(int item)
1697 {
1698         bool const enable = (item == 1);
1699         textLayoutModule->indentLE->setEnabled(enable);
1700         textLayoutModule->indentLengthCO->setEnabled(enable);
1701         textLayoutModule->skipLE->setEnabled(false);
1702         textLayoutModule->skipLengthCO->setEnabled(false);
1703         isValid();
1704 }
1705
1706
1707 void GuiDocument::enableIndent(bool indent)
1708 {
1709         textLayoutModule->skipLE->setEnabled(!indent);
1710         textLayoutModule->skipLengthCO->setEnabled(!indent);
1711         if (indent)
1712                 setIndent(textLayoutModule->indentCO->currentIndex());
1713 }
1714
1715
1716 void GuiDocument::setSkip(int item)
1717 {
1718         bool const enable = (item == 3);
1719         textLayoutModule->skipLE->setEnabled(enable);
1720         textLayoutModule->skipLengthCO->setEnabled(enable);
1721         isValid();
1722 }
1723
1724
1725 void GuiDocument::enableSkip(bool skip)
1726 {
1727         textLayoutModule->indentLE->setEnabled(!skip);
1728         textLayoutModule->indentLengthCO->setEnabled(!skip);
1729         if (skip)
1730                 setSkip(textLayoutModule->skipCO->currentIndex());
1731 }
1732
1733 void GuiDocument::allowMathIndent() {
1734         // only disable when not checked, checked does not always allow enabling
1735         if (!mathsModule->MathIndentCB->isChecked()) {
1736                 mathsModule->MathIndentLE->setEnabled(false);
1737                 mathsModule->MathIndentLengthCO->setEnabled(false);
1738         }
1739         if (mathsModule->MathIndentCB->isChecked()
1740             && mathsModule->MathIndentCO->currentIndex() == 1) {
1741                         mathsModule->MathIndentLE->setEnabled(true);
1742                         mathsModule->MathIndentLengthCO->setEnabled(true);
1743         }
1744         isValid();
1745 }
1746
1747 void GuiDocument::enableMathIndent(int item)
1748 {
1749         bool const enable = (item == 1);
1750         mathsModule->MathIndentLE->setEnabled(enable);
1751         mathsModule->MathIndentLengthCO->setEnabled(enable);
1752         isValid();
1753 }
1754
1755
1756 void GuiDocument::setMargins()
1757 {
1758         bool const extern_geometry =
1759                 documentClass().provides("geometry");
1760         marginsModule->marginCB->setEnabled(!extern_geometry);
1761         if (extern_geometry) {
1762                 marginsModule->marginCB->setChecked(false);
1763                 setCustomMargins(true);
1764         } else {
1765                 marginsModule->marginCB->setChecked(!bp_.use_geometry);
1766                 setCustomMargins(!bp_.use_geometry);
1767         }
1768 }
1769
1770
1771 void GuiDocument::papersizeChanged(int paper_size)
1772 {
1773         setCustomPapersize(paper_size == 1);
1774 }
1775
1776
1777 void GuiDocument::setCustomPapersize(bool custom)
1778 {
1779         pageLayoutModule->paperwidthL->setEnabled(custom);
1780         pageLayoutModule->paperwidthLE->setEnabled(custom);
1781         pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1782         pageLayoutModule->paperheightL->setEnabled(custom);
1783         pageLayoutModule->paperheightLE->setEnabled(custom);
1784         pageLayoutModule->paperheightLE->setFocus();
1785         pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1786 }
1787
1788
1789 void GuiDocument::setColSep()
1790 {
1791         setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1792 }
1793
1794
1795 void GuiDocument::setCustomMargins(bool custom)
1796 {
1797         marginsModule->topL->setEnabled(!custom);
1798         marginsModule->topLE->setEnabled(!custom);
1799         marginsModule->topUnit->setEnabled(!custom);
1800
1801         marginsModule->bottomL->setEnabled(!custom);
1802         marginsModule->bottomLE->setEnabled(!custom);
1803         marginsModule->bottomUnit->setEnabled(!custom);
1804
1805         marginsModule->innerL->setEnabled(!custom);
1806         marginsModule->innerLE->setEnabled(!custom);
1807         marginsModule->innerUnit->setEnabled(!custom);
1808
1809         marginsModule->outerL->setEnabled(!custom);
1810         marginsModule->outerLE->setEnabled(!custom);
1811         marginsModule->outerUnit->setEnabled(!custom);
1812
1813         marginsModule->headheightL->setEnabled(!custom);
1814         marginsModule->headheightLE->setEnabled(!custom);
1815         marginsModule->headheightUnit->setEnabled(!custom);
1816
1817         marginsModule->headsepL->setEnabled(!custom);
1818         marginsModule->headsepLE->setEnabled(!custom);
1819         marginsModule->headsepUnit->setEnabled(!custom);
1820
1821         marginsModule->footskipL->setEnabled(!custom);
1822         marginsModule->footskipLE->setEnabled(!custom);
1823         marginsModule->footskipUnit->setEnabled(!custom);
1824
1825         bool const enableColSep = !custom &&
1826                         textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1827         marginsModule->columnsepL->setEnabled(enableColSep);
1828         marginsModule->columnsepLE->setEnabled(enableColSep);
1829         marginsModule->columnsepUnit->setEnabled(enableColSep);
1830 }
1831
1832
1833 void GuiDocument::changeBackgroundColor()
1834 {
1835         QColor const & newColor = QColorDialog::getColor(
1836                 rgb2qcolor(set_backgroundcolor), asQWidget());
1837         if (!newColor.isValid())
1838                 return;
1839         // set the button color and text
1840         colorModule->backgroundPB->setStyleSheet(
1841                 colorButtonStyleSheet(newColor));
1842         colorModule->backgroundPB->setText(qt_("&Change..."));
1843         // save color
1844         set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
1845         is_backgroundcolor = true;
1846         change_adaptor();
1847 }
1848
1849
1850 void GuiDocument::deleteBackgroundColor()
1851 {
1852         // set the button color back to default by setting an empty StyleSheet
1853         colorModule->backgroundPB->setStyleSheet(QLatin1String(""));
1854         // change button text
1855         colorModule->backgroundPB->setText(qt_("&Default..."));
1856         // save default color (white)
1857         set_backgroundcolor = rgbFromHexName("#ffffff");
1858         is_backgroundcolor = false;
1859         change_adaptor();
1860 }
1861
1862
1863 void GuiDocument::changeFontColor()
1864 {
1865         QColor const & newColor = QColorDialog::getColor(
1866                 rgb2qcolor(set_fontcolor), asQWidget());
1867         if (!newColor.isValid())
1868                 return;
1869         // set the button color and text
1870         colorModule->fontColorPB->setStyleSheet(
1871                 colorButtonStyleSheet(newColor));
1872         colorModule->fontColorPB->setText(qt_("&Change..."));
1873         // save color
1874         set_fontcolor = rgbFromHexName(fromqstr(newColor.name()));
1875         is_fontcolor = true;
1876         change_adaptor();
1877 }
1878
1879
1880 void GuiDocument::deleteFontColor()
1881 {
1882         // set the button color back to default by setting an empty StyleSheet
1883         colorModule->fontColorPB->setStyleSheet(QLatin1String(""));
1884         // change button text
1885         colorModule->fontColorPB->setText(qt_("&Default..."));
1886         // save default color (black)
1887         set_fontcolor = rgbFromHexName("#000000");
1888         is_fontcolor = false;
1889         change_adaptor();
1890 }
1891
1892
1893 void GuiDocument::changeNoteFontColor()
1894 {
1895         QColor const & newColor = QColorDialog::getColor(
1896                 rgb2qcolor(set_notefontcolor), asQWidget());
1897         if (!newColor.isValid())
1898                 return;
1899         // set the button color
1900         colorModule->noteFontColorPB->setStyleSheet(
1901                 colorButtonStyleSheet(newColor));
1902         // save color
1903         set_notefontcolor = rgbFromHexName(fromqstr(newColor.name()));
1904         change_adaptor();
1905 }
1906
1907
1908 void GuiDocument::deleteNoteFontColor()
1909 {
1910         // set the button color back to pref
1911         theApp()->getRgbColor(Color_greyedouttext, set_notefontcolor);
1912         colorModule->noteFontColorPB->setStyleSheet(
1913                 colorButtonStyleSheet(rgb2qcolor(set_notefontcolor)));
1914         change_adaptor();
1915 }
1916
1917
1918 void GuiDocument::changeBoxBackgroundColor()
1919 {
1920         QColor const & newColor = QColorDialog::getColor(
1921                 rgb2qcolor(set_boxbgcolor), asQWidget());
1922         if (!newColor.isValid())
1923                 return;
1924         // set the button color
1925         colorModule->boxBackgroundPB->setStyleSheet(
1926                 colorButtonStyleSheet(newColor));
1927         // save color
1928         set_boxbgcolor = rgbFromHexName(fromqstr(newColor.name()));
1929         change_adaptor();
1930 }
1931
1932
1933 void GuiDocument::deleteBoxBackgroundColor()
1934 {
1935         // set the button color back to pref
1936         theApp()->getRgbColor(Color_shadedbg, set_boxbgcolor);
1937         colorModule->boxBackgroundPB->setStyleSheet(
1938                 colorButtonStyleSheet(rgb2qcolor(set_boxbgcolor)));
1939         change_adaptor();
1940 }
1941
1942
1943 void GuiDocument::updateQuoteStyles(bool const set)
1944 {
1945         Language const * lang = lyx::languages.getLanguage(
1946                 fromqstr(langModule->languageCO->itemData(
1947                         langModule->languageCO->currentIndex()).toString()));
1948
1949         InsetQuotesParams::QuoteStyle def = bp_.getQuoteStyle(lang->quoteStyle());
1950
1951         langModule->quoteStyleCO->clear();
1952
1953         bool has_default = false;
1954         for (int i = 0; i < quoteparams.stylescount(); ++i) {
1955                 InsetQuotesParams::QuoteStyle qs = InsetQuotesParams::QuoteStyle(i);
1956                 if (qs == InsetQuotesParams::DynamicQuotes)
1957                         continue;
1958                 bool const langdef = (qs == def);
1959                 if (langdef) {
1960                         // add the default style on top
1961                         langModule->quoteStyleCO->insertItem(0,
1962                                 toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
1963                         has_default = true;
1964                 }
1965                 else
1966                         langModule->quoteStyleCO->addItem(
1967                                 toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
1968         }
1969         if (set && has_default)
1970                 // (re)set to the default style
1971                 langModule->quoteStyleCO->setCurrentIndex(0);
1972 }
1973
1974
1975 void GuiDocument::languageChanged(int i)
1976 {
1977         // some languages only work with polyglossia
1978         Language const * lang = lyx::languages.getLanguage(
1979                 fromqstr(langModule->languageCO->itemData(i).toString()));
1980         if (lang->babel().empty() && !lang->polyglossia().empty()) {
1981                         // If we force to switch fontspec on, store
1982                         // current state (#8717)
1983                         if (fontModule->osFontsCB->isEnabled())
1984                                 forced_fontspec_activation =
1985                                         !fontModule->osFontsCB->isChecked();
1986                         fontModule->osFontsCB->setChecked(true);
1987                         fontModule->osFontsCB->setEnabled(false);
1988         }
1989         else {
1990                 fontModule->osFontsCB->setEnabled(true);
1991                 // If we have forced to switch fontspec on,
1992                 // restore previous state (#8717)
1993                 if (forced_fontspec_activation)
1994                         fontModule->osFontsCB->setChecked(false);
1995                 forced_fontspec_activation = false;
1996         }
1997
1998         // set appropriate quotation mark style
1999         updateQuoteStyles(true);
2000 }
2001
2002
2003 void GuiDocument::osFontsChanged(bool nontexfonts)
2004 {
2005         bool const tex_fonts = !nontexfonts;
2006         // store current fonts
2007         QString const font_roman = fontModule->fontsRomanCO->itemData(
2008                         fontModule->fontsRomanCO->currentIndex()).toString();
2009         QString const font_sans = fontModule->fontsSansCO->itemData(
2010                         fontModule->fontsSansCO->currentIndex()).toString();
2011         QString const font_typewriter = fontModule->fontsTypewriterCO->itemData(
2012                         fontModule->fontsTypewriterCO->currentIndex()).toString();
2013         QString const font_math = fontModule->fontsMathCO->itemData(
2014                         fontModule->fontsMathCO->currentIndex()).toString();
2015         int const font_sf_scale = fontModule->scaleSansSB->value();
2016         int const font_tt_scale = fontModule->scaleTypewriterSB->value();
2017
2018         updateFontlist();
2019         // store default format
2020         QString const dformat = outputModule->defaultFormatCO->itemData(
2021                 outputModule->defaultFormatCO->currentIndex()).toString();
2022         updateDefaultFormat();
2023         // try to restore default format
2024         int index = outputModule->defaultFormatCO->findData(dformat);
2025         // set to default if format is not found
2026         if (index == -1)
2027                 index = 0;
2028         outputModule->defaultFormatCO->setCurrentIndex(index);
2029
2030         // try to restore fonts which were selected two toggles ago
2031         index = fontModule->fontsRomanCO->findData(fontModule->font_roman);
2032         if (index != -1)
2033                 fontModule->fontsRomanCO->setCurrentIndex(index);
2034         index = fontModule->fontsSansCO->findData(fontModule->font_sans);
2035         if (index != -1)
2036                 fontModule->fontsSansCO->setCurrentIndex(index);
2037         index = fontModule->fontsTypewriterCO->findData(fontModule->font_typewriter);
2038         if (index != -1)
2039                 fontModule->fontsTypewriterCO->setCurrentIndex(index);
2040         index = fontModule->fontsMathCO->findData(fontModule->font_math);
2041         if (index != -1)
2042                 fontModule->fontsMathCO->setCurrentIndex(index);
2043         // save fonts for next next toggle
2044         fontModule->font_roman = font_roman;
2045         fontModule->font_sans = font_sans;
2046         fontModule->font_typewriter = font_typewriter;
2047         fontModule->font_math = font_math;
2048         fontModule->font_sf_scale = font_sf_scale;
2049         fontModule->font_tt_scale = font_tt_scale;
2050
2051         langModule->encodingCO->setEnabled(tex_fonts &&
2052                 !langModule->defaultencodingRB->isChecked());
2053         langModule->defaultencodingRB->setEnabled(tex_fonts);
2054         langModule->otherencodingRB->setEnabled(tex_fonts);
2055
2056         fontModule->fontsDefaultCO->setEnabled(tex_fonts);
2057         fontModule->fontsDefaultLA->setEnabled(tex_fonts);
2058         fontModule->cjkFontLE->setEnabled(tex_fonts);
2059         fontModule->cjkFontLA->setEnabled(tex_fonts);
2060
2061         updateFontOptions();
2062
2063         fontModule->fontencLA->setEnabled(tex_fonts);
2064         fontModule->fontencCO->setEnabled(tex_fonts);
2065         if (!tex_fonts)
2066                 fontModule->fontencLE->setEnabled(false);
2067         else
2068                 fontencChanged(fontModule->fontencCO->currentIndex());
2069 }
2070
2071
2072 void GuiDocument::mathFontChanged(int)
2073 {
2074         updateFontOptions();
2075 }
2076
2077
2078 void GuiDocument::fontOsfToggled(bool state)
2079 {
2080         if (fontModule->osFontsCB->isChecked())
2081                 return;
2082         QString font = fontModule->fontsRomanCO->itemData(
2083                         fontModule->fontsRomanCO->currentIndex()).toString();
2084         if (hasMonolithicExpertSet(font))
2085                 fontModule->fontScCB->setChecked(state);
2086 }
2087
2088
2089 void GuiDocument::fontScToggled(bool state)
2090 {
2091         if (fontModule->osFontsCB->isChecked())
2092                 return;
2093         QString font = fontModule->fontsRomanCO->itemData(
2094                         fontModule->fontsRomanCO->currentIndex()).toString();
2095         if (hasMonolithicExpertSet(font))
2096                 fontModule->fontOsfCB->setChecked(state);
2097 }
2098
2099
2100 void GuiDocument::updateFontOptions()
2101 {
2102         bool const tex_fonts = !fontModule->osFontsCB->isChecked();
2103         QString font;
2104         if (tex_fonts)
2105                 font = fontModule->fontsSansCO->itemData(
2106                                 fontModule->fontsSansCO->currentIndex()).toString();
2107         bool scaleable = providesScale(font);
2108         fontModule->scaleSansSB->setEnabled(scaleable);
2109         fontModule->scaleSansLA->setEnabled(scaleable);
2110         if (tex_fonts)
2111                 font = fontModule->fontsTypewriterCO->itemData(
2112                                 fontModule->fontsTypewriterCO->currentIndex()).toString();
2113         scaleable = providesScale(font);
2114         fontModule->scaleTypewriterSB->setEnabled(scaleable);
2115         fontModule->scaleTypewriterLA->setEnabled(scaleable);
2116         if (tex_fonts)
2117                 font = fontModule->fontsRomanCO->itemData(
2118                                 fontModule->fontsRomanCO->currentIndex()).toString();
2119         fontModule->fontScCB->setEnabled(providesSC(font));
2120         fontModule->fontOsfCB->setEnabled(providesOSF(font));
2121         updateMathFonts(font);
2122 }
2123
2124
2125 void GuiDocument::updateFontsize(string const & items, string const & sel)
2126 {
2127         fontModule->fontsizeCO->clear();
2128         fontModule->fontsizeCO->addItem(qt_("Default"));
2129
2130         for (int n = 0; !token(items,'|',n).empty(); ++n)
2131                 fontModule->fontsizeCO->
2132                         addItem(toqstr(token(items,'|',n)));
2133
2134         for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
2135                 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
2136                         fontModule->fontsizeCO->setCurrentIndex(n);
2137                         break;
2138                 }
2139         }
2140 }
2141
2142
2143 bool GuiDocument::ot1() const
2144 {
2145         QString const fontenc =
2146                 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
2147         return (fontenc == "default"
2148                 || (fontenc == "global" && (lyxrc.fontenc == "default" || lyxrc.fontenc == "OT1"))
2149                 || (fontenc == "custom" && fontModule->fontencLE->text() == "OT1"));
2150 }
2151
2152
2153 bool GuiDocument::completeFontset() const
2154 {
2155         return (fontModule->fontsSansCO->itemData(
2156                         fontModule->fontsSansCO->currentIndex()).toString() == "default"
2157                 && fontModule->fontsSansCO->itemData(
2158                         fontModule->fontsTypewriterCO->currentIndex()).toString() == "default");
2159 }
2160
2161
2162 bool GuiDocument::noMathFont() const
2163 {
2164         return (fontModule->fontsMathCO->itemData(
2165                 fontModule->fontsMathCO->currentIndex()).toString() == "default");
2166 }
2167
2168
2169 void GuiDocument::updateTexFonts()
2170 {
2171         LaTeXFonts::TexFontMap texfontmap = theLaTeXFonts().getLaTeXFonts();
2172
2173         LaTeXFonts::TexFontMap::const_iterator it = texfontmap.begin();
2174         LaTeXFonts::TexFontMap::const_iterator end = texfontmap.end();
2175         for (; it != end; ++it) {
2176                 LaTeXFont lf = it->second;
2177                 if (lf.name().empty()) {
2178                         LYXERR0("Error: Unnamed font: " << it->first);
2179                         continue;
2180                 }
2181                 docstring const family = lf.family();
2182                 docstring guiname = translateIfPossible(lf.guiname());
2183                 if (!lf.available(ot1(), noMathFont()))
2184                         guiname += _(" (not installed)");
2185                 if (family == "rm")
2186                         rmfonts_.insert(toqstr(guiname), toqstr(it->first));
2187                 else if (family == "sf")
2188                         sffonts_.insert(toqstr(guiname), toqstr(it->first));
2189                 else if (family == "tt")
2190                         ttfonts_.insert(toqstr(guiname), toqstr(it->first));
2191                 else if (family == "math")
2192                         mathfonts_.insert(toqstr(guiname), toqstr(it->first));
2193         }
2194 }
2195
2196
2197 void GuiDocument::updateFontlist()
2198 {
2199         fontModule->fontsRomanCO->clear();
2200         fontModule->fontsSansCO->clear();
2201         fontModule->fontsTypewriterCO->clear();
2202         fontModule->fontsMathCO->clear();
2203
2204         // With fontspec (XeTeX, LuaTeX), we have access to all system fonts, but not the LaTeX fonts
2205         if (fontModule->osFontsCB->isChecked()) {
2206                 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
2207                 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
2208                 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
2209                 QString unimath = qt_("Non-TeX Fonts Default");
2210                 if (!LaTeXFeatures::isAvailable("unicode-math"))
2211                         unimath += qt_(" (not available)");
2212                 fontModule->fontsMathCO->addItem(qt_("Class Default (TeX Fonts)"), QString("auto"));
2213                 fontModule->fontsMathCO->addItem(unimath, QString("default"));
2214
2215                 QFontDatabase fontdb;
2216                 QStringList families(fontdb.families());
2217                 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
2218                         fontModule->fontsRomanCO->addItem(*it, *it);
2219                         fontModule->fontsSansCO->addItem(*it, *it);
2220                         fontModule->fontsTypewriterCO->addItem(*it, *it);
2221                 }
2222                 return;
2223         }
2224
2225         if (rmfonts_.empty())
2226                 updateTexFonts();
2227
2228         fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
2229         QMap<QString, QString>::const_iterator rmi = rmfonts_.constBegin();
2230         while (rmi != rmfonts_.constEnd()) {
2231                 fontModule->fontsRomanCO->addItem(rmi.key(), rmi.value());
2232                 ++rmi;
2233         }
2234
2235         fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
2236         QMap<QString, QString>::const_iterator sfi = sffonts_.constBegin();
2237         while (sfi != sffonts_.constEnd()) {
2238                 fontModule->fontsSansCO->addItem(sfi.key(), sfi.value());
2239                 ++sfi;
2240         }
2241
2242         fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
2243         QMap<QString, QString>::const_iterator tti = ttfonts_.constBegin();
2244         while (tti != ttfonts_.constEnd()) {
2245                 fontModule->fontsTypewriterCO->addItem(tti.key(), tti.value());
2246                 ++tti;
2247         }
2248
2249         fontModule->fontsMathCO->addItem(qt_("Automatic"), QString("auto"));
2250         fontModule->fontsMathCO->addItem(qt_("Class Default"), QString("default"));
2251         QMap<QString, QString>::const_iterator mmi = mathfonts_.constBegin();
2252         while (mmi != mathfonts_.constEnd()) {
2253                 fontModule->fontsMathCO->addItem(mmi.key(), mmi.value());
2254                 ++mmi;
2255         }
2256 }
2257
2258
2259 void GuiDocument::fontencChanged(int item)
2260 {
2261         fontModule->fontencLE->setEnabled(
2262                 fontModule->fontencCO->itemData(item).toString() == "custom");
2263         // The availability of TeX fonts depends on the font encoding
2264         updateTexFonts();
2265         updateFontOptions();
2266 }
2267
2268
2269 void GuiDocument::updateMathFonts(QString const & rm)
2270 {
2271         if (fontModule->osFontsCB->isChecked())
2272                 return;
2273         QString const math =
2274                 fontModule->fontsMathCO->itemData(fontModule->fontsMathCO->currentIndex()).toString();
2275         int const i = fontModule->fontsMathCO->findData("default");
2276         if (providesNoMath(rm) && i == -1)
2277                 fontModule->fontsMathCO->insertItem(1, qt_("Class Default"), QString("default"));
2278         else if (!providesNoMath(rm) && i != -1) {
2279                 int const c = fontModule->fontsMathCO->currentIndex();
2280                 fontModule->fontsMathCO->removeItem(i);
2281                 if (c == i)
2282                         fontModule->fontsMathCO->setCurrentIndex(0);
2283         }
2284 }
2285
2286
2287 void GuiDocument::romanChanged(int item)
2288 {
2289         if (fontModule->osFontsCB->isChecked())
2290                 return;
2291         QString const font =
2292                 fontModule->fontsRomanCO->itemData(item).toString();
2293         fontModule->fontScCB->setEnabled(providesSC(font));
2294         fontModule->fontOsfCB->setEnabled(providesOSF(font));
2295         updateMathFonts(font);
2296 }
2297
2298
2299 void GuiDocument::sansChanged(int item)
2300 {
2301         if (fontModule->osFontsCB->isChecked())
2302                 return;
2303         QString const font =
2304                 fontModule->fontsSansCO->itemData(item).toString();
2305         bool scaleable = providesScale(font);
2306         fontModule->scaleSansSB->setEnabled(scaleable);
2307         fontModule->scaleSansLA->setEnabled(scaleable);
2308 }
2309
2310
2311 void GuiDocument::ttChanged(int item)
2312 {
2313         if (fontModule->osFontsCB->isChecked())
2314                 return;
2315         QString const font =
2316                 fontModule->fontsTypewriterCO->itemData(item).toString();
2317         bool scaleable = providesScale(font);
2318         fontModule->scaleTypewriterSB->setEnabled(scaleable);
2319         fontModule->scaleTypewriterLA->setEnabled(scaleable);
2320 }
2321
2322
2323 void GuiDocument::updatePagestyle(string const & items, string const & sel)
2324 {
2325         pagestyles.clear();
2326         pageLayoutModule->pagestyleCO->clear();
2327         pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
2328
2329         for (int n = 0; !token(items, '|', n).empty(); ++n) {
2330                 string style = token(items, '|', n);
2331                 QString style_gui = qt_(style);
2332                 pagestyles.push_back(pair<string, QString>(style, style_gui));
2333                 pageLayoutModule->pagestyleCO->addItem(style_gui);
2334         }
2335
2336         if (sel == "default") {
2337                 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
2338                 return;
2339         }
2340
2341         int nn = 0;
2342
2343         for (size_t i = 0; i < pagestyles.size(); ++i)
2344                 if (pagestyles[i].first == sel)
2345                         nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
2346
2347         if (nn > 0)
2348                 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
2349 }
2350
2351
2352 void GuiDocument::browseLayout()
2353 {
2354         QString const label1 = qt_("Lay&outs");
2355         QString const dir1 = toqstr(lyxrc.document_path);
2356         QStringList const filter(qt_("LyX Layout (*.layout)"));
2357         QString file = browseRelToParent(QString(), bufferFilePath(),
2358                 qt_("Local layout file"), filter, false,
2359                 label1, dir1);
2360
2361         if (!file.endsWith(".layout"))
2362                 return;
2363
2364         FileName layoutFile = support::makeAbsPath(fromqstr(file),
2365                 fromqstr(bufferFilePath()));
2366
2367         int const ret = Alert::prompt(_("Local layout file"),
2368                 _("The layout file you have selected is a local layout\n"
2369                   "file, not one in the system or user directory.\n"
2370                   "Your document will not work with this layout if you\n"
2371                   "move the layout file to a different directory."),
2372                   1, 1, _("&Set Layout"), _("&Cancel"));
2373         if (ret == 1)
2374                 return;
2375
2376         // load the layout file
2377         LayoutFileList & bcl = LayoutFileList::get();
2378         string classname = layoutFile.onlyFileName();
2379         // this will update an existing layout if that layout has been loaded before.
2380         LayoutFileIndex name = support::onlyFileName(bcl.addLocalLayout(
2381                 classname.substr(0, classname.size() - 7),
2382                 layoutFile.onlyPath().absFileName()));
2383
2384         if (name.empty()) {
2385                 Alert::error(_("Error"),
2386                         _("Unable to read local layout file."));
2387                 return;
2388         }
2389
2390         const_cast<Buffer &>(buffer()).setLayoutPos(layoutFile.onlyPath().absFileName());
2391
2392         // do not trigger classChanged if there is no change.
2393         if (latexModule->classCO->currentText() == toqstr(name))
2394                 return;
2395
2396         // add to combo box
2397         bool const avail = latexModule->classCO->set(toqstr(name));
2398         if (!avail) {
2399                 LayoutFile const & tc = bcl[name];
2400                 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
2401                 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
2402                 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
2403                 tooltip += '\n' + qt_("This is a local layout file.");
2404                 latexModule->classCO->addItemSort(toqstr(tc.name()), toqstr(guiname),
2405                                                   toqstr(translateIfPossible(from_utf8(tc.category()))),
2406                                                   tooltip,
2407                                                   true, true, true, true);
2408                 latexModule->classCO->set(toqstr(name));
2409         }
2410
2411         classChanged();
2412 }
2413
2414
2415 void GuiDocument::browseMaster()
2416 {
2417         QString const title = qt_("Select master document");
2418         QString const dir1 = toqstr(lyxrc.document_path);
2419         QString const old = latexModule->childDocLE->text();
2420         QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
2421         QStringList const filter(qt_("LyX Files (*.lyx)"));
2422         QString file = browseRelToSub(old, docpath, title, filter, false,
2423                 qt_("D&ocuments"), toqstr(lyxrc.document_path));
2424
2425         if (!file.isEmpty())
2426                 latexModule->childDocLE->setText(file);
2427 }
2428
2429
2430 void GuiDocument::classChanged_adaptor()
2431 {
2432         const_cast<Buffer &>(buffer()).setLayoutPos(string());
2433         classChanged();
2434 }
2435
2436
2437 void GuiDocument::classChanged()
2438 {
2439         int idx = latexModule->classCO->currentIndex();
2440         if (idx < 0)
2441                 return;
2442         string const classname = fromqstr(latexModule->classCO->getData(idx));
2443
2444         if (applyPB->isEnabled()) {
2445                 int const ret = Alert::prompt(_("Unapplied changes"),
2446                                 _("Some changes in the dialog were not yet applied.\n"
2447                                 "If you do not apply now, they will be lost after this action."),
2448                                 1, 1, _("&Apply"), _("&Dismiss"));
2449                 if (ret == 0)
2450                         applyView();
2451         }
2452
2453         // We load the TextClass as soon as it is selected. This is
2454         // necessary so that other options in the dialog can be updated
2455         // according to the new class. Note, however, that, if you use
2456         // the scroll wheel when sitting on the combo box, we'll load a
2457         // lot of TextClass objects very quickly....
2458         if (!bp_.setBaseClass(classname)) {
2459                 Alert::error(_("Error"), _("Unable to set document class."));
2460                 return;
2461         }
2462         if (lyxrc.auto_reset_options)
2463                 bp_.useClassDefaults();
2464
2465         // With the introduction of modules came a distinction between the base
2466         // class and the document class. The former corresponds to the main layout
2467         // file; the latter is that plus the modules (or the document-specific layout,
2468         // or  whatever else there could be). Our parameters come from the document
2469         // class. So when we set the base class, we also need to recreate the document
2470         // class. Otherwise, we still have the old one.
2471         bp_.makeDocumentClass();
2472         paramsToDialog();
2473 }
2474
2475
2476 void GuiDocument::languagePackageChanged(int i)
2477 {
2478          langModule->languagePackageLE->setEnabled(
2479                 langModule->languagePackageCO->itemData(i).toString() == "custom");
2480 }
2481
2482
2483 void GuiDocument::biblioChanged()
2484 {
2485         biblioChanged_ = true;
2486         change_adaptor();
2487 }
2488
2489
2490 void GuiDocument::checkPossibleCiteEngines()
2491 {
2492         // Check if the class provides a specific engine,
2493         // and if so, enforce this.
2494         string force_engine;
2495         if (documentClass().provides("natbib")
2496             || documentClass().provides("natbib-internal"))
2497                 force_engine = "natbib";
2498         else if (documentClass().provides("jurabib"))
2499                 force_engine = "jurabib";
2500         else if (documentClass().provides("biblatex"))
2501                 force_engine = "biblatex";
2502         else if (documentClass().provides("biblatex-natbib"))
2503                 force_engine = "biblatex-natbib";
2504
2505         if (!force_engine.empty())
2506                 biblioModule->citeEngineCO->setCurrentIndex(
2507                         biblioModule->citeEngineCO->findData(toqstr(force_engine)));
2508         biblioModule->citeEngineCO->setEnabled(force_engine.empty());
2509 }
2510
2511
2512 void GuiDocument::rescanBibFiles()
2513 {
2514         if (isBiblatex())
2515                 rescanTexStyles("bbx cbx");
2516         else
2517                 rescanTexStyles("bst");
2518 }
2519
2520
2521 void GuiDocument::resetDefaultBibfile(string const & which)
2522 {
2523         QString const engine =
2524                 biblioModule->citeEngineCO->itemData(
2525                                 biblioModule->citeEngineCO->currentIndex()).toString();
2526
2527         CiteEngineType const cet =
2528                 CiteEngineType(biblioModule->citeStyleCO->itemData(
2529                                                           biblioModule->citeStyleCO->currentIndex()).toInt());
2530
2531         updateDefaultBiblio(theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet), which);
2532 }
2533
2534
2535 void GuiDocument::resetDefaultBbxBibfile()
2536 {
2537         resetDefaultBibfile("bbx");
2538 }
2539
2540
2541 void GuiDocument::resetDefaultCbxBibfile()
2542 {
2543         resetDefaultBibfile("cbx");
2544 }
2545
2546
2547 void GuiDocument::citeEngineChanged(int n)
2548 {
2549         QString const engine =
2550                 biblioModule->citeEngineCO->itemData(n).toString();
2551
2552         vector<string> const engs =
2553                 theCiteEnginesList[fromqstr(engine)]->getEngineType();
2554
2555         updateCiteStyles(engs);
2556         updateEngineDependends();
2557         resetDefaultBibfile();
2558         biblioChanged();
2559 }
2560
2561
2562 void GuiDocument::updateEngineDependends()
2563 {
2564         bool const biblatex = isBiblatex();
2565
2566         // These are only useful with BibTeX
2567         biblioModule->defaultBiblioCO->setEnabled(!biblatex);
2568         biblioModule->bibtexStyleLA->setEnabled(!biblatex);
2569         biblioModule->resetDefaultBiblioPB->setEnabled(!biblatex);
2570         biblioModule->bibtopicCB->setEnabled(!biblatex);
2571
2572         // These are only useful with Biblatex
2573         biblioModule->biblatexBbxCO->setEnabled(biblatex);
2574         biblioModule->biblatexBbxLA->setEnabled(biblatex);
2575         biblioModule->biblatexCbxCO->setEnabled(biblatex);
2576         biblioModule->biblatexCbxLA->setEnabled(biblatex);
2577         biblioModule->resetBbxPB->setEnabled(biblatex);
2578         biblioModule->resetCbxPB->setEnabled(biblatex);
2579         biblioModule->matchBbxPB->setEnabled(biblatex);
2580
2581         // These are useful with biblatex, jurabib and natbib
2582         QString const engine =
2583                 biblioModule->citeEngineCO->itemData(
2584                                 biblioModule->citeEngineCO->currentIndex()).toString();
2585         LyXCiteEngine const * ce = theCiteEnginesList[fromqstr(engine)];
2586
2587         bool const citepack = ce->requires("biblatex.sty") || ce->requires("jurabib.sty")
2588                         || ce->requires("natbib.sty");
2589         biblioModule->citePackageOptionsLE->setEnabled(citepack);
2590         biblioModule->citePackageOptionsL->setEnabled(citepack);
2591 }
2592
2593
2594 void GuiDocument::citeStyleChanged()
2595 {
2596         QString const engine =
2597                 biblioModule->citeEngineCO->itemData(
2598                                 biblioModule->citeEngineCO->currentIndex()).toString();
2599         QString const currentDef = isBiblatex() ?
2600                 biblioModule->biblatexBbxCO->currentText()
2601                 : biblioModule->defaultBiblioCO->currentText();
2602         if (theCiteEnginesList[fromqstr(engine)]->isDefaultBiblio(fromqstr(currentDef)))
2603                 resetDefaultBibfile();
2604
2605         biblioChanged();
2606 }
2607
2608
2609 void GuiDocument::bibtexChanged(int n)
2610 {
2611         biblioModule->bibtexOptionsLE->setEnabled(
2612                 biblioModule->bibtexCO->itemData(n).toString() != "default");
2613         biblioChanged();
2614 }
2615
2616
2617 void GuiDocument::updateCiteStyles(vector<string> const & engs, CiteEngineType const & sel)
2618 {
2619         biblioModule->citeStyleCO->clear();
2620
2621         vector<string>::const_iterator it  = engs.begin();
2622         vector<string>::const_iterator end = engs.end();
2623         for (; it != end; ++it) {
2624                 if (*it == "default")
2625                         biblioModule->citeStyleCO->addItem(qt_("Basic numerical"),
2626                                                            ENGINE_TYPE_DEFAULT);
2627                 else if (*it == "authoryear")
2628                         biblioModule->citeStyleCO->addItem(qt_("Author-year"),
2629                                                            ENGINE_TYPE_AUTHORYEAR);
2630                 else if (*it == "numerical")
2631                         biblioModule->citeStyleCO->addItem(qt_("Author-number"),
2632                                                            ENGINE_TYPE_NUMERICAL);
2633         }
2634         int i = biblioModule->citeStyleCO->findData(sel);
2635         if (biblioModule->citeStyleCO->findData(sel) == -1)
2636                 i = 0;
2637         biblioModule->citeStyleCO->setCurrentIndex(i);
2638
2639         biblioModule->citationStyleL->setEnabled(engs.size() > 1);
2640         biblioModule->citeStyleCO->setEnabled(engs.size() > 1);
2641 }
2642
2643
2644 void GuiDocument::updateEngineType(string const & items, CiteEngineType const & sel)
2645 {
2646         engine_types_.clear();
2647
2648         int nn = 0;
2649
2650         for (int n = 0; !token(items, '|', n).empty(); ++n) {
2651                 nn += 1;
2652                 string style = token(items, '|', n);
2653                 engine_types_.push_back(style);
2654         }
2655
2656         updateCiteStyles(engine_types_, sel);
2657 }
2658
2659
2660 namespace {
2661         // FIXME unicode
2662         // both of these should take a vector<docstring>
2663
2664         // This is an insanely complicated attempt to make this sort of thing
2665         // work with RTL languages.
2666         docstring formatStrVec(vector<string> const & v, docstring const & s)
2667         {
2668                 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
2669                 if (v.empty())
2670                         return docstring();
2671                 if (v.size() == 1)
2672                         return translateIfPossible(from_utf8(v[0]));
2673                 if (v.size() == 2) {
2674                         docstring retval = _("%1$s and %2$s");
2675                         retval = subst(retval, _("and"), s);
2676                         return bformat(retval, translateIfPossible(from_utf8(v[0])),
2677                                        translateIfPossible(from_utf8(v[1])));
2678                 }
2679                 // The idea here is to format all but the last two items...
2680                 int const vSize = v.size();
2681                 docstring t2 = _("%1$s, %2$s");
2682                 docstring retval = translateIfPossible(from_utf8(v[0]));
2683                 for (int i = 1; i < vSize - 2; ++i)
2684                         retval = bformat(t2, retval, translateIfPossible(from_utf8(v[i])));
2685                 //...and then to  plug them, and the last two, into this schema
2686                 docstring t = _("%1$s, %2$s, and %3$s");
2687                 t = subst(t, _("and"), s);
2688                 return bformat(t, retval, translateIfPossible(from_utf8(v[vSize - 2])),
2689                                translateIfPossible(from_utf8(v[vSize - 1])));
2690         }
2691
2692         vector<string> idsToNames(vector<string> const & idList)
2693         {
2694                 vector<string> retval;
2695                 vector<string>::const_iterator it  = idList.begin();
2696                 vector<string>::const_iterator end = idList.end();
2697                 for (; it != end; ++it) {
2698                         LyXModule const * const mod = theModuleList[*it];
2699                         if (!mod)
2700                                 retval.push_back(to_utf8(bformat(_("%1$s (unavailable)"),
2701                                                 translateIfPossible(from_utf8(*it)))));
2702                         else
2703                                 retval.push_back(mod->getName());
2704                 }
2705                 return retval;
2706         }
2707 } // end anonymous namespace
2708
2709
2710 void GuiDocument::modulesToParams(BufferParams & bp)
2711 {
2712         // update list of loaded modules
2713         bp.clearLayoutModules();
2714         int const srows = modules_sel_model_.rowCount();
2715         for (int i = 0; i < srows; ++i)
2716                 bp.addLayoutModule(modules_sel_model_.getIDString(i));
2717
2718         // update the list of removed modules
2719         bp.clearRemovedModules();
2720         LayoutModuleList const & reqmods = bp.baseClass()->defaultModules();
2721         list<string>::const_iterator rit = reqmods.begin();
2722         list<string>::const_iterator ren = reqmods.end();
2723
2724         // check each of the default modules
2725         for (; rit != ren; ++rit) {
2726                 list<string>::const_iterator mit = bp.getModules().begin();
2727                 list<string>::const_iterator men = bp.getModules().end();
2728                 bool found = false;
2729                 for (; mit != men; ++mit) {
2730                         if (*rit == *mit) {
2731                                 found = true;
2732                                 break;
2733                         }
2734                 }
2735                 if (!found) {
2736                         // the module isn't present so must have been removed by the user
2737                         bp.addRemovedModule(*rit);
2738                 }
2739         }
2740 }
2741
2742 void GuiDocument::modulesChanged()
2743 {
2744         modulesToParams(bp_);
2745
2746         if (applyPB->isEnabled() && (nonModuleChanged_ || shellescapeChanged_)) {
2747                 int const ret = Alert::prompt(_("Unapplied changes"),
2748                                 _("Some changes in the dialog were not yet applied.\n"
2749                                 "If you do not apply now, they will be lost after this action."),
2750                                 1, 1, _("&Apply"), _("&Dismiss"));
2751                 if (ret == 0)
2752                         applyView();
2753         }
2754
2755         modulesChanged_ = true;
2756         bp_.makeDocumentClass();
2757         paramsToDialog();
2758         changed();
2759 }
2760
2761
2762 void GuiDocument::updateModuleInfo()
2763 {
2764         selectionManager->update();
2765
2766         //Module description
2767         bool const focus_on_selected = selectionManager->selectedFocused();
2768         QAbstractItemView * lv;
2769         if (focus_on_selected)
2770                 lv = modulesModule->selectedLV;
2771         else
2772                 lv = modulesModule->availableLV;
2773         if (lv->selectionModel()->selectedIndexes().isEmpty()) {
2774                 modulesModule->infoML->document()->clear();
2775                 return;
2776         }
2777         QModelIndex const & idx = lv->selectionModel()->currentIndex();
2778         GuiIdListModel const & id_model =
2779                         focus_on_selected  ? modules_sel_model_ : modules_av_model_;
2780         string const modName = id_model.getIDString(idx.row());
2781         docstring desc = getModuleDescription(modName);
2782
2783         LayoutModuleList const & provmods = bp_.baseClass()->providedModules();
2784         if (std::find(provmods.begin(), provmods.end(), modName) != provmods.end()) {
2785                 if (!desc.empty())
2786                         desc += "\n";
2787                 desc += _("Module provided by document class.");
2788         }
2789
2790         docstring cat = getModuleCategory(modName);
2791         if (!cat.empty()) {
2792                 if (!desc.empty())
2793                         desc += "\n";
2794                 desc += bformat(_("Category: %1$s."), cat);
2795         }
2796
2797         vector<string> pkglist = getPackageList(modName);
2798         docstring pkgdesc = formatStrVec(pkglist, _("and"));
2799         if (!pkgdesc.empty()) {
2800                 if (!desc.empty())
2801                         desc += "\n";
2802                 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
2803         }
2804
2805         pkglist = getRequiredList(modName);
2806         if (!pkglist.empty()) {
2807                 vector<string> const reqdescs = idsToNames(pkglist);
2808                 pkgdesc = formatStrVec(reqdescs, _("or"));
2809                 if (!desc.empty())
2810                         desc += "\n";
2811                 desc += bformat(_("Modules required: %1$s."), pkgdesc);
2812         }
2813
2814         pkglist = getExcludedList(modName);
2815         if (!pkglist.empty()) {
2816                 vector<string> const reqdescs = idsToNames(pkglist);
2817                 pkgdesc = formatStrVec(reqdescs, _( "and"));
2818                 if (!desc.empty())
2819                         desc += "\n";
2820                 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
2821         }
2822
2823         if (!isModuleAvailable(modName)) {
2824                 if (!desc.empty())
2825                         desc += "\n";
2826                 desc += _("WARNING: Some required packages are unavailable!");
2827         }
2828
2829         modulesModule->infoML->document()->setPlainText(toqstr(desc));
2830 }
2831
2832
2833 void GuiDocument::updateNumbering()
2834 {
2835         DocumentClass const & tclass = documentClass();
2836
2837         numberingModule->tocTW->setUpdatesEnabled(false);
2838         numberingModule->tocTW->clear();
2839
2840         int const depth = numberingModule->depthSL->value();
2841         int const toc = numberingModule->tocSL->value();
2842         QString const no = qt_("No");
2843         QString const yes = qt_("Yes");
2844         QTreeWidgetItem * item = 0;
2845
2846         DocumentClass::const_iterator lit = tclass.begin();
2847         DocumentClass::const_iterator len = tclass.end();
2848         for (; lit != len; ++lit) {
2849                 int const toclevel = lit->toclevel;
2850                 if (toclevel != Layout::NOT_IN_TOC && !lit->counter.empty()) {
2851                         item = new QTreeWidgetItem(numberingModule->tocTW);
2852                         item->setText(0, toqstr(translateIfPossible(lit->name())));
2853                         item->setText(1, (toclevel <= depth) ? yes : no);
2854                         item->setText(2, (toclevel <= toc) ? yes : no);
2855                 }
2856         }
2857
2858         numberingModule->tocTW->setUpdatesEnabled(true);
2859         numberingModule->tocTW->update();
2860 }
2861
2862
2863 void GuiDocument::updateDefaultFormat()
2864 {
2865         if (!bufferview())
2866                 return;
2867         // make a copy in order to consider unapplied changes
2868         BufferParams param_copy = buffer().params();
2869         param_copy.useNonTeXFonts = fontModule->osFontsCB->isChecked();
2870         int const idx = latexModule->classCO->currentIndex();
2871         if (idx >= 0) {
2872                 string const classname = fromqstr(latexModule->classCO->getData(idx));
2873                 param_copy.setBaseClass(classname);
2874                 param_copy.makeDocumentClass(true);
2875         }
2876         outputModule->defaultFormatCO->blockSignals(true);
2877         outputModule->defaultFormatCO->clear();
2878         outputModule->defaultFormatCO->addItem(qt_("Default"),
2879                                 QVariant(QString("default")));
2880         FormatList const & formats =
2881                                 param_copy.exportableFormats(true);
2882         for (Format const * f : formats)
2883                 outputModule->defaultFormatCO->addItem
2884                         (toqstr(translateIfPossible(f->prettyname())),
2885                          QVariant(toqstr(f->name())));
2886         outputModule->defaultFormatCO->blockSignals(false);
2887 }
2888
2889
2890 bool GuiDocument::isChildIncluded(string const & child)
2891 {
2892         if (includeonlys_.empty())
2893                 return false;
2894         return (std::find(includeonlys_.begin(),
2895                           includeonlys_.end(), child) != includeonlys_.end());
2896 }
2897
2898
2899 void GuiDocument::applyView()
2900 {
2901         // preamble
2902         preambleModule->apply(bp_);
2903         localLayout->apply(bp_);
2904
2905         // date
2906         bp_.suppress_date = latexModule->suppressDateCB->isChecked();
2907         bp_.use_refstyle  = latexModule->refstyleCB->isChecked();
2908
2909         // biblio
2910         string const engine =
2911                 fromqstr(biblioModule->citeEngineCO->itemData(
2912                                 biblioModule->citeEngineCO->currentIndex()).toString());
2913         bp_.setCiteEngine(engine);
2914
2915         CiteEngineType const style = CiteEngineType(biblioModule->citeStyleCO->itemData(
2916                 biblioModule->citeStyleCO->currentIndex()).toInt());
2917         if (theCiteEnginesList[engine]->hasEngineType(style))
2918                 bp_.setCiteEngineType(style);
2919         else
2920                 bp_.setCiteEngineType(ENGINE_TYPE_DEFAULT);
2921
2922         bp_.splitbib(biblioModule->bibtopicCB->isChecked());
2923
2924         bp_.multibib = fromqstr(biblioModule->bibunitsCO->itemData(
2925                                 biblioModule->bibunitsCO->currentIndex()).toString());
2926
2927         bp_.setDefaultBiblioStyle(fromqstr(biblioModule->defaultBiblioCO->currentText()));
2928
2929         bp_.biblatex_bibstyle = fromqstr(biblioModule->biblatexBbxCO->currentText());
2930         bp_.biblatex_citestyle = fromqstr(biblioModule->biblatexCbxCO->currentText());
2931         bp_.biblio_opts = fromqstr(biblioModule->citePackageOptionsLE->text());
2932
2933         string const bibtex_command =
2934                 fromqstr(biblioModule->bibtexCO->itemData(
2935                         biblioModule->bibtexCO->currentIndex()).toString());
2936         string const bibtex_options =
2937                 fromqstr(biblioModule->bibtexOptionsLE->text());
2938         if (bibtex_command == "default" || bibtex_options.empty())
2939                 bp_.bibtex_command = bibtex_command;
2940         else
2941                 bp_.bibtex_command = bibtex_command + " " + bibtex_options;
2942
2943         if (biblioChanged_) {
2944                 buffer().invalidateBibinfoCache();
2945                 buffer().removeBiblioTempFiles();
2946         }
2947
2948         // Indices
2949         indicesModule->apply(bp_);
2950
2951         // language & quotes
2952         if (langModule->defaultencodingRB->isChecked()) {
2953                 bp_.inputenc = "auto";
2954         } else {
2955                 int i = langModule->encodingCO->currentIndex();
2956                 if (i == 0)
2957                         bp_.inputenc = "default";
2958                 else {
2959                         QString const enc_gui =
2960                                 langModule->encodingCO->currentText();
2961                         Encodings::const_iterator it = encodings.begin();
2962                         Encodings::const_iterator const end = encodings.end();
2963                         bool found = false;
2964                         for (; it != end; ++it) {
2965                                 if (qt_(it->guiName()) == enc_gui &&
2966                                     !it->unsafe()) {
2967                                         bp_.inputenc = it->name();
2968                                         found = true;
2969                                         break;
2970                                 }
2971                         }
2972                         if (!found) {
2973                                 // should not happen
2974                                 lyxerr << "GuiDocument::apply: Unknown encoding! Resetting to default" << endl;
2975                                 bp_.inputenc = "default";
2976                         }
2977                 }
2978         }
2979
2980         bp_.quotes_style = (InsetQuotesParams::QuoteStyle) langModule->quoteStyleCO->itemData(
2981                 langModule->quoteStyleCO->currentIndex()).toInt();
2982         bp_.dynamic_quotes = langModule->dynamicQuotesCB->isChecked();
2983
2984         QString const langname = langModule->languageCO->itemData(
2985                 langModule->languageCO->currentIndex()).toString();
2986         Language const * newlang = lyx::languages.getLanguage(fromqstr(langname));
2987         Cursor & cur = const_cast<BufferView *>(bufferview())->cursor();
2988         // If current cursor language was the document language, then update it too.
2989         if (cur.current_font.language() == bp_.language) {
2990                 cur.current_font.setLanguage(newlang);
2991                 cur.real_current_font.setLanguage(newlang);
2992         }
2993         bp_.language = newlang;
2994
2995         QString const pack = langModule->languagePackageCO->itemData(
2996                 langModule->languagePackageCO->currentIndex()).toString();
2997         if (pack == "custom")
2998                 bp_.lang_package =
2999                         fromqstr(langModule->languagePackageLE->text());
3000         else
3001                 bp_.lang_package = fromqstr(pack);
3002
3003         //color
3004         bp_.backgroundcolor = set_backgroundcolor;
3005         bp_.isbackgroundcolor = is_backgroundcolor;
3006         bp_.fontcolor = set_fontcolor;
3007         bp_.isfontcolor = is_fontcolor;
3008         bp_.notefontcolor = set_notefontcolor;
3009         bp_.boxbgcolor = set_boxbgcolor;
3010
3011         // numbering
3012         if (bp_.documentClass().hasTocLevels()) {
3013                 bp_.tocdepth = numberingModule->tocSL->value();
3014                 bp_.secnumdepth = numberingModule->depthSL->value();
3015         }
3016
3017         // bullets
3018         bp_.user_defined_bullet(0) = bulletsModule->bullet(0);
3019         bp_.user_defined_bullet(1) = bulletsModule->bullet(1);
3020         bp_.user_defined_bullet(2) = bulletsModule->bullet(2);
3021         bp_.user_defined_bullet(3) = bulletsModule->bullet(3);
3022
3023         // packages
3024         bp_.graphics_driver =
3025                 tex_graphics[latexModule->psdriverCO->currentIndex()];
3026
3027         // text layout
3028         int idx = latexModule->classCO->currentIndex();
3029         if (idx >= 0) {
3030                 string const classname = fromqstr(latexModule->classCO->getData(idx));
3031                 bp_.setBaseClass(classname);
3032         }
3033
3034         // Modules
3035         modulesToParams(bp_);
3036
3037         // Math
3038         map<string, string> const & packages = BufferParams::auto_packages();
3039         for (map<string, string>::const_iterator it = packages.begin();
3040              it != packages.end(); ++it) {
3041                 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
3042                 if (!item)
3043                         continue;
3044                 int row = mathsModule->packagesTW->row(item);
3045
3046                 QRadioButton * rb =
3047                         (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1)->layout()->itemAt(0)->widget();
3048                 if (rb->isChecked()) {
3049                         bp_.use_package(it->first, BufferParams::package_auto);
3050                         continue;
3051                 }
3052                 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2)->layout()->itemAt(0)->widget();
3053                 if (rb->isChecked()) {
3054                         bp_.use_package(it->first, BufferParams::package_on);
3055                         continue;
3056                 }
3057                 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3)->layout()->itemAt(0)->widget();
3058                 if (rb->isChecked())
3059                         bp_.use_package(it->first, BufferParams::package_off);
3060         }
3061         // if math is indented
3062         bp_.is_math_indent = mathsModule->MathIndentCB->isChecked();
3063         if (bp_.is_math_indent) {
3064                 // if formulas are indented
3065                 switch (mathsModule->MathIndentCO->currentIndex()) {
3066                 case 0:
3067                         bp_.setMathIndent(Length());
3068                         break;
3069                 case 1: {
3070                         Length mathindent(widgetsToLength(mathsModule->MathIndentLE,
3071                                                           mathsModule->MathIndentLengthCO));
3072                         bp_.setMathIndent(mathindent);
3073                         break;
3074                 }
3075                 default:
3076                         // this should never happen
3077                         bp_.setMathIndent(Length());
3078                         break;
3079                 }
3080         }
3081         switch (mathsModule->MathNumberingPosCO->currentIndex()) {
3082                 case 0:
3083                         bp_.math_numbering_side = BufferParams::LEFT;
3084                         break;
3085                 case 1:
3086                         bp_.math_numbering_side = BufferParams::DEFAULT;
3087                         break;
3088                 case 2:
3089                         bp_.math_numbering_side = BufferParams::RIGHT;
3090                         break;
3091                 default:
3092                         // this should never happen
3093                         bp_.math_numbering_side = BufferParams::DEFAULT;
3094                         break;
3095         }
3096
3097         // Page Layout
3098         if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
3099                 bp_.pagestyle = "default";
3100         else {
3101                 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
3102                 for (size_t i = 0; i != pagestyles.size(); ++i)
3103                         if (pagestyles[i].second == style_gui)
3104                                 bp_.pagestyle = pagestyles[i].first;
3105         }
3106
3107         // Text Layout
3108         switch (textLayoutModule->lspacingCO->currentIndex()) {
3109         case 0:
3110                 bp_.spacing().set(Spacing::Single);
3111                 break;
3112         case 1:
3113                 bp_.spacing().set(Spacing::Onehalf);
3114                 break;
3115         case 2:
3116                 bp_.spacing().set(Spacing::Double);
3117                 break;
3118         case 3: {
3119                 string s = widgetToDoubleStr(textLayoutModule->lspacingLE);
3120                 if (s.empty())
3121                         bp_.spacing().set(Spacing::Single);
3122                 else
3123                         bp_.spacing().set(Spacing::Other, s);
3124                 break;
3125                 }
3126         }
3127
3128         if (textLayoutModule->twoColumnCB->isChecked())
3129                 bp_.columns = 2;
3130         else
3131                 bp_.columns = 1;
3132
3133         bp_.justification = textLayoutModule->justCB->isChecked();
3134
3135         if (textLayoutModule->indentRB->isChecked()) {
3136                 // if paragraphs are separated by an indentation
3137                 bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
3138                 switch (textLayoutModule->indentCO->currentIndex()) {
3139                 case 0:
3140                         bp_.setParIndent(Length());
3141                         break;
3142                 case 1: {
3143                         Length parindent(widgetsToLength(textLayoutModule->indentLE,
3144                                                          textLayoutModule->indentLengthCO));
3145                         bp_.setParIndent(parindent);
3146                         break;
3147                 }
3148                 default:
3149                         // this should never happen
3150                         bp_.setParIndent(Length());
3151                         break;
3152                 }
3153         } else {
3154                 // if paragraphs are separated by a skip
3155                 bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
3156                 switch (textLayoutModule->skipCO->currentIndex()) {
3157                 case 0:
3158                         bp_.setDefSkip(VSpace(VSpace::SMALLSKIP));
3159                         break;
3160                 case 1:
3161                         bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
3162                         break;
3163                 case 2:
3164                         bp_.setDefSkip(VSpace(VSpace::BIGSKIP));
3165                         break;
3166                 case 3:
3167                         {
3168                         VSpace vs = VSpace(
3169                                 widgetsToLength(textLayoutModule->skipLE,
3170                                 textLayoutModule->skipLengthCO)
3171                                 );
3172                         bp_.setDefSkip(vs);
3173                         break;
3174                         }
3175                 default:
3176                         // this should never happen
3177                         bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
3178                         break;
3179                 }
3180         }
3181
3182         bp_.options =
3183                 fromqstr(latexModule->optionsLE->text());
3184
3185         bp_.use_default_options =
3186                 latexModule->defaultOptionsCB->isChecked();
3187
3188         if (latexModule->childDocGB->isChecked())
3189                 bp_.master =
3190                         fromqstr(latexModule->childDocLE->text());
3191         else
3192                 bp_.master = string();
3193
3194         // Master/Child
3195         bp_.clearIncludedChildren();
3196         if (masterChildModule->includeonlyRB->isChecked()) {
3197                 list<string>::const_iterator it = includeonlys_.begin();
3198                 for (; it != includeonlys_.end() ; ++it) {
3199                         bp_.addIncludedChildren(*it);
3200                 }
3201         }
3202         bp_.maintain_unincluded_children =
3203                 masterChildModule->maintainAuxCB->isChecked();
3204
3205         // Float Placement
3206         bp_.float_placement = floatModule->get();
3207
3208         // Listings
3209         // text should have passed validation
3210         idx = listingsModule->packageCO->currentIndex();
3211         bp_.use_minted = string(lst_packages[idx]) == "Minted";
3212         bp_.listings_params =
3213                 InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
3214
3215         // Formats
3216         bp_.default_output_format = fromqstr(outputModule->defaultFormatCO->itemData(
3217                 outputModule->defaultFormatCO->currentIndex()).toString());
3218
3219         bool const nontexfonts = fontModule->osFontsCB->isChecked();
3220         bp_.useNonTeXFonts = nontexfonts;
3221
3222         bp_.shell_escape = outputModule->shellescapeCB->isChecked();
3223         if (!bp_.shell_escape)
3224             theSession().shellescapeFiles().remove(buffer().absFileName());
3225         else if (!theSession().shellescapeFiles().find(buffer().absFileName()))
3226             theSession().shellescapeFiles().insert(buffer().absFileName());
3227         Buffer & buf = const_cast<Buffer &>(buffer());
3228         buf.params().shell_escape = bp_.shell_escape;
3229
3230         bp_.output_sync = outputModule->outputsyncCB->isChecked();
3231
3232         bp_.output_sync_macro = fromqstr(outputModule->synccustomCB->currentText());
3233
3234         int mathfmt = outputModule->mathoutCB->currentIndex();
3235         if (mathfmt == -1)
3236                 mathfmt = 0;
3237         BufferParams::MathOutput const mo =
3238                 static_cast<BufferParams::MathOutput>(mathfmt);
3239         bp_.html_math_output = mo;
3240         bp_.html_be_strict = outputModule->strictCB->isChecked();
3241         bp_.html_css_as_file = outputModule->cssCB->isChecked();
3242         bp_.html_math_img_scale = outputModule->mathimgSB->value();
3243         bp_.display_pixel_ratio = theGuiApp()->pixelRatio();
3244
3245         bp_.save_transient_properties =
3246                 outputModule->saveTransientPropertiesCB->isChecked();
3247
3248         // fonts
3249         bp_.fonts_roman[nontexfonts] =
3250                 fromqstr(fontModule->fontsRomanCO->
3251                         itemData(fontModule->fontsRomanCO->currentIndex()).toString());
3252         bp_.fonts_roman[!nontexfonts] = fromqstr(fontModule->font_roman);
3253
3254         bp_.fonts_sans[nontexfonts] =
3255                 fromqstr(fontModule->fontsSansCO->
3256                         itemData(fontModule->fontsSansCO->currentIndex()).toString());
3257         bp_.fonts_sans[!nontexfonts] = fromqstr(fontModule->font_sans);
3258
3259         bp_.fonts_typewriter[nontexfonts] =
3260                 fromqstr(fontModule->fontsTypewriterCO->
3261                         itemData(fontModule->fontsTypewriterCO->currentIndex()).toString());
3262         bp_.fonts_typewriter[!nontexfonts] = fromqstr(fontModule->font_typewriter);
3263
3264         bp_.fonts_math[nontexfonts] =
3265                 fromqstr(fontModule->fontsMathCO->
3266                         itemData(fontModule->fontsMathCO->currentIndex()).toString());
3267         bp_.fonts_math[!nontexfonts] = fromqstr(fontModule->font_math);
3268
3269         QString const fontenc =
3270                 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
3271         if (fontenc == "custom")
3272                 bp_.fontenc = fromqstr(fontModule->fontencLE->text());
3273         else
3274                 bp_.fontenc = fromqstr(fontenc);
3275
3276         bp_.fonts_cjk =
3277                 fromqstr(fontModule->cjkFontLE->text());
3278
3279         bp_.use_microtype = fontModule->microtypeCB->isChecked();
3280         bp_.use_dash_ligatures = !fontModule->dashesCB->isChecked();
3281
3282         bp_.fonts_sans_scale[nontexfonts] = fontModule->scaleSansSB->value();
3283         bp_.fonts_sans_scale[!nontexfonts] = fontModule->font_sf_scale;
3284
3285         bp_.fonts_typewriter_scale[nontexfonts] = fontModule->scaleTypewriterSB->value();
3286         bp_.fonts_typewriter_scale[!nontexfonts] = fontModule->font_tt_scale;
3287
3288         bp_.fonts_expert_sc = fontModule->fontScCB->isChecked();
3289
3290         bp_.fonts_old_figures = fontModule->fontOsfCB->isChecked();
3291
3292         if (nontexfonts)
3293                 bp_.fonts_default_family = "default";
3294         else
3295                 bp_.fonts_default_family = GuiDocument::fontfamilies[
3296                         fontModule->fontsDefaultCO->currentIndex()];
3297
3298         if (fontModule->fontsizeCO->currentIndex() == 0)
3299                 bp_.fontsize = "default";
3300         else
3301                 bp_.fontsize =
3302                         fromqstr(fontModule->fontsizeCO->currentText());
3303
3304         // paper
3305         bp_.papersize = PAPER_SIZE(
3306                 pageLayoutModule->papersizeCO->currentIndex());
3307
3308         bp_.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
3309                 pageLayoutModule->paperwidthUnitCO);
3310
3311         bp_.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
3312                 pageLayoutModule->paperheightUnitCO);
3313
3314         if (pageLayoutModule->facingPagesCB->isChecked())
3315                 bp_.sides = TwoSides;
3316         else
3317                 bp_.sides = OneSide;
3318
3319         if (pageLayoutModule->landscapeRB->isChecked())
3320                 bp_.orientation = ORIENTATION_LANDSCAPE;
3321         else
3322                 bp_.orientation = ORIENTATION_PORTRAIT;
3323
3324         // margins
3325         bp_.use_geometry = !marginsModule->marginCB->isChecked();
3326
3327         Ui::MarginsUi const * m = marginsModule;
3328
3329         bp_.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
3330         bp_.topmargin = widgetsToLength(m->topLE, m->topUnit);
3331         bp_.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
3332         bp_.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
3333         bp_.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
3334         bp_.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
3335         bp_.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
3336         bp_.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
3337
3338         // branches
3339         branchesModule->apply(bp_);
3340
3341         // PDF support
3342         PDFOptions & pdf = bp_.pdfoptions();
3343         pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
3344         pdf.title = fromqstr(pdfSupportModule->titleLE->text());
3345         pdf.author = fromqstr(pdfSupportModule->authorLE->text());
3346         pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
3347         pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
3348
3349         pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
3350         pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
3351         pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
3352         pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
3353
3354         pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
3355         pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
3356         pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
3357         pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
3358         pdf.backref =
3359                 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
3360         if (pdfSupportModule->fullscreenCB->isChecked())
3361                 pdf.pagemode = pdf.pagemode_fullscreen;
3362         else
3363                 pdf.pagemode.clear();
3364         pdf.quoted_options = pdf.quoted_options_check(
3365                                 fromqstr(pdfSupportModule->optionsLE->text()));
3366
3367         // reset trackers
3368         nonModuleChanged_ = false;
3369         shellescapeChanged_ = false;
3370 }
3371
3372
3373 void GuiDocument::paramsToDialog()
3374 {
3375         // set the default unit
3376         Length::UNIT const default_unit = Length::defaultUnit();
3377
3378         // preamble
3379         preambleModule->update(bp_, id());
3380         localLayout->update(bp_, id());
3381
3382         // date
3383         latexModule->suppressDateCB->setChecked(bp_.suppress_date);
3384         latexModule->refstyleCB->setChecked(bp_.use_refstyle);
3385
3386         // biblio
3387         string const cite_engine = bp_.citeEngine().list().front();
3388
3389         biblioModule->citeEngineCO->setCurrentIndex(
3390                 biblioModule->citeEngineCO->findData(toqstr(cite_engine)));
3391
3392         updateEngineType(documentClass().opt_enginetype(),
3393                 bp_.citeEngineType());
3394
3395         checkPossibleCiteEngines();
3396
3397         biblioModule->citeStyleCO->setCurrentIndex(
3398                 biblioModule->citeStyleCO->findData(bp_.citeEngineType()));
3399
3400         biblioModule->bibtopicCB->setChecked(bp_.splitbib());
3401
3402         biblioModule->bibunitsCO->clear();
3403         biblioModule->bibunitsCO->addItem(qt_("No"), QString());
3404         if (documentClass().hasLaTeXLayout("part"))
3405                 biblioModule->bibunitsCO->addItem(qt_("per part"), toqstr("part"));
3406         if (documentClass().hasLaTeXLayout("chapter"))
3407                 biblioModule->bibunitsCO->addItem(qt_("per chapter"), toqstr("chapter"));
3408         if (documentClass().hasLaTeXLayout("section"))
3409                 biblioModule->bibunitsCO->addItem(qt_("per section"), toqstr("section"));
3410         if (documentClass().hasLaTeXLayout("subsection"))
3411                 biblioModule->bibunitsCO->addItem(qt_("per subsection"), toqstr("subsection"));
3412         biblioModule->bibunitsCO->addItem(qt_("per child document"), toqstr("child"));
3413
3414         int const mbpos = biblioModule->bibunitsCO->findData(toqstr(bp_.multibib));
3415         if (mbpos != -1)
3416                 biblioModule->bibunitsCO->setCurrentIndex(mbpos);
3417         else
3418                 biblioModule->bibunitsCO->setCurrentIndex(0);
3419
3420         updateEngineDependends();
3421
3422         if (isBiblatex()) {
3423                 updateDefaultBiblio(bp_.biblatex_bibstyle, "bbx");
3424                 updateDefaultBiblio(bp_.biblatex_citestyle, "cbx");
3425         } else
3426                 updateDefaultBiblio(bp_.defaultBiblioStyle());
3427
3428         biblioModule->citePackageOptionsLE->setText(toqstr(bp_.biblio_opts));
3429
3430         string command;
3431         string options =
3432                 split(bp_.bibtex_command, command, ' ');
3433
3434         int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
3435         if (bpos != -1) {
3436                 biblioModule->bibtexCO->setCurrentIndex(bpos);
3437                 biblioModule->bibtexOptionsLE->setText(toqstr(options).trimmed());
3438         } else {
3439                 // We reset to default if we do not know the specified compiler
3440                 // This is for security reasons
3441                 biblioModule->bibtexCO->setCurrentIndex(
3442                         biblioModule->bibtexCO->findData(toqstr("default")));
3443                 biblioModule->bibtexOptionsLE->clear();
3444         }
3445         biblioModule->bibtexOptionsLE->setEnabled(
3446                 biblioModule->bibtexCO->currentIndex() != 0);
3447
3448         biblioChanged_ = false;
3449
3450         // indices
3451         // We may be called when there is no Buffer, e.g., when
3452         // the last view has just been closed.
3453         bool const isReadOnly = isBufferAvailable() ? buffer().isReadonly() : false;
3454         indicesModule->update(bp_, isReadOnly);
3455
3456         // language & quotes
3457         int const pos = langModule->languageCO->findData(toqstr(
3458                 bp_.language->lang()));
3459         langModule->languageCO->setCurrentIndex(pos);
3460
3461         updateQuoteStyles();
3462
3463         langModule->quoteStyleCO->setCurrentIndex(
3464                 langModule->quoteStyleCO->findData(bp_.quotes_style));
3465         langModule->dynamicQuotesCB->setChecked(bp_.dynamic_quotes);
3466
3467         bool default_enc = true;
3468         if (bp_.inputenc != "auto") {
3469                 default_enc = false;
3470                 if (bp_.inputenc == "default") {
3471                         langModule->encodingCO->setCurrentIndex(0);
3472                 } else {
3473                         string enc_gui;
3474                         Encodings::const_iterator it = encodings.begin();
3475                         Encodings::const_iterator const end = encodings.end();
3476                         for (; it != end; ++it) {
3477                                 if (it->name() == bp_.inputenc &&
3478                                     !it->unsafe()) {
3479                                         enc_gui = it->guiName();
3480                                         break;
3481                                 }
3482                         }
3483                         int const i = langModule->encodingCO->findText(
3484                                         qt_(enc_gui));
3485                         if (i >= 0)
3486                                 langModule->encodingCO->setCurrentIndex(i);
3487                         else
3488                                 // unknown encoding. Set to default.
3489                                 default_enc = true;
3490                 }
3491         }
3492         langModule->defaultencodingRB->setChecked(default_enc);
3493         langModule->otherencodingRB->setChecked(!default_enc);
3494
3495         int const p = langModule->languagePackageCO->findData(toqstr(bp_.lang_package));
3496         if (p == -1) {
3497                 langModule->languagePackageCO->setCurrentIndex(
3498                           langModule->languagePackageCO->findData("custom"));
3499                 langModule->languagePackageLE->setText(toqstr(bp_.lang_package));
3500         } else {
3501                 langModule->languagePackageCO->setCurrentIndex(p);
3502                 langModule->languagePackageLE->clear();
3503         }
3504
3505         //color
3506         if (bp_.isfontcolor) {
3507                 colorModule->fontColorPB->setStyleSheet(
3508                         colorButtonStyleSheet(rgb2qcolor(bp_.fontcolor)));
3509         }
3510         set_fontcolor = bp_.fontcolor;
3511         is_fontcolor = bp_.isfontcolor;
3512
3513         colorModule->noteFontColorPB->setStyleSheet(
3514                 colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor)));
3515         set_notefontcolor = bp_.notefontcolor;
3516
3517         if (bp_.isbackgroundcolor) {
3518                 colorModule->backgroundPB->setStyleSheet(
3519                         colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
3520         }
3521         set_backgroundcolor = bp_.backgroundcolor;
3522         is_backgroundcolor = bp_.isbackgroundcolor;
3523
3524         colorModule->boxBackgroundPB->setStyleSheet(
3525                 colorButtonStyleSheet(rgb2qcolor(bp_.boxbgcolor)));
3526         set_boxbgcolor = bp_.boxbgcolor;
3527
3528         // numbering
3529         int const min_toclevel = documentClass().min_toclevel();
3530         int const max_toclevel = documentClass().max_toclevel();
3531         if (documentClass().hasTocLevels()) {
3532                 numberingModule->setEnabled(true);
3533                 numberingModule->depthSL->setMinimum(min_toclevel - 1);
3534                 numberingModule->depthSL->setMaximum(max_toclevel);
3535                 numberingModule->depthSL->setValue(bp_.secnumdepth);
3536                 numberingModule->tocSL->setMaximum(min_toclevel - 1);
3537                 numberingModule->tocSL->setMaximum(max_toclevel);
3538                 numberingModule->tocSL->setValue(bp_.tocdepth);
3539                 updateNumbering();
3540         } else {
3541                 numberingModule->setEnabled(false);
3542                 numberingModule->tocTW->clear();
3543         }
3544
3545         // bullets
3546         bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
3547         bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
3548         bulletsModule->setBullet(2, bp_.user_defined_bullet(2));
3549         bulletsModule->setBullet(3, bp_.user_defined_bullet(3));
3550         bulletsModule->init();
3551
3552         // packages
3553         int nitem = findToken(tex_graphics, bp_.graphics_driver);
3554         if (nitem >= 0)
3555                 latexModule->psdriverCO->setCurrentIndex(nitem);
3556         updateModuleInfo();
3557
3558         // math
3559         mathsModule->MathIndentCB->setChecked(bp_.is_math_indent);
3560         if (bp_.is_math_indent) {
3561                 Length const mathindent = bp_.getMathIndent();
3562                 int indent = 0;
3563                 if (!mathindent.empty()) {
3564                         lengthToWidgets(mathsModule->MathIndentLE,
3565                                         mathsModule->MathIndentLengthCO,
3566                                         mathindent, default_unit);
3567                         indent = 1;
3568                 }
3569                 mathsModule->MathIndentCO->setCurrentIndex(indent);
3570                 enableMathIndent(indent);
3571         }
3572         switch(bp_.math_numbering_side) {
3573         case BufferParams::LEFT:
3574                 mathsModule->MathNumberingPosCO->setCurrentIndex(0);
3575                 break;
3576         case BufferParams::DEFAULT:
3577                 mathsModule->MathNumberingPosCO->setCurrentIndex(1);
3578                 break;
3579         case BufferParams::RIGHT:
3580                 mathsModule->MathNumberingPosCO->setCurrentIndex(2);
3581         }
3582
3583         map<string, string> const & packages = BufferParams::auto_packages();
3584         for (map<string, string>::const_iterator it = packages.begin();
3585              it != packages.end(); ++it) {
3586                 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
3587                 if (!item)
3588                         continue;
3589                 int row = mathsModule->packagesTW->row(item);
3590                 switch (bp_.use_package(it->first)) {
3591                         case BufferParams::package_off: {
3592                                 QRadioButton * rb =
3593                                         (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3)->layout()->itemAt(0)->widget();
3594                                 rb->setChecked(true);
3595                                 break;
3596                         }
3597                         case BufferParams::package_on: {
3598                                 QRadioButton * rb =
3599                                         (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2)->layout()->itemAt(0)->widget();
3600                                 rb->setChecked(true);
3601                                 break;
3602                         }
3603                         case BufferParams::package_auto: {
3604                                 QRadioButton * rb =
3605                                         (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1)->layout()->itemAt(0)->widget();
3606                                 rb->setChecked(true);
3607                                 break;
3608                         }
3609                 }
3610         }
3611
3612         switch (bp_.spacing().getSpace()) {
3613                 case Spacing::Other: nitem = 3; break;
3614                 case Spacing::Double: nitem = 2; break;
3615                 case Spacing::Onehalf: nitem = 1; break;
3616                 case Spacing::Default: case Spacing::Single: nitem = 0; break;
3617         }
3618
3619         // text layout
3620         string const & layoutID = bp_.baseClassID();
3621         setLayoutComboByIDString(layoutID);
3622
3623         updatePagestyle(documentClass().opt_pagestyle(),
3624                                  bp_.pagestyle);
3625
3626         textLayoutModule->lspacingCO->setCurrentIndex(nitem);
3627         if (bp_.spacing().getSpace() == Spacing::Other) {
3628                 doubleToWidget(textLayoutModule->lspacingLE,
3629                         bp_.spacing().getValueAsString());
3630         }
3631         setLSpacing(nitem);
3632
3633         if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
3634                 textLayoutModule->indentRB->setChecked(true);
3635                 string parindent = bp_.getParIndent().asString();
3636                 int indent = 0;
3637                 if (!parindent.empty()) {
3638                         lengthToWidgets(textLayoutModule->indentLE,
3639                                         textLayoutModule->indentLengthCO,
3640                                         parindent, default_unit);
3641                         indent = 1;
3642                 }
3643                 textLayoutModule->indentCO->setCurrentIndex(indent);
3644                 setIndent(indent);
3645         } else {
3646                 textLayoutModule->skipRB->setChecked(true);
3647                 int skip = 0;
3648                 switch (bp_.getDefSkip().kind()) {
3649                 case VSpace::SMALLSKIP:
3650                         skip = 0;
3651                         break;
3652                 case VSpace::MEDSKIP:
3653                         skip = 1;
3654                         break;
3655                 case VSpace::BIGSKIP:
3656                         skip = 2;
3657                         break;
3658                 case VSpace::LENGTH:
3659                         {
3660                         skip = 3;
3661                         string const length = bp_.getDefSkip().asLyXCommand();
3662                         lengthToWidgets(textLayoutModule->skipLE,
3663                                 textLayoutModule->skipLengthCO,
3664                                 length, default_unit);
3665                         break;
3666                         }
3667                 default:
3668                         skip = 0;
3669                         break;
3670                 }
3671                 textLayoutModule->skipCO->setCurrentIndex(skip);
3672                 setSkip(skip);
3673         }
3674
3675         textLayoutModule->twoColumnCB->setChecked(
3676                 bp_.columns == 2);
3677         textLayoutModule->justCB->setChecked(bp_.justification);
3678
3679         if (!bp_.options.empty()) {
3680                 latexModule->optionsLE->setText(
3681                         toqstr(bp_.options));
3682         } else {
3683                 latexModule->optionsLE->setText(QString());
3684         }
3685
3686         // latex
3687         latexModule->defaultOptionsCB->setChecked(
3688                         bp_.use_default_options);
3689         updateSelectedModules();
3690         selectionManager->updateProvidedModules(
3691                         bp_.baseClass()->providedModules());
3692         selectionManager->updateExcludedModules(
3693                         bp_.baseClass()->excludedModules());
3694
3695         if (!documentClass().options().empty()) {
3696                 latexModule->defaultOptionsLE->setText(
3697                         toqstr(documentClass().options()));
3698         } else {
3699                 latexModule->defaultOptionsLE->setText(
3700                         toqstr(_("[No options predefined]")));
3701         }
3702
3703         latexModule->defaultOptionsLE->setEnabled(
3704                 bp_.use_default_options
3705                 && !documentClass().options().empty());
3706
3707         latexModule->defaultOptionsCB->setEnabled(
3708                 !documentClass().options().empty());
3709
3710         if (!bp_.master.empty()) {
3711                 latexModule->childDocGB->setChecked(true);
3712                 latexModule->childDocLE->setText(
3713                         toqstr(bp_.master));
3714         } else {
3715                 latexModule->childDocLE->setText(QString());
3716                 latexModule->childDocGB->setChecked(false);
3717         }
3718
3719         // Master/Child
3720         if (!bufferview() || !buffer().hasChildren()) {
3721                 masterChildModule->childrenTW->clear();
3722                 includeonlys_.clear();
3723                 docPS->showPanel("Child Documents", false);
3724                 if (docPS->isCurrentPanel("Child Documents"))
3725                         docPS->setCurrentPanel("Document Class");
3726         } else {
3727                 docPS->showPanel("Child Documents", true);
3728                 masterChildModule->setEnabled(true);
3729                 includeonlys_ = bp_.getIncludedChildren();
3730                 updateIncludeonlys();
3731         }
3732         masterChildModule->maintainAuxCB->setChecked(
3733                 bp_.maintain_unincluded_children);
3734
3735         // Float Settings
3736         floatModule->set(bp_.float_placement);
3737
3738         // ListingsSettings
3739         // break listings_params to multiple lines
3740         string lstparams =
3741                 InsetListingsParams(bp_.listings_params).separatedParams();
3742         listingsModule->listingsED->setPlainText(toqstr(lstparams));
3743         int nn = findToken(lst_packages, bp_.use_minted ? "Minted" : "Listings");
3744         if (nn >= 0)
3745                 listingsModule->packageCO->setCurrentIndex(nn);
3746
3747
3748         // Fonts
3749         // some languages only work with polyglossia/XeTeX
3750         Language const * lang = lyx::languages.getLanguage(
3751                 fromqstr(langModule->languageCO->itemData(
3752                         langModule->languageCO->currentIndex()).toString()));
3753         bool const need_fontspec =
3754                 lang->babel().empty() && !lang->polyglossia().empty();
3755         bool const os_fonts_available =
3756                 bp_.baseClass()->outputType() == lyx::LATEX
3757                 && LaTeXFeatures::isAvailable("fontspec");
3758         fontModule->osFontsCB->setEnabled(os_fonts_available && !need_fontspec);
3759         fontModule->osFontsCB->setChecked(
3760                 (os_fonts_available && bp_.useNonTeXFonts) || need_fontspec);
3761         updateFontsize(documentClass().opt_fontsize(),
3762                         bp_.fontsize);
3763
3764         QString font = toqstr(bp_.fontsRoman());
3765         int rpos = fontModule->fontsRomanCO->findData(font);
3766         if (rpos == -1) {
3767                 rpos = fontModule->fontsRomanCO->count();
3768                 fontModule->fontsRomanCO->addItem(font + qt_(" (not installed)"), font);
3769         }
3770         fontModule->fontsRomanCO->setCurrentIndex(rpos);
3771         fontModule->font_roman = toqstr(bp_.fonts_roman[!bp_.useNonTeXFonts]);
3772
3773         font = toqstr(bp_.fontsSans());
3774         int spos = fontModule->fontsSansCO->findData(font);
3775         if (spos == -1) {
3776                 spos = fontModule->fontsSansCO->count();
3777                 fontModule->fontsSansCO->addItem(font + qt_(" (not installed)"), font);
3778         }
3779         fontModule->fontsSansCO->setCurrentIndex(spos);
3780         fontModule->font_sans = toqstr(bp_.fonts_sans[!bp_.useNonTeXFonts]);
3781
3782         font = toqstr(bp_.fontsTypewriter());
3783         int tpos = fontModule->fontsTypewriterCO->findData(font);
3784         if (tpos == -1) {
3785                 tpos = fontModule->fontsTypewriterCO->count();
3786                 fontModule->fontsTypewriterCO->addItem(font + qt_(" (not installed)"), font);
3787         }
3788         fontModule->fontsTypewriterCO->setCurrentIndex(tpos);
3789         fontModule->font_typewriter = toqstr(bp_.fonts_typewriter[!bp_.useNonTeXFonts]);
3790
3791         font = toqstr(bp_.fontsMath());
3792         int mpos = fontModule->fontsMathCO->findData(font);
3793         if (mpos == -1) {
3794                 mpos = fontModule->fontsMathCO->count();
3795                 fontModule->fontsMathCO->addItem(font + qt_(" (not installed)"), font);
3796         }
3797         fontModule->fontsMathCO->setCurrentIndex(mpos);
3798         fontModule->font_math = toqstr(bp_.fonts_math[!bp_.useNonTeXFonts]);
3799
3800         if (bp_.useNonTeXFonts && os_fonts_available) {
3801                 fontModule->fontencLA->setEnabled(false);
3802                 fontModule->fontencCO->setEnabled(false);
3803                 fontModule->fontencLE->setEnabled(false);
3804         } else {
3805                 fontModule->fontencLA->setEnabled(true);
3806                 fontModule->fontencCO->setEnabled(true);
3807                 fontModule->fontencLE->setEnabled(true);
3808                 romanChanged(rpos);
3809                 sansChanged(spos);
3810                 ttChanged(tpos);
3811         }
3812
3813         if (!bp_.fonts_cjk.empty())
3814                 fontModule->cjkFontLE->setText(
3815                         toqstr(bp_.fonts_cjk));
3816         else
3817                 fontModule->cjkFontLE->setText(QString());
3818
3819         fontModule->microtypeCB->setChecked(bp_.use_microtype);
3820         fontModule->dashesCB->setChecked(!bp_.use_dash_ligatures);
3821
3822         fontModule->fontScCB->setChecked(bp_.fonts_expert_sc);
3823         fontModule->fontOsfCB->setChecked(bp_.fonts_old_figures);
3824         fontModule->scaleSansSB->setValue(bp_.fontsSansScale());
3825         fontModule->font_sf_scale = bp_.fonts_sans_scale[!bp_.useNonTeXFonts];
3826         fontModule->scaleTypewriterSB->setValue(bp_.fontsTypewriterScale());
3827         fontModule->font_tt_scale = bp_.fonts_typewriter_scale[!bp_.useNonTeXFonts];
3828
3829         nn = findToken(GuiDocument::fontfamilies, bp_.fonts_default_family);
3830         if (nn >= 0)
3831                 fontModule->fontsDefaultCO->setCurrentIndex(nn);
3832
3833         if (bp_.fontenc == "global" || bp_.fontenc == "default") {
3834                 fontModule->fontencCO->setCurrentIndex(
3835                         fontModule->fontencCO->findData(toqstr(bp_.fontenc)));
3836                 fontModule->fontencLE->setEnabled(false);
3837         } else {
3838                 fontModule->fontencCO->setCurrentIndex(1);
3839                 fontModule->fontencLE->setText(toqstr(bp_.fontenc));
3840         }
3841
3842         // Formats
3843         // This must be set _after_ fonts since updateDefaultFormat()
3844         // checks osFontsCB settings.
3845         // update combobox with formats
3846         updateDefaultFormat();
3847         int index = outputModule->defaultFormatCO->findData(toqstr(
3848                 bp_.default_output_format));
3849         // set to default if format is not found
3850         if (index == -1)
3851                 index = 0;
3852         outputModule->defaultFormatCO->setCurrentIndex(index);
3853
3854         outputModule->shellescapeCB->setChecked(bp_.shell_escape);
3855         outputModule->outputsyncCB->setChecked(bp_.output_sync);
3856         outputModule->synccustomCB->setEditText(toqstr(bp_.output_sync_macro));
3857
3858         outputModule->mathimgSB->setValue(bp_.html_math_img_scale);
3859         outputModule->mathoutCB->setCurrentIndex(bp_.html_math_output);
3860         outputModule->strictCB->setChecked(bp_.html_be_strict);
3861         outputModule->cssCB->setChecked(bp_.html_css_as_file);
3862
3863         outputModule->saveTransientPropertiesCB
3864                 ->setChecked(bp_.save_transient_properties);
3865
3866         // paper
3867         bool const extern_geometry =
3868                 documentClass().provides("geometry");
3869         int const psize = bp_.papersize;
3870         pageLayoutModule->papersizeCO->setCurrentIndex(psize);
3871         setCustomPapersize(!extern_geometry && psize == 1);
3872         pageLayoutModule->papersizeCO->setEnabled(!extern_geometry);
3873
3874         bool const landscape =
3875                 bp_.orientation == ORIENTATION_LANDSCAPE;
3876         pageLayoutModule->landscapeRB->setChecked(landscape);
3877         pageLayoutModule->portraitRB->setChecked(!landscape);
3878         pageLayoutModule->landscapeRB->setEnabled(!extern_geometry);
3879         pageLayoutModule->portraitRB->setEnabled(!extern_geometry);
3880
3881         pageLayoutModule->facingPagesCB->setChecked(
3882                 bp_.sides == TwoSides);
3883
3884         lengthToWidgets(pageLayoutModule->paperwidthLE,
3885                 pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, default_unit);
3886         lengthToWidgets(pageLayoutModule->paperheightLE,
3887                 pageLayoutModule->paperheightUnitCO, bp_.paperheight, default_unit);
3888
3889         // margins
3890         Ui::MarginsUi * m = marginsModule;
3891
3892         setMargins();
3893
3894         lengthToWidgets(m->topLE, m->topUnit,
3895                 bp_.topmargin, default_unit);
3896
3897         lengthToWidgets(m->bottomLE, m->bottomUnit,
3898                 bp_.bottommargin, default_unit);
3899
3900         lengthToWidgets(m->innerLE, m->innerUnit,
3901                 bp_.leftmargin, default_unit);
3902
3903         lengthToWidgets(m->outerLE, m->outerUnit,
3904                 bp_.rightmargin, default_unit);
3905
3906         lengthToWidgets(m->headheightLE, m->headheightUnit,
3907                 bp_.headheight, default_unit);
3908
3909         lengthToWidgets(m->headsepLE, m->headsepUnit,
3910                 bp_.headsep, default_unit);
3911
3912         lengthToWidgets(m->footskipLE, m->footskipUnit,
3913                 bp_.footskip, default_unit);
3914
3915         lengthToWidgets(m->columnsepLE, m->columnsepUnit,
3916                 bp_.columnsep, default_unit);
3917
3918         // branches
3919         updateUnknownBranches();
3920         branchesModule->update(bp_);
3921
3922         // PDF support
3923         PDFOptions const & pdf = bp_.pdfoptions();
3924         pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
3925         if (bp_.documentClass().provides("hyperref"))
3926                 pdfSupportModule->use_hyperrefGB->setTitle(qt_("C&ustomize Hyperref Options"));
3927         else
3928                 pdfSupportModule->use_hyperrefGB->setTitle(qt_("&Use Hyperref Support"));
3929         pdfSupportModule->titleLE->setText(toqstr(pdf.title));
3930         pdfSupportModule->authorLE->setText(toqstr(pdf.author));
3931         pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
3932         pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
3933
3934         pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
3935         pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
3936         pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
3937
3938         pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
3939
3940         pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
3941         pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
3942         pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
3943         pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
3944
3945         nn = findToken(backref_opts, pdf.backref);
3946         if (nn >= 0)
3947                 pdfSupportModule->backrefCO->setCurrentIndex(nn);
3948
3949         pdfSupportModule->fullscreenCB->setChecked
3950                 (pdf.pagemode == pdf.pagemode_fullscreen);
3951
3952         pdfSupportModule->optionsLE->setText(
3953                 toqstr(pdf.quoted_options));
3954
3955         // Make sure that the bc is in the INITIAL state
3956         if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3957                 bc().restore();
3958
3959         // clear changed branches cache
3960         changedBranches_.clear();
3961
3962         // reset trackers
3963         nonModuleChanged_ = false;
3964         shellescapeChanged_ = false;
3965 }
3966
3967
3968 void GuiDocument::saveDocDefault()
3969 {
3970         // we have to apply the params first
3971         applyView();
3972         saveAsDefault();
3973 }
3974
3975
3976 void GuiDocument::updateAvailableModules()
3977 {
3978         modules_av_model_.clear();
3979         list<modInfoStruct> modInfoList = getModuleInfo();
3980         // Sort names according to the locale
3981         modInfoList.sort([](modInfoStruct const & a, modInfoStruct const & b) {
3982                         return 0 < b.name.localeAwareCompare(a.name);
3983                 });
3984         int i = 0;
3985         for (modInfoStruct const & m : modInfoList) {
3986                 modules_av_model_.insertRow(i, m.name, m.id, m.description);
3987                 ++i;
3988         }
3989 }
3990
3991
3992 void GuiDocument::updateSelectedModules()
3993 {
3994         modules_sel_model_.clear();
3995         list<modInfoStruct> const selModList = getSelectedModules();
3996         int i = 0;
3997         for (modInfoStruct const & m : selModList) {
3998                 modules_sel_model_.insertRow(i, m.name, m.id, m.description);
3999                 ++i;
4000         }
4001 }
4002
4003
4004 void GuiDocument::updateIncludeonlys()
4005 {
4006         masterChildModule->childrenTW->clear();
4007         QString const no = qt_("No");
4008         QString const yes = qt_("Yes");
4009
4010         if (includeonlys_.empty()) {
4011                 masterChildModule->includeallRB->setChecked(true);
4012                 masterChildModule->childrenTW->setEnabled(false);
4013                 masterChildModule->maintainAuxCB->setEnabled(false);
4014         } else {
4015                 masterChildModule->includeonlyRB->setChecked(true);
4016                 masterChildModule->childrenTW->setEnabled(true);
4017                 masterChildModule->maintainAuxCB->setEnabled(true);
4018         }
4019         ListOfBuffers children = buffer().getChildren();
4020         ListOfBuffers::const_iterator it  = children.begin();
4021         ListOfBuffers::const_iterator end = children.end();
4022         bool has_unincluded = false;
4023         bool all_unincluded = true;
4024         for (; it != end; ++it) {
4025                 QTreeWidgetItem * item = new QTreeWidgetItem(masterChildModule->childrenTW);
4026                 // FIXME Unicode
4027                 string const name =
4028                         to_utf8(makeRelPath(from_utf8((*it)->fileName().absFileName()),
4029                                                         from_utf8(buffer().filePath())));
4030                 item->setText(0, toqstr(name));
4031                 item->setText(1, isChildIncluded(name) ? yes : no);
4032                 if (!isChildIncluded(name))
4033                         has_unincluded = true;
4034                 else
4035                         all_unincluded = false;
4036         }
4037         // Both if all childs are included and if none is included
4038         // is equal to "include all" (i.e., omit \includeonly).
4039         // Thus, reset the GUI.
4040         if (!has_unincluded || all_unincluded) {
4041                 masterChildModule->includeallRB->setChecked(true);
4042                 masterChildModule->childrenTW->setEnabled(false);
4043                 includeonlys_.clear();
4044         }
4045         // If all are included, we need to update again.
4046         if (!has_unincluded)
4047                 updateIncludeonlys();
4048 }
4049
4050
4051 bool GuiDocument::isBiblatex() const
4052 {
4053         QString const engine =
4054                 biblioModule->citeEngineCO->itemData(
4055                                 biblioModule->citeEngineCO->currentIndex()).toString();
4056
4057         // this can happen if the cite engine is unknown, which can happen
4058         // if one is using a file that came from someone else, etc. in that
4059         // case, we crash if we proceed.
4060         if (engine.isEmpty())
4061             return false;
4062
4063         return theCiteEnginesList[fromqstr(engine)]->getCiteFramework() == "biblatex";
4064 }
4065
4066
4067 void GuiDocument::updateDefaultBiblio(string const & style,
4068                                       string const & which)
4069 {
4070         QString const bibstyle = toqstr(style);
4071         biblioModule->defaultBiblioCO->clear();
4072
4073         int item_nr = -1;
4074
4075         if (isBiblatex()) {
4076                 if (which != "cbx") {
4077                         // First the bbx styles
4078                         biblioModule->biblatexBbxCO->clear();
4079                         QStringList str = texFileList("bbxFiles.lst");
4080                         // test whether we have a valid list, otherwise run rescan
4081                         if (str.isEmpty()) {
4082                                 rescanTexStyles("bbx");
4083                                 str = texFileList("bbxFiles.lst");
4084                         }
4085                         for (int i = 0; i != str.size(); ++i)
4086                                 str[i] = onlyFileName(str[i]);
4087                         // sort on filename only (no path)
4088                         str.sort();
4089
4090                         for (int i = 0; i != str.count(); ++i) {
4091                                 QString item = changeExtension(str[i], "");
4092                                 if (item == bibstyle)
4093                                         item_nr = i;
4094                                 biblioModule->biblatexBbxCO->addItem(item);
4095                         }
4096
4097                         if (item_nr == -1 && !bibstyle.isEmpty()) {
4098                                 biblioModule->biblatexBbxCO->addItem(bibstyle);
4099                                 item_nr = biblioModule->biblatexBbxCO->count() - 1;
4100                         }
4101
4102                         if (item_nr != -1)
4103                                 biblioModule->biblatexBbxCO->setCurrentIndex(item_nr);
4104                         else
4105                                 biblioModule->biblatexBbxCO->clearEditText();
4106                 }
4107
4108                 if (which != "bbx") {
4109                         // now the cbx styles
4110                         biblioModule->biblatexCbxCO->clear();
4111                         QStringList str = texFileList("cbxFiles.lst");
4112                         // test whether we have a valid list, otherwise run rescan
4113                         if (str.isEmpty()) {
4114                                 rescanTexStyles("cbx");
4115                                 str = texFileList("cbxFiles.lst");
4116                         }
4117                         for (int i = 0; i != str.size(); ++i)
4118                                 str[i] = onlyFileName(str[i]);
4119                         // sort on filename only (no path)
4120                         str.sort();
4121
4122                         for (int i = 0; i != str.count(); ++i) {
4123                                 QString item = changeExtension(str[i], "");
4124                                 if (item == bibstyle)
4125                                         item_nr = i;
4126                                 biblioModule->biblatexCbxCO->addItem(item);
4127                         }
4128
4129                         if (item_nr == -1 && !bibstyle.isEmpty()) {
4130                                 biblioModule->biblatexCbxCO->addItem(bibstyle);
4131                                 item_nr = biblioModule->biblatexCbxCO->count() - 1;
4132                         }
4133
4134                         if (item_nr != -1)
4135                                 biblioModule->biblatexCbxCO->setCurrentIndex(item_nr);
4136                         else
4137                                 biblioModule->biblatexCbxCO->clearEditText();
4138                 }
4139         } else {// BibTeX
4140                 biblioModule->biblatexBbxCO->clear();
4141                 biblioModule->biblatexCbxCO->clear();
4142                 QStringList str = texFileList("bstFiles.lst");
4143                 // test whether we have a valid list, otherwise run rescan
4144                 if (str.isEmpty()) {
4145                         rescanTexStyles("bst");
4146                         str = texFileList("bstFiles.lst");
4147                 }
4148                 for (int i = 0; i != str.size(); ++i)
4149                         str[i] = onlyFileName(str[i]);
4150                 // sort on filename only (no path)
4151                 str.sort();
4152
4153                 for (int i = 0; i != str.count(); ++i) {
4154                         QString item = changeExtension(str[i], "");
4155                         if (item == bibstyle)
4156                                 item_nr = i;
4157                         biblioModule->defaultBiblioCO->addItem(item);
4158                 }
4159
4160                 if (item_nr == -1 && !bibstyle.isEmpty()) {
4161                         biblioModule->defaultBiblioCO->addItem(bibstyle);
4162                         item_nr = biblioModule->defaultBiblioCO->count() - 1;
4163                 }
4164
4165                 if (item_nr != -1)
4166                         biblioModule->defaultBiblioCO->setCurrentIndex(item_nr);
4167                 else
4168                         biblioModule->defaultBiblioCO->clearEditText();
4169         }
4170
4171         updateResetDefaultBiblio();
4172 }
4173
4174
4175 void GuiDocument::updateResetDefaultBiblio()
4176 {
4177         QString const engine =
4178                 biblioModule->citeEngineCO->itemData(
4179                                 biblioModule->citeEngineCO->currentIndex()).toString();
4180         CiteEngineType const cet =
4181                 CiteEngineType(biblioModule->citeStyleCO->itemData(
4182                                                           biblioModule->citeStyleCO->currentIndex()).toInt());
4183
4184         string const defbib = theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet);
4185         if (isBiblatex()) {
4186                 QString const bbx = biblioModule->biblatexBbxCO->currentText();
4187                 QString const cbx = biblioModule->biblatexCbxCO->currentText();
4188                 biblioModule->resetCbxPB->setEnabled(defbib != fromqstr(cbx));
4189                 biblioModule->resetBbxPB->setEnabled(defbib != fromqstr(bbx));
4190                 biblioModule->matchBbxPB->setEnabled(bbx != cbx && !cbx.isEmpty()
4191                         && biblioModule->biblatexBbxCO->findText(cbx) != -1);
4192         } else
4193                 biblioModule->resetDefaultBiblioPB->setEnabled(
4194                         defbib != fromqstr(biblioModule->defaultBiblioCO->currentText()));
4195 }
4196
4197
4198 void GuiDocument::matchBiblatexStyles()
4199 {
4200         updateDefaultBiblio(fromqstr(biblioModule->biblatexCbxCO->currentText()), "bbx");
4201         biblioChanged();
4202 }
4203
4204
4205 void GuiDocument::updateContents()
4206 {
4207         // Nothing to do here as the document settings is not cursor dependant.
4208         return;
4209 }
4210
4211
4212 void GuiDocument::useClassDefaults()
4213 {
4214         if (applyPB->isEnabled()) {
4215                 int const ret = Alert::prompt(_("Unapplied changes"),
4216                                 _("Some changes in the dialog were not yet applied.\n"
4217                                   "If you do not apply now, they will be lost after this action."),
4218                                 1, 1, _("&Apply"), _("&Dismiss"));
4219                 if (ret == 0)
4220                         applyView();
4221         }
4222
4223         int idx = latexModule->classCO->currentIndex();
4224         string const classname = fromqstr(latexModule->classCO->getData(idx));
4225         if (!bp_.setBaseClass(classname)) {
4226                 Alert::error(_("Error"), _("Unable to set document class."));
4227                 return;
4228         }
4229         bp_.useClassDefaults();
4230         paramsToDialog();
4231         changed();
4232 }
4233
4234
4235 void GuiDocument::setLayoutComboByIDString(string const & idString)
4236 {
4237         if (!latexModule->classCO->set(toqstr(idString)))
4238                 Alert::warning(_("Can't set layout!"),
4239                         bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
4240 }
4241
4242
4243 bool GuiDocument::isValid()
4244 {
4245         return
4246                 validateListingsParameters().isEmpty() &&
4247                 localLayout->isValid() &&
4248                 (
4249                         // if we're asking for skips between paragraphs
4250                         !textLayoutModule->skipRB->isChecked() ||
4251                         // then either we haven't chosen custom
4252                         textLayoutModule->skipCO->currentIndex() != 3 ||
4253                         // or else a length has been given
4254                         !textLayoutModule->skipLE->text().isEmpty()
4255                 ) &&
4256                 (
4257                         // if we're asking for indentation
4258                         !textLayoutModule->indentRB->isChecked() ||
4259                         // then either we haven't chosen custom
4260                         textLayoutModule->indentCO->currentIndex() != 1 ||
4261                         // or else a length has been given
4262                         !textLayoutModule->indentLE->text().isEmpty()
4263                 ) &&
4264                 (
4265                         // if we're asking for math indentation
4266                         !mathsModule->MathIndentCB->isChecked() ||
4267                         // then either we haven't chosen custom
4268                         mathsModule->MathIndentCO->currentIndex() != 1 ||
4269                         // or else a length has been given
4270                         !mathsModule->MathIndentLE->text().isEmpty()
4271                 );
4272 }
4273
4274
4275 char const * const GuiDocument::fontfamilies[5] = {
4276         "default", "rmdefault", "sfdefault", "ttdefault", ""
4277 };
4278
4279
4280 char const * GuiDocument::fontfamilies_gui[5] = {
4281         N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
4282 };
4283
4284
4285 bool GuiDocument::initialiseParams(string const &)
4286 {
4287         BufferView const * view = bufferview();
4288         if (!view) {
4289                 bp_ = BufferParams();
4290                 paramsToDialog();
4291                 return true;
4292         }
4293         bp_ = view->buffer().params();
4294         loadModuleInfo();
4295         updateAvailableModules();
4296         //FIXME It'd be nice to make sure here that the selected
4297         //modules are consistent: That required modules are actually
4298         //selected, and that we don't have conflicts. If so, we could
4299         //at least pop up a warning.
4300         paramsToDialog();
4301         return true;
4302 }
4303
4304
4305 void GuiDocument::clearParams()
4306 {
4307         bp_ = BufferParams();
4308 }
4309
4310
4311 BufferId GuiDocument::id() const
4312 {
4313         BufferView const * const view = bufferview();
4314         return view? &view->buffer() : 0;
4315 }
4316
4317
4318 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
4319 {
4320         return moduleNames_;
4321 }
4322
4323
4324 list<GuiDocument::modInfoStruct> const
4325 GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
4326 {
4327         list<modInfoStruct> mInfo;
4328         for (string const & name : mods) {
4329                 modInfoStruct m;
4330                 LyXModule const * const mod = theModuleList[name];
4331                 if (mod)
4332                         m = modInfo(*mod);
4333                 else {
4334                         m.id = name;
4335                         m.name = toqstr(name + " (") + qt_("Not Found") + toqstr(")");
4336                 }
4337                 mInfo.push_back(m);
4338         }
4339         return mInfo;
4340 }
4341
4342
4343 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
4344 {
4345         return makeModuleInfo(params().getModules());
4346 }
4347
4348
4349 list<GuiDocument::modInfoStruct> const GuiDocument::getProvidedModules()
4350 {
4351         return makeModuleInfo(params().baseClass()->providedModules());
4352 }
4353
4354
4355 DocumentClass const & GuiDocument::documentClass() const
4356 {
4357         return bp_.documentClass();
4358 }
4359
4360
4361 static void dispatch_bufferparams(Dialog const & dialog,
4362         BufferParams const & bp, FuncCode lfun, Buffer const * buf)
4363 {
4364         ostringstream ss;
4365         ss << "\\begin_header\n";
4366         bp.writeFile(ss, buf);
4367         ss << "\\end_header\n";
4368         dialog.dispatch(FuncRequest(lfun, ss.str()));
4369 }
4370
4371
4372 void GuiDocument::dispatchParams()
4373 {
4374         // We need a non-const buffer object.
4375         Buffer & buf = const_cast<BufferView *>(bufferview())->buffer();
4376         // There may be several undo records; group them (bug #8998)
4377         // This handles undo groups automagically
4378         UndoGroupHelper ugh(&buf);
4379
4380         // This must come first so that a language change is correctly noticed
4381         setLanguage();
4382
4383         // Apply the BufferParams. Note that this will set the base class
4384         // and then update the buffer's layout.
4385         dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY, &buffer());
4386
4387         if (!params().master.empty()) {
4388                 FileName const master_file = support::makeAbsPath(params().master,
4389                            support::onlyPath(buffer().absFileName()));
4390                 if (isLyXFileName(master_file.absFileName())) {
4391                         Buffer * master = checkAndLoadLyXFile(master_file);
4392                         if (master) {
4393                                 if (master->isChild(const_cast<Buffer *>(&buffer())))
4394                                         const_cast<Buffer &>(buffer()).setParent(master);
4395                                 else
4396                                         Alert::warning(_("Assigned master does not include this file"),
4397                                                 bformat(_("You must include this file in the document\n"
4398                                                           "'%1$s' in order to use the master document\n"
4399                                                           "feature."), from_utf8(params().master)));
4400                         } else
4401                                 Alert::warning(_("Could not load master"),
4402                                                 bformat(_("The master document '%1$s'\n"
4403                                                            "could not be loaded."),
4404                                                            from_utf8(params().master)));
4405                 }
4406         }
4407
4408         // Generate the colours requested by each new branch.
4409         BranchList & branchlist = params().branchlist();
4410         if (!branchlist.empty()) {
4411                 BranchList::const_iterator it = branchlist.begin();
4412                 BranchList::const_iterator const end = branchlist.end();
4413                 for (; it != end; ++it) {
4414                         docstring const & current_branch = it->branch();
4415                         Branch const * branch = branchlist.find(current_branch);
4416                         string const x11hexname = X11hexname(branch->color());
4417                         // display the new color
4418                         docstring const str = current_branch + ' ' + from_ascii(x11hexname);
4419                         dispatch(FuncRequest(LFUN_SET_COLOR, str));
4420                 }
4421         }
4422         // rename branches in the document
4423         executeBranchRenaming();
4424         // and clear changed branches cache
4425         changedBranches_.clear();
4426
4427         // Generate the colours requested by indices.
4428         IndicesList & indiceslist = params().indiceslist();
4429         if (!indiceslist.empty()) {
4430                 IndicesList::const_iterator it = indiceslist.begin();
4431                 IndicesList::const_iterator const end = indiceslist.end();
4432                 for (; it != end; ++it) {
4433                         docstring const & current_index = it->shortcut();
4434                         Index const * index = indiceslist.findShortcut(current_index);
4435                         string const x11hexname = X11hexname(index->color());
4436                         // display the new color
4437                         docstring const str = current_index + ' ' + from_ascii(x11hexname);
4438                         dispatch(FuncRequest(LFUN_SET_COLOR, str));
4439                 }
4440         }
4441         // FIXME LFUN
4442         // If we used an LFUN, we would not need these two lines:
4443         BufferView * bv = const_cast<BufferView *>(bufferview());
4444         bv->processUpdateFlags(Update::Force | Update::FitCursor);
4445 }
4446
4447
4448 void GuiDocument::setLanguage() const
4449 {
4450         Language const * const newL = bp_.language;
4451         if (buffer().params().language == newL)
4452                 return;
4453
4454         string const & lang_name = newL->lang();
4455         dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
4456 }
4457
4458
4459 void GuiDocument::saveAsDefault() const
4460 {
4461         dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT, &buffer());
4462 }
4463
4464
4465 bool GuiDocument::providesOSF(QString const & font) const
4466 {
4467         if (fontModule->osFontsCB->isChecked())
4468                 // FIXME: we should check if the fonts really
4469                 // have OSF support. But how?
4470                 return true;
4471         return theLaTeXFonts().getLaTeXFont(
4472                                 qstring_to_ucs4(font)).providesOSF(ot1(),
4473                                                                    completeFontset(),
4474                                                                    noMathFont());
4475 }
4476
4477
4478 bool GuiDocument::providesSC(QString const & font) const
4479 {
4480         if (fontModule->osFontsCB->isChecked())
4481                 return false;
4482         return theLaTeXFonts().getLaTeXFont(
4483                                 qstring_to_ucs4(font)).providesSC(ot1(),
4484                                                                   completeFontset(),
4485                                                                   noMathFont());
4486 }
4487
4488
4489 bool GuiDocument::providesScale(QString const & font) const
4490 {
4491         if (fontModule->osFontsCB->isChecked())
4492                 return true;
4493         return theLaTeXFonts().getLaTeXFont(
4494                                 qstring_to_ucs4(font)).providesScale(ot1(),
4495                                                                      completeFontset(),
4496                                                                      noMathFont());
4497 }
4498
4499
4500 bool GuiDocument::providesNoMath(QString const & font) const
4501 {
4502         if (fontModule->osFontsCB->isChecked())
4503                 return false;
4504         return theLaTeXFonts().getLaTeXFont(
4505                                 qstring_to_ucs4(font)).providesNoMath(ot1(),
4506                                                                       completeFontset());
4507 }
4508
4509
4510 bool GuiDocument::hasMonolithicExpertSet(QString const & font) const
4511 {
4512         if (fontModule->osFontsCB->isChecked())
4513                 return false;
4514         return theLaTeXFonts().getLaTeXFont(
4515                                 qstring_to_ucs4(font)).hasMonolithicExpertSet(ot1(),
4516                                                                               completeFontset(),
4517                                                                               noMathFont());
4518 }
4519
4520
4521 //static
4522 GuiDocument::modInfoStruct GuiDocument::modInfo(LyXModule const & mod)
4523 {
4524         // FIXME Unicode: docstrings would be better for these parameters but this
4525         // change requires a lot of others
4526         modInfoStruct m;
4527         m.id = mod.getID();
4528         m.name = toqstr(translateIfPossible(from_utf8(mod.getName())));
4529         QString desc = toqstr(translateIfPossible(from_utf8(mod.getDescription())));
4530         // Find the first sentence of the description
4531         QTextBoundaryFinder bf(QTextBoundaryFinder::Sentence, desc);
4532         int pos = bf.toNextBoundary();
4533         if (pos > 0)
4534                 desc.truncate(pos);
4535         QString modulename = QString(qt_("(Module name: %1)")).arg(toqstr(m.id));
4536         // Tooltip is the desc followed by the module name
4537         m.description = QString("%1<i>%2</i>")
4538                 .arg(desc.isEmpty() ? QString() : QString("<p>%1</p>").arg(desc),
4539                      modulename);
4540         return m;
4541 }
4542
4543
4544 void GuiDocument::loadModuleInfo()
4545 {
4546         moduleNames_.clear();
4547         for (LyXModule const & mod : theModuleList)
4548                 if (mod.category().substr(0, 8) != "Citation")
4549                         moduleNames_.push_back(modInfo(mod));
4550 }
4551
4552
4553 void GuiDocument::updateUnknownBranches()
4554 {
4555         if (!bufferview())
4556                 return;
4557         list<docstring> used_branches;
4558         buffer().getUsedBranches(used_branches);
4559         list<docstring>::const_iterator it = used_branches.begin();
4560         QStringList unknown_branches;
4561         for (; it != used_branches.end() ; ++it) {
4562                 if (!buffer().params().branchlist().find(*it))
4563                         unknown_branches.append(toqstr(*it));
4564         }
4565         branchesModule->setUnknownBranches(unknown_branches);
4566 }
4567
4568
4569 void GuiDocument::branchesRename(docstring const & oldname, docstring const & newname)
4570 {
4571         map<docstring, docstring>::iterator it = changedBranches_.begin();
4572         for (; it != changedBranches_.end() ; ++it) {
4573                 if (it->second == oldname) {
4574                         // branch has already been renamed
4575                         it->second = newname;
4576                         return;
4577                 }
4578         }
4579         // store new name
4580         changedBranches_[oldname] = newname;
4581 }
4582
4583
4584 void GuiDocument::executeBranchRenaming() const
4585 {
4586         map<docstring, docstring>::const_iterator it = changedBranches_.begin();
4587         for (; it != changedBranches_.end() ; ++it) {
4588                 docstring const arg = '"' + it->first + '"' + " " + '"' + it->second + '"';
4589                 dispatch(FuncRequest(LFUN_BRANCHES_RENAME, arg));
4590         }
4591 }
4592
4593
4594 void GuiDocument::allPackagesAuto()
4595 {
4596         allPackages(1);
4597 }
4598
4599
4600 void GuiDocument::allPackagesAlways()
4601 {
4602         allPackages(2);
4603 }
4604
4605
4606 void GuiDocument::allPackagesNot()
4607 {
4608         allPackages(3);
4609 }
4610
4611
4612 void GuiDocument::allPackages(int col)
4613 {
4614         for (int row = 0; row < mathsModule->packagesTW->rowCount(); ++row) {
4615                 QRadioButton * rb =
4616                         (QRadioButton*)mathsModule->packagesTW->cellWidget(row, col)->layout()->itemAt(0)->widget();
4617                 rb->setChecked(true);
4618         }
4619 }
4620
4621
4622 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
4623
4624
4625 } // namespace frontend
4626 } // namespace lyx
4627
4628 #include "moc_GuiDocument.cpp"