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