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