When an inset such as InsetInclude does not have a valid
ParConstIterator (because it does not have valid paragraphs), it has
to use the iterator of its parent paragraph. This patch implements
this and add InsetInclude with a caption to nagivation -> list of
listings.

To test, look under nagivatio -> list of listings for your
lstinputlisting with captions.

Using the same logic, 'list of any sort of inset' can be added easily.

OK to apply?

Bo
Index: src/insets/InsetInclude.cpp
===================================================================
--- src/insets/InsetInclude.cpp	(revision 18628)
+++ src/insets/InsetInclude.cpp	(working copy)
@@ -883,6 +883,18 @@
 
 void InsetInclude::addToToc(TocList & toclist, Buffer const & buffer) const
 {
+	if (isListings(params_)) {
+		InsetListingsParams params(params_.getOptions());
+		string caption = params.getParamValue("caption");
+		if (!caption.empty()) {
+			Toc & toc = toclist["listing"];
+			// This inset does not have a valid ParConstIterator 
+			// so it has to use the iterator of its parent paragraph
+			throw outerTocItem("listing", 0, convert<docstring>(toc.size() + 1)
+				+ ". " +  params_["filename"]);
+		}
+		return;
+	}
 	Buffer const * const childbuffer = getChildBuffer(buffer, params_);
 	if (!childbuffer)
 		return;
Index: src/TocBackend.cpp
===================================================================
--- src/TocBackend.cpp	(revision 18628)
+++ src/TocBackend.cpp	(working copy)
@@ -184,7 +184,14 @@
 		InsetList::const_iterator end = pit->insetlist.end();
 		for (; it != end; ++it) {
 			Inset & inset = *it->inset;
-			inset.addToToc(tocs_, *buffer_);
+			try {
+				inset.addToToc(tocs_, *buffer_);
+			} catch (outerTocItem const & item) {
+				// if an inset does not have its own ParConstIterator
+				// (e.g. InsetInclude), it can throw an outerTocItem 
+				// to use the ParConstIterator of its parent paragraph.
+				tocs_[item.type()].push_back(TocItem(pit, item.depth(), item.str()));
+			}
 			switch (inset.lyxCode()) {
 			case Inset::OPTARG_CODE: {
 				if (!tocstring.empty())
Index: src/TocBackend.h
===================================================================
--- src/TocBackend.h	(revision 18628)
+++ src/TocBackend.h	(working copy)
@@ -81,6 +81,30 @@
 };
 
 
+/// thrown by an inset that does not have a valid ParConstIterator
+/// so the paragraph containing this inset has to be used
+class outerTocItem
+{
+public:
+	///
+	outerTocItem(std::string const & type, int depth, docstring const & str)
+		: type_(type), depth_(depth), str_(str) {}
+	///
+	std::string const & type() const { return type_; }
+	///
+	int const depth() const { return depth_; }
+	///
+	docstring const & str() const { return str_; }
+private:
+	/// Toc type
+	std::string type_;
+	/// nested depth
+	int depth_;
+	/// Full item string
+	docstring str_;
+};
+
+
 ///
 /**
 */

Reply via email to