]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiDocument.cpp
PrefLanguageUi.ui: this string was forgotten in r39449
[lyx.git] / src / frontends / qt4 / GuiDocument.cpp
index 3fa13ebc3adb2edf715d8bbd7178187c3e2462b0..31d2c14b7a8c54a859c39df4e44d068a689c1af5 100644 (file)
@@ -537,6 +537,7 @@ LocalLayout::LocalLayout() : current_id_(0), is_valid_(false)
 {
        connect(locallayoutTE, SIGNAL(textChanged()), this, SLOT(textChanged()));
        connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
+       connect(convertPB, SIGNAL(clicked()), this, SLOT(convertPressed()));
 }
 
 
@@ -567,8 +568,30 @@ void LocalLayout::textChanged()
        static const QString unknown = qt_("Press button to check validity...");
 
        is_valid_ = false;
-       infoLB->setText(unknown);
+       validLB->setText(unknown);
        validatePB->setEnabled(true);
+       convertPB->setEnabled(false);
+       changed();
+}
+
+
+void LocalLayout::convert() {
+       string const layout =
+               fromqstr(locallayoutTE->document()->toPlainText().trimmed());
+       string const newlayout = TextClass::convert(layout);
+       LYXERR0(newlayout);
+       if (newlayout.empty()) {
+               Alert::error(_("Conversion Failed!"),
+                     _("Failed to convert local layout to current format."));
+       } else {
+               locallayoutTE->setPlainText(toqstr(newlayout));
+       }
+       validate();
+}
+
+
+void LocalLayout::convertPressed() {
+       convert();
        changed();
 }
 
@@ -587,12 +610,25 @@ void LocalLayout::validate() {
                fromqstr(locallayoutTE->document()->toPlainText().trimmed());
        if (layout.empty()) {
                is_valid_ = true;
-               infoLB->setText("");
+               validatePB->setEnabled(false);
+               validLB->setText("");
+               convertPB->hide();
+               convertLB->hide();
        } else {
-               is_valid_ = TextClass::validate(layout);
-               infoLB->setText(is_valid_ ? vtext : ivtext);
+               TextClass::ReturnValues const ret = TextClass::validate(layout);
+               is_valid_ = (ret == TextClass::OK) || (ret == TextClass::OK_OLDFORMAT);
+               validatePB->setEnabled(false);
+               validLB->setText(is_valid_ ? vtext : ivtext);
+               if (ret == TextClass::OK_OLDFORMAT) {
+                       convertPB->show();
+                       convertPB->setEnabled(true);
+                       convertLB->setText(qt_("Convert to current format"));
+                       convertLB->show();
+               } else {
+                       convertPB->hide();
+                       convertLB->hide();
+               }
        }
-       validatePB->setEnabled(false);
 }
 
 
@@ -744,6 +780,9 @@ GuiDocument::GuiDocument(GuiView & lv)
        outputModule->synccustomCB->addItem("\\synctex=-1");
        outputModule->synccustomCB->addItem("\\usepackage[active]{srcltx}");
 
+       outputModule->synccustomCB->setValidator(new NoNewLineValidator(
+               outputModule->synccustomCB));
+
        // fonts
        fontModule = new UiWidget<Ui::FontUi>;
        connect(fontModule->osFontsCB, SIGNAL(clicked()),
@@ -783,6 +822,11 @@ GuiDocument::GuiDocument(GuiView & lv)
        connect(fontModule->fontOsfCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
 
+       fontModule->fontencLE->setValidator(new NoNewLineValidator(
+               fontModule->fontencLE));
+       fontModule->cjkFontLE->setValidator(new NoNewLineValidator(
+               fontModule->cjkFontLE));
+
        updateFontlist();
 
        fontModule->fontsizeCO->addItem(qt_("Default"));
@@ -798,6 +842,11 @@ GuiDocument::GuiDocument(GuiView & lv)
                fontModule->fontsDefaultCO->addItem(
                        qt_(GuiDocument::fontfamilies_gui[n]));
 
+       if (!LaTeXFeatures::isAvailable("fontspec"))
+               fontModule->osFontsCB->setToolTip(
+                       qt_("Use OpenType and TrueType fonts directly (requires XeTeX or LuaTeX)\n"
+                           "You need to install the package \"fontspec\" to use this feature"));
+
 
        // page layout
        pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
@@ -966,11 +1015,14 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(change_adaptor()));
        connect(langModule->languagePackageCO, SIGNAL(activated(int)),
                this, SLOT(change_adaptor()));
-       connect(langModule->languagePackageED, SIGNAL(textChanged(QString)),
+       connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
                this, SLOT(change_adaptor()));
        connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
                this, SLOT(languagePackageChanged(int)));
 
+       langModule->languagePackageLE->setValidator(new NoNewLineValidator(
+               langModule->languagePackageLE));
+
        QAbstractItemModel * language_model = guiApp->languageModel();
        // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
        language_model->sort(0);
@@ -1040,6 +1092,7 @@ GuiDocument::GuiDocument(GuiView & lv)
        numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
        numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
        numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
+       numberingModule->tocTW->header()->setResizeMode(QHeaderView::ResizeToContents);
 
 
        // biblio
@@ -1060,13 +1113,17 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(change_adaptor()));
        connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
                this, SLOT(bibtexChanged(int)));
-       connect(biblioModule->bibtexOptionsED, SIGNAL(textChanged(QString)),
+       connect(biblioModule->bibtexOptionsLE, SIGNAL(textChanged(QString)),
                this, SLOT(change_adaptor()));
 
+       biblioModule->bibtexOptionsLE->setValidator(new NoNewLineValidator(
+               biblioModule->bibtexOptionsLE));
+
        biblioModule->citeStyleCO->addItem(qt_("Author-year"));
        biblioModule->citeStyleCO->addItem(qt_("Numerical"));
        biblioModule->citeStyleCO->setCurrentIndex(0);
-       
+
+       // NOTE: we do not provide "custom" here for security reasons!
        biblioModule->bibtexCO->clear();
        biblioModule->bibtexCO->addItem(qt_("Default"), QString("default"));
        for (set<string>::const_iterator it = lyxrc.bibtex_alternatives.begin();
@@ -1074,7 +1131,6 @@ GuiDocument::GuiDocument(GuiView & lv)
                QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
                biblioModule->bibtexCO->addItem(command, command);
        }
-       biblioModule->bibtexCO->addItem(qt_("Custom"), QString("custom"));
 
 
        // indices
@@ -1093,6 +1149,8 @@ GuiDocument::GuiDocument(GuiView & lv)
                mathsModule->mhchemCB, SLOT(setDisabled(bool)));
        connect(mathsModule->mathdotsautoCB, SIGNAL(toggled(bool)),
                mathsModule->mathdotsCB, SLOT(setDisabled(bool)));
+       connect(mathsModule->undertildeautoCB, SIGNAL(toggled(bool)),
+               mathsModule->undertildeCB, SLOT(setDisabled(bool)));
        
        connect(mathsModule->amsCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
@@ -1110,6 +1168,10 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(change_adaptor()));
        connect(mathsModule->mathdotsautoCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
+       connect(mathsModule->undertildeCB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(mathsModule->undertildeautoCB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
        
 
        // latex class
@@ -1139,6 +1201,11 @@ GuiDocument::GuiDocument(GuiView & lv)
        connect(latexModule->refstyleCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
 
+       latexModule->optionsLE->setValidator(new NoNewLineValidator(
+               latexModule->optionsLE));
+       latexModule->childDocLE->setValidator(new NoNewLineValidator(
+               latexModule->childDocLE));
+
        // postscript drivers
        for (int n = 0; tex_graphics[n][0]; ++n) {
                QString enc = qt_(tex_graphics_gui[n]);
@@ -1189,6 +1256,8 @@ GuiDocument::GuiDocument(GuiView & lv)
        // Modules
        modulesModule = new UiWidget<Ui::ModulesUi>;
        modulesModule->availableLV->header()->setVisible(false);
+       modulesModule->availableLV->header()->setResizeMode(QHeaderView::ResizeToContents);
+       modulesModule->availableLV->header()->setStretchLastSection(false);
        selectionManager =
                new ModuleSelectionManager(modulesModule->availableLV,
                        modulesModule->selectedLV,
@@ -1238,6 +1307,17 @@ GuiDocument::GuiDocument(GuiView & lv)
        connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
                this, SLOT(change_adaptor()));
 
+       pdfSupportModule->titleLE->setValidator(new NoNewLineValidator(
+               pdfSupportModule->titleLE));
+       pdfSupportModule->authorLE->setValidator(new NoNewLineValidator(
+               pdfSupportModule->authorLE));
+       pdfSupportModule->subjectLE->setValidator(new NoNewLineValidator(
+               pdfSupportModule->subjectLE));
+       pdfSupportModule->keywordsLE->setValidator(new NoNewLineValidator(
+               pdfSupportModule->keywordsLE));
+       pdfSupportModule->optionsLE->setValidator(new NoNewLineValidator(
+               pdfSupportModule->optionsLE));
+
        for (int i = 0; backref_opts[i][0]; ++i)
                pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
 
@@ -1500,7 +1580,7 @@ void GuiDocument::changeBackgroundColor()
        // set the button color and text
        colorModule->backgroundPB->setStyleSheet(
                colorButtonStyleSheet(newColor));
-       colorModule->backgroundPB->setText(toqstr("Change..."));
+       colorModule->backgroundPB->setText(qt_("&Change..."));
        // save color
        set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
        is_backgroundcolor = true;
@@ -1510,10 +1590,10 @@ void GuiDocument::changeBackgroundColor()
 
 void GuiDocument::deleteBackgroundColor()
 {
-       // set the button color back to default by setting an epmty StyleSheet
+       // set the button color back to default by setting an empty StyleSheet
        colorModule->backgroundPB->setStyleSheet(QLatin1String(""));
        // change button text
-       colorModule->backgroundPB->setText(toqstr("Default..."));
+       colorModule->backgroundPB->setText(qt_("&Default..."));
        // save default color (white)
        set_backgroundcolor = rgbFromHexName("#ffffff");
        is_backgroundcolor = false;
@@ -1530,7 +1610,7 @@ void GuiDocument::changeFontColor()
        // set the button color and text
        colorModule->fontColorPB->setStyleSheet(
                colorButtonStyleSheet(newColor));
-       colorModule->fontColorPB->setText(toqstr("Change..."));
+       colorModule->fontColorPB->setText(qt_("&Change..."));
        // save color
        set_fontcolor = rgbFromHexName(fromqstr(newColor.name()));
        is_fontcolor = true;
@@ -1540,10 +1620,10 @@ void GuiDocument::changeFontColor()
 
 void GuiDocument::deleteFontColor()
 {
-       // set the button color back to default by setting an epmty StyleSheet
+       // set the button color back to default by setting an empty StyleSheet
        colorModule->fontColorPB->setStyleSheet(QLatin1String(""));
        // change button text
-       colorModule->fontColorPB->setText(toqstr("Default..."));
+       colorModule->fontColorPB->setText(qt_("&Default..."));
        // save default color (black)
        set_fontcolor = rgbFromHexName("#000000");
        is_fontcolor = false;
@@ -1568,11 +1648,10 @@ void GuiDocument::changeNoteFontColor()
 
 void GuiDocument::deleteNoteFontColor()
 {
-       // set the button color back to light gray
+       // set the button color back to pref
+       theApp()->getRgbColor(Color_greyedouttext, set_notefontcolor);
        colorModule->noteFontColorPB->setStyleSheet(
-               colorButtonStyleSheet(QColor(204, 204, 204, 255)));
-       // save light gray as the set color
-       set_notefontcolor = rgbFromHexName("#cccccc");
+               colorButtonStyleSheet(rgb2qcolor(set_notefontcolor)));
        changed();
 }
 
@@ -1594,11 +1673,10 @@ void GuiDocument::changeBoxBackgroundColor()
 
 void GuiDocument::deleteBoxBackgroundColor()
 {
-       // set the button color back to red
+       // set the button color back to pref
+       theApp()->getRgbColor(Color_shadedbg, set_boxbgcolor);
        colorModule->boxBackgroundPB->setStyleSheet(
-               colorButtonStyleSheet(QColor(Qt::red)));
-       // save red as the set color
-       set_boxbgcolor = rgbFromHexName("#ff0000");
+               colorButtonStyleSheet(rgb2qcolor(set_boxbgcolor)));
        changed();
 }
 
@@ -1668,16 +1746,16 @@ void GuiDocument::updateFontlist()
 
        // With XeTeX, we have access to all system fonts, but not the LaTeX fonts
        if (fontModule->osFontsCB->isChecked()) {
-               fontModule->fontsRomanCO->addItem(qt_("Default"));
-               fontModule->fontsSansCO->addItem(qt_("Default"));
-               fontModule->fontsTypewriterCO->addItem(qt_("Default"));
+               fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
+               fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
+               fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
        
                QFontDatabase fontdb;
                QStringList families(fontdb.families());
                for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
-                       fontModule->fontsRomanCO->addItem(*it);
-                       fontModule->fontsSansCO->addItem(*it);
-                       fontModule->fontsTypewriterCO->addItem(*it);
+                       fontModule->fontsRomanCO->addItem(*it, *it);
+                       fontModule->fontsSansCO->addItem(*it, *it);
+                       fontModule->fontsTypewriterCO->addItem(*it, *it);
                }
                return;
        }
@@ -1686,19 +1764,19 @@ void GuiDocument::updateFontlist()
                QString font = qt_(tex_fonts_roman_gui[n]);
                if (!isFontAvailable(tex_fonts_roman[n]))
                        font += qt_(" (not installed)");
-               fontModule->fontsRomanCO->addItem(font);
+               fontModule->fontsRomanCO->addItem(font, qt_(tex_fonts_roman[n]));
        }
        for (int n = 0; tex_fonts_sans[n][0]; ++n) {
                QString font = qt_(tex_fonts_sans_gui[n]);
                if (!isFontAvailable(tex_fonts_sans[n]))
                        font += qt_(" (not installed)");
-               fontModule->fontsSansCO->addItem(font);
+               fontModule->fontsSansCO->addItem(font, qt_(tex_fonts_sans[n]));
        }
        for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
                QString font = qt_(tex_fonts_monospaced_gui[n]);
                if (!isFontAvailable(tex_fonts_monospaced[n]))
                        font += qt_(" (not installed)");
-               fontModule->fontsTypewriterCO->addItem(font);
+               fontModule->fontsTypewriterCO->addItem(font, qt_(tex_fonts_monospaced[n]));
        }
 }
 
@@ -1775,7 +1853,7 @@ void GuiDocument::browseLayout()
        QString const label1 = qt_("Layouts|#o#O");
        QString const dir1 = toqstr(lyxrc.document_path);
        QStringList const filter(qt_("LyX Layout (*.layout)"));
-       QString file = browseRelFile(QString(), bufferFilePath(),
+       QString file = browseRelToParent(QString(), bufferFilePath(),
                qt_("Local layout file"), filter, false,
                label1, dir1);
 
@@ -1831,7 +1909,7 @@ void GuiDocument::browseMaster()
        QString const old = latexModule->childDocLE->text();
        QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
        QStringList const filter(qt_("LyX Files (*.lyx)"));
-       QString file = browseRelFile(old, docpath, title, filter, false,
+       QString file = browseRelToSub(old, docpath, title, filter, false,
                qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
 
        if (!file.isEmpty())
@@ -1897,20 +1975,15 @@ void GuiDocument::classChanged()
 
 void GuiDocument::languagePackageChanged(int i)
 {
-        langModule->languagePackageED->setEnabled(
+        langModule->languagePackageLE->setEnabled(
                langModule->languagePackageCO->itemData(i).toString() == "custom");
 }
 
 
 void GuiDocument::bibtexChanged(int n)
 {
-       QString const data =
-               biblioModule->bibtexCO->itemData(n).toString();
-       biblioModule->bibtexOptionsED->setEnabled(data != "default");
-       if (data == "custom")
-               biblioModule->bibtexOptionsLA->setText(qt_("Co&mmand:"));
-       else
-               biblioModule->bibtexOptionsLA->setText(qt_("&Options:"));
+       biblioModule->bibtexOptionsLE->setEnabled(
+               biblioModule->bibtexCO->itemData(n).toString() != "default");
        changed();
 }
 
@@ -2104,29 +2177,26 @@ void GuiDocument::updateDefaultFormat()
        if (!bufferview())
                return;
        // make a copy in order to consider unapplied changes
-       Buffer * tmpbuf = buffer().clone();
-       tmpbuf->params().useNonTeXFonts =
-               fontModule->osFontsCB->isChecked();
-       int idx = latexModule->classCO->currentIndex();
+       BufferParams param_copy = buffer().params();
+       param_copy.useNonTeXFonts = fontModule->osFontsCB->isChecked();
+       int const idx = latexModule->classCO->currentIndex();
        if (idx >= 0) {
                string const classname = classes_model_.getIDString(idx);
-               tmpbuf->params().setBaseClass(classname);
-               tmpbuf->params().makeDocumentClass();
+               param_copy.setBaseClass(classname);
+               param_copy.makeDocumentClass();
        }
        outputModule->defaultFormatCO->blockSignals(true);
        outputModule->defaultFormatCO->clear();
        outputModule->defaultFormatCO->addItem(qt_("Default"),
                                QVariant(QString("default")));
        typedef vector<Format const *> Formats;
-       Formats formats = tmpbuf->exportableFormats(true);
+       Formats formats = param_copy.exportableFormats(true);
        Formats::const_iterator cit = formats.begin();
        Formats::const_iterator end = formats.end();
        for (; cit != end; ++cit)
                outputModule->defaultFormatCO->addItem(qt_((*cit)->prettyname()),
                                QVariant(toqstr((*cit)->name())));
        outputModule->defaultFormatCO->blockSignals(false);
-       // delete the copy
-       delete tmpbuf;
 }
 
 
@@ -2170,10 +2240,8 @@ void GuiDocument::applyView()
                fromqstr(biblioModule->bibtexCO->itemData(
                        biblioModule->bibtexCO->currentIndex()).toString());
        string const bibtex_options =
-               fromqstr(biblioModule->bibtexOptionsED->text());
-       if (bibtex_command == "custom")
-               bp_.bibtex_command = bibtex_options;
-       else if (bibtex_command == "default" || bibtex_options.empty())
+               fromqstr(biblioModule->bibtexOptionsLE->text());
+       if (bibtex_command == "default" || bibtex_options.empty())
                bp_.bibtex_command = bibtex_command;
        else
                bp_.bibtex_command = bibtex_command + " " + bibtex_options;
@@ -2240,7 +2308,7 @@ void GuiDocument::applyView()
                langModule->languagePackageCO->currentIndex()).toString();
        if (pack == "custom")
                bp_.lang_package =
-                       fromqstr(langModule->languagePackageED->text());
+                       fromqstr(langModule->languagePackageLE->text());
        else
                bp_.lang_package = fromqstr(pack);
 
@@ -2311,6 +2379,14 @@ void GuiDocument::applyView()
                else
                        bp_.use_mathdots = BufferParams::package_off;
        }
+       if (mathsModule->undertildeautoCB->isChecked())
+               bp_.use_undertilde = BufferParams::package_auto;
+       else {
+               if (mathsModule->undertildeCB->isChecked())
+                       bp_.use_undertilde = BufferParams::package_on;
+               else
+                       bp_.use_undertilde = BufferParams::package_off;
+       }
        
        // Page Layout
        if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
@@ -2448,34 +2524,17 @@ void GuiDocument::applyView()
        bp_.html_math_img_scale = outputModule->mathimgSB->value();
 
        // fonts
-       if (nontexfonts) {
-               if (fontModule->fontsRomanCO->currentIndex() == 0)
-                       bp_.fonts_roman = "default";
-               else
-                       bp_.fonts_roman =
-                               fromqstr(fontModule->fontsRomanCO->currentText());
-       
-               if (fontModule->fontsSansCO->currentIndex() == 0)
-                       bp_.fonts_sans = "default";
-               else
-                       bp_.fonts_sans =
-                               fromqstr(fontModule->fontsSansCO->currentText());
-       
-               if (fontModule->fontsTypewriterCO->currentIndex() == 0)
-                       bp_.fonts_typewriter = "default";
-               else
-                       bp_.fonts_typewriter =
-                               fromqstr(fontModule->fontsTypewriterCO->currentText());
-       } else {
-               bp_.fonts_roman =
-                       tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
-       
-               bp_.fonts_sans =
-                       tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
-       
-               bp_.fonts_typewriter =
-                       tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
-       }
+       bp_.fonts_roman =
+               fromqstr(fontModule->fontsRomanCO->
+                       itemData(fontModule->fontsRomanCO->currentIndex()).toString());
+
+       bp_.fonts_sans =
+               fromqstr(fontModule->fontsSansCO->
+                       itemData(fontModule->fontsSansCO->currentIndex()).toString());
+
+       bp_.fonts_typewriter =
+               fromqstr(fontModule->fontsTypewriterCO->
+                       itemData(fontModule->fontsTypewriterCO->currentIndex()).toString());
 
        if (fontModule->fontencCO->currentIndex() == 0)
                bp_.fontenc = "global";
@@ -2609,15 +2668,15 @@ void GuiDocument::paramsToDialog()
        int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
        if (bpos != -1) {
                biblioModule->bibtexCO->setCurrentIndex(bpos);
-               biblioModule->bibtexOptionsED->setText(toqstr(options).trimmed());
-               biblioModule->bibtexOptionsLA->setText(qt_("&Options:"));
+               biblioModule->bibtexOptionsLE->setText(toqstr(options).trimmed());
        } else {
+               // We reset to default if we do not know the specified compiler
+               // This is for security reasons
                biblioModule->bibtexCO->setCurrentIndex(
-                       biblioModule->bibtexCO->findData(toqstr("custom")));
-               biblioModule->bibtexOptionsED->setText(toqstr(bp_.bibtex_command));
-               biblioModule->bibtexOptionsLA->setText(qt_("&Command:"));
+                       biblioModule->bibtexCO->findData(toqstr("default")));
+               biblioModule->bibtexOptionsLE->clear();
        }
-       biblioModule->bibtexOptionsED->setEnabled(
+       biblioModule->bibtexOptionsLE->setEnabled(
                biblioModule->bibtexCO->currentIndex() != 0);
 
        // indices
@@ -2662,10 +2721,10 @@ void GuiDocument::paramsToDialog()
        if (p == -1) {
                langModule->languagePackageCO->setCurrentIndex(
                          langModule->languagePackageCO->findData("custom"));
-               langModule->languagePackageED->setText(toqstr(bp_.lang_package));
+               langModule->languagePackageLE->setText(toqstr(bp_.lang_package));
        } else {
                langModule->languagePackageCO->setCurrentIndex(p);
-               langModule->languagePackageED->clear();
+               langModule->languagePackageLE->clear();
        }
 
        //color
@@ -2741,6 +2800,11 @@ void GuiDocument::paramsToDialog()
        mathsModule->mathdotsautoCB->setChecked(
                bp_.use_mathdots == BufferParams::package_auto);
 
+       mathsModule->undertildeCB->setChecked(
+               bp_.use_undertilde == BufferParams::package_on);
+       mathsModule->undertildeautoCB->setChecked(
+               bp_.use_undertilde == BufferParams::package_auto);
+
        switch (bp_.spacing().getSpace()) {
                case Spacing::Other: nitem = 3; break;
                case Spacing::Double: nitem = 2; break;
@@ -2881,9 +2945,12 @@ void GuiDocument::paramsToDialog()
        if (index == -1)
                index = 0;
        outputModule->defaultFormatCO->setCurrentIndex(index);
-       fontModule->osFontsCB->setEnabled(bp_.baseClass()->outputType() == lyx::LATEX);
+       bool const os_fonts_available =
+               bp_.baseClass()->outputType() == lyx::LATEX
+               && LaTeXFeatures::isAvailable("fontspec");
+       fontModule->osFontsCB->setEnabled(os_fonts_available);
        fontModule->osFontsCB->setChecked(
-               bp_.baseClass()->outputType() == lyx::LATEX && bp_.useNonTeXFonts);
+               os_fonts_available && bp_.useNonTeXFonts);
 
        outputModule->outputsyncCB->setChecked(bp_.output_sync);
        outputModule->synccustomCB->setEditText(toqstr(bp_.output_sync_macro));
@@ -2896,51 +2963,41 @@ void GuiDocument::paramsToDialog()
        updateFontsize(documentClass().opt_fontsize(),
                        bp_.fontsize);
 
-       if (bp_.useNonTeXFonts) {
+       QString font = toqstr(bp_.fonts_roman);
+       int rpos = fontModule->fontsRomanCO->findData(font);
+       if (rpos == -1) {
+               rpos = fontModule->fontsRomanCO->count();
+               fontModule->fontsRomanCO->addItem(font + qt_(" (not installed)"), font);
+       }
+       fontModule->fontsRomanCO->setCurrentIndex(rpos);
+
+       font = toqstr(bp_.fonts_sans);
+       int spos = fontModule->fontsSansCO->findData(font);
+       if (spos == -1) {
+               spos = fontModule->fontsSansCO->count();
+               fontModule->fontsSansCO->addItem(font + qt_(" (not installed)"), font);
+       }
+       fontModule->fontsSansCO->setCurrentIndex(spos);
+
+       font = toqstr(bp_.fonts_typewriter);
+       int tpos = fontModule->fontsTypewriterCO->findData(font);
+       if (tpos == -1) {
+               tpos = fontModule->fontsTypewriterCO->count();
+               fontModule->fontsTypewriterCO->addItem(font + qt_(" (not installed)"), font);
+       }
+       fontModule->fontsTypewriterCO->setCurrentIndex(tpos);
+
+       if (bp_.useNonTeXFonts && os_fonts_available) {
                fontModule->fontencLA->setEnabled(false);
                fontModule->fontencCO->setEnabled(false);
                fontModule->fontencLE->setEnabled(false);
-               for (int i = 0; i < fontModule->fontsRomanCO->count(); ++i) {
-                       if (fontModule->fontsRomanCO->itemText(i) == toqstr(bp_.fonts_roman)) {
-                               fontModule->fontsRomanCO->setCurrentIndex(i);
-                               break;
-                       }
-               }
-               
-               for (int i = 0; i < fontModule->fontsSansCO->count(); ++i) {
-                       if (fontModule->fontsSansCO->itemText(i) == toqstr(bp_.fonts_sans)) {
-                               fontModule->fontsSansCO->setCurrentIndex(i);
-                               break;
-                       }
-               }
-               for (int i = 0; i < fontModule->fontsTypewriterCO->count(); ++i) {
-                       if (fontModule->fontsTypewriterCO->itemText(i) == 
-                               toqstr(bp_.fonts_typewriter)) {
-                               fontModule->fontsTypewriterCO->setCurrentIndex(i);
-                               break;
-                       }
-               }
        } else {
                fontModule->fontencLA->setEnabled(true);
                fontModule->fontencCO->setEnabled(true);
                fontModule->fontencLE->setEnabled(true);
-               int n = findToken(tex_fonts_roman, bp_.fonts_roman);
-               if (n >= 0) {
-                       fontModule->fontsRomanCO->setCurrentIndex(n);
-                       romanChanged(n);
-               }
-       
-               n = findToken(tex_fonts_sans, bp_.fonts_sans);
-               if (n >= 0) {
-                       fontModule->fontsSansCO->setCurrentIndex(n);
-                       sansChanged(n);
-               }
-       
-               n = findToken(tex_fonts_monospaced, bp_.fonts_typewriter);
-               if (n >= 0) {
-                       fontModule->fontsTypewriterCO->setCurrentIndex(n);
-                       ttChanged(n);
-               }
+               romanChanged(rpos);
+               sansChanged(spos);
+               ttChanged(tpos);
        }
 
        if (!bp_.fonts_cjk.empty())