}
-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;
+
+ // 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;
+ }
+ }
- tocs_.insert(make_pair(type, Toc()));
- types_.push_back(type);
+ 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);
- return 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();
+ Toc & toc = tocs_["tableofcontents"];
ParConstIterator pit = buffer_->par_iterator_begin();
ParConstIterator end = buffer_->par_iterator_end();
for (; pit != end; ++pit) {
InsetList::const_iterator it = pit->insetlist.begin();
InsetList::const_iterator end = pit->insetlist.end();
for (; it != end; ++it) {
- it->inset->addToToc(tocs_, *buffer_);
- switch (it->inset->lyxCode()) {
+ InsetBase & inset = *it->inset;
+ inset.addToToc(tocs_, *buffer_);
+ switch (inset.lyxCode()) {
case InsetBase::OPTARG_CODE: {
if (!tocstring.empty())
break;
- Paragraph const & par = *static_cast<InsetOptArg*>(it->inset)->paragraphs().begin();
+ Paragraph const & par =
+ *static_cast<InsetOptArg&>(inset).paragraphs().begin();
if (!pit->getLabelstring().empty())
tocstring = pit->getLabelstring() + ' ';
tocstring += par.asString(*buffer_, false);
// insert this into the table of contents
if (tocstring.empty())
tocstring = pit->asString(*buffer_, true);
- TocItem const item(pit, toclevel - min_toclevel, tocstring);
- tocs_["tableofcontents"].push_back(item);
+ toc.push_back(
+ TocItem(pit, toclevel - min_toclevel, tocstring));
}
}
-
- TocList::iterator it = tocs_.begin();
- for (; it != tocs_.end(); ++it)
- types_.push_back(it->first);
}
Toc const & toc_vector = toclist_it->second;
TocIterator last = toc_vector.begin();
TocIterator it = toc_vector.end();
+ if (it == last)
+ return it;
+
--it;
+ ParConstIterator par_it_text = par_it;
+ if (par_it_text.inMathed())
+ // It would be better to do
+ // par_it_text.backwardInset();
+ // but this method does not exist.
+ while (par_it_text.inMathed())
+ par_it_text.backwardPos();
+
for (; it != last; --it) {
// A good solution for Items inside insets would be to do:
// But for an unknown reason, std::distance(current, it->par_it_) always
// returns a positive value and std::distance(it->par_it_, current) takes forever...
// So for now, we do:
- if (it->par_it_.pit() <= par_it.pit())
+ if (it->par_it_.pit() <= par_it_text.pit())
return it;
}
}
-void TocBackend::asciiTocList(string const & type, odocstream & os) const
+void TocBackend::writePlaintextTocList(string const & type, odocstream & os) const
{
TocList::const_iterator cit = tocs_.find(type);
if (cit != tocs_.end()) {