Make the generation of children's tocs more robust

Let the children directly access the TocBuilders, instead of concatenating
after the fact.
This commit is contained in:
Guillaume Munch 2017-01-13 11:06:48 +01:00
parent 461fda9ca9
commit 3391fed36a
40 changed files with 111 additions and 107 deletions

View File

@ -475,12 +475,12 @@ void Changes::checkAuthors(AuthorList const & authorList)
void Changes::addToToc(DocIterator const & cdit, Buffer const & buffer, void Changes::addToToc(DocIterator const & cdit, Buffer const & buffer,
bool output_active) const bool output_active, TocBackend & backend) const
{ {
if (table_.empty()) if (table_.empty())
return; return;
shared_ptr<Toc> change_list = buffer.tocBackend().toc("change"); shared_ptr<Toc> change_list = backend.toc("change");
AuthorList const & author_list = buffer.params().authors(); AuthorList const & author_list = buffer.params().authors();
DocIterator dit = cdit; DocIterator dit = cdit;

View File

@ -29,10 +29,11 @@ namespace lyx {
class AuthorList; class AuthorList;
class Buffer; class Buffer;
class DocIterator; class DocIterator;
class FontInfo;
class OutputParams; class OutputParams;
class otexstream; class otexstream;
class PainterInfo; class PainterInfo;
class FontInfo; class TocBackend;
class Change { class Change {
@ -137,7 +138,7 @@ public:
/// ///
void addToToc(DocIterator const & cdit, Buffer const & buffer, void addToToc(DocIterator const & cdit, Buffer const & buffer,
bool output_active) const; bool output_active, TocBackend & backend) const;
/// ///
void updateBuffer(Buffer const & buf); void updateBuffer(Buffer const & buf);

View File

@ -562,10 +562,10 @@ Paragraph::Private::Private(Private const & p, Paragraph * owner,
} }
void Paragraph::addChangesToToc(DocIterator const & cdit, void Paragraph::addChangesToToc(DocIterator const & cdit, Buffer const & buf,
Buffer const & buf, bool output_active) const bool output_active, TocBackend & backend) const
{ {
d->changes_.addToToc(cdit, buf, output_active); d->changes_.addToToc(cdit, buf, output_active, backend);
} }

View File

@ -47,6 +47,7 @@ class MetricsInfo;
class OutputParams; class OutputParams;
class PainterInfo; class PainterInfo;
class ParagraphParameters; class ParagraphParameters;
class TocBackend;
class WordLangTuple; class WordLangTuple;
class XHTMLStream; class XHTMLStream;
class otexstream; class otexstream;
@ -150,7 +151,7 @@ public:
/// ///
void addChangesToToc(DocIterator const & cdit, Buffer const & buf, void addChangesToToc(DocIterator const & cdit, Buffer const & buf,
bool output_active) const; bool output_active, TocBackend & backend) const;
/// set the buffer flag if there are changes in the paragraph /// set the buffer flag if there are changes in the paragraph
void addChangesToBuffer(Buffer const & buf) const; void addChangesToBuffer(Buffer const & buf) const;
/// ///

View File

@ -217,7 +217,7 @@ void TocBackend::update(bool output_active, UpdateType utype)
resetOutlinerNames(); resetOutlinerNames();
if (!buffer_->isInternal()) { if (!buffer_->isInternal()) {
DocIterator dit; DocIterator dit;
buffer_->inset().addToToc(dit, output_active, utype); buffer_->inset().addToToc(dit, output_active, utype, *this);
} }
} }

View File

@ -1311,20 +1311,20 @@ void MenuDefinition::expandToc(Buffer const * buf)
} }
MenuDefinition other_lists; MenuDefinition other_lists;
TocList const & toc_list = buf->tocBackend().tocs(); // In the navigation menu, only add tocs from this document
TocList::const_iterator cit = toc_list.begin(); TocBackend const & backend = buf->tocBackend();
TocList::const_iterator end = toc_list.end(); TocList const & toc_list = backend.tocs();
for (; cit != end; ++cit) { for (pair<string, shared_ptr<Toc>> const & toc : toc_list) {
// Handle table of contents later // Handle table of contents later
if (cit->first == "tableofcontents" || cit->second->empty()) if (toc.first == "tableofcontents" || toc.second->empty())
continue; continue;
MenuDefinition submenu; MenuDefinition submenu;
submenu.expandTocSubmenu(cit->first, *cit->second); submenu.expandTocSubmenu(toc.first, *toc.second);
docstring const toc_name = buf->tocBackend().outlinerName(cit->first); docstring const toc_name = backend.outlinerName(toc.first);
MenuItem item(MenuItem::Submenu, toqstr(toc_name)); MenuItem item(MenuItem::Submenu, toqstr(toc_name));
item.setSubmenu(submenu); item.setSubmenu(submenu);
// deserves to be in the main menu? // deserves to be in the main menu?
if (!TocBackend::isOther(cit->first)) if (!TocBackend::isOther(toc.first))
add(item); add(item);
else else
other_lists.add(item); other_lists.add(item);
@ -1336,8 +1336,8 @@ void MenuDefinition::expandToc(Buffer const * buf)
} }
// Handle normal TOC // Handle normal TOC
add(MenuItem(MenuItem::Separator)); add(MenuItem(MenuItem::Separator));
cit = toc_list.find("tableofcontents"); TocList::const_iterator cit = toc_list.find("tableofcontents");
if (cit == end) if (cit == toc_list.end())
LYXERR(Debug::GUI, "No table of contents."); LYXERR(Debug::GUI, "No table of contents.");
else { else {
if (!cit->second->empty()) if (!cit->second->empty())

View File

@ -351,21 +351,19 @@ void TocModels::reset(BufferView const * bv)
names_->blockSignals(true); names_->blockSignals(true);
names_->beginResetModel(); names_->beginResetModel();
names_->insertColumns(0, 1); names_->insertColumns(0, 1);
// In the outliner, add Tocs from the master document
TocBackend const & backend = bv->buffer().masterBuffer()->tocBackend(); TocBackend const & backend = bv->buffer().masterBuffer()->tocBackend();
TocList const & tocs = backend.tocs(); for (pair<string, shared_ptr<Toc>> const & toc : backend.tocs()) {
TocList::const_iterator it = tocs.begin(); QString const type = toqstr(toc.first);
TocList::const_iterator toc_end = tocs.end();
for (; it != toc_end; ++it) {
QString const type = toqstr(it->first);
// First, fill in the toc models. // First, fill in the toc models.
iterator mod_it = models_.find(type); iterator mod_it = models_.find(type);
if (mod_it == models_.end()) if (mod_it == models_.end())
mod_it = models_.insert(type, new TocModel(this)); mod_it = models_.insert(type, new TocModel(this));
mod_it.value()->reset(it->second); mod_it.value()->reset(toc.second);
// Fill in the names_ model. // Fill in the names_ model.
QString const gui_name = toqstr(backend.outlinerName(it->first)); QString const gui_name = toqstr(backend.outlinerName(toc.first));
int const current_row = names_->rowCount(); int const current_row = names_->rowCount();
names_->insertRows(current_row, 1); names_->insertRows(current_row, 1);
QModelIndex const index = names_->index(current_row, 0); QModelIndex const index = names_->index(current_row, 0);

View File

@ -57,6 +57,7 @@ class PainterInfo;
class ParConstIterator; class ParConstIterator;
class ParIterator; class ParIterator;
class Text; class Text;
class TocBackend;
class TocList; class TocList;
class XHTMLStream; class XHTMLStream;
class otexstream; class otexstream;
@ -512,9 +513,12 @@ public:
/// ///
/// \param utype : is the toc being generated for use by the output /// \param utype : is the toc being generated for use by the output
/// routines? /// routines?
///
/// \param tocbackend : where to add the toc information.
virtual void addToToc(DocIterator const & /* di */, virtual void addToToc(DocIterator const & /* di */,
bool /* output_active */, bool /* output_active */,
UpdateType /* utype*/) const {} UpdateType /* utype*/,
TocBackend & /* tocbackend */) const {}
/// Collect BibTeX information /// Collect BibTeX information
virtual void collectBibKeys(InsetIterator const &) const {} virtual void collectBibKeys(InsetIterator const &) const {}
/// Update the counters of this inset and of its contents. /// Update the counters of this inset and of its contents.

View File

@ -317,17 +317,16 @@ void InsetArgument::latexArgument(otexstream & os,
} }
void InsetArgument::addToToc(DocIterator const & dit, bool output_active, void InsetArgument::addToToc(DocIterator const & dit, bool output_active,
UpdateType utype) const UpdateType utype, TocBackend & backend) const
{ {
if (!caption_of_toc_.empty()) { if (!caption_of_toc_.empty()) {
docstring str; docstring str;
text().forOutliner(str, TOC_ENTRY_LENGTH); text().forOutliner(str, TOC_ENTRY_LENGTH);
buffer().tocBackend().builder(caption_of_toc_).argumentItem(str); backend.builder(caption_of_toc_).argumentItem(str);
} }
// Proceed with the rest of the inset. // Proceed with the rest of the inset.
InsetText::addToToc(dit, output_active, utype); InsetText::addToToc(dit, output_active, utype, backend);
} }

View File

@ -83,7 +83,7 @@ public:
//@} //@}
/// ///
void addToToc(DocIterator const & dit, bool output_active, void addToToc(DocIterator const & dit, bool output_active,
UpdateType utype) const; //override UpdateType utype, TocBackend & backend) const; //override
private: private:
/// ///

View File

@ -94,7 +94,7 @@ void InsetCaption::setCustomLabel(docstring const & label)
void InsetCaption::addToToc(DocIterator const & cpit, bool output_active, void InsetCaption::addToToc(DocIterator const & cpit, bool output_active,
UpdateType utype) const UpdateType utype, TocBackend & backend) const
{ {
string const & type = floattype_.empty() ? "senseless" : floattype_; string const & type = floattype_.empty() ? "senseless" : floattype_;
DocIterator pit = cpit; DocIterator pit = cpit;
@ -109,9 +109,9 @@ void InsetCaption::addToToc(DocIterator const & cpit, bool output_active,
str = full_label_; str = full_label_;
text().forOutliner(str, length); text().forOutliner(str, length);
} }
buffer().tocBackend().builder(type).captionItem(pit, str, output_active); backend.builder(type).captionItem(pit, str, output_active);
// Proceed with the rest of the inset. // Proceed with the rest of the inset.
InsetText::addToToc(cpit, output_active, utype); InsetText::addToToc(cpit, output_active, utype, backend);
} }

View File

@ -82,7 +82,8 @@ private:
/// ///
void setCustomLabel(docstring const & label); void setCustomLabel(docstring const & label);
/// ///
void addToToc(DocIterator const & di, bool output_active, UpdateType utype) const; void addToToc(DocIterator const & di, bool output_active, UpdateType utype,
TocBackend & backend) const;
/// ///
virtual bool forcePlainLayout(idx_type = 0) const { return true; } virtual bool forcePlainLayout(idx_type = 0) const { return true; }
/// Captions don't accept alignment, spacing, etc. /// Captions don't accept alignment, spacing, etc.

View File

@ -97,7 +97,7 @@ docstring InsetCaptionable::getCaptionHTML(OutputParams const & runparams) const
void InsetCaptionable::addToToc(DocIterator const & cpit, bool output_active, void InsetCaptionable::addToToc(DocIterator const & cpit, bool output_active,
UpdateType utype) const UpdateType utype, TocBackend & backend) const
{ {
DocIterator pit = cpit; DocIterator pit = cpit;
pit.push_back(CursorSlice(const_cast<InsetCaptionable &>(*this))); pit.push_back(CursorSlice(const_cast<InsetCaptionable &>(*this)));
@ -107,10 +107,10 @@ void InsetCaptionable::addToToc(DocIterator const & cpit, bool output_active,
// non-empty. // non-empty.
if (utype != OutputUpdate) if (utype != OutputUpdate)
text().forOutliner(str, TOC_ENTRY_LENGTH); text().forOutliner(str, TOC_ENTRY_LENGTH);
TocBuilder & b = buffer().tocBackend().builder(caption_type_); TocBuilder & b = backend.builder(caption_type_);
b.pushItem(pit, str, output_active); b.pushItem(pit, str, output_active);
// Proceed with the rest of the inset. // Proceed with the rest of the inset.
InsetCollapsable::addToToc(cpit, output_active, utype); InsetCollapsable::addToToc(cpit, output_active, utype, backend);
b.pop(); b.pop();
} }

View File

@ -43,7 +43,7 @@ protected:
virtual bool hasSubCaptions(ParIterator const &) const { return false; } virtual bool hasSubCaptions(ParIterator const &) const { return false; }
/// ///
void addToToc(DocIterator const & di, bool output_active, void addToToc(DocIterator const & di, bool output_active,
UpdateType utype) const; UpdateType utype, TocBackend & backend) const;
/// Update the counters of this inset and of its contents /// Update the counters of this inset and of its contents
void updateBuffer(ParIterator const &, UpdateType); void updateBuffer(ParIterator const &, UpdateType);
/// ///

View File

@ -420,7 +420,7 @@ void InsetCitation::updateBuffer(ParIterator const &, UpdateType)
void InsetCitation::addToToc(DocIterator const & cpit, bool output_active, void InsetCitation::addToToc(DocIterator const & cpit, bool output_active,
UpdateType) const UpdateType, TocBackend & backend) const
{ {
// NOTE // NOTE
// BiblioInfo::collectCitedEntries() uses the TOC to collect the citations // BiblioInfo::collectCitedEntries() uses the TOC to collect the citations
@ -428,7 +428,7 @@ void InsetCitation::addToToc(DocIterator const & cpit, bool output_active,
// by both XHTML and plaintext output. So, if we change what goes into the TOC, // by both XHTML and plaintext output. So, if we change what goes into the TOC,
// then we will also need to change that routine. // then we will also need to change that routine.
docstring const tocitem = getParam("key"); docstring const tocitem = getParam("key");
TocBuilder & b = buffer().tocBackend().builder("citation"); TocBuilder & b = backend.builder("citation");
b.pushItem(cpit, tocitem, output_active); b.pushItem(cpit, tocitem, output_active);
b.pop(); b.pop();
} }

View File

@ -69,7 +69,7 @@ public:
void updateBuffer(ParIterator const & it, UpdateType); void updateBuffer(ParIterator const & it, UpdateType);
/// ///
void addToToc(DocIterator const & di, bool output_active, void addToToc(DocIterator const & di, bool output_active,
UpdateType utype) const; UpdateType utype, TocBackend & backend) const;
/// ///
std::string contextMenuName() const; std::string contextMenuName() const;
//@} //@}

View File

@ -662,19 +662,19 @@ bool InsetCollapsable::canPaintChange(BufferView const & bv) const
void InsetCollapsable::addToToc(DocIterator const & cpit, bool output_active, void InsetCollapsable::addToToc(DocIterator const & cpit, bool output_active,
UpdateType utype) const UpdateType utype, TocBackend & backend) const
{ {
bool doing_output = output_active && producesOutput(); bool doing_output = output_active && producesOutput();
InsetLayout const & layout = getLayout(); InsetLayout const & layout = getLayout();
if (layout.addToToc()) { if (layout.addToToc()) {
TocBuilder & b = buffer().tocBackend().builder(layout.tocType()); TocBuilder & b = backend.builder(layout.tocType());
// Cursor inside the inset // Cursor inside the inset
DocIterator pit = cpit; DocIterator pit = cpit;
pit.push_back(CursorSlice(const_cast<InsetCollapsable &>(*this))); pit.push_back(CursorSlice(const_cast<InsetCollapsable &>(*this)));
docstring const label = getLabel(); docstring const label = getLabel();
b.pushItem(pit, label + (label.empty() ? "" : ": "), output_active); b.pushItem(pit, label + (label.empty() ? "" : ": "), output_active);
// Proceed with the rest of the inset. // Proceed with the rest of the inset.
InsetText::addToToc(cpit, doing_output, utype); InsetText::addToToc(cpit, doing_output, utype, backend);
if (layout.isTocCaption()) { if (layout.isTocCaption()) {
docstring str; docstring str;
text().forOutliner(str, TOC_ENTRY_LENGTH); text().forOutliner(str, TOC_ENTRY_LENGTH);
@ -682,7 +682,7 @@ void InsetCollapsable::addToToc(DocIterator const & cpit, bool output_active,
} }
b.pop(); b.pop();
} else } else
InsetText::addToToc(cpit, doing_output, utype); InsetText::addToToc(cpit, doing_output, utype, backend);
} }

View File

@ -152,7 +152,7 @@ public:
std::string contextMenuName() const; std::string contextMenuName() const;
/// ///
void addToToc(DocIterator const & dit, bool output_active, void addToToc(DocIterator const & dit, bool output_active,
UpdateType utype) const; //override UpdateType utype, TocBackend & backend) const; //override
protected: protected:
/// ///

View File

@ -504,10 +504,10 @@ bool InsetExternal::getStatus(Cursor & cur, FuncRequest const & cmd,
void InsetExternal::addToToc(DocIterator const & cpit, bool output_active, void InsetExternal::addToToc(DocIterator const & cpit, bool output_active,
UpdateType) const UpdateType, TocBackend & backend) const
{ {
docstring str = screenLabel(params_, buffer()); docstring str = screenLabel(params_, buffer());
TocBuilder & b = buffer().tocBackend().builder("external"); TocBuilder & b = backend.builder("external");
b.pushItem(cpit, str, output_active); b.pushItem(cpit, str, output_active);
b.pop(); b.pop();
} }

View File

@ -121,7 +121,7 @@ public:
bool clickable(BufferView const &, int, int) const { return true; } bool clickable(BufferView const &, int, int) const { return true; }
/// ///
void addToToc(DocIterator const & di, bool output_active, void addToToc(DocIterator const & di, bool output_active,
UpdateType utype) const; UpdateType utype, TocBackend & backend) const;
private: private:
/// ///
InsetExternal(InsetExternal const &); InsetExternal(InsetExternal const &);

View File

@ -1036,11 +1036,11 @@ void InsetGraphics::editGraphics(InsetGraphicsParams const & p) const
void InsetGraphics::addToToc(DocIterator const & cpit, bool output_active, void InsetGraphics::addToToc(DocIterator const & cpit, bool output_active,
UpdateType) const UpdateType, TocBackend & backend) const
{ {
//FIXME UNICODE //FIXME UNICODE
docstring const str = from_utf8(params_.filename.onlyFileName()); docstring const str = from_utf8(params_.filename.onlyFileName());
TocBuilder & b = buffer().tocBackend().builder("graphics"); TocBuilder & b = backend.builder("graphics");
b.pushItem(cpit, str, output_active); b.pushItem(cpit, str, output_active);
b.pop(); b.pop();
} }

View File

@ -102,7 +102,7 @@ private:
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const; bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
/// ///
void addToToc(DocIterator const & di, bool output_active, void addToToc(DocIterator const & di, bool output_active,
UpdateType utype) const; UpdateType utype, TocBackend & backend) const;
/// ///
std::string contextMenuName() const; std::string contextMenuName() const;
/// Force inset into LTR environment if surroundings are RTL /// Force inset into LTR environment if surroundings are RTL

View File

@ -1141,12 +1141,11 @@ void InsetInclude::addPreview(DocIterator const & /*inset_pos*/,
void InsetInclude::addToToc(DocIterator const & cpit, bool output_active, void InsetInclude::addToToc(DocIterator const & cpit, bool output_active,
UpdateType utype) const UpdateType utype, TocBackend & backend) const
{ {
TocBackend & backend = buffer().tocBackend();
if (isListings(params())) { if (isListings(params())) {
if (label_) if (label_)
label_->addToToc(cpit, output_active, utype); label_->addToToc(cpit, output_active, utype, backend);
TocBuilder & b = backend.builder("listing"); TocBuilder & b = backend.builder("listing");
b.pushItem(cpit, screenLabel(), output_active); b.pushItem(cpit, screenLabel(), output_active);
InsetListingsParams p(to_utf8(params()["lstparams"])); InsetListingsParams p(to_utf8(params()["lstparams"]));
@ -1165,13 +1164,7 @@ void InsetInclude::addToToc(DocIterator const & cpit, bool output_active,
return; return;
// Include Tocs from children // Include Tocs from children
childbuffer->tocBackend().update(output_active, utype); childbuffer->inset().addToToc(cpit, output_active, utype, backend);
for(auto const & pair : childbuffer->tocBackend().tocs()) {
string const & type = pair.first;
shared_ptr<Toc const> child_toc = pair.second;
shared_ptr<Toc> toc = backend.toc(type);
toc->insert(toc->end(), child_toc->begin(), child_toc->end());
}
//Copy missing outliner names (though the user has been warned against //Copy missing outliner names (though the user has been warned against
//having different document class and module selection between master //having different document class and module selection between master
//and child). //and child).

View File

@ -110,7 +110,7 @@ public:
void addPreview(DocIterator const &, graphics::PreviewLoader &) const; void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
/// ///
void addToToc(DocIterator const & di, bool output_active, void addToToc(DocIterator const & di, bool output_active,
UpdateType utype) const; UpdateType utype, TocBackend & backend) const;
/// ///
void updateBuffer(ParIterator const &, UpdateType); void updateBuffer(ParIterator const &, UpdateType);
/// ///

View File

@ -351,7 +351,7 @@ void InsetIndex::string2params(string const & in, InsetIndexParams & params)
void InsetIndex::addToToc(DocIterator const & cpit, bool output_active, void InsetIndex::addToToc(DocIterator const & cpit, bool output_active,
UpdateType utype) const UpdateType utype, TocBackend & backend) const
{ {
DocIterator pit = cpit; DocIterator pit = cpit;
pit.push_back(CursorSlice(const_cast<InsetIndex &>(*this))); pit.push_back(CursorSlice(const_cast<InsetIndex &>(*this)));
@ -361,10 +361,10 @@ void InsetIndex::addToToc(DocIterator const & cpit, bool output_active,
type += ":" + to_utf8(params_.index); type += ":" + to_utf8(params_.index);
// this is unlikely to be terribly long // this is unlikely to be terribly long
text().forOutliner(str, INT_MAX); text().forOutliner(str, INT_MAX);
TocBuilder & b = buffer().tocBackend().builder(type); TocBuilder & b = backend.builder(type);
b.pushItem(pit, str, output_active); b.pushItem(pit, str, output_active);
// Proceed with the rest of the inset. // Proceed with the rest of the inset.
InsetCollapsable::addToToc(cpit, output_active, utype); InsetCollapsable::addToToc(cpit, output_active, utype, backend);
b.pop(); b.pop();
} }

View File

@ -72,7 +72,7 @@ private:
bool neverIndent() const { return true; } bool neverIndent() const { return true; }
/// ///
void addToToc(DocIterator const & di, bool output_active, void addToToc(DocIterator const & di, bool output_active,
UpdateType utype) const; UpdateType utype, TocBackend & backend) const;
/// ///
docstring toolTip(BufferView const & bv, int x, int y) const; docstring toolTip(BufferView const & bv, int x, int y) const;
/// ///

View File

@ -170,10 +170,10 @@ void InsetLabel::updateBuffer(ParIterator const & par, UpdateType utype)
void InsetLabel::addToToc(DocIterator const & cpit, bool output_active, void InsetLabel::addToToc(DocIterator const & cpit, bool output_active,
UpdateType) const UpdateType, TocBackend & backend) const
{ {
docstring const & label = getParam("name"); docstring const & label = getParam("name");
shared_ptr<Toc> toc = buffer().tocBackend().toc("label"); shared_ptr<Toc> toc = backend.toc("label");
if (buffer().insetLabel(label) != this) { if (buffer().insetLabel(label) != this) {
toc->push_back(TocItem(cpit, 0, screen_label_, output_active)); toc->push_back(TocItem(cpit, 0, screen_label_, output_active));
} else { } else {

View File

@ -58,7 +58,7 @@ public:
void updateBuffer(ParIterator const & it, UpdateType); void updateBuffer(ParIterator const & it, UpdateType);
/// ///
void addToToc(DocIterator const & di, bool output_active, void addToToc(DocIterator const & di, bool output_active,
UpdateType utype) const; UpdateType utype, TocBackend & backend) const;
/// Is the content of this inset part of the immediate (visible) text sequence? /// Is the content of this inset part of the immediate (visible) text sequence?
bool isPartOfTextSequence() const { return false; } bool isPartOfTextSequence() const { return false; }
//@} //@}

View File

@ -138,10 +138,10 @@ void InsetNomencl::validate(LaTeXFeatures & features) const
void InsetNomencl::addToToc(DocIterator const & cpit, bool output_active, void InsetNomencl::addToToc(DocIterator const & cpit, bool output_active,
UpdateType) const UpdateType, TocBackend & backend) const
{ {
docstring const str = getParam("symbol"); docstring const str = getParam("symbol");
TocBuilder & b = buffer().tocBackend().builder("nomencl"); TocBuilder & b = backend.builder("nomencl");
b.pushItem(cpit, str, output_active); b.pushItem(cpit, str, output_active);
b.pop(); b.pop();
} }

View File

@ -41,7 +41,7 @@ public:
void validate(LaTeXFeatures & features) const; void validate(LaTeXFeatures & features) const;
/// ///
void addToToc(DocIterator const & di, bool output_active, void addToToc(DocIterator const & di, bool output_active,
UpdateType utype) const; UpdateType utype, TocBackend & backend) const;
/// ///
InsetCode lyxCode() const { return NOMENCL_CODE; } InsetCode lyxCode() const { return NOMENCL_CODE; }
/// ///

View File

@ -356,7 +356,7 @@ void InsetRef::updateBuffer(ParIterator const & it, UpdateType)
void InsetRef::addToToc(DocIterator const & cpit, bool output_active, void InsetRef::addToToc(DocIterator const & cpit, bool output_active,
UpdateType) const UpdateType, TocBackend & backend) const
{ {
docstring const & label = getParam("reference"); docstring const & label = getParam("reference");
if (buffer().insetLabel(label)) if (buffer().insetLabel(label))
@ -365,7 +365,7 @@ void InsetRef::addToToc(DocIterator const & cpit, bool output_active,
// It seems that this reference does not point to any valid label. // It seems that this reference does not point to any valid label.
screen_label_ = _("BROKEN: ") + screen_label_; screen_label_ = _("BROKEN: ") + screen_label_;
shared_ptr<Toc> toc = buffer().tocBackend().toc("label"); shared_ptr<Toc> toc = backend.toc("label");
toc->push_back(TocItem(cpit, 0, screen_label_, output_active)); toc->push_back(TocItem(cpit, 0, screen_label_, output_active));
} }

View File

@ -71,7 +71,7 @@ public:
void updateBuffer(ParIterator const & it, UpdateType); void updateBuffer(ParIterator const & it, UpdateType);
/// ///
void addToToc(DocIterator const & di, bool output_active, void addToToc(DocIterator const & di, bool output_active,
UpdateType utype) const; UpdateType utype, TocBackend & backend) const;
/// ///
bool forceLTR() const { return true; } bool forceLTR() const { return true; }
//@} //@}

View File

@ -3510,9 +3510,9 @@ docstring InsetTableCell::asString(bool intoInsets)
void InsetTableCell::addToToc(DocIterator const & di, bool output_active, void InsetTableCell::addToToc(DocIterator const & di, bool output_active,
UpdateType utype) const UpdateType utype, TocBackend & backend) const
{ {
InsetText::iterateForToc(di, output_active, utype); InsetText::iterateForToc(di, output_active, utype, backend);
} }
@ -3981,13 +3981,13 @@ void InsetTabular::updateBuffer(ParIterator const & it, UpdateType utype)
void InsetTabular::addToToc(DocIterator const & cpit, bool output_active, void InsetTabular::addToToc(DocIterator const & cpit, bool output_active,
UpdateType utype) const UpdateType utype, TocBackend & backend) const
{ {
DocIterator dit = cpit; DocIterator dit = cpit;
dit.forwardPos(); dit.forwardPos();
size_t const end = dit.nargs(); size_t const end = dit.nargs();
for ( ; dit.idx() < end; dit.top().forwardIdx()) for ( ; dit.idx() < end; dit.top().forwardIdx())
cell(dit.idx())->addToToc(dit, output_active, utype); cell(dit.idx())->addToToc(dit, output_active, utype, backend);
} }

View File

@ -71,7 +71,7 @@ public:
docstring xhtml(XHTMLStream &, OutputParams const &) const; docstring xhtml(XHTMLStream &, OutputParams const &) const;
/// ///
void addToToc(DocIterator const & di, bool output_active, void addToToc(DocIterator const & di, bool output_active,
UpdateType utype) const; UpdateType utype, TocBackend & backend) const;
private: private:
/// unimplemented /// unimplemented
InsetTableCell(); InsetTableCell();
@ -959,7 +959,7 @@ public:
void updateBuffer(ParIterator const &, UpdateType); void updateBuffer(ParIterator const &, UpdateType);
/// ///
void addToToc(DocIterator const & di, bool output_active, void addToToc(DocIterator const & di, bool output_active,
UpdateType utype) const; UpdateType utype, TocBackend & backend) const;
/// ///
bool completionSupported(Cursor const &) const; bool completionSupported(Cursor const &) const;

View File

@ -830,20 +830,20 @@ void InsetText::forOutliner(docstring & os, size_t const maxlen,
void InsetText::addToToc(DocIterator const & cdit, bool output_active, void InsetText::addToToc(DocIterator const & cdit, bool output_active,
UpdateType utype) const UpdateType utype, TocBackend & backend) const
{ {
DocIterator dit = cdit; DocIterator dit = cdit;
dit.push_back(CursorSlice(const_cast<InsetText &>(*this))); dit.push_back(CursorSlice(const_cast<InsetText &>(*this)));
iterateForToc(dit, output_active, utype); iterateForToc(dit, output_active, utype, backend);
} }
void InsetText::iterateForToc(DocIterator const & cdit, bool output_active, void InsetText::iterateForToc(DocIterator const & cdit, bool output_active,
UpdateType utype) const UpdateType utype, TocBackend & backend) const
{ {
DocIterator dit = cdit; DocIterator dit = cdit;
// This also ensures that any document has a table of contents // This also ensures that any document has a table of contents
shared_ptr<Toc> toc = buffer().tocBackend().toc("tableofcontents"); shared_ptr<Toc> toc = backend.toc("tableofcontents");
BufferParams const & bufparams = buffer_->params(); BufferParams const & bufparams = buffer_->params();
int const min_toclevel = bufparams.documentClass().min_toclevel(); int const min_toclevel = bufparams.documentClass().min_toclevel();
@ -870,7 +870,8 @@ void InsetText::iterateForToc(DocIterator const & cdit, bool output_active,
// Custom AddToToc in paragraph layouts (i.e. theorems) // Custom AddToToc in paragraph layouts (i.e. theorems)
if (par.layout().addToToc() && text().isFirstInSequence(pit)) { if (par.layout().addToToc() && text().isFirstInSequence(pit)) {
pit_type end = openAddToTocForParagraph(pit, dit, output_active); pit_type end =
openAddToTocForParagraph(pit, dit, output_active, backend);
addtotoc_stack.push({pit, end}); addtotoc_stack.push({pit, end});
} }
@ -882,7 +883,7 @@ void InsetText::iterateForToc(DocIterator const & cdit, bool output_active,
Inset & inset = *it->inset; Inset & inset = *it->inset;
dit.pos() = it->pos; dit.pos() = it->pos;
//lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl; //lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl;
inset.addToToc(dit, doing_output, utype); inset.addToToc(dit, doing_output, utype, backend);
if (inset.lyxCode() == ARG_CODE) if (inset.lyxCode() == ARG_CODE)
arginset = inset.asInsetText(); arginset = inset.asInsetText();
} }
@ -891,7 +892,7 @@ void InsetText::iterateForToc(DocIterator const & cdit, bool output_active,
while (!addtotoc_stack.empty() && addtotoc_stack.top().second == pit) { while (!addtotoc_stack.empty() && addtotoc_stack.top().second == pit) {
// execute the closing function // execute the closing function
closeAddToTocForParagraph(addtotoc_stack.top().first, closeAddToTocForParagraph(addtotoc_stack.top().first,
addtotoc_stack.top().second); addtotoc_stack.top().second, backend);
addtotoc_stack.pop(); addtotoc_stack.pop();
} }
@ -915,27 +916,29 @@ void InsetText::iterateForToc(DocIterator const & cdit, bool output_active,
} }
// And now the list of changes. // And now the list of changes.
par.addChangesToToc(dit, buffer(), doing_output); par.addChangesToToc(dit, buffer(), doing_output, backend);
} }
} }
pit_type InsetText::openAddToTocForParagraph(pit_type pit, pit_type InsetText::openAddToTocForParagraph(pit_type pit,
DocIterator const & dit, DocIterator const & dit,
bool output_active) const bool output_active,
TocBackend & backend) const
{ {
Paragraph const & par = paragraphs()[pit]; Paragraph const & par = paragraphs()[pit];
TocBuilder & b = buffer().tocBackend().builder(par.layout().tocType()); TocBuilder & b = backend.builder(par.layout().tocType());
docstring const label = par.labelString(); docstring const label = par.labelString();
b.pushItem(dit, label + (label.empty() ? "" : " "), output_active); b.pushItem(dit, label + (label.empty() ? "" : " "), output_active);
return text().lastInSequence(pit); return text().lastInSequence(pit);
} }
void InsetText::closeAddToTocForParagraph(pit_type start, pit_type end) const void InsetText::closeAddToTocForParagraph(pit_type start, pit_type end,
TocBackend & backend) const
{ {
Paragraph const & par = paragraphs()[start]; Paragraph const & par = paragraphs()[start];
TocBuilder & b = buffer().tocBackend().builder(par.layout().tocType()); TocBuilder & b = backend.builder(par.layout().tocType());
if (par.layout().isTocCaption()) { if (par.layout().isTocCaption()) {
docstring str; docstring str;
text().forOutliner(str, TOC_ENTRY_LENGTH, start, end); text().forOutliner(str, TOC_ENTRY_LENGTH, start, end);

View File

@ -25,6 +25,7 @@ class Dimension;
class ParagraphList; class ParagraphList;
class InsetCaption; class InsetCaption;
class InsetTabular; class InsetTabular;
class TocBuilder;
/** /**
A text inset is like a TeX box to write full text A text inset is like a TeX box to write full text
@ -176,7 +177,7 @@ public:
void forOutliner(docstring &, size_t const, bool const) const; void forOutliner(docstring &, size_t const, bool const) const;
/// ///
void addToToc(DocIterator const & di, bool output_active, void addToToc(DocIterator const & di, bool output_active,
UpdateType utype) const; UpdateType utype, TocBackend & backend) const;
/// ///
Inset * clone() const { return new InsetText(*this); } Inset * clone() const { return new InsetText(*this); }
/// ///
@ -221,15 +222,17 @@ public:
protected: protected:
/// ///
void iterateForToc(DocIterator const & cdit, bool output_active, void iterateForToc(DocIterator const & cdit, bool output_active,
UpdateType utype) const; UpdateType utype, TocBackend & backend) const;
private: private:
/// Open the toc item for paragraph pit. Returns the paragraph index where /// Open the toc item for paragraph pit. Returns the paragraph index where
/// it should end. /// it should end.
pit_type openAddToTocForParagraph(pit_type pit, pit_type openAddToTocForParagraph(pit_type pit,
DocIterator const & dit, DocIterator const & dit,
bool output_active) const; bool output_active,
TocBackend & backend) const;
/// Close a toc item opened in start and closed in end /// Close a toc item opened in start and closed in end
void closeAddToTocForParagraph(pit_type start, pit_type end) const; void closeAddToTocForParagraph(pit_type start, pit_type end,
TocBackend & backend) const;
/// ///
bool drawFrame_; bool drawFrame_;
/// ///

View File

@ -335,7 +335,7 @@ void InsetMathHull::updateBuffer(ParIterator const & it, UpdateType utype)
void InsetMathHull::addToToc(DocIterator const & pit, bool output_active, void InsetMathHull::addToToc(DocIterator const & pit, bool output_active,
UpdateType utype) const UpdateType utype, TocBackend & backend) const
{ {
if (!buffer_) { if (!buffer_) {
//FIXME: buffer_ should be set at creation for this inset! Problem is //FIXME: buffer_ should be set at creation for this inset! Problem is
@ -344,7 +344,7 @@ void InsetMathHull::addToToc(DocIterator const & pit, bool output_active,
return; return;
} }
TocBuilder & b = buffer().tocBackend().builder("equation"); TocBuilder & b = backend.builder("equation");
// compute first and last item // compute first and last item
row_type first = nrows(); row_type first = nrows();
for (row_type row = 0; row != nrows(); ++row) for (row_type row = 0; row != nrows(); ++row)
@ -368,7 +368,7 @@ void InsetMathHull::addToToc(DocIterator const & pit, bool output_active,
if (!numbered(row)) if (!numbered(row))
continue; continue;
if (label_[row]) if (label_[row])
label_[row]->addToToc(pit, output_active, utype); label_[row]->addToToc(pit, output_active, utype, backend);
docstring label = nicelabel(row); docstring label = nicelabel(row);
if (first == last) if (first == last)
// this is the only equation // this is the only equation

View File

@ -52,7 +52,7 @@ public:
void updateBuffer(ParIterator const &, UpdateType); void updateBuffer(ParIterator const &, UpdateType);
/// ///
void addToToc(DocIterator const & di, bool output_active, void addToToc(DocIterator const & di, bool output_active,
UpdateType utype) const; UpdateType utype, TocBackend & backend) const;
/// ///
InsetMathHull & operator=(InsetMathHull const &); InsetMathHull & operator=(InsetMathHull const &);
/// ///

View File

@ -1384,15 +1384,16 @@ string MathMacroTemplate::contextMenuName() const
return "context-math-macro-definition"; return "context-math-macro-definition";
} }
void MathMacroTemplate::addToToc(DocIterator const & pit, bool output_active, void MathMacroTemplate::addToToc(DocIterator const & pit, bool output_active,
UpdateType) const UpdateType, TocBackend & backend) const
{ {
docstring str; docstring str;
if (!validMacro()) if (!validMacro())
str = bformat(_("Invalid macro! \\%1$s"), name()); str = bformat(_("Invalid macro! \\%1$s"), name());
else else
str = "\\" + name(); str = "\\" + name();
TocBuilder & b = buffer().tocBackend().builder("math-macro"); TocBuilder & b = backend.builder("math-macro");
b.pushItem(pit, str, output_active); b.pushItem(pit, str, output_active);
b.pop(); b.pop();
} }

View File

@ -105,7 +105,7 @@ public:
std::string contextMenuName() const; std::string contextMenuName() const;
/// ///
void addToToc(DocIterator const & di, bool output_active, void addToToc(DocIterator const & di, bool output_active,
UpdateType utype) const; UpdateType utype, TocBackend & backend) const;
protected: protected:
/// ///
virtual void doDispatch(Cursor & cur, FuncRequest & cmd); virtual void doDispatch(Cursor & cur, FuncRequest & cmd);