Hi,
 
I reworked some things which resulted in this new patch.
 
The patch contains now the following:
 
- It prevents that the package "listings" is included twice. 
- Corrected parsing of the Listings settings. When the following setting was 
parsed: 'backgroundcolor=\color{red}'; the last brace wasn't counted, which 
lead to the conversion errors and the '\n' error (solving part of bug 4884). 
- The widgets in Document Settings->Listings Settings are switched. The text in 
the feedback window said that you had to enter the text at the right, while the 
text edit widget was on the left.
- I gave both the InsetListing Settings UI and the Document Settings->Listings 
Settings UI the same appearance. 
- I replaced twice from_ascii into from_utf8, to be able to specify a title 
with non-ascii characters without causing LyX to crash (as discussed in bug 
5221).
- The color package is now automatically included when you either specify a 
color in the global settings or in the insetListing settings (also a reason why 
the test file of Georg in bug 4884 did not compile).
 
At home I had indeed an older package of listings, but everything works fine 
for me now.
 
Vincent
Index: src/BufferParams.cpp
===================================================================
--- src/BufferParams.cpp        (revision 26301)
+++ src/BufferParams.cpp        (working copy)
@@ -1081,15 +1081,20 @@
        // 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: src/insets/InsetListings.cpp
===================================================================
--- src/insets/InsetListings.cpp        (revision 26301)
+++ src/insets/InsetListings.cpp        (working copy)
@@ -228,7 +228,7 @@
                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::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: src/insets/InsetListingsParams.cpp
===================================================================
--- src/insets/InsetListingsParams.cpp  (revision 26301)
+++ src/insets/InsetListingsParams.cpp  (working copy)
@@ -795,11 +795,10 @@
                } 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)
+                       ++braces;
+               else if (par[i] == '}' && (i != par.size() - 1))
+                       --braces;
 
                if (isValue)
                        value += par[i];
Index: src/frontends/qt4/ui/TextLayoutUi.ui
===================================================================
--- src/frontends/qt4/ui/TextLayoutUi.ui        (revision 26301)
+++ src/frontends/qt4/ui/TextLayoutUi.ui        (working copy)
@@ -131,7 +131,7 @@
         </property>
        </widget>
       </item>
-      <item row="0" column="1" >
+      <item row="0" column="0" >
        <widget class="QTextBrowser" name="listingsTB" >
         <property name="sizePolicy" >
          <sizepolicy>
@@ -147,6 +147,9 @@
         <property name="acceptDrops" >
          <bool>false</bool>
         </property>
+        <property name="toolTip" >
+         <string>Feedback window</string>
+        </property>
         <property name="frameShape" >
          <enum>QFrame::Box</enum>
         </property>
@@ -158,7 +161,7 @@
         </property>
        </widget>
       </item>
-      <item row="0" column="0" >
+      <item row="0" column="1" >
        <widget class="QTextEdit" name="listingsED" >
         <property name="sizePolicy" >
          <sizepolicy>
Index: src/frontends/qt4/ui/ListingsUi.ui
===================================================================
--- src/frontends/qt4/ui/ListingsUi.ui  (revision 26301)
+++ src/frontends/qt4/ui/ListingsUi.ui  (working copy)
@@ -545,14 +545,11 @@
               <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: src/LaTeXFeatures.cpp
===================================================================
--- src/LaTeXFeatures.cpp       (revision 26301)
+++ src/LaTeXFeatures.cpp       (working copy)
@@ -471,7 +471,7 @@
        "endnotes",
        "ifthen",
        "amsthm",
-       "listings",
+       // listings is handled in BufferParams.cpp
        "bm",
        "pdfpages",
        "relsize",

Reply via email to