]> git.lyx.org Git - features.git/blobdiff - src/frontends/qt4/GuiDocument.cpp
Translations for listings insets
[features.git] / src / frontends / qt4 / GuiDocument.cpp
index 44f2afd7f79e6d567b78f4814b3bfa7d09f97638..9f3f7ea0dcaadab54b96a0c0d8af8517c9965487 100644 (file)
@@ -54,6 +54,7 @@
 #include "support/FileName.h"
 #include "support/filetools.h"
 #include "support/gettext.h"
+#include "support/lassert.h"
 #include "support/lstrings.h"
 
 #include "frontends/alert.h"
@@ -171,6 +172,37 @@ char const * backref_opts_gui[] =
 };
 
 
+char const * packages_gui[][4] =
+{
+       {"amsmath",
+        N_("&Use AMS math package automatically"),
+        N_("Use AMS &math package"),
+        N_("The AMS LaTeX packages are only used if symbols from the AMS math toolbars are inserted into formulas")},
+       {"esint",
+        N_("Use esint package &automatically"),
+        N_("Use &esint package"),
+        N_("The LaTeX package esint is only used if special integral symbols are inserted into formulas")},
+       {"mathdots",
+        N_("Use math&dots package automatically"),
+        N_("Use mathdo&ts package"),
+        N_("The LaTeX package mathdots is only used if the command \\iddots is inserted into formulas")},
+       {"mathtools",
+        N_("Use mathtools package automatically"),
+        N_("Use mathtools package"),
+        N_("The LaTeX package mathtools is only used if some mathematical relations are inserted into formulas")},
+       {"mhchem",
+        N_("Use mhchem &package automatically"),
+        N_("Use mh&chem package"),
+        N_("The LaTeX package mhchem is only used if either the command \\ce or \\cf is inserted into formulas")},
+       {"undertilde",
+        N_("Use u&ndertilde package automatically"),
+        N_("Use undertilde pac&kage"),
+        N_("The LaTeX package undertilde is only used if you use the math frame decoration 'utilde'")},
+       {"", "", "", ""}
+};
+
+
+vector<string> engine_types_;
 vector<pair<string, QString> > pagestyles;
 
 
@@ -229,6 +261,15 @@ vector<string> getExcludedList(string const & modName)
 }
 
 
+docstring getModuleCategory(string const & modName)
+{
+       LyXModule const * const mod = theModuleList[modName];
+       if (!mod)
+               return docstring();
+       return from_utf8(mod->category());
+}
+
+
 docstring getModuleDescription(string const & modName)
 {
        LyXModule const * const mod = theModuleList[modName];
@@ -1101,6 +1142,10 @@ GuiDocument::GuiDocument(GuiView & lv)
 
        // biblio
        biblioModule = new UiWidget<Ui::BiblioUi>;
+       connect(biblioModule->citeDefaultRB, SIGNAL(toggled(bool)),
+               this, SLOT(setNumerical(bool)));
+       connect(biblioModule->citeJurabibRB, SIGNAL(toggled(bool)),
+               this, SLOT(setAuthorYear(bool)));
        connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
                biblioModule->citationStyleL, SLOT(setEnabled(bool)));
        connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
@@ -1148,38 +1193,49 @@ GuiDocument::GuiDocument(GuiView & lv)
 
 
        // maths
+       // FIXME This UI has problems:
+       //       1) It is not generic, packages_gui needs to be changed for each new package
+       //       2) Two checkboxes have 4 states, but one is invalid (both pressed)
+       //       3) The auto cb is not disabled if the use cb is checked
        mathsModule = new UiWidget<Ui::MathsUi>;
-       connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
-               mathsModule->amsCB, SLOT(setDisabled(bool)));
-       connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
-               mathsModule->esintCB, SLOT(setDisabled(bool)));
-       connect(mathsModule->mhchemautoCB, SIGNAL(toggled(bool)),
-               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()));
-       connect(mathsModule->amsautoCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(mathsModule->esintCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(mathsModule->esintautoCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(mathsModule->mhchemCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(mathsModule->mhchemautoCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(mathsModule->mathdotsCB, SIGNAL(clicked()),
-               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()));
+       vector<string> const & packages = BufferParams::auto_packages();
+        for (size_t i = 0; i < packages.size(); ++i) {
+               // Use the order of BufferParams::auto_packages() for easier
+               // access in applyView() and paramsToDialog()
+               int n = 0;
+               for (n = 0; packages_gui[n][0][0]; n++)
+                       if (packages_gui[n][0] == packages[i])
+                               break;
+               // If this fires somebody changed
+               // BufferParams::auto_packages() without adjusting packages_gui
+               LASSERT(packages_gui[n][0][0], /**/);
+               QString autoText = qt_(packages_gui[n][1]);
+               QString alwaysText = qt_(packages_gui[n][2]);
+               QString autoTooltip = qt_(packages_gui[n][3]);
+               QString alwaysTooltip;
+               if (packages[i] == "amsmath")
+                       alwaysTooltip =
+                               qt_("The AMS LaTeX packages are always used");
+               else
+                       alwaysTooltip = toqstr(bformat(
+                               _("The LaTeX package %1$s is always used"),
+                               from_ascii(packages[i])));
+               QCheckBox * autoCB = new QCheckBox(autoText, mathsModule);
+               QCheckBox * alwaysCB = new QCheckBox(alwaysText, mathsModule);
+               mathsModule->gridLayout->addWidget(autoCB, 2 * i, 0);
+               mathsModule->gridLayout->addWidget(alwaysCB, 2 * i + 1, 0);
+               autoCB->setToolTip(autoTooltip);
+               alwaysCB->setToolTip(alwaysTooltip);
+               connect(autoCB, SIGNAL(toggled(bool)),
+                       alwaysCB, SLOT(setDisabled(bool)));
+               connect(autoCB, SIGNAL(clicked()),
+                       this, SLOT(change_adaptor()));
+               connect(alwaysCB, SIGNAL(clicked()),
+                       this, SLOT(change_adaptor()));
+       }
+       QSpacerItem * spacer = new QSpacerItem(20, 20, QSizePolicy::Minimum,
+                                              QSizePolicy::Expanding);
+       mathsModule->gridLayout->addItem(spacer, 2 * packages.size(), 0);
 
 
        // latex class
@@ -1242,6 +1298,7 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(change_adaptor()));
        connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
                this, SLOT(branchesRename(docstring const &, docstring const &)));
+       connect(branchesModule, SIGNAL(okPressed()), this, SLOT(slotOK()));
        updateUnknownBranches();
 
 
@@ -1367,7 +1424,7 @@ GuiDocument::GuiDocument(GuiView & lv)
        docPS->addPanel(pdfSupportModule, qt_("PDF Properties"));
        docPS->addPanel(mathsModule, qt_("Math Options"));
        docPS->addPanel(floatModule, qt_("Float Placement"));
-       docPS->addPanel(listingsModule, qt_("Listings"));
+       docPS->addPanel(listingsModule, qt_("Listings[[inset]]"));
        docPS->addPanel(bulletsModule, qt_("Bullets"));
        docPS->addPanel(branchesModule, qt_("Branches"));
        docPS->addPanel(outputModule, qt_("Output"));
@@ -2003,6 +2060,58 @@ void GuiDocument::bibtexChanged(int n)
 }
 
 
+void GuiDocument::setAuthorYear(bool authoryear)
+{
+       if (authoryear)
+               biblioModule->citeStyleCO->setCurrentIndex(0);
+       biblioChanged();
+}
+
+
+void GuiDocument::setNumerical(bool numerical)
+{
+       if (numerical)
+               biblioModule->citeStyleCO->setCurrentIndex(1);
+       biblioChanged();
+}
+
+
+void GuiDocument::updateEngineType(string const & items, CiteEngineType const & sel)
+{
+       engine_types_.clear();
+
+       int nn = 0;
+
+       for (int n = 0; !token(items, '|', n).empty(); ++n) {
+               nn += 1;
+               string style = token(items, '|', n);
+               engine_types_.push_back(style);
+       }
+
+       switch (sel) {
+               case ENGINE_TYPE_AUTHORYEAR:
+                       biblioModule->citeStyleCO->setCurrentIndex(0);
+                       break;
+               case ENGINE_TYPE_NUMERICAL:
+                       biblioModule->citeStyleCO->setCurrentIndex(1);
+                       break;
+       }
+
+       biblioModule->citationStyleL->setEnabled(nn > 1);
+       biblioModule->citeStyleCO->setEnabled(nn > 1);
+
+       if (nn != 1)
+               return;
+
+       // If the textclass allows only one of authoryear or numerical,
+       // we have no choice but to force that engine type.
+       if (engine_types_[0] == "authoryear")
+               biblioModule->citeStyleCO->setCurrentIndex(0);
+       else
+               biblioModule->citeStyleCO->setCurrentIndex(1);
+}
+
+
 namespace {
        // FIXME unicode
        // both of these should take a vector<docstring>
@@ -2103,7 +2212,7 @@ void GuiDocument::updateModuleInfo()
        if (focus_on_selected)
                lv = modulesModule->selectedLV;
        else
-               lv= modulesModule->availableLV;
+               lv = modulesModule->availableLV;
        if (lv->selectionModel()->selectedIndexes().isEmpty()) {
                modulesModule->infoML->document()->clear();
                return;
@@ -2121,6 +2230,13 @@ void GuiDocument::updateModuleInfo()
                desc += _("Module provided by document class.");
        }
 
+       docstring cat = getModuleCategory(modName);
+       if (!cat.empty()) {
+               if (!desc.empty())
+                       desc += "\n";
+               desc += bformat(_("Category: %1$s."), cat);
+       }
+
        vector<string> pkglist = getPackageList(modName);
        docstring pkgdesc = formatStrVec(pkglist, _("and"));
        if (!pkgdesc.empty()) {
@@ -2235,18 +2351,17 @@ void GuiDocument::applyView()
        bp_.use_refstyle  = latexModule->refstyleCB->isChecked();
 
        // biblio
-       bp_.setCiteEngine(ENGINE_BASIC);
-
-       if (biblioModule->citeNatbibRB->isChecked()) {
-               bool const use_numerical_citations =
-                       biblioModule->citeStyleCO->currentIndex();
-               if (use_numerical_citations)
-                       bp_.setCiteEngine(ENGINE_NATBIB_NUMERICAL);
-               else
-                       bp_.setCiteEngine(ENGINE_NATBIB_AUTHORYEAR);
+       if (biblioModule->citeNatbibRB->isChecked())
+               bp_.setCiteEngine("natbib");
+       else if (biblioModule->citeJurabibRB->isChecked())
+               bp_.setCiteEngine("jurabib");
+       else
+               bp_.setCiteEngine("basic");
 
-       } else if (biblioModule->citeJurabibRB->isChecked())
-               bp_.setCiteEngine(ENGINE_JURABIB);
+       if (biblioModule->citeStyleCO->currentIndex())
+               bp_.setCiteEngineType(ENGINE_TYPE_NUMERICAL);
+       else
+               bp_.setCiteEngineType(ENGINE_TYPE_AUTHORYEAR);
 
        bp_.use_bibtopic =
                biblioModule->bibtopicCB->isChecked();
@@ -2369,45 +2484,20 @@ void GuiDocument::applyView()
        modulesToParams(bp_);
 
        // Math
-       if (mathsModule->amsautoCB->isChecked())
-               bp_.use_amsmath = BufferParams::package_auto;
-       else {
-               if (mathsModule->amsCB->isChecked())
-                       bp_.use_amsmath = BufferParams::package_on;
-               else
-                       bp_.use_amsmath = BufferParams::package_off;
-       }
-       if (mathsModule->esintautoCB->isChecked())
-               bp_.use_esint = BufferParams::package_auto;
-       else {
-               if (mathsModule->esintCB->isChecked())
-                       bp_.use_esint = BufferParams::package_on;
-               else
-                       bp_.use_esint = BufferParams::package_off;
-       }
-       if (mathsModule->mhchemautoCB->isChecked())
-               bp_.use_mhchem = BufferParams::package_auto;
-       else {
-               if (mathsModule->mhchemCB->isChecked())
-                       bp_.use_mhchem = BufferParams::package_on;
-               else
-                       bp_.use_mhchem = BufferParams::package_off;
-       }
-       if (mathsModule->mathdotsautoCB->isChecked())
-               bp_.use_mathdots = BufferParams::package_auto;
-       else {
-               if (mathsModule->mathdotsCB->isChecked())
-                       bp_.use_mathdots = BufferParams::package_on;
-               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;
+       vector<string> const & packages = BufferParams::auto_packages();
+        for (size_t n = 0; n < packages.size(); ++n) {
+               QCheckBox * autoCB = static_cast<QCheckBox *>(
+                       mathsModule->gridLayout->itemAtPosition(2 * n, 0)->widget());
+               if (autoCB->isChecked())
+                       bp_.use_package(packages[n], BufferParams::package_auto);
+               else {
+                       QCheckBox * alwaysCB = static_cast<QCheckBox *>(
+                               mathsModule->gridLayout->itemAtPosition(2 * n + 1, 0)->widget());
+                       if (alwaysCB->isChecked())
+                               bp_.use_package(packages[n], BufferParams::package_on);
+                       else
+                               bp_.use_package(packages[n], BufferParams::package_off);
+               }
        }
 
        // Page Layout
@@ -2671,18 +2761,22 @@ void GuiDocument::paramsToDialog()
        latexModule->refstyleCB->setChecked(bp_.use_refstyle);
 
        // biblio
+       string const cite_engine = bp_.citeEngine().list().front();
+
        biblioModule->citeDefaultRB->setChecked(
-               bp_.citeEngine() == ENGINE_BASIC);
+               cite_engine == "basic");
+
+       biblioModule->citeJurabibRB->setChecked(
+               cite_engine == "jurabib");
 
        biblioModule->citeNatbibRB->setChecked(
-               bp_.citeEngine() == ENGINE_NATBIB_NUMERICAL ||
-               bp_.citeEngine() == ENGINE_NATBIB_AUTHORYEAR);
+               cite_engine == "natbib");
 
        biblioModule->citeStyleCO->setCurrentIndex(
-               bp_.citeEngine() == ENGINE_NATBIB_NUMERICAL);
+               bp_.citeEngineType() == ENGINE_TYPE_NUMERICAL);
 
-       biblioModule->citeJurabibRB->setChecked(
-               bp_.citeEngine() == ENGINE_JURABIB);
+       updateEngineType(documentClass().opt_enginetype(),
+               bp_.citeEngineType());
 
        biblioModule->bibtopicCB->setChecked(
                bp_.use_bibtopic);
@@ -2810,30 +2904,15 @@ void GuiDocument::paramsToDialog()
                latexModule->psdriverCO->setCurrentIndex(nitem);
        updateModuleInfo();
 
-       mathsModule->amsCB->setChecked(
-               bp_.use_amsmath == BufferParams::package_on);
-       mathsModule->amsautoCB->setChecked(
-               bp_.use_amsmath == BufferParams::package_auto);
-
-       mathsModule->esintCB->setChecked(
-               bp_.use_esint == BufferParams::package_on);
-       mathsModule->esintautoCB->setChecked(
-               bp_.use_esint == BufferParams::package_auto);
-
-       mathsModule->mhchemCB->setChecked(
-               bp_.use_mhchem == BufferParams::package_on);
-       mathsModule->mhchemautoCB->setChecked(
-               bp_.use_mhchem == BufferParams::package_auto);
-
-       mathsModule->mathdotsCB->setChecked(
-               bp_.use_mathdots == BufferParams::package_on);
-       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);
+       vector<string> const & packages = BufferParams::auto_packages();
+        for (size_t n = 0; n < packages.size(); ++n) {
+               QCheckBox * alwaysCB = static_cast<QCheckBox *>(
+                       mathsModule->gridLayout->itemAtPosition(2 * n + 1, 0)->widget());
+               alwaysCB->setChecked(bp_.use_package(packages[n]) == BufferParams::package_on);
+               QCheckBox * autoCB = static_cast<QCheckBox *>(
+                       mathsModule->gridLayout->itemAtPosition(2 * n, 0)->widget());
+               autoCB->setChecked(bp_.use_package(packages[n]) == BufferParams::package_auto);
+       }
 
        switch (bp_.spacing().getSpace()) {
                case Spacing::Other: nitem = 3; break;
@@ -2967,31 +3046,13 @@ void GuiDocument::paramsToDialog()
                InsetListingsParams(bp_.listings_params).separatedParams();
        listingsModule->listingsED->setPlainText(toqstr(lstparams));
 
-       // Output
-       // update combobox with formats
-       updateDefaultFormat();
-       int index = outputModule->defaultFormatCO->findData(toqstr(
-               bp_.default_output_format));
-       // set to default if format is not found
-       if (index == -1)
-               index = 0;
-       outputModule->defaultFormatCO->setCurrentIndex(index);
+       // Fonts
        bool const os_fonts_available =
                bp_.baseClass()->outputType() == lyx::LATEX
                && LaTeXFeatures::isAvailable("fontspec");
        fontModule->osFontsCB->setEnabled(os_fonts_available);
        fontModule->osFontsCB->setChecked(
                os_fonts_available && bp_.useNonTeXFonts);
-
-       outputModule->outputsyncCB->setChecked(bp_.output_sync);
-       outputModule->synccustomCB->setEditText(toqstr(bp_.output_sync_macro));
-
-       outputModule->mathimgSB->setValue(bp_.html_math_img_scale);
-       outputModule->mathoutCB->setCurrentIndex(bp_.html_math_output);
-       outputModule->strictCB->setChecked(bp_.html_be_strict);
-       outputModule->cssCB->setChecked(bp_.html_css_as_file);
-
-       // Fonts
        updateFontsize(documentClass().opt_fontsize(),
                        bp_.fontsize);
 
@@ -3058,6 +3119,26 @@ void GuiDocument::paramsToDialog()
                fontModule->fontencLE->setText(toqstr(bp_.fontenc));
        }
 
+       // Output
+       // This must be set _after_ fonts since updateDefaultFormat()
+       // checks osFontsCB settings.
+       // update combobox with formats
+       updateDefaultFormat();
+       int index = outputModule->defaultFormatCO->findData(toqstr(
+               bp_.default_output_format));
+       // set to default if format is not found
+       if (index == -1)
+               index = 0;
+       outputModule->defaultFormatCO->setCurrentIndex(index);
+
+       outputModule->outputsyncCB->setChecked(bp_.output_sync);
+       outputModule->synccustomCB->setEditText(toqstr(bp_.output_sync_macro));
+
+       outputModule->mathimgSB->setValue(bp_.html_math_img_scale);
+       outputModule->mathoutCB->setCurrentIndex(bp_.html_math_output);
+       outputModule->strictCB->setChecked(bp_.html_be_strict);
+       outputModule->cssCB->setChecked(bp_.html_css_as_file);
+
        // paper
        bool const extern_geometry =
                documentClass().provides("geometry");
@@ -3566,7 +3647,8 @@ void GuiDocument::loadModuleInfo()
                if (pos > 0)
                        desc.truncate(pos + 1);
                m.description = desc;
-               moduleNames_.push_back(m);
+               if (it->category().substr(0, 8) != "Citation")
+                       moduleNames_.push_back(m);
        }
 }