José Matos wrote:
> > 3637 is attached. (Get label from parameter string and push to label
> > list).
>
>   Jürgen is this OK with you?

Hm, I missed this and did something similar. Bo's patch is generally better, 
but lacks changeRefsIfUnique.

I propose to put in the attached (which is a synthesis of Bo's and my patch).

Jürgen
Index: src/insets/InsetListingsParams.h
===================================================================
--- src/insets/InsetListingsParams.h	(Revision 18396)
+++ src/insets/InsetListingsParams.h	(Arbeitskopie)
@@ -66,6 +66,9 @@
 	///
 	void setInline(bool i) { inline_ = i; }
 
+	/// get value of option \c param
+	std::string getParamValue(std::string const & param) const;
+
 	///
 	void clear() { params_.clear(); }
 
Index: src/insets/InsetInclude.cpp
===================================================================
--- src/insets/InsetInclude.cpp	(Revision 18396)
+++ src/insets/InsetInclude.cpp	(Arbeitskopie)
@@ -62,6 +62,7 @@
 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::makeRelPath;
 using support::onlyFilename;
 using support::onlyPath;
+using support::prefixIs;
 using support::subst;
 using support::sum;
 
@@ -79,6 +81,7 @@
 using std::istringstream;
 using std::ostream;
 using std::ostringstream;
+using std::vector;
 
 namespace Alert = frontend::Alert;
 namespace fs = boost::filesystem;
@@ -92,6 +95,12 @@
 	return "file" + convert<docstring>(++seed);
 }
 
+
+bool isListings(InsetCommandParams const & params)
+{
+	return params.getCmdName() == "lstinputlisting";
+}
+
 } // namespace anon
 
 
@@ -129,6 +138,16 @@
 		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"))
+					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 +228,6 @@
 }
 
 
-bool isListings(InsetCommandParams const & params)
-{
-	return params.getCmdName() == "lstinputlisting";
-}
-
-
 string const masterFilename(Buffer const & buffer)
 {
 	return buffer.getMasterBuffer()->fileName();
@@ -630,7 +643,13 @@
 void InsetInclude::getLabelList(Buffer const & buffer,
 				std::vector<docstring> & 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("");
Index: src/insets/InsetListingsParams.cpp
===================================================================
--- src/insets/InsetListingsParams.cpp	(Revision 18396)
+++ src/insets/InsetListingsParams.cpp	(Arbeitskopie)
@@ -28,6 +28,9 @@
 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 @@
 }
 
 
+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<string> pars = getVectorFromString(separatedParams(), "\n");
+	for (vector<string>::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

Reply via email to