In this particular case, I think
that I'd prefer to pass a cursor to addToToc.

Do you mean the attached? This looks better to me but I was trying not
to alter the inset interface.

Bo
Index: src/insets/InsetCaption.cpp
===================================================================
--- src/insets/InsetCaption.cpp	(revision 18652)
+++ src/insets/InsetCaption.cpp	(working copy)
@@ -115,7 +115,7 @@
 }
 
 
-void InsetCaption::addToToc(TocList & toclist, Buffer const & buf) const
+void InsetCaption::addToToc(TocList & toclist, Buffer const & buf, ParConstIterator &) const
 {
 	if (type_.empty())
 		return;
Index: src/insets/InsetWrap.h
===================================================================
--- src/insets/InsetWrap.h	(revision 18652)
+++ src/insets/InsetWrap.h	(working copy)
@@ -66,7 +66,7 @@
 	///
 	bool insetAllowed(Inset::Code) const;
 	///
-	void addToToc(TocList &, Buffer const &) const;
+	void addToToc(TocList &, Buffer const &, ParConstIterator &) const;
 	///
 	bool showInsetDialog(BufferView *) const;
 	///
Index: src/insets/InsetCaption.h
===================================================================
--- src/insets/InsetCaption.h	(revision 18652)
+++ src/insets/InsetCaption.h	(working copy)
@@ -84,7 +84,7 @@
 	///
 	void setCustomLabel(docstring const & label);
 	///
-	void addToToc(TocList &, Buffer const &) const;
+	void addToToc(TocList &, Buffer const &, ParConstIterator &) const;
 	/// Captions don't accept alignment, spacing, etc.
 	bool forceDefaultParagraphs(idx_type) const { return true; }
 
Index: src/insets/InsetInclude.cpp
===================================================================
--- src/insets/InsetInclude.cpp	(revision 18652)
+++ src/insets/InsetInclude.cpp	(working copy)
@@ -881,8 +881,21 @@
 }
 
 
-void InsetInclude::addToToc(TocList & toclist, Buffer const & buffer) const
+void InsetInclude::addToToc(TocList & toclist, Buffer const & buffer, ParConstIterator & pit) const
 {
+	if (isListings(params_)) {
+		InsetListingsParams params(params_.getOptions());
+		string caption = params.getParamValue("caption");
+		if (!caption.empty()) {
+			Toc & toc = toclist["listing"];
+			docstring const str = convert<docstring>(toc.size() + 1)
+				+ ". " +  params_["filename"];
+			// This inset does not have a valid ParConstIterator 
+			// so it has to use the iterator of its parent paragraph
+			toc.push_back(TocItem(pit, 0, str));
+		}
+		return;
+	}
 	Buffer const * const childbuffer = getChildBuffer(buffer, params_);
 	if (!childbuffer)
 		return;
Index: src/insets/Inset.h
===================================================================
--- src/insets/Inset.h	(revision 18652)
+++ src/insets/Inset.h	(working copy)
@@ -30,6 +30,7 @@
 class Buffer;
 class BufferParams;
 class BufferView;
+class ParConstIterator;
 class CursorSlice;
 class FuncRequest;
 class FuncStatus;
@@ -425,7 +426,8 @@
 	 */
 	virtual void addPreview(graphics::PreviewLoader &) const {}
 	/// Add an entry to the TocList
-	virtual void addToToc(TocList &, Buffer const &) const {}
+	/// pit is the ParConstIterator of the paragraph containing the inset
+	virtual void addToToc(TocList &, Buffer const &, ParConstIterator & pit) const {}
 
 public:
 	/// returns LyX code associated with the inset. Used for TOC, ...)
Index: src/insets/InsetFloat.cpp
===================================================================
--- src/insets/InsetFloat.cpp	(revision 18652)
+++ src/insets/InsetFloat.cpp	(working copy)
@@ -386,7 +386,7 @@
 }
 
 
-void InsetFloat::addToToc(TocList & toclist, Buffer const & buf) const
+void InsetFloat::addToToc(TocList & toclist, Buffer const & buf, ParConstIterator &) const
 {
 	// Is there a need to provide a list of float insets?
 	return;
Index: src/insets/InsetInclude.h
===================================================================
--- src/insets/InsetInclude.h	(revision 18652)
+++ src/insets/InsetInclude.h	(working copy)
@@ -95,7 +95,7 @@
 	///
 	void addPreview(graphics::PreviewLoader &) const;
 	///
-	void addToToc(TocList &, Buffer const &) const;
+	void addToToc(TocList &, Buffer const &, ParConstIterator &) const;
 	///
 	void updateLabels(Buffer const & buffer) const;
 	///
Index: src/insets/InsetWrap.cpp
===================================================================
--- src/insets/InsetWrap.cpp	(revision 18652)
+++ src/insets/InsetWrap.cpp	(working copy)
@@ -234,7 +234,7 @@
 }
 
 
-void InsetWrap::addToToc(TocList & toclist, Buffer const & buf) const
+void InsetWrap::addToToc(TocList & toclist, Buffer const & buf, ParConstIterator &) const
 {
 	// Is there a need to provide a list of wrap insets?
 	return;
Index: src/insets/InsetFloat.h
===================================================================
--- src/insets/InsetFloat.h	(revision 18652)
+++ src/insets/InsetFloat.h	(working copy)
@@ -82,7 +82,7 @@
 	///
 	void sideways(bool s, BufferParams const &);
 	///
-	void addToToc(TocList &, Buffer const &) const;
+	void addToToc(TocList &, Buffer const &, ParConstIterator &) const;
 	///
 	bool  showInsetDialog(BufferView *) const;
 	///
Index: src/TocBackend.cpp
===================================================================
--- src/TocBackend.cpp	(revision 18652)
+++ src/TocBackend.cpp	(working copy)
@@ -184,7 +184,7 @@
 		InsetList::const_iterator end = pit->insetlist.end();
 		for (; it != end; ++it) {
 			Inset & inset = *it->inset;
-			inset.addToToc(tocs_, *buffer_);
+			inset.addToToc(tocs_, *buffer_, pit);
 			switch (inset.lyxCode()) {
 			case Inset::OPTARG_CODE: {
 				if (!tocstring.empty())

Reply via email to