mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-03 16:31:13 +00:00
various listings fixes by Vincent, see http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg143302.html
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26341 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
19c8baa1e1
commit
eb963540d4
@ -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')
|
||||
|
@ -471,7 +471,7 @@ char const * simplefeatures[] = {
|
||||
"endnotes",
|
||||
"ifthen",
|
||||
"amsthm",
|
||||
"listings",
|
||||
// listings is handled in BufferParams.cpp
|
||||
"bm",
|
||||
"pdfpages",
|
||||
"relsize",
|
||||
|
@ -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);
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -99,12 +99,18 @@ 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_) {
|
||||
|
||||
@ -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];
|
||||
|
Loading…
Reference in New Issue
Block a user