]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt/GuiDocument.cpp
Change Doc Settings "Edit" PB to "Edit Externally"
[lyx.git] / src / frontends / qt / GuiDocument.cpp
index 5a4584eece42f57ce92028341e6660e514c9302d..4bfda55f468d76f839759c6a1206dde438eb37d6 100644 (file)
@@ -265,15 +265,15 @@ class ModuleSelectionManager : public GuiSelectionManager
 public:
        ///
        ModuleSelectionManager(QObject * parent,
-                                                  QTreeView * availableLVarg,
-                                                  QTreeView * selectedLVarg,
-                                                  QPushButton * addPBarg,
-                                                  QPushButton * delPBarg,
-                                                  QPushButton * upPBarg,
-                                                  QPushButton * downPBarg,
-                                                  QStandardItemModel * availableModelarg,
-                                                  GuiIdListModel * selectedModelarg,
-                              GuiDocument const * container)
+                              QTreeView * availableLVarg,
+                              QTreeView * selectedLVarg,
+                              QPushButton * addPBarg,
+                              QPushButton * delPBarg,
+                              QPushButton * upPBarg,
+                              QPushButton * downPBarg,
+                              QStandardItemModel * availableModelarg,
+                              GuiIdListModel * selectedModelarg,
+                              GuiDocument const * container)
                : GuiSelectionManager(parent, availableLVarg, selectedLVarg, addPBarg, delPBarg,
                                                          upPBarg, downPBarg, availableModelarg, selectedModelarg),
                  container_(container)
@@ -488,8 +488,7 @@ PreambleModule::PreambleModule(QWidget * parent)
        connect(editPB, SIGNAL(clicked()), this, SLOT(editExternal()));
        connect(findLE, SIGNAL(returnPressed()), this, SLOT(findText()));
        checkFindButton();
-       // https://stackoverflow.com/questions/13027091/how-to-override-tab-width-in-qt
-       const int tabStop = 4;
+       int const tabStop = 4;
        QFontMetrics metrics(preambleTE->currentFont());
 #if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
        // horizontalAdvance() is available starting in 5.11.0
@@ -576,7 +575,7 @@ void PreambleModule::editExternal() {
                docstring const s = tempfilename.fileContents("UTF-8");
                preambleTE->document()->setPlainText(toqstr(s));
                tempfile_.reset();
-               editPB->setText(qt_("&Edit"));
+               editPB->setText(qt_("&Edit Externally"));
                changed();
                return;
        }
@@ -612,6 +611,15 @@ LocalLayout::LocalLayout(QWidget * parent)
        connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
        connect(convertPB, SIGNAL(clicked()), this, SLOT(convertPressed()));
        connect(editPB, SIGNAL(clicked()), this, SLOT(editExternal()));
+       int const tabStop = 4;
+       QFontMetrics metrics(locallayoutTE->currentFont());
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
+       // horizontalAdvance() is available starting in 5.11.0
+       // setTabStopDistance() is available starting in 5.10.0
+       locallayoutTE->setTabStopDistance(tabStop * metrics.horizontalAdvance(' '));
+#else
+       locallayoutTE->setTabStopWidth(tabStop * metrics.width(' '));
+#endif
 }
 
 
@@ -649,23 +657,18 @@ void LocalLayout::hideConvert()
 
 void LocalLayout::textChanged()
 {
-       // Flashy red bold text
-       static const QString ivpar("<p style=\"color: #c00000; font-weight: bold; text-align:left\">"
-                                  "%1</p>");
-       static const QString message = ivpar.arg(qt_("Validation required!"));
+       validLB->setText("");
        string const layout =
                fromqstr(locallayoutTE->document()->toPlainText().trimmed());
 
        if (layout.empty()) {
                validated_ = true;
                validatePB->setEnabled(false);
-               validLB->setText("");
                hideConvert();
                changed();
        } else if (!validatePB->isEnabled()) {
                // if that's already enabled, we shouldn't need to do anything.
                validated_ = false;
-               validLB->setText(message);
                validatePB->setEnabled(true);
                hideConvert();
                changed();
@@ -748,7 +751,7 @@ void LocalLayout::editExternal() {
                docstring const s = tempfilename.fileContents("UTF-8");
                locallayoutTE->document()->setPlainText(toqstr(s));
                tempfile_.reset();
-               editPB->setText(qt_("&Edit"));
+               editPB->setText(qt_("&Edit Externally"));
                changed();
                return;
        }
@@ -780,7 +783,8 @@ void LocalLayout::editExternal() {
 GuiDocument::GuiDocument(GuiView & lv)
        : GuiDialog(lv, "document", qt_("Document Settings")),
          biblioChanged_(false), nonModuleChanged_(false),
-         modulesChanged_(false), shellescapeChanged_(false)
+         modulesChanged_(false), shellescapeChanged_(false),
+         switchback_(false), prompted_(false)
 {
        setupUi(this);
 
@@ -855,13 +859,13 @@ GuiDocument::GuiDocument(GuiView & lv)
        textLayoutModule->skipLE->setValidator(new LengthValidator(
                textLayoutModule->skipLE));
 
-       textLayoutModule->indentCO->addItem(qt_("Default"));
-       textLayoutModule->indentCO->addItem(qt_("Custom"));
+       textLayoutModule->indentCO->addItem(qt_("Default"), toqstr("default"));
+       textLayoutModule->indentCO->addItem(qt_("Custom"), toqstr("custom"));
        textLayoutModule->skipCO->addItem(qt_("Half line height"), VSpace::HALFLINE);
        textLayoutModule->skipCO->addItem(qt_("Line height"), VSpace::FULLLINE);
-       textLayoutModule->skipCO->addItem(qt_("SmallSkip"), VSpace::SMALLSKIP);
-       textLayoutModule->skipCO->addItem(qt_("MedSkip"), VSpace::MEDSKIP);
-       textLayoutModule->skipCO->addItem(qt_("BigSkip"), VSpace::BIGSKIP);
+       textLayoutModule->skipCO->addItem(qt_("Small Skip"), VSpace::SMALLSKIP);
+       textLayoutModule->skipCO->addItem(qt_("Medium Skip"), VSpace::MEDSKIP);
+       textLayoutModule->skipCO->addItem(qt_("Big Skip"), VSpace::BIGSKIP);
        textLayoutModule->skipCO->addItem(qt_("Custom"), VSpace::LENGTH);
        textLayoutModule->lspacingCO->insertItem(
                Spacing::Single, qt_("Single"));
@@ -901,13 +905,8 @@ GuiDocument::GuiDocument(GuiView & lv)
        masterChildModule->childrenTW->setColumnCount(2);
        masterChildModule->childrenTW->headerItem()->setText(0, qt_("Child Document"));
        masterChildModule->childrenTW->headerItem()->setText(1, qt_("Include to Output"));
-#if (QT_VERSION > 0x050000)
-        masterChildModule->childrenTW->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
-        masterChildModule->childrenTW->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
-#else
-        masterChildModule->childrenTW->header()->setResizeMode(0, QHeaderView::ResizeToContents);
-        masterChildModule->childrenTW->header()->setResizeMode(1, QHeaderView::ResizeToContents);
-#endif
+       masterChildModule->childrenTW->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
+       masterChildModule->childrenTW->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
 
        // Formats
        outputModule = new UiWidget<Ui::OutputUi>(this);
@@ -925,9 +924,9 @@ GuiDocument::GuiDocument(GuiView & lv)
        connect(outputModule->tableoutCB, SIGNAL(currentIndexChanged(int)),
                this, SLOT(change_adaptor()));
        connect(outputModule->mathmlprefixCB, SIGNAL(currentIndexChanged(int)),
-        this, SLOT(change_adaptor()));
+               this, SLOT(change_adaptor()));
 
-    connect(outputModule->shellescapeCB, SIGNAL(stateChanged(int)),
+       connect(outputModule->shellescapeCB, SIGNAL(stateChanged(int)),
                this, SLOT(shellescapeChanged()));
        connect(outputModule->outputsyncCB, SIGNAL(toggled(bool)),
                this, SLOT(setOutputSync(bool)));
@@ -1323,6 +1322,7 @@ GuiDocument::GuiDocument(GuiView & lv)
        connect(colorModule->delBoxBackgroundTB, SIGNAL(clicked()),
                this, SLOT(deleteBoxBackgroundColor()));
 
+
        // change tracking
        changesModule = new UiWidget<Ui::ChangeTrackingUi>(this);
        connect(changesModule->trackChangesCB, SIGNAL(clicked()),
@@ -1332,6 +1332,7 @@ GuiDocument::GuiDocument(GuiView & lv)
        connect(changesModule->changeBarsCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
 
+
        // numbering
        numberingModule = new UiWidget<Ui::NumberingUi>(this);
        connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
@@ -1346,7 +1347,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"));
-       setSectionResizeMode(numberingModule->tocTW->header(), QHeaderView::ResizeToContents);
+       numberingModule->tocTW->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
        connect(numberingModule->linenoCB, SIGNAL(toggled(bool)),
                this, SLOT(linenoToggled(bool)));
        connect(numberingModule->linenoCB, SIGNAL(clicked()),
@@ -1436,7 +1437,7 @@ GuiDocument::GuiDocument(GuiView & lv)
        headers << qt_("Package") << qt_("Load automatically")
                << qt_("Load always") << qt_("Do not load");
        mathsModule->packagesTW->setHorizontalHeaderLabels(headers);
-       setSectionResizeMode(mathsModule->packagesTW->horizontalHeader(), QHeaderView::Stretch);
+       mathsModule->packagesTW->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
        map<string, string> const & packages = BufferParams::auto_packages();
        mathsModule->packagesTW->setRowCount(packages.size());
        int packnum = 0;
@@ -1535,8 +1536,8 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(change_adaptor()));
 
 
-       mathsModule->MathIndentCO->addItem(qt_("Default"));
-       mathsModule->MathIndentCO->addItem(qt_("Custom"));
+       mathsModule->MathIndentCO->addItem(qt_("Default"), toqstr("default"));
+       mathsModule->MathIndentCO->addItem(qt_("Custom"), toqstr("custom"));
        mathsModule->MathIndentLE->setValidator(new LengthValidator(
                mathsModule->MathIndentLE));
        // initialize the length validator
@@ -1639,10 +1640,10 @@ GuiDocument::GuiDocument(GuiView & lv)
        // Modules
        modulesModule = new UiWidget<Ui::ModulesUi>(this);
        modulesModule->availableLV->header()->setVisible(false);
-       setSectionResizeMode(modulesModule->availableLV->header(), QHeaderView::ResizeToContents);
+       modulesModule->availableLV->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
        modulesModule->availableLV->header()->setStretchLastSection(false);
        modulesModule->selectedLV->header()->setVisible(false);
-       setSectionResizeMode(modulesModule->selectedLV->header(), QHeaderView::ResizeToContents);
+       modulesModule->selectedLV->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
        modulesModule->selectedLV->header()->setStretchLastSection(false);
        selectionManager =
                new ModuleSelectionManager(this, modulesModule->availableLV,
@@ -1669,13 +1670,8 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(moduleFilterChanged(QString)));
        connect(filter_, SIGNAL(returnPressed()),
                this, SLOT(moduleFilterPressed()));
-#if (QT_VERSION < 0x050000)
-       connect(filter_, SIGNAL(downPressed()),
-               modulesModule->availableLV, SLOT(setFocus()));
-#else
        connect(filter_, &FancyLineEdit::downPressed,
                modulesModule->availableLV, [this](){ focusAndHighlight(modulesModule->availableLV); });
-#endif
 
 
        // PDF support
@@ -1712,7 +1708,9 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(change_adaptor()));
        connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
                this, SLOT(change_adaptor()));
-       connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
+       connect(pdfSupportModule->optionsTE, SIGNAL(textChanged()),
+               this, SLOT(change_adaptor()));
+       connect(pdfSupportModule->metadataTE, SIGNAL(textChanged()),
                this, SLOT(change_adaptor()));
 
        pdfSupportModule->titleLE->setValidator(new NoNewLineValidator(
@@ -1723,8 +1721,8 @@ GuiDocument::GuiDocument(GuiView & lv)
                pdfSupportModule->subjectLE));
        pdfSupportModule->keywordsLE->setValidator(new NoNewLineValidator(
                pdfSupportModule->keywordsLE));
-       pdfSupportModule->optionsLE->setValidator(new NoNewLineValidator(
-               pdfSupportModule->optionsLE));
+       (void) new LaTeXHighlighter(pdfSupportModule->optionsTE->document(), true, true);
+       (void) new LaTeXHighlighter(pdfSupportModule->metadataTE->document(), true, true);
 
        for (int i = 0; backref_opts[i][0]; ++i)
                pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
@@ -1754,7 +1752,7 @@ GuiDocument::GuiDocument(GuiView & lv)
                qt_("Input listings parameters below. Enter ? for a list of parameters."));
 
        for (int i = 0; lst_packages[i][0]; ++i)
-            listingsModule->packageCO->addItem(lst_packages[i]);
+               listingsModule->packageCO->addItem(lst_packages[i]);
 
 
        // add the panels
@@ -1781,16 +1779,44 @@ GuiDocument::GuiDocument(GuiView & lv)
        docPS->addPanel(outputModule, N_("Formats[[output]]"));
        docPS->addPanel(preambleModule, N_("LaTeX Preamble"));
        docPS->setCurrentPanel("Document Class");
-// FIXME: hack to work around resizing bug in Qt >= 4.2
-// bug verified with Qt 4.2.{0-3} (JSpitzm)
-#if QT_VERSION >= 0x040200
-       docPS->updateGeometry();
-#endif
 }
 
 
 void GuiDocument::onBufferViewChanged()
 {
+       if (switchback_) {
+               // We are just switching back. Nothing to do.
+               switchback_ = false;
+               return;
+       }
+       BufferView const * view = bufferview();
+       string const new_filename = view ? view->buffer().absFileName() : string();
+       // If we switched buffer really and the previous file name is different to
+       // the current one, we ask on unapplied changes (#9369)
+       // FIXME: This is more complicated than it should be. Why do we need these to cycles?
+       // And ideally, we should propose to apply without having to switch back
+       // (e.g., via a LFUN_BUFFER_PARAMS_APPLY_OTHER)
+       if (!prev_buffer_filename_.empty() && prev_buffer_filename_ != new_filename
+           && buttonBox->button(QDialogButtonBox::Apply)->isEnabled()) {
+               // Only ask if we haven't yet in this cycle
+               int const ret = prompted_ ? 3 : Alert::prompt(_("Unapplied changes"),
+                               _("Some changes in the previous document were not yet applied.\n"
+                               "Do you want to switch back and apply them?"),
+                               1, 1, _("Yes, &Switch Back"), _("No, &Dismiss Changes"));
+               if (ret == 0) {
+                       // Switch to previous buffer view and apply
+                       switchback_ = true;
+                       // Record that we have asked.
+                       prompted_ = true;
+                       lyx::dispatch(FuncRequest(LFUN_BUFFER_SWITCH, prev_buffer_filename_));
+                       return;
+               } else if (ret == 3) {
+                       // We are in the second cycle. Set back.
+                       prompted_ = false;
+                       return;
+               }
+       }
+
        if (isVisibleView())
                initialiseParams("");
 }
@@ -2009,7 +2035,7 @@ void GuiDocument::setLSpacing(int item)
 
 void GuiDocument::setIndent(int item)
 {
-       bool const enable = (item == 1);
+       bool const enable = (textLayoutModule->indentCO->itemData(item) == "custom");
        textLayoutModule->indentLE->setEnabled(enable);
        textLayoutModule->indentLengthCO->setEnabled(enable);
        textLayoutModule->skipLE->setEnabled(false);
@@ -2053,7 +2079,7 @@ void GuiDocument::allowMathIndent() {
                mathsModule->MathIndentLengthCO->setEnabled(false);
        }
        if (mathsModule->MathIndentCB->isChecked()
-           && mathsModule->MathIndentCO->currentIndex() == 1) {
+           && mathsModule->MathIndentCO->itemData(mathsModule->MathIndentCO->currentIndex()) == "custom") {
                        mathsModule->MathIndentLE->setEnabled(true);
                        mathsModule->MathIndentLengthCO->setEnabled(true);
        }
@@ -2671,8 +2697,12 @@ void GuiDocument::updateFontlist()
                fontModule->fontsMathCO->addItem(qt_("Class Default (TeX Fonts)"), QString("auto"));
                fontModule->fontsMathCO->addItem(unimath, QString("default"));
 
+#if QT_VERSION >= 0x060000
+               const QStringList families(QFontDatabase::families());
+#else
                QFontDatabase fontdb;
-               QStringList families(fontdb.families());
+               const QStringList families(fontdb.families());
+#endif
                for (auto const & family : families) {
                        fontModule->fontsRomanCO->addItem(family, family);
                        fontModule->fontsSansCO->addItem(family, family);
@@ -3417,6 +3447,16 @@ bool GuiDocument::isChildIncluded(string const & child)
 
 void GuiDocument::applyView()
 {
+       // auto-validate local layout
+       if (!localLayout->isValid()) {
+               localLayout->validate();
+               if (!localLayout->isValid()) {
+                       setApplyStopped(true);
+                       docPS->setCurrentPanel(N_("Local Layout"));
+                       return;
+               }
+       }
+
        // preamble
        preambleModule->apply(bp_);
        localLayout->apply(bp_);
@@ -3584,21 +3624,13 @@ void GuiDocument::applyView()
        bp_.is_math_indent = mathsModule->MathIndentCB->isChecked();
        if (bp_.is_math_indent) {
                // if formulas are indented
-               switch (mathsModule->MathIndentCO->currentIndex()) {
-               case 0:
-                       bp_.setMathIndent(Length());
-                       break;
-               case 1: {
+               if (mathsModule->MathIndentCO->itemData(mathsModule->MathIndentCO->currentIndex()) == "custom") {
                        Length mathindent(widgetsToLength(mathsModule->MathIndentLE,
                                                          mathsModule->MathIndentLengthCO));
                        bp_.setMathIndent(mathindent);
-                       break;
-               }
-               default:
-                       // this should never happen
+               } else
+                       // default
                        bp_.setMathIndent(Length());
-                       break;
-               }
        }
        switch (mathsModule->MathNumberingPosCO->currentIndex()) {
                case 0:
@@ -3657,21 +3689,13 @@ void GuiDocument::applyView()
        if (textLayoutModule->indentRB->isChecked()) {
                // if paragraphs are separated by an indentation
                bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
-               switch (textLayoutModule->indentCO->currentIndex()) {
-               case 0:
-                       bp_.setParIndent(Length());
-                       break;
-               case 1: {
+               if (textLayoutModule->indentCO->itemData(textLayoutModule->indentCO->currentIndex()) == "custom") {
                        Length parindent(widgetsToLength(textLayoutModule->indentLE,
                                                         textLayoutModule->indentLengthCO));
                        bp_.setParIndent(parindent);
-                       break;
-               }
-               default:
-                       // this should never happen
+               } else
+                       // default
                        bp_.setParIndent(Length());
-                       break;
-               }
        } else {
                // if paragraphs are separated by a skip
                bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
@@ -3913,7 +3937,14 @@ void GuiDocument::applyView()
        else
                pdf.pagemode.clear();
        pdf.quoted_options = pdf.quoted_options_check(
-                               fromqstr(pdfSupportModule->optionsLE->text()));
+                               fromqstr(pdfSupportModule->optionsTE->toPlainText()));
+#if QT_VERSION < 0x060000
+       bp_.document_metadata = qstring_to_ucs4(pdfSupportModule->metadataTE->toPlainText()
+                                               .trimmed().replace(QRegExp("\n+"), "\n"));
+#else
+       bp_.document_metadata = qstring_to_ucs4(pdfSupportModule->metadataTE->toPlainText()
+                                               .trimmed().replace(QRegularExpression("\n+"), "\n"));
+#endif
 
        // change tracking
        bp_.track_changes = changesModule->trackChangesCB->isChecked();
@@ -4179,15 +4210,15 @@ void GuiDocument::paramsToDialog()
        if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
                textLayoutModule->indentRB->setChecked(true);
                string parindent = bp_.getParIndent().asString();
-               int indent = 0;
+               QString indent = toqstr("default");
                if (!parindent.empty()) {
                        lengthToWidgets(textLayoutModule->indentLE,
                                        textLayoutModule->indentLengthCO,
                                        parindent, default_unit);
-                       indent = 1;
+                       indent = toqstr("custom");
                }
-               textLayoutModule->indentCO->setCurrentIndex(indent);
-               setIndent(indent);
+               textLayoutModule->indentCO->setCurrentIndex(textLayoutModule->indentCO->findData(indent));
+               setIndent(textLayoutModule->indentCO->currentIndex());
        } else {
                textLayoutModule->skipRB->setChecked(true);
                VSpace::VSpaceKind skip = bp_.getDefSkip().kind();
@@ -4521,9 +4552,12 @@ void GuiDocument::paramsToDialog()
        pdfSupportModule->fullscreenCB->setChecked
                (pdf.pagemode == pdf.pagemode_fullscreen);
 
-       pdfSupportModule->optionsLE->setText(
+       pdfSupportModule->optionsTE->setPlainText(
                toqstr(pdf.quoted_options));
 
+       pdfSupportModule->metadataTE->setPlainText(
+               toqstr(bp_.document_metadata));
+
        // change tracking
        changesModule->trackChangesCB->setChecked(bp_.track_changes);
        changesModule->outputChangesCB->setChecked(bp_.output_changes);
@@ -4854,14 +4888,16 @@ bool GuiDocument::isValid()
 {
        return
                validateListingsParameters().isEmpty() &&
-               localLayout->isValid() &&
                !localLayout->editing() &&
                !preambleModule->editing() &&
                (
                        // if we're asking for skips between paragraphs
                        !textLayoutModule->skipRB->isChecked() ||
                        // then either we haven't chosen custom
-                       textLayoutModule->skipCO->currentIndex() != 3 ||
+                       VSpace::VSpaceKind(
+                               textLayoutModule->skipCO->itemData(
+                                       textLayoutModule->skipCO->currentIndex()).toInt())
+                               != VSpace::LENGTH ||
                        // or else a length has been given
                        !textLayoutModule->skipLE->text().isEmpty()
                ) &&
@@ -4869,7 +4905,8 @@ bool GuiDocument::isValid()
                        // if we're asking for indentation
                        !textLayoutModule->indentRB->isChecked() ||
                        // then either we haven't chosen custom
-                       textLayoutModule->indentCO->currentIndex() != 1 ||
+                       (textLayoutModule->indentCO->itemData(
+                               textLayoutModule->indentCO->currentIndex()) != "custom") ||
                        // or else a length has been given
                        !textLayoutModule->indentLE->text().isEmpty()
                ) &&
@@ -4877,7 +4914,8 @@ bool GuiDocument::isValid()
                        // if we're asking for math indentation
                        !mathsModule->MathIndentCB->isChecked() ||
                        // then either we haven't chosen custom
-                       mathsModule->MathIndentCO->currentIndex() != 1 ||
+                       (mathsModule->MathIndentCO->itemData(
+                               mathsModule->MathIndentCO->currentIndex()) != "custom") ||
                        // or else a length has been given
                        !mathsModule->MathIndentLE->text().isEmpty()
                );
@@ -4902,6 +4940,7 @@ bool GuiDocument::initialiseParams(string const &)
                paramsToDialog();
                return true;
        }
+       prev_buffer_filename_ = view->buffer().absFileName();
        bp_ = view->buffer().params();
        loadModuleInfo();
        updateAvailableModules();