From a42d3e670b8b2d1c33cbbc146c8473bb4c001c60 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Fri, 18 May 2007 14:40:39 +0000 Subject: [PATCH] Fix for bug 3637, joint work of Bo Peng and myself: * src/insets/InsetListingsParams.{cpp,h} - implement getParamValue that returns the value of a listings param * src/insets/InsetInclude.cpp: - (getLabelList): pass listings label to the list, if available - doDispatch: implement changeRefsIfUnique for listing labels git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18405 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/InsetInclude.cpp | 34 ++++++++++++++++++++++++------ src/insets/InsetListingsParams.cpp | 22 +++++++++++++++++++ src/insets/InsetListingsParams.h | 3 +++ 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 0ff5c25d89..8ec571d605 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -62,6 +62,7 @@ using support::copy; using support::DocFileName; using support::FileName; using support::getFileContents; +using support::getVectorFromString; using support::isFileReadable; using support::isLyXFilename; using support::latex_path; @@ -70,6 +71,7 @@ using support::makeDisplayPath; using support::makeRelPath; using support::onlyFilename; using support::onlyPath; +using support::prefixIs; using support::subst; using support::sum; @@ -79,6 +81,7 @@ using std::auto_ptr; using std::istringstream; using std::ostream; using std::ostringstream; +using std::vector; namespace Alert = frontend::Alert; namespace fs = boost::filesystem; @@ -92,6 +95,12 @@ docstring const uniqueID() return "file" + convert(++seed); } + +bool isListings(InsetCommandParams const & params) +{ + return params.getCmdName() == "lstinputlisting"; +} + } // namespace anon @@ -129,6 +138,17 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd) InsetCommandParams p("include"); InsetIncludeMailer::string2params(to_utf8(cmd.argument()), p); if (!p.getCmdName().empty()) { + if (isListings(p)){ + InsetListingsParams par_old(params().getOptions()); + InsetListingsParams par_new(p.getOptions()); + if (par_old.getParamValue("label") != + par_new.getParamValue("label") + && !par_new.getParamValue("label").empty()) + cur.bv().buffer()->changeRefsIfUnique( + from_utf8(par_old.getParamValue("label")), + from_utf8(par_new.getParamValue("label")), + Inset::REF_CODE); + } set(p, cur.buffer()); cur.buffer().updateBibfilesCache(); } else @@ -209,12 +229,6 @@ bool isVerbatim(InsetCommandParams const & params) } -bool isListings(InsetCommandParams const & params) -{ - return params.getCmdName() == "lstinputlisting"; -} - - string const masterFilename(Buffer const & buffer) { return buffer.getMasterBuffer()->fileName(); @@ -630,7 +644,13 @@ void InsetInclude::validate(LaTeXFeatures & features) const void InsetInclude::getLabelList(Buffer const & buffer, std::vector & list) const { - if (loadIfNeeded(buffer, params_)) { + if (isListings(params_)) { + InsetListingsParams params(params_.getOptions()); + string label = params.getParamValue("label"); + if (!label.empty()) + list.push_back(from_utf8(label)); + } + else if (loadIfNeeded(buffer, params_)) { string const included_file = includedFilename(buffer, params_).absFilename(); Buffer * tmp = theBufferList().getBuffer(included_file); tmp->setParentName(""); diff --git a/src/insets/InsetListingsParams.cpp b/src/insets/InsetListingsParams.cpp index 61fc1c220e..f651f453b4 100644 --- a/src/insets/InsetListingsParams.cpp +++ b/src/insets/InsetListingsParams.cpp @@ -28,6 +28,9 @@ using std::string; using std::exception; using lyx::support::trim; using lyx::support::isStrInt; +using lyx::support::prefixIs; +using lyx::support::suffixIs; +using lyx::support::getVectorFromString; namespace lyx { @@ -557,5 +560,24 @@ void InsetListingsParams::fromEncodedString(string const & in) } +string InsetListingsParams::getParamValue(string const & param) const +{ + // is this parameter defined? + if (find(keys_.begin(), keys_.end(), param) == keys_.end()) + return string(); + // if so, search for it + vector pars = getVectorFromString(separatedParams(), "\n"); + for (vector::iterator it = pars.begin(); it != pars.end(); ++it) + if (prefixIs(*it, param + "=")) { + string par = it->substr(param.size() + 1); + if (prefixIs(par, "{") && suffixIs(par, "}")) + return par.substr(1, par.size() - 2); + else + return par; + } + // if param= is not found, should be something like float, return "" + return string(); +} + } // namespace lyx diff --git a/src/insets/InsetListingsParams.h b/src/insets/InsetListingsParams.h index 3d99a30d09..56a70d7fc8 100644 --- a/src/insets/InsetListingsParams.h +++ b/src/insets/InsetListingsParams.h @@ -66,6 +66,9 @@ public: /// void setInline(bool i) { inline_ = i; } + /// get value of option \c param + std::string getParamValue(std::string const & param) const; + /// void clear() { params_.clear(); } -- 2.39.2