Abdelrazak Younes wrote:

> Georg Baum wrote:
>> Abdelrazak Younes wrote:
>> 
>>> For example, on a multipart document it would be a good idea to navigate
>>> to whatever part of the document. So you don't want to restrain the
>>> MenuBackend to be usable only for the currently visible Buffer but for
>>> any Buffer that you pass to it.
>> 
>> See http://www.lyx.org/trac/changeset/15075 for a solution for this
>> problem that does not need a current buffer.
> 
> Trac is down?

Yes, I forgot. Take this patch instead.


Georg
diff -ruNpx .svn lyx-1.4-clean/src/buffer_funcs.C lyx-1.4-gb/src/buffer_funcs.C
--- lyx-1.4-clean/src/buffer_funcs.C	2006-08-11 15:38:40.000000000 +0200
+++ lyx-1.4-gb/src/buffer_funcs.C	2006-09-21 17:39:39.000000000 +0200
@@ -37,6 +37,7 @@
 #include "frontends/Alert.h"
 
 #include "insets/insetbibitem.h"
+#include "insets/insetinclude.h"
 
 #include "support/filetools.h"
 #include "support/fs_extras.h"
@@ -348,11 +349,9 @@ bool needEnumCounterReset(ParIterator co
 
 
 // set the counter of a paragraph. This includes the labels
-void setCounter(Buffer const & buf, ParIterator & it)
+void setCounter(Buffer const & buf, ParIterator & it, LyXTextClass const & textclass)
 {
 	Paragraph & par = *it;
-	BufferParams const & bufparams = buf.params();
-	LyXTextClass const & textclass = bufparams.getLyXTextClass();
 	LyXLayout_ptr const & layout = par.layout();
 	Counters & counters = textclass.counters();
 
@@ -394,7 +393,7 @@ void setCounter(Buffer const & buf, ParI
 		// At some point of time we should do something more
 		// clever here, like:
 		//   par.params().labelString(
-		//    bufparams.user_defined_bullet(par.itemdepth).getText());
+		//    buf.params().user_defined_bullet(par.itemdepth).getText());
 		// for now, use a simple hardcoded label
 		string itemlabel;
 		switch (par.itemdepth) {
@@ -506,10 +505,22 @@ void setCounter(Buffer const & buf, ParI
 } // anon namespace
 
 
-void updateCounters(Buffer const & buf)
+void updateCounters(Buffer const & buf, bool childonly)
 {
-	// start over
-	buf.params().getLyXTextClass().counters().reset();
+	// Use the master text class also for child documents
+	LyXTextClass const & textclass = buf.params().getLyXTextClass();
+
+	if (!childonly) {
+		// If this is a child document start with the master
+		Buffer const * const master = buf.getMasterBuffer();
+		if (master != &buf) {
+			updateCounters(*master);
+			return;
+		}
+
+		// start over
+		textclass.counters().reset();
+	}
 
 	for (ParIterator it = par_iterator_begin(buf.inset()); it; ++it) {
 		// reduce depth if necessary
@@ -521,7 +532,16 @@ void updateCounters(Buffer const & buf)
 			it->params().depth(0);
 
 		// set the counter for this paragraph
-		setCounter(buf, it);
+		setCounter(buf, it, textclass);
+
+		// Now included docs
+		InsetList::const_iterator iit = it->insetlist.begin();
+		InsetList::const_iterator end = it->insetlist.end();
+		for (; iit != end; ++iit) {
+			if (iit->inset->lyxCode() == InsetBase::INCLUDE_CODE)
+				static_cast<InsetInclude const *>(iit->inset)
+					->updateCounters(buf);
+		}
 	}
 }
 
diff -ruNpx .svn lyx-1.4-clean/src/buffer_funcs.h lyx-1.4-gb/src/buffer_funcs.h
--- lyx-1.4-clean/src/buffer_funcs.h	2006-03-02 17:02:25.000000000 +0100
+++ lyx-1.4-gb/src/buffer_funcs.h	2006-09-21 17:39:33.000000000 +0200
@@ -49,7 +49,7 @@ std::string expandLabel(Buffer const & b
 			bool appendix);
 
 /// updates all counters
-void updateCounters(Buffer const &);
+void updateCounters(Buffer const &, bool childonly = false);
 
 
 #endif // BUFFER_FUNCS_H
diff -ruNpx .svn lyx-1.4-clean/src/BufferView_pimpl.C lyx-1.4-gb/src/BufferView_pimpl.C
--- lyx-1.4-clean/src/BufferView_pimpl.C	2006-09-21 09:47:48.000000000 +0200
+++ lyx-1.4-gb/src/BufferView_pimpl.C	2006-09-25 15:22:29.000000000 +0200
@@ -1176,21 +1176,30 @@ bool BufferView::Pimpl::dispatch(FuncReq
 
 	case LFUN_GOTO_PARAGRAPH: {
 		int const id = convert<int>(cmd.argument);
-		ParIterator par = buffer_->getParFromID(id);
-		if (par == buffer_->par_iterator_end()) {
-			lyxerr[Debug::INFO] << "No matching paragraph found! ["
-					    << id << ']' << endl;
-			break;
-		} else {
-			lyxerr[Debug::INFO] << "Paragraph " << par->id()
-					    << " found." << endl;
+		int i = 0;
+		for (Buffer * b = buffer_; i == 0 || b != buffer_; b = bufferlist.next(b)) {
+			ParIterator par = b->getParFromID(id);
+			if (par == b->par_iterator_end()) {
+				lyxerr[Debug::INFO] << "No matching paragraph found! ["
+						    << id << "'], buffer `"
+				                    << b->fileName() << "'." << endl;
+			} else {
+				lyxerr[Debug::INFO] << "Paragraph " << par->id()
+						    << " found in buffer `"
+						    << b->fileName() << "'." << endl;
+
+				if (b != buffer_)
+					setBuffer(b);
+
+				// Set the cursor
+				bv_->setCursor(makeDocIterator(par, 0));
+
+				update();
+				switchKeyMap();
+				break;
+			}
+			++i;
 		}
-
-		// Set the cursor
-		bv_->setCursor(makeDocIterator(par, 0));
-
-		update();
-		switchKeyMap();
 		break;
 	}
 
diff -ruNpx .svn lyx-1.4-clean/src/insets/insetbase.h lyx-1.4-gb/src/insets/insetbase.h
--- lyx-1.4-clean/src/insets/insetbase.h	2006-08-18 08:47:18.000000000 +0200
+++ lyx-1.4-gb/src/insets/insetbase.h	2006-09-21 17:39:34.000000000 +0200
@@ -12,6 +12,8 @@
 #ifndef INSETBASE_H
 #define INSETBASE_H
 
+#include "toc.h"
+
 #include <memory>
 #include <string>
 #include <vector>
@@ -375,6 +377,8 @@ public:
 	 *  defaults to empty.
 	 */
 	virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
+	///
+	virtual void addToToc(lyx::toc::TocList &, Buffer const &) const {}
 public:
 	/// returns LyX code associated with the inset. Used for TOC, ...)
 	virtual Code lyxCode() const { return NO_CODE; }
diff -ruNpx .svn lyx-1.4-clean/src/insets/insetfloat.h lyx-1.4-gb/src/insets/insetfloat.h
--- lyx-1.4-clean/src/insets/insetfloat.h	2006-03-02 17:01:38.000000000 +0100
+++ lyx-1.4-gb/src/insets/insetfloat.h	2006-09-21 17:39:34.000000000 +0200
@@ -14,7 +14,6 @@
 #define INSETFLOAT_H
 
 #include "insetcollapsable.h"
-#include "toc.h"
 
 
 class InsetFloatParams {
diff -ruNpx .svn lyx-1.4-clean/src/insets/insetinclude.C lyx-1.4-gb/src/insets/insetinclude.C
--- lyx-1.4-clean/src/insets/insetinclude.C	2006-05-22 10:04:30.000000000 +0200
+++ lyx-1.4-gb/src/insets/insetinclude.C	2006-09-21 17:39:34.000000000 +0200
@@ -774,6 +774,34 @@ void InsetInclude::addPreview(lyx::graph
 }
 
 
+void InsetInclude::addToToc(lyx::toc::TocList & toclist, Buffer const & buffer) const
+{
+	if (!loadIfNeeded(buffer, params_))
+		return;
+
+	string const included_file = includedFilename(buffer, params_);
+	Buffer const * const childbuffer = bufferlist.getBuffer(included_file);
+	lyx::toc::TocList const childtoclist =
+		lyx::toc::getTocList(*childbuffer);
+	lyx::toc::TocList::const_iterator it = childtoclist.begin();
+	lyx::toc::TocList::const_iterator const end = childtoclist.end();
+	for(; it != end; ++it)
+		toclist[it->first].insert(toclist[it->first].end(),
+				it->second.begin(), it->second.end());
+}
+
+
+void InsetInclude::updateCounters(Buffer const & buffer) const
+{
+	if (!loadIfNeeded(buffer, params_))
+		return;
+
+	string const included_file = includedFilename(buffer, params_);
+	Buffer const * const childbuffer = bufferlist.getBuffer(included_file);
+	::updateCounters(*childbuffer, true);
+}
+
+
 string const InsetIncludeMailer::name_("include");
 
 InsetIncludeMailer::InsetIncludeMailer(InsetInclude & inset)
diff -ruNpx .svn lyx-1.4-clean/src/insets/insetinclude.h lyx-1.4-gb/src/insets/insetinclude.h
--- lyx-1.4-clean/src/insets/insetinclude.h	2006-05-22 10:04:30.000000000 +0200
+++ lyx-1.4-gb/src/insets/insetinclude.h	2006-09-21 17:39:34.000000000 +0200
@@ -91,6 +91,10 @@ public:
 	///
 	void addPreview(lyx::graphics::PreviewLoader &) const;
 	///
+	void addToToc(lyx::toc::TocList &, Buffer const &) const;
+	///
+	void updateCounters(Buffer const & buffer) const;
+	///
 	bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
 protected:
 	InsetInclude(InsetInclude const &);
diff -ruNpx .svn lyx-1.4-clean/src/insets/insetwrap.h lyx-1.4-gb/src/insets/insetwrap.h
--- lyx-1.4-clean/src/insets/insetwrap.h	2006-03-02 17:01:38.000000000 +0100
+++ lyx-1.4-gb/src/insets/insetwrap.h	2006-09-21 17:39:34.000000000 +0200
@@ -13,7 +13,6 @@
 #define INSETWRAP_H
 
 #include "insetcollapsable.h"
-#include "toc.h"
 #include "lyxlength.h"
 
 
diff -ruNpx .svn lyx-1.4-clean/src/MenuBackend.C lyx-1.4-gb/src/MenuBackend.C
--- lyx-1.4-clean/src/MenuBackend.C	2006-03-02 17:02:26.000000000 +0100
+++ lyx-1.4-gb/src/MenuBackend.C	2006-09-21 17:39:39.000000000 +0200
@@ -35,6 +35,8 @@
 #include "lyx_main.h" // for lastfiles
 #include "lyxfunc.h"
 #include "lyxlex.h"
+#include "paragraph.h"
+#include "pariterator.h"
 #include "toc.h"
 
 #include "frontends/LyXView.h"
@@ -681,6 +683,15 @@ void expandToc(Menu & tomenu, LyXView co
 		return;
 	}
 
+	// Add an entry for the master doc if this is a child doc
+	Buffer const * const master = buf->getMasterBuffer();
+	if (buf != master) {
+		ParIterator const pit = par_iterator_begin(master->inset());
+		string const arg = convert<string>(pit->id());
+		FuncRequest f(LFUN_GOTO_PARAGRAPH, arg);
+		tomenu.add(MenuItem(MenuItem::Command, _("Master Document"), f));
+	}
+
 	FloatList const & floatlist = buf->params().getLyXTextClass().floats();
 	lyx::toc::TocList toc_list = lyx::toc::getTocList(*buf);
 	lyx::toc::TocList::const_iterator cit = toc_list.begin();
diff -ruNpx .svn lyx-1.4-clean/src/toc.C lyx-1.4-gb/src/toc.C
--- lyx-1.4-clean/src/toc.C	2006-03-02 17:02:26.000000000 +0100
+++ lyx-1.4-gb/src/toc.C	2006-09-21 17:39:39.000000000 +0200
@@ -23,9 +23,7 @@
 
 #include "frontends/LyXView.h"
 
-#include "insets/insetfloat.h"
 #include "insets/insetoptarg.h"
-#include "insets/insetwrap.h"
 
 #include "support/convert.h"
 
@@ -91,20 +89,12 @@ TocList const getTocList(Buffer const & 
 		// the string that goes to the toc (could be the optarg)
 		string tocstring;
 
-		// For each paragraph, traverse its insets and look for
-		// FLOAT_CODE or WRAP_CODE
+		// For each paragraph, traverse its insets and add them
+		// to the toc.
 		InsetList::const_iterator it = pit->insetlist.begin();
 		InsetList::const_iterator end = pit->insetlist.end();
 		for (; it != end; ++it) {
 			switch (it->inset->lyxCode()) {
-			case InsetBase::FLOAT_CODE:
-				static_cast<InsetFloat*>(it->inset)
-					->addToToc(toclist, buf);
-				break;
-			case InsetBase::WRAP_CODE:
-				static_cast<InsetWrap*>(it->inset)
-					->addToToc(toclist, buf);
-				break;
 			case InsetBase::OPTARG_CODE: {
 				if (!tocstring.empty())
 					break;
@@ -116,6 +106,7 @@ TocList const getTocList(Buffer const & 
 				break;
 			}
 			default:
+				it->inset->addToToc(toclist, buf);
 				break;
 			}
 		}

Reply via email to