From 072ed23ffcd4a4a883f3521d0295d7555d40fecc Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Thu, 19 Feb 2009 04:50:25 +0000 Subject: [PATCH] Patch from Bo. Fixes problem with labels in child docs of the listings type: Duplicate labels were not being updated. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28556 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/CutAndPaste.cpp | 7 +++++++ src/insets/InsetInclude.cpp | 21 +++++++++++++++++++++ src/insets/InsetInclude.h | 2 ++ src/insets/InsetListingsParams.cpp | 5 +++-- src/insets/InsetListingsParams.h | 6 ++++-- 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index bfce241918..36cbd7ab42 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -41,6 +41,7 @@ #include "insets/InsetCommand.h" #include "insets/InsetGraphics.h" #include "insets/InsetGraphicsParams.h" +#include "insets/InsetInclude.h" #include "insets/InsetTabular.h" #include "mathed/MathData.h" @@ -244,6 +245,12 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist, break; } + case INCLUDE_CODE: { + InsetInclude & inc = static_cast(*it); + inc.updateCommand(); + break; + } + case BIBITEM_CODE: { // check for duplicates InsetCommand & bib = static_cast(*it); diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 4521fa43b0..13938aaf90 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -922,6 +922,27 @@ void InsetInclude::addToToc(DocIterator const & cpit) } +void InsetInclude::updateCommand() +{ + if (!label_) + return; + + docstring old_label = label_->getParam("name"); + label_->updateCommand(old_label, false); + // the label might have been adapted (duplicate) + docstring new_label = label_->getParam("name"); + if (old_label == new_label) + return; + + // update listings parameters... + InsetCommandParams p(INCLUDE_CODE); + p = params(); + InsetListingsParams par(to_utf8(params()["lstparams"])); + par.addParam("label", "{" + to_utf8(new_label) + "}", true); + p["lstparams"] = from_utf8(par.params()); + setParams(p); +} + void InsetInclude::updateLabels(ParIterator const & it) { Buffer const * const childbuffer = getChildBuffer(buffer()); diff --git a/src/insets/InsetInclude.h b/src/insets/InsetInclude.h index 3afb11ecee..410b71270c 100644 --- a/src/insets/InsetInclude.h +++ b/src/insets/InsetInclude.h @@ -86,6 +86,8 @@ public: /// void addToToc(DocIterator const &); /// + void updateCommand(); + /// void updateLabels(ParIterator const &); /// static ParamInfo const & findInfo(std::string const &); diff --git a/src/insets/InsetListingsParams.cpp b/src/insets/InsetListingsParams.cpp index 99ecbb0fdf..473341e52a 100644 --- a/src/insets/InsetListingsParams.cpp +++ b/src/insets/InsetListingsParams.cpp @@ -741,14 +741,15 @@ string InsetListingsParams::params(string const & sep) const } -void InsetListingsParams::addParam(string const & key, string const & value) +void InsetListingsParams::addParam(string const & key, + string const & value, bool replace) { if (key.empty()) return; // duplicate parameters! string keyname = key; - if (params_.find(key) != params_.end()) + if (!replace && params_.find(key) != params_.end()) // key=value,key=value1 is allowed in listings // use key_, key__, key___ etc to avoid name conflict while (params_.find(keyname += '_') != params_.end()) { } diff --git a/src/insets/InsetListingsParams.h b/src/insets/InsetListingsParams.h index dc76ed40ad..6a7b46f98a 100644 --- a/src/insets/InsetListingsParams.h +++ b/src/insets/InsetListingsParams.h @@ -37,8 +37,10 @@ public: /// valid parameter string std::string params(std::string const & sep=",") const; - /// add key=value to params_ - void addParam(std::string const & key, std::string const & value); + /// add key=value to params_. key_=value will be used if key=value already exists + /// unless replace=true. + void addParam(std::string const & key, std::string const & value, + bool replace = false); /// add a few parameters void addParams(std::string const & par); -- 2.39.2