]> git.lyx.org Git - lyx.git/blobdiff - src/TocBackend.C
Scons: update_po target, part one: language_l10n.pot
[lyx.git] / src / TocBackend.C
index 48847483a05e807b8ac893e735cd8798827b3128..6b12ad2bee7fa1d4b60b02bc08b1153bb458fdc6 100644 (file)
@@ -121,24 +121,47 @@ Toc const & TocBackend::toc(std::string const & type) const
 }
 
 
-bool TocBackend::addType(std::string const & type)
+void TocBackend::updateItem(ParConstIterator const & par_it)
 {
-       // Is the type already supported?
-       TocList::iterator toclist_it = tocs_.find(type);
-       if (toclist_it != tocs_.end())
-               return false;
+       BufferParams const & bufparams = buffer_->params();
+       const int min_toclevel = bufparams.getLyXTextClass().min_toclevel();
+
+       TocIterator toc_item = item("tableofcontents", par_it);
+
+       docstring tocstring;
 
-       tocs_.insert(make_pair(type, Toc()));
-       types_.push_back(type);
+       // For each paragraph, traverse its insets and let them add
+       // their toc items
+       InsetList::const_iterator it = toc_item->par_it_->insetlist.begin();
+       InsetList::const_iterator end = toc_item->par_it_->insetlist.end();
+       for (; it != end; ++it) {
+               InsetBase & inset = *it->inset;
+               if (inset.lyxCode() == InsetBase::OPTARG_CODE) {
+                       if (!tocstring.empty())
+                               break;
+                       Paragraph const & par = 
+                               *static_cast<InsetOptArg&>(inset).paragraphs().begin();
+                       if (!toc_item->par_it_->getLabelstring().empty())
+                               tocstring = toc_item->par_it_->getLabelstring() + ' ';
+                       tocstring += par.asString(*buffer_, false);
+                       break;
+               }
+       }
 
-       return true;
+       int const toclevel = toc_item->par_it_->layout()->toclevel;
+       if (toclevel != LyXLayout::NOT_IN_TOC
+           && toclevel >= min_toclevel
+           && toclevel <= bufparams.tocdepth
+               && tocstring.empty())
+                       tocstring = toc_item->par_it_->asString(*buffer_, true);
+
+       const_cast<TocItem &>(*toc_item).str_ = tocstring;
 }
 
 
 void TocBackend::update()
 {
        tocs_.clear();
-       types_.clear();
 
        BufferParams const & bufparams = buffer_->params();
        const int min_toclevel = bufparams.getLyXTextClass().min_toclevel();
@@ -186,10 +209,6 @@ void TocBackend::update()
                                TocItem(pit, toclevel - min_toclevel, tocstring));
                }
        }
-
-       TocList::iterator it = tocs_.begin();
-       for (; it != tocs_.end(); ++it)
-               types_.push_back(it->first);
 }