git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26341 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Uwe Stöhr 2008-09-08 21:51:38 +00:00
parent 19c8baa1e1
commit eb963540d4
7 changed files with 37 additions and 21 deletions

View File

@ -1081,15 +1081,20 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
// handle inputenc etc. // handle inputenc etc.
writeEncodingPreamble(os, features, texrow); writeEncodingPreamble(os, features, texrow);
if (!listings_params.empty()) { if (!listings_params.empty() || features.isRequired("listings")) {
os << "\\usepackage{listings}\n"; os << "\\usepackage{listings}\n";
texrow.newline(); texrow.newline();
}
if (!listings_params.empty()) {
os << "\\lstset{"; os << "\\lstset{";
// do not test validity because listings_params is // do not test validity because listings_params is
// supposed to be valid // supposed to be valid
string par = string par =
InsetListingsParams(listings_params).separatedParams(true); 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 // count the number of newlines
for (size_t i = 0; i < par.size(); ++i) for (size_t i = 0; i < par.size(); ++i)
if (par[i] == '\n') if (par[i] == '\n')

View File

@ -471,7 +471,7 @@ char const * simplefeatures[] = {
"endnotes", "endnotes",
"ifthen", "ifthen",
"amsthm", "amsthm",
"listings", // listings is handled in BufferParams.cpp
"bm", "bm",
"pdfpages", "pdfpages",
"relsize", "relsize",

View File

@ -228,6 +228,7 @@ GuiListings::GuiListings(GuiView & lv)
lastlineLE->setValidator(new QIntValidator(0, 1000000, this)); lastlineLE->setValidator(new QIntValidator(0, 1000000, this));
placementLE->setValidator(new QRegExpValidator(QRegExp("[\\*tbph]*"), this)); placementLE->setValidator(new QRegExpValidator(QRegExp("[\\*tbph]*"), this));
bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
bc().setOK(okPB); bc().setOK(okPB);
bc().setApply(applyPB); bc().setApply(applyPB);
bc().setCancel(closePB); bc().setCancel(closePB);

View File

@ -545,14 +545,11 @@
<string>Feedback window</string> <string>Feedback window</string>
</property> </property>
<property name="frameShape" > <property name="frameShape" >
<enum>QFrame::NoFrame</enum> <enum>QFrame::Box</enum>
</property> </property>
<property name="frameShadow" > <property name="frameShadow" >
<enum>QFrame::Plain</enum> <enum>QFrame::Plain</enum>
</property> </property>
<property name="lineWidth" >
<number>0</number>
</property>
<property name="acceptRichText" > <property name="acceptRichText" >
<bool>false</bool> <bool>false</bool>
</property> </property>

View File

@ -131,7 +131,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1" > <item row="0" column="0" >
<widget class="QTextBrowser" name="listingsTB" > <widget class="QTextBrowser" name="listingsTB" >
<property name="sizePolicy" > <property name="sizePolicy" >
<sizepolicy> <sizepolicy>
@ -147,6 +147,9 @@
<property name="acceptDrops" > <property name="acceptDrops" >
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="toolTip" >
<string>Feedback window</string>
</property>
<property name="frameShape" > <property name="frameShape" >
<enum>QFrame::Box</enum> <enum>QFrame::Box</enum>
</property> </property>
@ -158,7 +161,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0" > <item row="0" column="1" >
<widget class="QTextEdit" name="listingsED" > <widget class="QTextEdit" name="listingsED" >
<property name="sizePolicy" > <property name="sizePolicy" >
<sizepolicy> <sizepolicy>

View File

@ -228,7 +228,7 @@ int InsetListings::latex(odocstream & os, OutputParams const & runparams) const
if (param_string.empty()) if (param_string.empty())
os << "\\lstinline" << *delimiter; os << "\\lstinline" << *delimiter;
else else
os << "\\lstinline[" << from_ascii(param_string) << "]" << *delimiter; os << "\\lstinline[" << from_utf8(param_string) << "]" << *delimiter;
os << code os << code
<< *delimiter; << *delimiter;
} else { } else {
@ -326,6 +326,9 @@ void InsetListings::setButtonLabel()
void InsetListings::validate(LaTeXFeatures & features) const void InsetListings::validate(LaTeXFeatures & features) const
{ {
features.require("listings"); features.require("listings");
string param_string = params().params();
if (param_string.find("\\color") != string::npos)
features.require("color");
InsetCollapsable::validate(features); InsetCollapsable::validate(features);
} }

View File

@ -99,13 +99,19 @@ docstring ListingsParam::validate(string const & par) const
bool unclosed = false; bool unclosed = false;
string par2 = par; string par2 = par;
// braces are allowed // braces are allowed
if (prefixIs(par, "{") && suffixIs(par, "}")) if (prefixIs(par, "{") && suffixIs(par, "}") && !suffixIs(par, "\\}"))
par2 = par.substr(1, par.size() - 2); 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_) { switch (type_) {
case ALL: case ALL:
@ -116,7 +122,7 @@ docstring ListingsParam::validate(string const & par) const
return _("A value is expected."); return _("A value is expected.");
} }
if (unclosed) if (unclosed)
return _("Unbalanced braces!"); return _("Unbalanced braces!");
return docstring(); return docstring();
case TRUEFALSE: case TRUEFALSE:
@ -795,11 +801,12 @@ void InsetListingsParams::addParams(string const & par)
} else if (par[i] == '=' && braces == 0) { } else if (par[i] == '=' && braces == 0) {
isValue = true; isValue = true;
continue; continue;
} else if (par[i] == '{' && i > 0 && par[i - 1] == '=') } else if (par[i] == '{' && i > 0 && par[i-1] != '\\')
braces ++; // don't count a brace in first position
else if (par[i] == '}' ++braces;
&& (i == par.size() - 1 || par[i + 1] == ',' || par[i + 1] == '\n')) else if (par[i] == '}' && i != par.size() - 1
braces --; && (i == 0 || (i > 0 && par[i-1] != '\\')))
--braces;
if (isValue) if (isValue)
value += par[i]; value += par[i];