From eb963540d4532d716a7d460eee6a3ab5d976e0c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20St=C3=B6hr?= Date: Mon, 8 Sep 2008 21:51:38 +0000 Subject: [PATCH] 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 --- src/BufferParams.cpp | 9 +++++++-- src/LaTeXFeatures.cpp | 2 +- src/frontends/qt4/GuiListings.cpp | 1 + src/frontends/qt4/ui/ListingsUi.ui | 5 +---- src/frontends/qt4/ui/TextLayoutUi.ui | 7 +++++-- src/insets/InsetListings.cpp | 5 ++++- src/insets/InsetListingsParams.cpp | 29 +++++++++++++++++----------- 7 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index e470adf1fa..2b4e937da3 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -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') diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index 4b994e6bef..cf85ec5648 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -471,7 +471,7 @@ char const * simplefeatures[] = { "endnotes", "ifthen", "amsthm", - "listings", + // listings is handled in BufferParams.cpp "bm", "pdfpages", "relsize", diff --git a/src/frontends/qt4/GuiListings.cpp b/src/frontends/qt4/GuiListings.cpp index 11472e7463..38077d434c 100644 --- a/src/frontends/qt4/GuiListings.cpp +++ b/src/frontends/qt4/GuiListings.cpp @@ -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); diff --git a/src/frontends/qt4/ui/ListingsUi.ui b/src/frontends/qt4/ui/ListingsUi.ui index 5b6726a278..cd7075bfcb 100644 --- a/src/frontends/qt4/ui/ListingsUi.ui +++ b/src/frontends/qt4/ui/ListingsUi.ui @@ -545,14 +545,11 @@ Feedback window - QFrame::NoFrame + QFrame::Box QFrame::Plain - - 0 - false diff --git a/src/frontends/qt4/ui/TextLayoutUi.ui b/src/frontends/qt4/ui/TextLayoutUi.ui index a34443c39c..5a89db6738 100644 --- a/src/frontends/qt4/ui/TextLayoutUi.ui +++ b/src/frontends/qt4/ui/TextLayoutUi.ui @@ -131,7 +131,7 @@ - + @@ -147,6 +147,9 @@ false + + Feedback window + QFrame::Box @@ -158,7 +161,7 @@ - + diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp index 93b1931f53..38dc99c1e0 100644 --- a/src/insets/InsetListings.cpp +++ b/src/insets/InsetListings.cpp @@ -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); } diff --git a/src/insets/InsetListingsParams.cpp b/src/insets/InsetListingsParams.cpp index 2c87a4095c..99ecbb0fdf 100644 --- a/src/insets/InsetListingsParams.cpp +++ b/src/insets/InsetListingsParams.cpp @@ -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];