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