Abdelrazak Younes wrote:
Georg Baum wrote:
Am Donnerstag, 9. November 2006 13:40 schrieb Abdelrazak Younes:
Georg Baum wrote:
Abdelrazak Younes wrote:

Georg Baum wrote:
This patch adds support for the esint package:
Georg, could you post an updated patch for the multi-document toc?
I never had it in 1.5 so far. If you can tell me what happened to
updateCounters() and where I can find the replacement code I can create
a
patch.
updateLabels()

Thanks, here is the patch. In the 1.4 version I was able to make addToToc a virtual function of InsetBase, but in trunk that is not possible anymore because it would create a circular include dependency (insetbase.h -> toc.h -> pariterator.h -> ... -> insetbase.h).

I wonder if this addToToc() method is a good idea at all... I'd prefer the TocBackend to it himself. InsetInclude doesn't need to know how to do that. The same goes for InsetFloat and InsetWrap I guess.

Here is a patch that does that for InsetInclude. This is cleaner IMHO even if the special cases in TocBackend are still ugly.

Abdel.

Index: buffer_funcs.C
===================================================================
--- buffer_funcs.C      (revision 15852)
+++ buffer_funcs.C      (working copy)
@@ -38,6 +38,7 @@
 #include "frontends/Alert.h"
 
 #include "insets/insetbibitem.h"
+#include "insets/insetinclude.h"
 
 #include "support/filetools.h"
 #include "support/fs_extras.h"
@@ -349,11 +350,9 @@
 
 
 // set the label of a paragraph. This includes the counters.
-void setLabel(Buffer const & buf, ParIterator & it)
+void setLabel(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();
 
@@ -395,7 +394,7 @@
                // 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
                docstring itemlabel;
                switch (par.itemdepth) {
@@ -528,7 +527,7 @@
        case LABEL_CENTERED_TOP_ENVIRONMENT:
        case LABEL_STATIC:
        case LABEL_ITEMIZE:
-               setLabel(buf, it);
+               setLabel(buf, it, buf.params().getLyXTextClass());
                return true;
 
        case LABEL_SENSITIVE:
@@ -544,34 +543,45 @@
 
 
 void updateLabels(Buffer const & buf,
-       ParIterator & from, ParIterator & to)
+       ParIterator & from, ParIterator & to, bool childonly)
 {
        for (ParIterator it = from; it != to; ++it) {
                if (it.pit() > it.lastpit())
                        return;
                if (!updateCurrentLabel (buf, it)) {
-                       updateLabels(buf);
+                       updateLabels(buf, childonly);
                        return;
                }
        }
 }
 
 
-void updateLabels(Buffer const & buf,
-       ParIterator & iter)
+void updateLabels(Buffer const & buf, ParIterator & iter, bool childonly)
 {
        if (updateCurrentLabel(buf, iter))
                return;
 
-       updateLabels(buf);
+       updateLabels(buf, childonly);
 }
 
 
-void updateLabels(Buffer const & buf)
+void updateLabels(Buffer const & buf, bool childonly)
 {
-       // start over the counters
-       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) {
+                       updateLabels(*master);
+                       return;
+               }
+
+               // start over the counters
+               textclass.counters().reset();
+       }
+
        ParIterator const end = par_iterator_end(buf.inset());
 
        for (ParIterator it = par_iterator_begin(buf.inset()); it != end; ++it) 
{
@@ -584,7 +594,16 @@
                        it->params().depth(0);
 
                // set the counter for this paragraph
-               setLabel(buf, it);
+               setLabel(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)
+                                       ->updateLabels(buf);
+               }
        }
 
        const_cast<Buffer &>(buf).tocBackend().update();
Index: buffer_funcs.h
===================================================================
--- buffer_funcs.h      (revision 15850)
+++ buffer_funcs.h      (working copy)
@@ -58,17 +58,17 @@
 /**
 A full updateLabels(Buffer const &) will be called if not possible.
 */
-void updateLabels(Buffer const & buf, ParIterator & it);
+void updateLabels(Buffer const & buf, ParIterator & it, bool childonly = 
false);
 
 /// update labels between "from" and "to" if possible.
 /**
 A full updateLabels(Buffer const &) will be called if not possible.
 */
 void updateLabels(Buffer const & buf,
-       ParIterator & from, ParIterator & to);
+       ParIterator & from, ParIterator & to, bool childonly = false);
 
 /// updates all counters
-void updateLabels(Buffer const &);
+void updateLabels(Buffer const &, bool childonly = false);
 
 
 } // namespace lyx
Index: BufferView.C
===================================================================
--- BufferView.C        (revision 15850)
+++ BufferView.C        (working copy)
@@ -727,21 +727,32 @@
 
        case LFUN_PARAGRAPH_GOTO: {
                int const id = convert<int>(to_utf8(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 = 
theBufferList().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;
 
-               // Set the cursor
-               setCursor(makeDocIterator(par, 0));
+                               if (b != buffer_)
+                                       setBuffer(b);
 
-               update();
-               switchKeyMap();
+                               // Set the cursor
+                               setCursor(makeDocIterator(par, 0));
+
+                               update();
+                               switchKeyMap();
+                               break;
+                       }
+                       ++i;
+               }
                break;
        }
 
Index: insets/insetinclude.C
===================================================================
--- insets/insetinclude.C       (revision 15850)
+++ insets/insetinclude.C       (working copy)
@@ -772,6 +772,27 @@
 }
 
 
+Buffer const * const InsetInclude::childBuffer(Buffer const & buffer) const
+{
+       if (!loadIfNeeded(buffer, params_))
+               return 0;
+
+       string const included_file = includedFilename(buffer, params_);
+       return theBufferList().getBuffer(included_file);
+}
+
+
+void InsetInclude::updateLabels(Buffer const & buffer) const
+{
+       if (!loadIfNeeded(buffer, params_))
+               return;
+
+       string const included_file = includedFilename(buffer, params_);
+       Buffer const * const childbuffer = 
theBufferList().getBuffer(included_file);
+       lyx::updateLabels(*childbuffer, true);
+}
+
+
 string const InsetIncludeMailer::name_("include");
 
 InsetIncludeMailer::InsetIncludeMailer(InsetInclude & inset)
Index: insets/insetinclude.h
===================================================================
--- insets/insetinclude.h       (revision 15850)
+++ insets/insetinclude.h       (working copy)
@@ -26,7 +26,6 @@
 class LaTeXFeatures;
 class RenderMonitoredPreview;
 
-
 /// for including tex/lyx files
 class InsetInclude : public InsetOld {
 public:
@@ -92,7 +91,11 @@
        ///
        void addPreview(graphics::PreviewLoader &) const;
        ///
+       void updateLabels(Buffer const & buffer) const;
+       ///
        bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
+       /// returns the included child Buffer.
+       Buffer const * const childBuffer(Buffer const & buffer) const;
 protected:
        InsetInclude(InsetInclude const &);
        ///
Index: TocBackend.C
===================================================================
--- TocBackend.C        (revision 15852)
+++ TocBackend.C        (working copy)
@@ -23,6 +23,7 @@
 #include "debug.h"
 
 #include "insets/insetfloat.h"
+#include "insets/insetinclude.h"
 #include "insets/insetoptarg.h"
 #include "insets/insetwrap.h"
 
@@ -158,14 +159,32 @@
                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(tocs_, *buffer_);
                                break;
+
+                       case InsetBase::INCLUDE_CODE: {
+                               Buffer const * const childbuffer = 
static_cast<InsetInclude*>(it->inset)
+                                       ->childBuffer(*buffer_);
+                               // break if there is no child document.
+                               if (!childbuffer)
+                                       break;
+                               TocList const childtoclist = 
childbuffer->tocBackend().tocs();
+                               TocList::const_iterator it = 
childtoclist.begin();
+                               TocList::const_iterator const end = 
childtoclist.end();
+                               for(; it != end; ++it)
+                                       
tocs_[it->first].insert(tocs_[it->first].end(),
+                                               it->second.begin(), 
it->second.end());
+                               break;
+                       }
+
                        case InsetBase::WRAP_CODE:
                                static_cast<InsetWrap*>(it->inset)
                                        ->addToToc(tocs_, *buffer_);
                                break;
+
                        case InsetBase::OPTARG_CODE: {
                                if (!tocstring.empty())
                                        break;

Reply via email to