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