]> 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 e5f51568a32720f8c30ad05f3c5993f2f462281f..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 {
@@ -1274,7 +1280,7 @@ GuiDocument::GuiDocument(GuiView & lv)
        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(
@@ -1285,7 +1291,7 @@ GuiDocument::GuiDocument(GuiView & lv)
        mathsModule->MathNumberingPosCO->addItem(qt_("Default"));
        mathsModule->MathNumberingPosCO->addItem(qt_("Right"));
        mathsModule->MathNumberingPosCO->setCurrentIndex(1);
-       
+
 
        // latex class
        latexModule = new UiWidget<Ui::LaTeXUi>(this);
@@ -1461,13 +1467,18 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(change_adaptor()));
        connect(listingsModule->bypassCB, SIGNAL(clicked()),
                this, SLOT(setListingsMessage()));
-       connect(listingsModule->mintedCB, SIGNAL(clicked()),
+       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"));
@@ -1550,9 +1561,11 @@ QString GuiDocument::validateListingsParameters()
 {
        if (listingsModule->bypassCB->isChecked())
                return QString();
+       string const package =
+           lst_packages[listingsModule->packageCO->currentIndex()];
        string params = fromqstr(listingsModule->listingsED->toPlainText());
        InsetListingsParams lstparams(params);
-       lstparams.setMinted(listingsModule->mintedCB->isChecked());
+       lstparams.setMinted(package == "Minted");
        return toqstr(lstparams.validate());
 }
 
@@ -1578,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);
@@ -3074,7 +3103,8 @@ void GuiDocument::applyView()
 
        // Listings
        // text should have passed validation
-       bp_.use_minted  = listingsModule->mintedCB->isChecked();
+       idx = listingsModule->packageCO->currentIndex();
+       bp_.use_minted = string(lst_packages[idx]) == "Minted";
        bp_.listings_params =
                InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
 
@@ -3303,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);
@@ -3592,7 +3622,9 @@ void GuiDocument::paramsToDialog()
        string lstparams =
                InsetListingsParams(bp_.listings_params).separatedParams();
        listingsModule->listingsED->setPlainText(toqstr(lstparams));
-       listingsModule->mintedCB->setChecked(bp_.use_minted);
+       int nn = findToken(lst_packages, bp_.use_minted ? "Minted" : "Listings");
+       if (nn >= 0)
+               listingsModule->packageCO->setCurrentIndex(nn);
 
 
        // Fonts
@@ -3665,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);
 
@@ -3676,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);