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