]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiDocument.cpp
Don't allow newline characters in preference (#5840).
[lyx.git] / src / frontends / qt4 / GuiDocument.cpp
index 05414d403978f199f5903a3d519290876afdb7b5..d4c88b506b9c9641485e9d5efbb23907756a8d59 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);
 }
 
 
@@ -1099,6 +1135,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()));
@@ -1116,6 +1154,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
@@ -1781,7 +1823,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);
 
@@ -1837,7 +1879,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())
@@ -2105,29 +2147,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;
 }
 
 
@@ -2310,6 +2349,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)
@@ -2723,6 +2770,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;