]> git.lyx.org Git - features.git/blobdiff - src/frontends/qt4/GuiDocument.cpp
Properly warn on missing pygmentize command
[features.git] / src / frontends / qt4 / GuiDocument.cpp
index 9d45890e9d119ff640f03db3eaef5e30e0475f25..c21ce4f0775767f0c787e168120d955ceaad86ea 100644 (file)
@@ -135,6 +135,12 @@ char const * backref_opts_gui[] =
 };
 
 
+char const * lst_packages[] =
+{
+       "Listings", "Minted", ""
+};
+
+
 vector<string> engine_types_;
 vector<pair<string, QString> > pagestyles;
 
@@ -177,7 +183,7 @@ public:
        }
 };
 
-}
+} // namespace
 
 namespace frontend {
 namespace {
@@ -724,27 +730,6 @@ GuiDocument::GuiDocument(GuiView & lv)
        connect(textLayoutModule->justCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
 
-       connect(textLayoutModule->MathIndentCB, SIGNAL(toggled(bool)),
-               this, SLOT(change_adaptor()));
-       connect(textLayoutModule->MathIndentCB, SIGNAL(toggled(bool)),
-               this, SLOT(allowMathIndent()));
-       connect(textLayoutModule->MathIndentCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(textLayoutModule->MathIndentCO, SIGNAL(activated(int)),
-               this, SLOT(setMathIndent(int)));
-       connect(textLayoutModule->MathIndentLE, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor()));
-       connect(textLayoutModule->MathIndentLengthCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-
-       
-       textLayoutModule->MathIndentCO->addItem(qt_("Default"));
-       textLayoutModule->MathIndentCO->addItem(qt_("Custom"));
-       textLayoutModule->MathIndentLE->setValidator(new LengthValidator(
-               textLayoutModule->MathIndentLE));
-       // initialize the length validator
-       bc().addCheckedLineEdit(textLayoutModule->MathIndentLE);
-       
        textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
                textLayoutModule->lspacingLE));
        textLayoutModule->indentLE->setValidator(new LengthValidator(
@@ -1279,7 +1264,34 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(change_adaptor()));
        connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
-       
+       connect(mathsModule->MathNumberingPosCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+
+       connect(mathsModule->MathIndentCB, SIGNAL(toggled(bool)),
+               this, SLOT(change_adaptor()));
+       connect(mathsModule->MathIndentCB, SIGNAL(toggled(bool)),
+               this, SLOT(allowMathIndent()));
+       connect(mathsModule->MathIndentCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(mathsModule->MathIndentCO, SIGNAL(activated(int)),
+               this, SLOT(enableMathIndent(int)));
+       connect(mathsModule->MathIndentLE, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor()));
+       connect(mathsModule->MathIndentLengthCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+
+
+       mathsModule->MathIndentCO->addItem(qt_("Default"));
+       mathsModule->MathIndentCO->addItem(qt_("Custom"));
+       mathsModule->MathIndentLE->setValidator(new LengthValidator(
+               mathsModule->MathIndentLE));
+       // initialize the length validator
+       bc().addCheckedLineEdit(mathsModule->MathIndentLE);
+       mathsModule->MathNumberingPosCO->addItem(qt_("Left"));
+       mathsModule->MathNumberingPosCO->addItem(qt_("Default"));
+       mathsModule->MathNumberingPosCO->addItem(qt_("Right"));
+       mathsModule->MathNumberingPosCO->setCurrentIndex(1);
+
 
        // latex class
        latexModule = new UiWidget<Ui::LaTeXUi>(this);
@@ -1455,11 +1467,18 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(change_adaptor()));
        connect(listingsModule->bypassCB, SIGNAL(clicked()),
                this, SLOT(setListingsMessage()));
+       connect(listingsModule->packageCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(listingsModule->packageCO, SIGNAL(activated(int)),
+               this, SLOT(listingsPackageChanged(int)));
        connect(listingsModule->listingsED, SIGNAL(textChanged()),
                this, SLOT(setListingsMessage()));
        listingsModule->listingsTB->setPlainText(
                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]);
+
 
        // add the panels
        docPS->addPanel(latexModule, N_("Document Class"));
@@ -1542,8 +1561,12 @@ QString GuiDocument::validateListingsParameters()
 {
        if (listingsModule->bypassCB->isChecked())
                return QString();
+       string const package =
+           lst_packages[listingsModule->packageCO->currentIndex()];
        string params = fromqstr(listingsModule->listingsED->toPlainText());
-       return toqstr(InsetListingsParams(params).validate());
+       InsetListingsParams lstparams(params);
+       lstparams.setMinted(package == "Minted");
+       return toqstr(lstparams.validate());
 }
 
 
@@ -1568,6 +1591,22 @@ void GuiDocument::setListingsMessage()
 }
 
 
+void GuiDocument::listingsPackageChanged(int index)
+{
+        string const package = lst_packages[index];
+        if (package == "Minted" && lyxrc.pygmentize_command.empty()) {
+                Alert::warning(_("Pygments driver command not found!"),
+                    _("The driver command necessary to use the minted package\n"
+                      "(pygmentize) has not been found. Make sure you have\n"
+                      "the python-pygments module installed or, if the driver\n"
+                      "is named differently, to add the following line to the\n"
+                      "document preamble:\n\n"
+                      "\\AtBeginDocument{\\renewcommand{\\MintedPygmentize}{driver}}\n\n"
+                      "where 'driver' is name of the driver command."));
+        }
+}
+
+
 void GuiDocument::setLSpacing(int item)
 {
        textLayoutModule->lspacingLE->setEnabled(item == 3);
@@ -1613,23 +1652,23 @@ void GuiDocument::enableSkip(bool skip)
 
 void GuiDocument::allowMathIndent() {
        // only disable when not checked, checked does not always allow enabling
-       if (!textLayoutModule->MathIndentCB->isChecked()) {
-               textLayoutModule->MathIndentLE->setEnabled(false);
-               textLayoutModule->MathIndentLengthCO->setEnabled(false);
+       if (!mathsModule->MathIndentCB->isChecked()) {
+               mathsModule->MathIndentLE->setEnabled(false);
+               mathsModule->MathIndentLengthCO->setEnabled(false);
        }
-       if (textLayoutModule->MathIndentCB->isChecked()
-           && textLayoutModule->MathIndentCO->currentIndex() == 1) {
-                       textLayoutModule->MathIndentLE->setEnabled(true);
-                       textLayoutModule->MathIndentLengthCO->setEnabled(true);
+       if (mathsModule->MathIndentCB->isChecked()
+           && mathsModule->MathIndentCO->currentIndex() == 1) {
+                       mathsModule->MathIndentLE->setEnabled(true);
+                       mathsModule->MathIndentLengthCO->setEnabled(true);
        }
        isValid();
 }
 
-void GuiDocument::setMathIndent(int item)
+void GuiDocument::enableMathIndent(int item)
 {
        bool const enable = (item == 1);
-       textLayoutModule->MathIndentLE->setEnabled(enable);
-       textLayoutModule->MathIndentLengthCO->setEnabled(enable);
+       mathsModule->MathIndentLE->setEnabled(enable);
+       mathsModule->MathIndentLengthCO->setEnabled(enable);
        isValid();
 }
 
@@ -2915,13 +2954,42 @@ void GuiDocument::applyView()
                if (rb->isChecked())
                        bp_.use_package(it->first, BufferParams::package_off);
        }
-       bp_.is_math_indent = textLayoutModule->MathIndentCB->isChecked();
        // if math is indented
+       bp_.is_math_indent = mathsModule->MathIndentCB->isChecked();
        if (bp_.is_math_indent) {
-               Length mathindent(widgetsToLength(textLayoutModule->MathIndentLE,
-                                                 textLayoutModule->MathIndentLengthCO));
-               bp_.setMathIndent(mathindent);
+               // if formulas are indented
+               switch (mathsModule->MathIndentCO->currentIndex()) {
+               case 0:
+                       bp_.setMathIndent(Length());
+                       break;
+               case 1: {
+                       Length mathindent(widgetsToLength(mathsModule->MathIndentLE,
+                                                         mathsModule->MathIndentLengthCO));
+                       bp_.setMathIndent(mathindent);
+                       break;
+               }
+               default:
+                       // this should never happen
+                       bp_.setMathIndent(Length());
+                       break;
+               }
        }
+       switch (mathsModule->MathNumberingPosCO->currentIndex()) {
+               case 0:
+                       bp_.math_numbering_side = BufferParams::LEFT;
+                       break;
+               case 1:
+                       bp_.math_numbering_side = BufferParams::DEFAULT;
+                       break;
+               case 2:
+                       bp_.math_numbering_side = BufferParams::RIGHT;
+                       break;
+               default:
+                       // this should never happen
+                       bp_.math_numbering_side = BufferParams::DEFAULT;
+                       break;
+       }
+
        // Page Layout
        if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
                bp_.pagestyle = "default";
@@ -3007,25 +3075,6 @@ void GuiDocument::applyView()
                }
        }
 
-       if (textLayoutModule->MathIndentCB->isChecked()) {
-               // if formulas are indented
-               switch (textLayoutModule->MathIndentCO->currentIndex()) {
-               case 0:
-                       bp_.setMathIndent(Length());
-                       break;
-               case 1: {
-                       Length mathindent(widgetsToLength(textLayoutModule->MathIndentLE,
-                                                         textLayoutModule->MathIndentLengthCO));
-                       bp_.setMathIndent(mathindent);
-                       break;
-               }
-               default:
-                       // this should never happen
-                       bp_.setMathIndent(Length());
-                       break;
-               }
-       }
-
        bp_.options =
                fromqstr(latexModule->optionsLE->text());
 
@@ -3054,6 +3103,8 @@ void GuiDocument::applyView()
 
        // Listings
        // text should have passed validation
+       idx = listingsModule->packageCO->currentIndex();
+       bp_.use_minted = string(lst_packages[idx]) == "Minted";
        bp_.listings_params =
                InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
 
@@ -3282,7 +3333,7 @@ void GuiDocument::paramsToDialog()
        biblioChanged_ = false;
 
        // indices
-       // We may be called when there is no Buffer, e.g., when 
+       // We may be called when there is no Buffer, e.g., when
        // the last view has just been closed.
        bool const isReadOnly = isBufferAvailable() ? buffer().isReadonly() : false;
        indicesModule->update(bp_, isReadOnly);
@@ -3390,18 +3441,28 @@ void GuiDocument::paramsToDialog()
        updateModuleInfo();
 
        // math
+       mathsModule->MathIndentCB->setChecked(bp_.is_math_indent);
        if (bp_.is_math_indent) {
-               textLayoutModule->MathIndentCB->setChecked(bp_.is_math_indent);
                Length const mathindent = bp_.getMathIndent();
                int indent = 0;
                if (!mathindent.empty()) {
-                       lengthToWidgets(textLayoutModule->MathIndentLE,
-                                       textLayoutModule->MathIndentLengthCO,
+                       lengthToWidgets(mathsModule->MathIndentLE,
+                                       mathsModule->MathIndentLengthCO,
                                        mathindent, default_unit);
                        indent = 1;
                }
-               textLayoutModule->MathIndentCO->setCurrentIndex(indent);
-               setMathIndent(indent);
+               mathsModule->MathIndentCO->setCurrentIndex(indent);
+               enableMathIndent(indent);
+       }
+       switch(bp_.math_numbering_side) {
+       case BufferParams::LEFT:
+               mathsModule->MathNumberingPosCO->setCurrentIndex(0);
+               break;
+       case BufferParams::DEFAULT:
+               mathsModule->MathNumberingPosCO->setCurrentIndex(1);
+               break;
+       case BufferParams::RIGHT:
+               mathsModule->MathNumberingPosCO->setCurrentIndex(2);
        }
 
        map<string, string> const & packages = BufferParams::auto_packages();
@@ -3561,6 +3622,10 @@ void GuiDocument::paramsToDialog()
        string lstparams =
                InsetListingsParams(bp_.listings_params).separatedParams();
        listingsModule->listingsED->setPlainText(toqstr(lstparams));
+       int nn = findToken(lst_packages, bp_.use_minted ? "Minted" : "Listings");
+       if (nn >= 0)
+               listingsModule->packageCO->setCurrentIndex(nn);
+
 
        // Fonts
        // some languages only work with polyglossia/XeTeX
@@ -3632,7 +3697,7 @@ void GuiDocument::paramsToDialog()
                        toqstr(bp_.fonts_cjk));
        else
                fontModule->cjkFontLE->setText(QString());
-       
+
        fontModule->microtypeCB->setChecked(bp_.use_microtype);
        fontModule->dashesCB->setChecked(bp_.use_dash_ligatures);
 
@@ -3643,7 +3708,7 @@ void GuiDocument::paramsToDialog()
        fontModule->scaleTypewriterSB->setValue(bp_.fontsTypewriterScale());
        fontModule->font_tt_scale = bp_.fonts_typewriter_scale[!bp_.useNonTeXFonts];
 
-       int nn = findToken(GuiDocument::fontfamilies, bp_.fonts_default_family);
+       nn = findToken(GuiDocument::fontfamilies, bp_.fonts_default_family);
        if (nn >= 0)
                fontModule->fontsDefaultCO->setCurrentIndex(nn);
 
@@ -4070,12 +4135,12 @@ bool GuiDocument::isValid()
                        !textLayoutModule->indentLE->text().isEmpty()
                ) &&
                (
-                       // if we're asking for indentation
-                       !textLayoutModule->MathIndentCB->isChecked() ||
+                       // if we're asking for math indentation
+                       !mathsModule->MathIndentCB->isChecked() ||
                        // then either we haven't chosen custom
-                       textLayoutModule->MathIndentCO->currentIndex() != 1 ||
+                       mathsModule->MathIndentCO->currentIndex() != 1 ||
                        // or else a length has been given
-                       !textLayoutModule->MathIndentLE->text().isEmpty()
+                       !mathsModule->MathIndentLE->text().isEmpty()
                );
 }