]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiDocument.cpp
QDialogButtonBox for the remaining dialogs.
[lyx.git] / src / frontends / qt4 / GuiDocument.cpp
index d05629568e604d8aed627ebe3e9ef7e7c0a0cbb9..d60385b041dd98d5bda834874fb4264347b5851a 100644 (file)
 #include "insets/InsetListingsParams.h"
 
 #include "support/debug.h"
+#include "support/docstream.h"
 #include "support/FileName.h"
 #include "support/filetools.h"
 #include "support/gettext.h"
 #include "support/lassert.h"
 #include "support/lstrings.h"
+#include "support/TempFile.h"
 
 #include "frontends/alert.h"
 
@@ -472,6 +474,7 @@ PreambleModule::PreambleModule(QWidget * parent)
        connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
        connect(findLE, SIGNAL(textEdited(const QString &)), this, SLOT(checkFindButton()));
        connect(findButtonPB, SIGNAL(clicked()), this, SLOT(findText()));
+       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
@@ -546,6 +549,36 @@ void PreambleModule::closeEvent(QCloseEvent * e)
 }
 
 
+void PreambleModule::editExternal() {
+       if (!current_id_)
+               return;
+
+       if (tempfile_) {
+               preambleTE->setReadOnly(false);
+               FileName const tempfilename = tempfile_->name();
+               docstring const s = tempfilename.fileContents("UTF-8");
+               preambleTE->document()->setPlainText(toqstr(s));
+               tempfile_.reset();
+               editPB->setText(qt_("Edit"));
+               changed();
+               return;
+       }
+
+       string const format =
+               current_id_->params().documentClass().outputFormat();
+       string const ext = theFormats().extension(format);
+       tempfile_.reset(new TempFile("preamble_editXXXXXX." + ext));
+       FileName const tempfilename = tempfile_->name();
+       string const name = tempfilename.toFilesystemEncoding();
+       ofdocstream os(name.c_str());
+       os << qstring_to_ucs4(preambleTE->document()->toPlainText());
+       os.close();
+       preambleTE->setReadOnly(true);
+       theFormats().edit(*current_id_, tempfilename, format);
+       editPB->setText(qt_("End Edit"));
+       changed();
+}
+
 /////////////////////////////////////////////////////////////////////
 //
 // LocalLayout
@@ -561,6 +594,7 @@ LocalLayout::LocalLayout(QWidget * parent)
        connect(locallayoutTE, SIGNAL(textChanged()), this, SLOT(textChanged()));
        connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
        connect(convertPB, SIGNAL(clicked()), this, SLOT(convertPressed()));
+       connect(editPB, SIGNAL(clicked()), this, SLOT(editExternal()));
 }
 
 
@@ -685,6 +719,38 @@ void LocalLayout::validatePressed() {
 }
 
 
+void LocalLayout::editExternal() {
+       if (!current_id_)
+               return;
+
+       if (tempfile_) {
+               locallayoutTE->setReadOnly(false);
+               FileName const tempfilename = tempfile_->name();
+               docstring const s = tempfilename.fileContents("UTF-8");
+               locallayoutTE->document()->setPlainText(toqstr(s));
+               tempfile_.reset();
+               editPB->setText(qt_("Edit"));
+               changed();
+               return;
+       }
+
+       string const format =
+               current_id_->params().documentClass().outputFormat();
+       string const ext = theFormats().extension(format);
+       tempfile_.reset(new TempFile("preamble_editXXXXXX." + ext));
+       FileName const tempfilename = tempfile_->name();
+       string const name = tempfilename.toFilesystemEncoding();
+       ofdocstream os(name.c_str());
+       os << qstring_to_ucs4(locallayoutTE->document()->toPlainText());
+       os.close();
+       locallayoutTE->setReadOnly(true);
+       theFormats().edit(*current_id_, tempfilename, format);
+       editPB->setText(qt_("End Edit"));
+       validatePB->setEnabled(false);
+       hideConvert();
+       changed();
+}
+
 /////////////////////////////////////////////////////////////////////
 //
 // DocumentDialog
@@ -699,20 +765,18 @@ GuiDocument::GuiDocument(GuiView & lv)
 {
        setupUi(this);
 
-       connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
-       connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
-       connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
-       connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
+       connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
+               this, SLOT(slotButtonBox(QAbstractButton *)));
 
        connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
        connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
 
        // Manage the restore, ok, apply, restore and cancel/close buttons
        bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
-       bc().setOK(okPB);
-       bc().setApply(applyPB);
-       bc().setCancel(closePB);
-       bc().setRestore(restorePB);
+       bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
+       bc().setApply(buttonBox->button(QDialogButtonBox::Apply));
+       bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
+       bc().setRestore(buttonBox->button(QDialogButtonBox::Reset));
 
 
        // text layout
@@ -841,6 +905,62 @@ GuiDocument::GuiDocument(GuiView & lv)
        connect(outputModule->saveTransientPropertiesCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
 
+
+       // language & quote
+       // this must preceed font, since fonts depend on this
+       langModule = new UiWidget<Ui::LanguageUi>(this);
+       connect(langModule->languageCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(langModule->languageCO, SIGNAL(activated(int)),
+               this, SLOT(languageChanged(int)));
+       connect(langModule->defaultencodingRB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(langModule->otherencodingRB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(langModule->encodingCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(langModule->languagePackageCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
+               this, SLOT(change_adaptor()));
+       connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
+               this, SLOT(languagePackageChanged(int)));
+       connect(langModule->dynamicQuotesCB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+
+       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);
+       langModule->languageCO->setModel(language_model);
+       langModule->languageCO->setModelColumn(0);
+
+       // Always put the default encoding in the first position.
+       langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
+       QStringList encodinglist;
+       for (auto const & encvar : encodings) {
+               if (!encvar.unsafe() && !encvar.guiName().empty())
+                       encodinglist.append(qt_(encvar.guiName()));
+       }
+       encodinglist.sort();
+       langModule->encodingCO->addItems(encodinglist);
+
+       langModule->languagePackageCO->addItem(
+               qt_("Default"), toqstr("default"));
+       langModule->languagePackageCO->addItem(
+               qt_("Automatic"), toqstr("auto"));
+       langModule->languagePackageCO->addItem(
+               qt_("Always Babel"), toqstr("babel"));
+       langModule->languagePackageCO->addItem(
+               qt_("Custom"), toqstr("custom"));
+       langModule->languagePackageCO->addItem(
+               qt_("None[[language package]]"), toqstr("none"));
+
+
        // fonts
        fontModule = new FontModule(this);
        connect(fontModule->osFontsCB, SIGNAL(clicked()),
@@ -904,9 +1024,9 @@ GuiDocument::GuiDocument(GuiView & lv)
        fontModule->fontsizeCO->addItem(qt_("11"));
        fontModule->fontsizeCO->addItem(qt_("12"));
 
-       fontModule->fontencCO->addItem(qt_("Default"), QString("global"));
+       fontModule->fontencCO->addItem(qt_("Automatic"), QString("auto"));
+       fontModule->fontencCO->addItem(qt_("Class Default"), QString("default"));
        fontModule->fontencCO->addItem(qt_("Custom"), QString("custom"));
-       fontModule->fontencCO->addItem(qt_("None (no fontenc)"), QString("default"));
 
        for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
                fontModule->fontsDefaultCO->addItem(
@@ -1071,60 +1191,6 @@ GuiDocument::GuiDocument(GuiView & lv)
                marginsModule->columnsepL);
 
 
-       // language & quote
-       langModule = new UiWidget<Ui::LanguageUi>(this);
-       connect(langModule->languageCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(langModule->languageCO, SIGNAL(activated(int)),
-               this, SLOT(languageChanged(int)));
-       connect(langModule->defaultencodingRB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(langModule->otherencodingRB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(langModule->encodingCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(langModule->languagePackageCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
-               this, SLOT(change_adaptor()));
-       connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
-               this, SLOT(languagePackageChanged(int)));
-       connect(langModule->dynamicQuotesCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-
-       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);
-       langModule->languageCO->setModel(language_model);
-       langModule->languageCO->setModelColumn(0);
-
-       // Always put the default encoding in the first position.
-       langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
-       QStringList encodinglist;
-       for (auto const & encvar : encodings) {
-               if (!encvar.unsafe() && !encvar.guiName().empty())
-                       encodinglist.append(qt_(encvar.guiName()));
-       }
-       encodinglist.sort();
-       langModule->encodingCO->addItems(encodinglist);
-
-       langModule->languagePackageCO->addItem(
-               qt_("Default"), toqstr("default"));
-       langModule->languagePackageCO->addItem(
-               qt_("Automatic"), toqstr("auto"));
-       langModule->languagePackageCO->addItem(
-               qt_("Always Babel"), toqstr("babel"));
-       langModule->languagePackageCO->addItem(
-               qt_("Custom"), toqstr("custom"));
-       langModule->languagePackageCO->addItem(
-               qt_("None[[language package]]"), toqstr("none"));
-
-
        // color
        colorModule = new UiWidget<Ui::ColorUi>(this);
        connect(colorModule->fontColorPB, SIGNAL(clicked()),
@@ -1554,7 +1620,7 @@ GuiDocument::GuiDocument(GuiView & lv)
        docPS->addPanel(indicesModule, N_("Indexes"));
        docPS->addPanel(pdfSupportModule, N_("PDF Properties"));
        docPS->addPanel(mathsModule, N_("Math Options"));
-       docPS->addPanel(floatModule, N_("Float Placement"));
+       docPS->addPanel(floatModule, N_("Float Settings"));
        docPS->addPanel(listingsModule, N_("Listings[[inset]]"));
        docPS->addPanel(bulletsModule, N_("Bullets"));
        docPS->addPanel(branchesModule, N_("Branches"));
@@ -1624,6 +1690,28 @@ void GuiDocument::slotOK()
 }
 
 
+void GuiDocument::slotButtonBox(QAbstractButton * button)
+{
+       switch (buttonBox->standardButton(button)) {
+       case QDialogButtonBox::Ok:
+               slotOK();
+               break;
+       case QDialogButtonBox::Apply:
+               slotApply();
+               break;
+       case QDialogButtonBox::Cancel:
+               slotClose();
+               break;
+       case QDialogButtonBox::Reset:
+       case QDialogButtonBox::RestoreDefaults:
+               slotRestore();
+               break;
+       default:
+               break;
+       }
+}
+
+
 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
 {
        if (item == 0)
@@ -2151,8 +2239,13 @@ bool GuiDocument::ot1() const
 {
        QString const fontenc =
                fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
+       int const i = langModule->languageCO->currentIndex();
+       if (i == -1)
+               return false;
+       QString const langname = langModule->languageCO->itemData(i).toString();
+       Language const * newlang = lyx::languages.getLanguage(fromqstr(langname));
        return (fontenc == "default"
-               || (fontenc == "global" && (lyxrc.fontenc == "default" || lyxrc.fontenc == "OT1"))
+               || (fontenc == "auto" && newlang->fontenc(buffer().params()) == "OT1")
                || (fontenc == "custom" && fontModule->fontencLE->text() == "OT1"));
 }
 
@@ -2448,7 +2541,7 @@ void GuiDocument::classChanged()
                return;
        string const classname = fromqstr(latexModule->classCO->getData(idx));
 
-       if (applyPB->isEnabled()) {
+       if (buttonBox->button(QDialogButtonBox::Apply)->isEnabled()) {
                int const ret = Alert::prompt(_("Unapplied changes"),
                                _("Some changes in the dialog were not yet applied.\n"
                                "If you do not apply now, they will be lost after this action."),
@@ -2750,7 +2843,8 @@ void GuiDocument::modulesChanged()
 {
        modulesToParams(bp_);
 
-       if (applyPB->isEnabled() && (nonModuleChanged_ || shellescapeChanged_)) {
+       if (buttonBox->button(QDialogButtonBox::Apply)->isEnabled()
+           && (nonModuleChanged_ || shellescapeChanged_)) {
                int const ret = Alert::prompt(_("Unapplied changes"),
                                _("Some changes in the dialog were not yet applied.\n"
                                "If you do not apply now, they will be lost after this action."),
@@ -3209,8 +3303,9 @@ void GuiDocument::applyView()
        bp_.maintain_unincluded_children =
                masterChildModule->maintainAuxCB->isChecked();
 
-       // Float Placement
-       bp_.float_placement = floatModule->get();
+       // Float Settings
+       bp_.float_placement = floatModule->getPlacement();
+       bp_.float_alignment = floatModule->getAlignment();
 
        // Listings
        // text should have passed validation
@@ -3391,7 +3486,7 @@ void GuiDocument::paramsToDialog()
        latexModule->refstyleCB->setChecked(bp_.use_refstyle);
 
        // biblio
-       string const cite_engine = bp_.citeEngine().list().front();
+       string const cite_engine = bp_.citeEngine();
 
        biblioModule->citeEngineCO->setCurrentIndex(
                biblioModule->citeEngineCO->findData(toqstr(cite_engine)));
@@ -3740,7 +3835,8 @@ void GuiDocument::paramsToDialog()
                bp_.maintain_unincluded_children);
 
        // Float Settings
-       floatModule->set(bp_.float_placement);
+       floatModule->setPlacement(bp_.float_placement);
+       floatModule->setAlignment(bp_.float_alignment);
 
        // ListingsSettings
        // break listings_params to multiple lines
@@ -3837,12 +3933,13 @@ void GuiDocument::paramsToDialog()
        if (nn >= 0)
                fontModule->fontsDefaultCO->setCurrentIndex(nn);
 
-       if (bp_.fontenc == "global" || bp_.fontenc == "default") {
+       if (bp_.fontenc == "auto" || bp_.fontenc == "default") {
                fontModule->fontencCO->setCurrentIndex(
                        fontModule->fontencCO->findData(toqstr(bp_.fontenc)));
                fontModule->fontencLE->setEnabled(false);
        } else {
-               fontModule->fontencCO->setCurrentIndex(1);
+               fontModule->fontencCO->setCurrentIndex(
+                                       fontModule->fontencCO->findData("custom"));
                fontModule->fontencLE->setText(toqstr(bp_.fontenc));
        }
 
@@ -4218,7 +4315,7 @@ void GuiDocument::updateContents()
 
 void GuiDocument::useClassDefaults()
 {
-       if (applyPB->isEnabled()) {
+       if (buttonBox->button(QDialogButtonBox::Apply)->isEnabled()) {
                int const ret = Alert::prompt(_("Unapplied changes"),
                                _("Some changes in the dialog were not yet applied.\n"
                                  "If you do not apply now, they will be lost after this action."),
@@ -4252,6 +4349,8 @@ bool GuiDocument::isValid()
        return
                validateListingsParameters().isEmpty() &&
                localLayout->isValid() &&
+               !localLayout->editing() &&
+               !preambleModule->editing() &&
                (
                        // if we're asking for skips between paragraphs
                        !textLayoutModule->skipRB->isChecked() ||