]> git.lyx.org Git - features.git/commitdiff
various listings fixes by Vincent, see http://www.mail-archive.com/lyx-devel@lists...
authorUwe Stöhr <uwestoehr@web.de>
Mon, 8 Sep 2008 21:51:38 +0000 (21:51 +0000)
committerUwe Stöhr <uwestoehr@web.de>
Mon, 8 Sep 2008 21:51:38 +0000 (21:51 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26341 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferParams.cpp
src/LaTeXFeatures.cpp
src/frontends/qt4/GuiListings.cpp
src/frontends/qt4/ui/ListingsUi.ui
src/frontends/qt4/ui/TextLayoutUi.ui
src/insets/InsetListings.cpp
src/insets/InsetListingsParams.cpp

index e470adf1faefaf69cfadf5b30c95de05cf8c1ce6..2b4e937da3861ab81d32c9492693e0f895a8d194 100644 (file)
@@ -1081,15 +1081,20 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
        // handle inputenc etc.
        writeEncodingPreamble(os, features, texrow);
 
-       if (!listings_params.empty()) {
+       if (!listings_params.empty() || features.isRequired("listings")) {
                os << "\\usepackage{listings}\n";
                texrow.newline();
+       }
+       if (!listings_params.empty()) {
                os << "\\lstset{";
                // do not test validity because listings_params is 
                // supposed to be valid
                string par =
                        InsetListingsParams(listings_params).separatedParams(true);
-               os << from_ascii(par);
+               // we can't support all packages, but we should load the color package
+               if (par.find("\\color", 0) != string::npos)
+                       features.require("color");
+               os << from_utf8(par);
                // count the number of newlines
                for (size_t i = 0; i < par.size(); ++i)
                        if (par[i] == '\n')
index 4b994e6befe29774167efe9e572a547bb49102bc..cf85ec564880e4ee7a45761877088ec115d4e162 100644 (file)
@@ -471,7 +471,7 @@ char const * simplefeatures[] = {
        "endnotes",
        "ifthen",
        "amsthm",
-       "listings",
+       // listings is handled in BufferParams.cpp
        "bm",
        "pdfpages",
        "relsize",
index 11472e7463daafe5ac2958b88a179cc581650328..38077d434cb08da1703274a01dd539fd97e8e45d 100644 (file)
@@ -228,6 +228,7 @@ GuiListings::GuiListings(GuiView & lv)
        lastlineLE->setValidator(new QIntValidator(0, 1000000, this));
        placementLE->setValidator(new QRegExpValidator(QRegExp("[\\*tbph]*"), this));
 
+       bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
        bc().setOK(okPB);
        bc().setApply(applyPB);
        bc().setCancel(closePB);
index 5b6726a2780c0050eefc592241fe75cff1dfcf15..cd7075bfcb0972865b55869759084fee208846a9 100644 (file)
               <string>Feedback window</string>
              </property>
              <property name="frameShape" >
-              <enum>QFrame::NoFrame</enum>
+              <enum>QFrame::Box</enum>
              </property>
              <property name="frameShadow" >
               <enum>QFrame::Plain</enum>
              </property>
-             <property name="lineWidth" >
-              <number>0</number>
-             </property>
              <property name="acceptRichText" >
               <bool>false</bool>
              </property>
index a34443c39c1f92f3625dca64772c20e5232eaf44..5a89db6738648408549a4a0abd546f568e854274 100644 (file)
         </property>
        </widget>
       </item>
-      <item row="0" column="1" >
+      <item row="0" column="0" >
        <widget class="QTextBrowser" name="listingsTB" >
         <property name="sizePolicy" >
          <sizepolicy>
         <property name="acceptDrops" >
          <bool>false</bool>
         </property>
+        <property name="toolTip" >
+         <string>Feedback window</string>
+        </property>
         <property name="frameShape" >
          <enum>QFrame::Box</enum>
         </property>
         </property>
        </widget>
       </item>
-      <item row="0" column="0" >
+      <item row="0" column="1" >
        <widget class="QTextEdit" name="listingsED" >
         <property name="sizePolicy" >
          <sizepolicy>
index 93b1931f533c710f70220a4e758d49c8afa2da2a..38dc99c1e02b240522f62d6ff6412ac8d1b740d2 100644 (file)
@@ -228,7 +228,7 @@ int InsetListings::latex(odocstream & os, OutputParams const & runparams) const
                if (param_string.empty())
                        os << "\\lstinline" << *delimiter;
                else
-                       os << "\\lstinline[" << from_ascii(param_string) << "]" << *delimiter;
+                       os << "\\lstinline[" << from_utf8(param_string) << "]" << *delimiter;
                 os << code
                    << *delimiter;
        } else {
@@ -326,6 +326,9 @@ void InsetListings::setButtonLabel()
 void InsetListings::validate(LaTeXFeatures & features) const
 {
        features.require("listings");
+       string param_string = params().params();
+       if (param_string.find("\\color") != string::npos)
+               features.require("color");
        InsetCollapsable::validate(features);
 }
 
index 2c87a4095c941e2a72eefca0544cab622b7f4dda..99ecbb0fdfac1d60f7b198d26797f108406c9ab7 100644 (file)
@@ -99,13 +99,19 @@ docstring ListingsParam::validate(string const & par) const
        bool unclosed = false;
        string par2 = par;
        // braces are allowed
-       if (prefixIs(par, "{") && suffixIs(par, "}"))
+       if (prefixIs(par, "{") && suffixIs(par, "}") && !suffixIs(par, "\\}"))  
                par2 = par.substr(1, par.size() - 2);
-       else if (prefixIs(par, "{")) {
-               par2 = par.substr(1);
-               unclosed = true;
-       }
 
+       // check for unmatched braces
+       int braces = 0;
+       for (size_t i = 0; i < par2.size(); ++i) {
+               if (par2[i] == '{' && (i == 0 || par2[i-1] != '\\'))
+                       ++braces;
+               else if (par2[i] == '}' && (i == 0 || par2[i-1] != '\\'))
+                       --braces;
+       }
+       unclosed = braces != 0;
+       
        switch (type_) {
 
        case ALL:
@@ -116,7 +122,7 @@ docstring ListingsParam::validate(string const & par) const
                                return _("A value is expected.");
                }
                if (unclosed)
-                               return _("Unbalanced braces!");
+                       return _("Unbalanced braces!");
                return docstring();
 
        case TRUEFALSE:
@@ -795,11 +801,12 @@ void InsetListingsParams::addParams(string const & par)
                } else if (par[i] == '=' && braces == 0) {
                        isValue = true;
                        continue;
-               } else if (par[i] == '{' && i > 0 && par[i - 1] == '=')
-                       braces ++;
-               else if (par[i] == '}'
-                       && (i == par.size() - 1 || par[i + 1] == ',' || par[i + 1] == '\n'))
-                       braces --;
+               } else if (par[i] == '{' && i > 0 && par[i-1] != '\\')
+                       // don't count a brace in first position
+                       ++braces;
+               else if (par[i] == '}' && i != par.size() - 1 
+                        && (i == 0 || (i > 0 && par[i-1] != '\\')))
+                       --braces;
 
                if (isValue)
                        value += par[i];