]> git.lyx.org Git - lyx.git/commitdiff
Use a combo box instead of a check box for selecting the listings package
authorEnrico Forestieri <forenr@lyx.org>
Mon, 12 Jun 2017 15:24:26 +0000 (17:24 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Mon, 12 Jun 2017 15:24:26 +0000 (17:24 +0200)
lib/configure.py
lib/doc/EmbeddedObjects.lyx
lib/scripts/prefs2prefs_prefs.py
src/LyXRC.cpp
src/LyXRC.h
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiDocument.h
src/frontends/qt4/ui/ListingsSettingsUi.ui

index 1ce081cd074389f76a8a51bc63ae710ee77b9d2c..8e7fedbb5ad0aba5c07ea3808455b28a5cae010b 100644 (file)
@@ -1203,6 +1203,8 @@ def checkOtherEntries():
         'splitindex.class'], rc_entry = [ r'\splitindex_command "%%"' ])
     checkProg('a nomenclature processor', ['makeindex'],
         rc_entry = [ r'\nomencl_command "makeindex -s nomencl.ist"' ])
+    checkProg('a python-pygments driver command', ['pygmentize'],
+        rc_entry = [ r'\pygmentize_command "%%"' ])
     ## FIXME: OCTAVE is not used anywhere
     # path, OCTAVE = checkProg('Octave', ['octave'])
     ## FIXME: MAPLE is not used anywhere
@@ -1756,7 +1758,7 @@ if __name__ == '__main__':
     lyx_check_config = True
     lyx_kpsewhich = True
     outfile = 'lyxrc.defaults'
-    lyxrc_fileformat = 21
+    lyxrc_fileformat = 22
     rc_entries = ''
     lyx_keep_temps = False
     version_suffix = ''
index 8708ca69b79d8ae64570f446d26234ef4fac23cc..c46d72276d53d120d051d9b0c935437da1dad9af 100644 (file)
 \change_unchanged
  a powerful and flexible way to insert program source code into your document.
 
-\change_inserted 5863344 1497178383
+\change_inserted 5863344 1497280755
  You can use either one in a document, but listings is used by default.
- In order to use minted, you need to check the box 
-\begin_inset Quotes eld
-\end_inset
-
-Use minted
-\begin_inset Quotes erd
-\end_inset
-
- in Document\SpecialChar menuseparator
+ In order to use minted, you need to select it as the syntax highlighting
+ package in Document\SpecialChar menuseparator
 Settings\SpecialChar menuseparator
 Listings.
  However, note that minted requires additional software (the pygments python
index b4acdc74d3c61512b5dc148351a98727c4465cf4..68b4d837dc2bdd01e6702999c3d6cd4c4e0c5a9c 100644 (file)
 #   default now)
 #   No conversion necessary.
 
+# Incremented to format 22, by ef
+#   Add pygmentize_command for the python pygments syntax highlighter
+#   No conversion necessary.
+
 # NOTE: The format should also be updated in LYXRC.cpp and
 # in configure.py.
 
@@ -387,5 +391,6 @@ conversions = [
        [ 18, []],
        [ 19, [remove_print_support]],
        [ 20, []],
-       [ 21, []]
+       [ 21, []],
+       [ 22, []]
 ]
index ae3569096ee9dacc8548451152cc0a95c65112e4..e6244f2d2ba03189d2ea8f0b015eb1f7dbd7f3a3 100644 (file)
@@ -59,7 +59,7 @@ namespace {
 
 // The format should also be updated in configure.py, and conversion code
 // should be added to prefs2prefs_prefs.py.
-static unsigned int const LYXRC_FILEFORMAT = 21; // spitz: jbibtex_alternatives
+static unsigned int const LYXRC_FILEFORMAT = 22; // ef: pygmentize_command
 
 // when adding something to this array keep it sorted!
 LexerKeyword lyxrcTags[] = {
@@ -158,6 +158,7 @@ LexerKeyword lyxrcTags[] = {
        { "\\print_landscape_flag", LyXRC::RC_PRINTLANDSCAPEFLAG },
        { "\\print_paper_dimension_flag", LyXRC::RC_PRINTPAPERDIMENSIONFLAG },
        { "\\print_paper_flag", LyXRC::RC_PRINTPAPERFLAG },
+       { "\\pygmentize_command", LyXRC::RC_PYGMENTIZE_COMMAND },
        { "\\save_compressed", LyXRC::RC_SAVE_COMPRESSED },
        { "\\save_origin", LyXRC::RC_SAVE_ORIGIN },
        { "\\screen_dpi", LyXRC::RC_SCREEN_DPI },
@@ -241,6 +242,7 @@ void LyXRC::setDefaults()
        fontenc = "default";
        index_command = "makeindex -c -q";
        nomencl_command = "makeindex -s nomencl.ist";
+       pygmentize_command = string();
        dpi = 75;
        // Because a screen is typically wider than a piece of paper:
        zoom = 150;
@@ -544,6 +546,12 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
                        lexrc >> print_paper_flag;
                        break;
 
+               case RC_PYGMENTIZE_COMMAND:
+                       if (lexrc.next(true)) {
+                               pygmentize_command = lexrc.getString();
+                       }
+                       break;
+
                case RC_VIEWDVI_PAPEROPTION:
                        if (lexrc.next())
                                view_dvi_paper_option = lexrc.getString();
@@ -1501,6 +1509,13 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
                }
                if (tag != RC_LAST)
                        break;
+       case RC_PYGMENTIZE_COMMAND:
+               if (ignore_system_lyxrc ||
+                   pygmentize_command != system_lyxrc.pygmentize_command) {
+                       os << "\\pygmentize_command \"" << escapeCommand(pygmentize_command) << "\"\n";
+               }
+               if (tag != RC_LAST)
+                       break;
        case RC_TEX_EXPECTS_WINDOWS_PATHS:
                // Don't write this setting to the preferences file,
                // but allow temporary changes (bug 7557).
@@ -2809,6 +2824,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_JBIBTEX_ALTERNATIVES:
        case LyXRC::RC_JINDEX_COMMAND:
        case LyXRC::RC_NOMENCL_COMMAND:
+       case LyXRC::RC_PYGMENTIZE_COMMAND:
        case LyXRC::RC_INPUT:
        case LyXRC::RC_KBMAP:
        case LyXRC::RC_KBMAP_PRIMARY:
@@ -3067,6 +3083,10 @@ string const LyXRC::getDescription(LyXRCTags tag)
                str = _("Define the options of makeindex (cf. man makeindex) to be used for nomenclatures. This might differ from the index processing options.");
                break;
 
+       case RC_PYGMENTIZE_COMMAND:
+               str = _("The command to run the python pygments syntax highlighter.");
+               break;
+
        case RC_INPUT:
                break;
 
index c7207048c2aebc832cd99c5103c67d5157f9e527..38fcd3739490f3f220d750ffbf684ab5c9a9c707 100644 (file)
@@ -133,6 +133,7 @@ public:
                RC_PRINTLANDSCAPEFLAG,
                RC_PRINTPAPERDIMENSIONFLAG,
                RC_PRINTPAPERFLAG,
+               RC_PYGMENTIZE_COMMAND,
                RC_SAVE_COMPRESSED,
                RC_SAVE_ORIGIN,
                RC_SCREEN_DPI,
@@ -253,6 +254,8 @@ public:
        std::string splitindex_command;
        /// command to run makeindex incl. options for nomencl
        std::string nomencl_command;
+       /// command to run the python pygments syntax highlighter
+       std::string pygmentize_command;
        ///
        std::string document_path;
        ///
index e5f51568a32720f8c30ad05f3c5993f2f462281f..8d09e591a28e7a9f5624f4967ed580365ca4f834 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;
 
@@ -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(currentIndexChanged(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();
 
@@ -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
@@ -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);
 
index b5e09d3ec4cea0fecdcc16cdce6438a4992977e7..0c39bf8f917cb3458e4dcbefc1ccd9204e2477a9 100644 (file)
@@ -92,6 +92,7 @@ private Q_SLOTS:
        void change_adaptor();
        void includeonlyClicked(QTreeWidgetItem * item, int);
        void setListingsMessage();
+       void listingsPackageChanged(int);
        void saveDefaultClicked();
        void useDefaultsClicked();
        void setLSpacing(int);
index 66f8ca073447e9bd67b1bd48a10ce0b7208e2bde..22c3453ee0f0d5b630cac4c45bbcd6a671c1cf58 100644 (file)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>219</width>
-    <height>256</height>
+    <width>281</width>
+    <height>282</height>
    </rect>
   </property>
   <property name="windowTitle">
      </property>
     </widget>
    </item>
-   <item row="3" column="0">
-    <widget class="QCheckBox" name="mintedCB">
-     <property name="toolTip">
-      <string>Use the minted package instead of the listings one</string>
-     </property>
-     <property name="text">
-      <string>Use &amp;minted</string>
-     </property>
-    </widget>
-   </item>
    <item row="2" column="0">
     <widget class="QCheckBox" name="bypassCB">
      <property name="toolTip">
      </property>
     </widget>
    </item>
+   <item row="3" column="0" rowspan="2">
+    <widget class="QGroupBox" name="packageGB">
+     <layout class="QHBoxLayout" name="horizontalLayout">
+      <item>
+       <widget class="QLabel" name="packageLBL">
+        <property name="toolTip">
+         <string>Choose the LaTeX package for code syntax highlighting</string>
+        </property>
+        <property name="text">
+         <string>&amp;Syntax Highlighting Package:</string>
+        </property>
+        <property name="buddy">
+         <cstring>packageCO</cstring>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QComboBox" name="packageCO"/>
+      </item>
+      <item>
+       <spacer name="horizontalSpacer">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>40</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+     </layout>
+    </widget>
+   </item>
   </layout>
  </widget>
  <includes>