Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-10 Thread Angus Leeming

Abdelrazak Younes wrote:

Bo Peng wrote:

Per the use of exception, I think exception should be used more often
in lyx.


LyX's code base is not exception safe. The code hasn't been written 
with exception safety in mind, largely because we weren't proficient 
in the use of exceptions. (I certainly include myself in that statement.)


For example, counters are not updated immediately after, say,

an caption is added to InsetInclude. It would be good to have
something like

try
   work on inset going on
except updateCounter (+1, or -1)
except updateScreen (partial or all)
except kill me please

Just some random thought.


IMHO exceptions should only be used in _exceptional_ situation because 
they bypass the normal function to function communication. I think the 
way you want to use them is going to slow down the code significantly. 
This is reason why I don't like for example the way exceptions are 
misused in the listings code.


Yes, unwinding the stack is very expensive.

Angus



Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-10 Thread Angus Leeming

Abdelrazak Younes wrote:

Bo Peng wrote:

Per the use of exception, I think exception should be used more often
in lyx.


LyX's code base is not exception safe. The code hasn't been written 
with exception safety in mind, largely because we weren't proficient 
in the use of exceptions. (I certainly include myself in that statement.)


For example, counters are not updated immediately after, say,

an caption is added to InsetInclude. It would be good to have
something like

try
   work on inset going on
except updateCounter (+1, or -1)
except updateScreen (partial or all)
except kill me please

Just some random thought.


IMHO exceptions should only be used in _exceptional_ situation because 
they bypass the normal function to function communication. I think the 
way you want to use them is going to slow down the code significantly. 
This is reason why I don't like for example the way exceptions are 
misused in the listings code.


Yes, unwinding the stack is very expensive.

Angus



Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-09 Thread Abdelrazak Younes

Bo Peng wrote:

Bo Fixed in the attached patch. Jose, OK to apply?

I am not very pleased with the use of an exception there, but on the
other hand I do not have (yet) a better idea.


I though of returning TocItem and let update() add the labels.
However, ParConstIterator does not have a default constructor like
ParConstIterator(0) so I can not test special cases in update().

Per the use of exception, I think exception should be used more often
in lyx. For example, counters are not updated immediately after, say,
an caption is added to InsetInclude. It would be good to have
something like

try
   work on inset going on
except updateCounter (+1, or -1)
except updateScreen (partial or all)
except kill me please

Just some random thought.


IMHO exceptions should only be used in _exceptional_ situation because 
they bypass the normal function to function communication. I think the 
way you want to use them is going to slow down the code significantly. 
This is reason why I don't like for example the way exceptions are 
misused in the listings code.


Abdel.



Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-09 Thread Abdelrazak Younes

Bo Peng wrote:

Bo> Fixed in the attached patch. Jose, OK to apply?

I am not very pleased with the use of an exception there, but on the
other hand I do not have (yet) a better idea.


I though of returning TocItem and let update() add the labels.
However, ParConstIterator does not have a default constructor like
ParConstIterator(0) so I can not test special cases in update().

Per the use of exception, I think exception should be used more often
in lyx. For example, counters are not updated immediately after, say,
an caption is added to InsetInclude. It would be good to have
something like

try
   work on inset going on
except updateCounter (+1, or -1)
except updateScreen (partial or all)
except kill me please

Just some random thought.


IMHO exceptions should only be used in _exceptional_ situation because 
they bypass the normal function to function communication. I think the 
way you want to use them is going to slow down the code significantly. 
This is reason why I don't like for example the way exceptions are 
misused in the listings code.


Abdel.



Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-04 Thread Bo Peng

Bo Fixed in the attached patch. Jose, OK to apply?

I am not very pleased with the use of an exception there, but on the
other hand I do not have (yet) a better idea.


Jose,

This patch works although JMarc does not like it.

I can commit it with your permission or put it to bugzilla if you
prefer a better solution.

Cheers,
Bo


Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-04 Thread Jean-Marc Lasgouttes
 Bo == Bo Peng [EMAIL PROTECTED] writes:

Bo This patch works although JMarc does not like it.

To clarify: I am not against using exceptions for something else than
an error, but we should make clear the kind of use we envision, not
just use them on an ad-hoc basis. In this particular case, I think
that I'd prefer to pass a cursor to addToToc.

JMarc


Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-04 Thread Bo Peng

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 = convertdocstring(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  

Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-04 Thread José Matos
On Monday 04 June 2007 16:59:59 Jean-Marc Lasgouttes wrote:
 To clarify: I am not against using exceptions for something else than
 an error, but we should make clear the kind of use we envision, not
 just use them on an ad-hoc basis.

  I agree with Jean-Marc here.

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

 JMarc

-- 
José Abílio


Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-04 Thread Bo Peng

Bo> Fixed in the attached patch. Jose, OK to apply?

I am not very pleased with the use of an exception there, but on the
other hand I do not have (yet) a better idea.


Jose,

This patch works although JMarc does not like it.

I can commit it with your permission or put it to bugzilla if you
prefer a better solution.

Cheers,
Bo


Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-04 Thread Jean-Marc Lasgouttes
> "Bo" == Bo Peng <[EMAIL PROTECTED]> writes:

Bo> This patch works although JMarc does not like it.

To clarify: I am not against using exceptions for something else than
an error, but we should make clear the kind of use we envision, not
just use them on an ad-hoc basis. In this particular case, I think
that I'd prefer to pass a cursor to addToToc.

JMarc


Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-04 Thread Bo Peng

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(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 &, 

Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-04 Thread José Matos
On Monday 04 June 2007 16:59:59 Jean-Marc Lasgouttes wrote:
> To clarify: I am not against using exceptions for something else than
> an error, but we should make clear the kind of use we envision, not
> just use them on an ad-hoc basis.

  I agree with Jean-Marc here.

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

> JMarc

-- 
José Abílio


Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-02 Thread Andre Poenitz
On Sat, Jun 02, 2007 at 12:26:48AM -0500, Bo Peng wrote:
 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?

 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

'OuterTocItem'

Andre'


Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-02 Thread Bo Peng

 +/// thrown by an inset that does not have a valid ParConstIterator
 +/// so the paragraph containing this inset has to be used
 +class outerTocItem

'OuterTocItem'


Fixed in the attached patch. Jose, OK to apply? (I assume Andre has
tested this patch).

Bo
Index: src/insets/InsetInclude.cpp
===
--- src/insets/InsetInclude.cpp	(revision 18631)
+++ 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, convertdocstring(toc.size() + 1)
++ .  +  params_[filename]);
+		}
+		return;
+	}
 	Buffer const * const childbuffer = getChildBuffer(buffer, params_);
 	if (!childbuffer)
 		return;
Index: src/TocBackend.cpp
===
--- src/TocBackend.cpp	(revision 18631)
+++ 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 18631)
+++ 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_;
+};
+
+
 ///
 /**
 */


Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-02 Thread Jean-Marc Lasgouttes
 Bo == Bo Peng [EMAIL PROTECTED] writes:

  +/// thrown by an inset that does not have a valid
 ParConstIterator  +/// so the paragraph containing this inset has
 to be used  +class outerTocItem
 
 'OuterTocItem'

Bo Fixed in the attached patch. Jose, OK to apply? 

I am not very pleased with the use of an exception there, but on the
other hand I do not have (yet) a better idea.

Bo (I assume Andre has tested this patch).

You should not...

JMarc


Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-02 Thread Bo Peng

Bo Fixed in the attached patch. Jose, OK to apply?

I am not very pleased with the use of an exception there, but on the
other hand I do not have (yet) a better idea.


I though of returning TocItem and let update() add the labels.
However, ParConstIterator does not have a default constructor like
ParConstIterator(0) so I can not test special cases in update().

Per the use of exception, I think exception should be used more often
in lyx. For example, counters are not updated immediately after, say,
an caption is added to InsetInclude. It would be good to have
something like

try
   work on inset going on
except updateCounter (+1, or -1)
except updateScreen (partial or all)
except kill me please

Just some random thought.

Bo


Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-02 Thread Andre Poenitz
On Sat, Jun 02, 2007 at 08:41:06AM -0500, Bo Peng wrote:
  +/// thrown by an inset that does not have a valid ParConstIterator
  +/// so the paragraph containing this inset has to be used
  +class outerTocItem
 
 'OuterTocItem'
 
 Fixed in the attached patch. Jose, OK to apply? (I assume Andre has
 tested this patch).

I didn't. I am not even remotely close to a machine being able to
compile LyX (in reasonable time). This is a PII/266 with 48 MB RAM.

Andre'


Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-02 Thread Andre Poenitz
On Sat, Jun 02, 2007 at 12:26:48AM -0500, Bo Peng wrote:
> 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?

> 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

'OuterTocItem'

Andre'


Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-02 Thread Bo Peng

> +/// thrown by an inset that does not have a valid ParConstIterator
> +/// so the paragraph containing this inset has to be used
> +class outerTocItem

'OuterTocItem'


Fixed in the attached patch. Jose, OK to apply? (I assume Andre has
tested this patch).

Bo
Index: src/insets/InsetInclude.cpp
===
--- src/insets/InsetInclude.cpp	(revision 18631)
+++ 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(toc.size() + 1)
++ ". " +  params_["filename"]);
+		}
+		return;
+	}
 	Buffer const * const childbuffer = getChildBuffer(buffer, params_);
 	if (!childbuffer)
 		return;
Index: src/TocBackend.cpp
===
--- src/TocBackend.cpp	(revision 18631)
+++ 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 18631)
+++ 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_;
+};
+
+
 ///
 /**
 */


Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-02 Thread Jean-Marc Lasgouttes
> "Bo" == Bo Peng <[EMAIL PROTECTED]> writes:

>> > +/// thrown by an inset that does not have a valid
>> ParConstIterator > +/// so the paragraph containing this inset has
>> to be used > +class outerTocItem
>> 
>> 'OuterTocItem'

Bo> Fixed in the attached patch. Jose, OK to apply? 

I am not very pleased with the use of an exception there, but on the
other hand I do not have (yet) a better idea.

Bo> (I assume Andre has tested this patch).

You should not...

JMarc


Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-02 Thread Bo Peng

Bo> Fixed in the attached patch. Jose, OK to apply?

I am not very pleased with the use of an exception there, but on the
other hand I do not have (yet) a better idea.


I though of returning TocItem and let update() add the labels.
However, ParConstIterator does not have a default constructor like
ParConstIterator(0) so I can not test special cases in update().

Per the use of exception, I think exception should be used more often
in lyx. For example, counters are not updated immediately after, say,
an caption is added to InsetInclude. It would be good to have
something like

try
   work on inset going on
except updateCounter (+1, or -1)
except updateScreen (partial or all)
except kill me please

Just some random thought.

Bo


Re: [PATCH] Bug 3711, add insets without valid ParConstIterator to TOC.

2007-06-02 Thread Andre Poenitz
On Sat, Jun 02, 2007 at 08:41:06AM -0500, Bo Peng wrote:
> >> +/// thrown by an inset that does not have a valid ParConstIterator
> >> +/// so the paragraph containing this inset has to be used
> >> +class outerTocItem
> >
> >'OuterTocItem'
> 
> Fixed in the attached patch. Jose, OK to apply? (I assume Andre has
> tested this patch).

I didn't. I am not even remotely close to a machine being able to
compile LyX (in reasonable time). This is a PII/266 with 48 MB RAM.

Andre'