From: Guillaume Munch Date: Mon, 9 Jan 2017 16:37:50 +0000 (+0100) Subject: Improve the list of equations X-Git-Tag: 2.3.0alpha1~495^2~2 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=5fdc577badb1cb133d6a0dc7d831bb1f82576adb;p=features.git Improve the list of equations Also convert other Tocs to TocBuilder when trivial, to make them customisable --- diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp index 13fddd7802..29a0fbfc07 100644 --- a/src/insets/InsetCitation.cpp +++ b/src/insets/InsetCitation.cpp @@ -334,8 +334,9 @@ void InsetCitation::addToToc(DocIterator const & cpit, bool output_active, // by both XHTML and plaintext output. So, if we change what goes into the TOC, // then we will also need to change that routine. docstring const tocitem = getParam("key"); - shared_ptr toc = buffer().tocBackend().toc("citation"); - toc->push_back(TocItem(cpit, 0, tocitem, output_active)); + TocBuilder & b = buffer().tocBackend().builder("citation"); + b.pushItem(cpit, tocitem, output_active); + b.pop(); } diff --git a/src/insets/InsetExternal.cpp b/src/insets/InsetExternal.cpp index 00c304ac30..6e0baff5d7 100644 --- a/src/insets/InsetExternal.cpp +++ b/src/insets/InsetExternal.cpp @@ -506,11 +506,10 @@ bool InsetExternal::getStatus(Cursor & cur, FuncRequest const & cmd, void InsetExternal::addToToc(DocIterator const & cpit, bool output_active, UpdateType) const { - DocIterator pit = cpit; - pit.push_back(CursorSlice(const_cast(*this))); - shared_ptr toc = buffer().tocBackend().toc("external"); docstring str = screenLabel(params_, buffer()); - toc->push_back(TocItem(pit, 0, str, output_active)); + TocBuilder & b = buffer().tocBackend().builder("external"); + b.pushItem(cpit, str, output_active); + b.pop(); } diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp index 4d850b59db..d1458c05a3 100644 --- a/src/insets/InsetGraphics.cpp +++ b/src/insets/InsetGraphics.cpp @@ -1040,7 +1040,9 @@ void InsetGraphics::addToToc(DocIterator const & cpit, bool output_active, { //FIXME UNICODE docstring const str = from_utf8(params_.filename.onlyFileName()); - buffer().tocBackend().toc("graphics")->push_back(TocItem(cpit, 0, str, output_active)); + TocBuilder & b = buffer().tocBackend().builder("graphics"); + b.pushItem(cpit, str, output_active); + b.pop(); } diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 7a35edd173..4e44ec8c87 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -1143,37 +1143,33 @@ void InsetInclude::addPreview(DocIterator const & /*inset_pos*/, void InsetInclude::addToToc(DocIterator const & cpit, bool output_active, UpdateType utype) const { - TocBackend & backend = buffer().tocBackend(); - if (isListings(params())) { if (label_) label_->addToToc(cpit, output_active, utype); - + TocBuilder & b = buffer().tocBackend().builder("listing"); + b.pushItem(cpit, screenLabel(), output_active); InsetListingsParams p(to_utf8(params()["lstparams"])); - string caption = p.getParamValue("caption"); - if (caption.empty()) - return; - shared_ptr toc = backend.toc("listing"); - docstring str = convert(toc->size() + 1) - + ". " + from_utf8(caption); - DocIterator pit = cpit; - toc->push_back(TocItem(pit, 0, str, output_active)); + b.argumentItem(from_utf8(p.getParamValue("caption"))); + b.pop(); } else { Buffer const * const childbuffer = getChildBuffer(); + + TocBuilder & b = buffer().tocBackend().builder("child"); + docstring str = childbuffer ? childbuffer->fileName().displayName() + : from_ascii("?"); + b.pushItem(cpit, str, output_active); + b.pop(); + if (!childbuffer) return; - shared_ptr toc = backend.toc("child"); - docstring str = childbuffer->fileName().displayName(); - toc->push_back(TocItem(cpit, 0, str, output_active)); - + // Include Tocs from children childbuffer->tocBackend().update(output_active, utype); - TocList const & childtoclist = childbuffer->tocBackend().tocs(); - TocList::const_iterator it = childtoclist.begin(); - TocList::const_iterator const end = childtoclist.end(); - for(; it != end; ++it) { - shared_ptr toc = backend.toc(it->first); - toc->insert(toc->end(), it->second->begin(), it->second->end()); + for(auto const & pair : childbuffer->tocBackend().tocs()) { + string const & type = pair.first; + shared_ptr child_toc = pair.second; + shared_ptr toc = buffer().tocBackend().toc(type); + toc->insert(toc->end(), child_toc->begin(), child_toc->end()); } } } diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp index 455b09fa87..a328d27de6 100644 --- a/src/insets/InsetIndex.cpp +++ b/src/insets/InsetIndex.cpp @@ -361,9 +361,11 @@ void InsetIndex::addToToc(DocIterator const & cpit, bool output_active, type += ":" + to_utf8(params_.index); // this is unlikely to be terribly long text().forOutliner(str, INT_MAX); - buffer().tocBackend().toc(type)->push_back(TocItem(pit, 0, str, output_active)); + TocBuilder & b = buffer().tocBackend().builder(type); + b.pushItem(pit, str, output_active); // Proceed with the rest of the inset. InsetCollapsable::addToToc(cpit, output_active, utype); + b.pop(); } diff --git a/src/insets/InsetNomencl.cpp b/src/insets/InsetNomencl.cpp index 7395b6c19e..fe4f7fb141 100644 --- a/src/insets/InsetNomencl.cpp +++ b/src/insets/InsetNomencl.cpp @@ -141,7 +141,9 @@ void InsetNomencl::addToToc(DocIterator const & cpit, bool output_active, UpdateType) const { docstring const str = getParam("symbol"); - buffer().tocBackend().toc("nomencl")->push_back(TocItem(cpit, 0, str, output_active)); + TocBuilder & b = buffer().tocBackend().builder("nomencl"); + b.pushItem(cpit, str, output_active); + b.pop(); } diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index 807475e63a..61e0210487 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -344,15 +344,42 @@ void InsetMathHull::addToToc(DocIterator const & pit, bool output_active, return; } - shared_ptr toc = buffer().tocBackend().toc("equation"); - + TocBuilder & b = buffer().tocBackend().builder("equation"); + // compute first and last item + row_type first = nrows(); + for (row_type row = 0; row != nrows(); ++row) + if (numbered(row)) { + first = row; + break; + } + if (first == nrows()) + // no equation + return; + row_type last = nrows() - 1; + for (; last != 0; --last) + if (numbered(last)) + break; + // add equation numbers + b.pushItem(pit, docstring(), output_active); + if (first != last) + b.argumentItem(bformat(from_ascii("(%1$s-%2$s)"), + numbers_[first], numbers_[last])); for (row_type row = 0; row != nrows(); ++row) { if (!numbered(row)) continue; if (label_[row]) label_[row]->addToToc(pit, output_active, utype); - toc->push_back(TocItem(pit, 0, nicelabel(row), output_active)); + docstring label = nicelabel(row); + if (first == last) + // this is the only equation + b.argumentItem(label); + else { + // insert as sub-items + b.pushItem(pit, label, output_active); + b.pop(); + } } + b.pop(); } diff --git a/src/mathed/MathMacroTemplate.cpp b/src/mathed/MathMacroTemplate.cpp index 2ac8703cb0..2c6cbf7a82 100644 --- a/src/mathed/MathMacroTemplate.cpp +++ b/src/mathed/MathMacroTemplate.cpp @@ -1389,13 +1389,14 @@ string MathMacroTemplate::contextMenuName() const void MathMacroTemplate::addToToc(DocIterator const & pit, bool output_active, UpdateType) const { - shared_ptr toc = buffer().tocBackend().toc("math-macro"); docstring str; if (!validMacro()) str = bformat(_("Invalid macro! \\%1$s"), name()); else str = "\\" + name(); - toc->push_back(TocItem(pit, 0, str, output_active)); + TocBuilder & b = buffer().tocBackend().builder("math-macro"); + b.pushItem(pit, str, output_active); + b.pop(); }