>
> PS. I don't like this way to insert labels. A) it seems prone for bugs,
> B) the label is not shown on the screen.
>
> PS2. I can't think of a good alternative right now.

Attached is a patch that fixes the bug. The only question I have is
whether or not CutAndPaste.cpp is the best place to update label.

Vincent: could you please take over this patch? If you do not have
time to review or test it, maybe you can create a bug and put the
patch over there.

Thank you very much.
Bo
Index: src/insets/InsetListingsParams.h
===================================================================
--- src/insets/InsetListingsParams.h	(revision 28539)
+++ src/insets/InsetListingsParams.h	(working copy)
@@ -37,8 +37,9 @@
 	/// 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);
Index: src/insets/InsetInclude.cpp
===================================================================
--- src/insets/InsetInclude.cpp	(revision 28539)
+++ src/insets/InsetInclude.cpp	(working copy)
@@ -920,6 +920,27 @@
 }
 
 
+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());
Index: src/insets/InsetListingsParams.cpp
===================================================================
--- src/insets/InsetListingsParams.cpp	(revision 28539)
+++ src/insets/InsetListingsParams.cpp	(working copy)
@@ -741,14 +741,14 @@
 }
 
 
-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()) { }
Index: src/insets/InsetInclude.h
===================================================================
--- src/insets/InsetInclude.h	(revision 28539)
+++ src/insets/InsetInclude.h	(working copy)
@@ -86,6 +86,8 @@
 	///
 	void addToToc(DocIterator const &);
 	///
+	void updateCommand();
+	///
 	void updateLabels(ParIterator const &);
 	///
 	static ParamInfo const & findInfo(std::string const &);
Index: src/CutAndPaste.cpp
===================================================================
--- src/CutAndPaste.cpp	(revision 28539)
+++ src/CutAndPaste.cpp	(working copy)
@@ -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"
@@ -245,7 +246,11 @@
 			}
 			break;
 		}
-
+		case INCLUDE_CODE: {
+			InsetInclude & inc = static_cast<InsetInclude &>(*it);
+			inc.updateCommand();
+			break;
+		}
 		case BIBITEM_CODE: {
 			// check for duplicates
 			InsetCommand & bib = static_cast<InsetCommand &>(*it);

Reply via email to