Improve the list of equations

Also convert other Tocs to TocBuilder when trivial, to make them customisable
This commit is contained in:
Guillaume Munch 2017-01-09 17:37:50 +01:00
parent e11a3cb895
commit 5fdc577bad
8 changed files with 65 additions and 35 deletions

View File

@ -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> 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();
}

View File

@ -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<InsetExternal &>(*this)));
shared_ptr<Toc> 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();
}

View File

@ -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();
}

View File

@ -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> toc = backend.toc("listing");
docstring str = convert<docstring>(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> 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> 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<Toc> child_toc = pair.second;
shared_ptr<Toc> toc = buffer().tocBackend().toc(type);
toc->insert(toc->end(), child_toc->begin(), child_toc->end());
}
}
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -344,15 +344,42 @@ void InsetMathHull::addToToc(DocIterator const & pit, bool output_active,
return;
}
shared_ptr<Toc> 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();
}

View File

@ -1389,13 +1389,14 @@ string MathMacroTemplate::contextMenuName() const
void MathMacroTemplate::addToToc(DocIterator const & pit, bool output_active,
UpdateType) const
{
shared_ptr<Toc> 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();
}