diff --git a/src/TextClass.cpp b/src/TextClass.cpp index 5d01b9d219..9b25a67b18 100644 --- a/src/TextClass.cpp +++ b/src/TextClass.cpp @@ -1416,18 +1416,6 @@ bool TextClass::readOutlinerName(Lexer & lexrc) } -docstring TextClass::outlinerName(std::string const & type) const -{ - std::map::const_iterator const it - = outliner_names_.find(type); - if (it == outliner_names_.end()) { - LYXERR0("Missing OutlinerName for " << type << "!"); - return translateIfPossible(from_utf8(type)); - } else - return translateIfPossible(it->second); -} - - string const & TextClass::prerequisites(string const & sep) const { if (contains(prerequisites_, ',')) { diff --git a/src/TextClass.h b/src/TextClass.h index da217a57aa..56a61da48f 100644 --- a/src/TextClass.h +++ b/src/TextClass.h @@ -205,8 +205,10 @@ public: OutputType outputType() const { return outputType_; } /// Can be latex, docbook ... (the name of a format) std::string outputFormat() const { return outputFormat_; } - /// - docstring outlinerName(std::string const & type) const; + /// Return the non-localised names for the toc types. + std::map const & + outlinerNames() const { return outliner_names_; } + protected: /// Protect construction TextClass(); diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp index 1c1606608e..4630d85b9d 100644 --- a/src/TocBackend.cpp +++ b/src/TocBackend.cpp @@ -17,6 +17,7 @@ #include "Buffer.h" #include "BufferParams.h" +#include "IndicesList.h" #include "InsetList.h" #include "Paragraph.h" #include "TextClass.h" @@ -213,6 +214,7 @@ void TocBackend::update(bool output_active, UpdateType utype) it->second->clear(); tocs_.clear(); builders_.clear(); + resetOutlinerNames(); if (!buffer_->isInternal()) { DocIterator dit; buffer_->inset().addToToc(dit, output_active, utype); @@ -249,8 +251,56 @@ void TocBackend::writePlaintextTocList(string const & type, docstring TocBackend::outlinerName(string const & type) const { - return translateIfPossible( - buffer_->params().documentClass().outlinerName(type)); + map::const_iterator const it + = outliner_names_.find(type); + if (it != outliner_names_.end()) + return it->second; + + // Legacy treatment of index:... type + if (support::prefixIs(type, "index:")) { + string const itype = support::split(type, ':'); + IndicesList const & indiceslist = buffer_->params().indiceslist(); + Index const * index = indiceslist.findShortcut(from_utf8(itype)); + docstring indextype = _("unknown type!"); + if (index) + indextype = index->index(); + return support::bformat(_("Index Entries (%1$s)"), indextype); + } + + LYXERR0("Missing OutlinerName for " << type << "!"); + return from_utf8(type); +} + + +void TocBackend::resetOutlinerNames() +{ + outliner_names_.clear(); + // names from this document class + for (pair const & name + : buffer_->params().documentClass().outlinerNames()) + addName(name.first, translateIfPossible(name.second)); + // Hardcoded types + addName("tableofcontents", _("Table of Contents")); + addName("change", _("Changes")); + addName("senseless", _("Senseless")); + addName("citation", _("Citations")); + addName("label", _("Labels and References")); + // Customizable, but the corresponding insets have no layout definition + addName("child", _("Child Documents")); + addName("graphics", _("Graphics")); + addName("equation", _("Equations")); + addName("external", _("External Material")); + addName("math-macro", _("Math Macros")); + addName("nomencl", _("Nomenclature Entries")); +} + + +void TocBackend::addName(string const & type, docstring const & name) +{ + if (name.empty()) + return; + // only inserts if the key does not exist + outliner_names_.insert({type, name}); } diff --git a/src/TocBackend.h b/src/TocBackend.h index 3f2ee419c0..a38a972834 100644 --- a/src/TocBackend.h +++ b/src/TocBackend.h @@ -133,17 +133,23 @@ public: /// void writePlaintextTocList(std::string const & type, odocstringstream & os, size_t max_length) const; - /// + /// Localised name for type docstring outlinerName(std::string const & type) const; + /// Add a new (localised) name if yet unknown + void addName(std::string const & type, docstring const & name); /// Whether a toc type is less important and appears in the "Other lists" /// submenu static bool isOther(std::string const & type); private: + /// + void resetOutlinerNames(); /// TocList tocs_; /// std::map> builders_; + /// Stores localised outliner names from this buffer and its children + std::map outliner_names_; /// Buffer const * buffer_; }; // TocBackend diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index 2a3032c4da..249d742013 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -1320,7 +1320,8 @@ void MenuDefinition::expandToc(Buffer const * buf) continue; MenuDefinition submenu; submenu.expandTocSubmenu(cit->first, *cit->second); - MenuItem item(MenuItem::Submenu, guiName(cit->first, buf->params())); + docstring const toc_name = buf->tocBackend().outlinerName(cit->first); + MenuItem item(MenuItem::Submenu, toqstr(toc_name)); item.setSubmenu(submenu); // deserves to be in the main menu? if (!TocBackend::isOther(cit->first)) diff --git a/src/frontends/qt4/TocModel.cpp b/src/frontends/qt4/TocModel.cpp index e40d99c9cb..03dbf38671 100644 --- a/src/frontends/qt4/TocModel.cpp +++ b/src/frontends/qt4/TocModel.cpp @@ -351,7 +351,8 @@ void TocModels::reset(BufferView const * bv) names_->blockSignals(true); names_->beginResetModel(); names_->insertColumns(0, 1); - TocList const & tocs = bv->buffer().masterBuffer()->tocBackend().tocs(); + TocBackend const & backend = bv->buffer().masterBuffer()->tocBackend(); + TocList const & tocs = backend.tocs(); TocList::const_iterator it = tocs.begin(); TocList::const_iterator toc_end = tocs.end(); for (; it != toc_end; ++it) { @@ -364,7 +365,7 @@ void TocModels::reset(BufferView const * bv) mod_it.value()->reset(it->second); // Fill in the names_ model. - QString const gui_name = guiName(it->first, bv->buffer().params()); + QString const gui_name = toqstr(backend.outlinerName(it->first)); int const current_row = names_->rowCount(); names_->insertRows(current_row, 1); QModelIndex const index = names_->index(current_row, 0); diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp index 2237d7d507..1e3befc79f 100644 --- a/src/frontends/qt4/qt_helpers.cpp +++ b/src/frontends/qt4/qt_helpers.cpp @@ -21,7 +21,6 @@ #include "BufferParams.h" #include "FloatList.h" -#include "IndicesList.h" #include "Language.h" #include "Length.h" #include "TextClass.h" @@ -596,47 +595,6 @@ QStringList fileFilters(QString const & desc) } -QString guiName(string const & type, BufferParams const & bp) -{ - // Hardcoded types - if (type == "tableofcontents") - return qt_("Table of Contents"); - if (type == "change") - return qt_("Changes"); - if (type == "senseless") - return qt_("Senseless"); - if (type == "citation") - return qt_("Citations"); - if (type == "label") - return qt_("Labels and References"); - // Customizable, but the corresponding insets have no layout definition - if (type == "child") - return qt_("Child Documents"); - if (type == "graphics") - return qt_("Graphics"); - if (type == "equation") - return qt_("Equations"); - if (type == "external") - return qt_("External material"); - if (type == "math-macro") - return qt_("Math macros"); - if (type == "nomencl") - return qt_("Nomenclature Entries"); - - if (prefixIs(type, "index:")) { - string const itype = split(type, ':'); - IndicesList const & indiceslist = bp.indiceslist(); - Index const * index = indiceslist.findShortcut(from_utf8(itype)); - docstring indextype = _("unknown type!"); - if (index) - indextype = index->index(); - return toqstr(bformat(_("Index Entries (%1$s)"), indextype)); - } - - return toqstr(bp.documentClass().outlinerName(type)); -} - - QString formatToolTip(QString text, int em) { // 1. QTooltip activates word wrapping only if mightBeRichText() diff --git a/src/frontends/qt4/qt_helpers.h b/src/frontends/qt4/qt_helpers.h index 9569d90f82..90f2017f43 100644 --- a/src/frontends/qt4/qt_helpers.h +++ b/src/frontends/qt4/qt_helpers.h @@ -191,10 +191,6 @@ QString getExtension(QString const & name); QString makeAbsPath(QString const & relpath, QString const & base); QString changeExtension(QString const & oldname, QString const & ext); -/// \return the display string associated with given type and buffer -/// parameter. -QString guiName(std::string const & type, BufferParams const & bp); - /// Format \param text for display as a ToolTip, breaking at lines of \param /// width ems. Note: this function is expensive. Better call it in a delayed /// manner, i.e. not to fill in a model (see for instance the function diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 4e44ec8c87..c39b7d349f 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -1143,10 +1143,11 @@ 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"); + TocBuilder & b = backend.builder("listing"); b.pushItem(cpit, screenLabel(), output_active); InsetListingsParams p(to_utf8(params()["lstparams"])); b.argumentItem(from_utf8(p.getParamValue("caption"))); @@ -1154,7 +1155,7 @@ void InsetInclude::addToToc(DocIterator const & cpit, bool output_active, } else { Buffer const * const childbuffer = getChildBuffer(); - TocBuilder & b = buffer().tocBackend().builder("child"); + TocBuilder & b = backend.builder("child"); docstring str = childbuffer ? childbuffer->fileName().displayName() : from_ascii("?"); b.pushItem(cpit, str, output_active); @@ -1167,10 +1168,16 @@ void InsetInclude::addToToc(DocIterator const & cpit, bool output_active, childbuffer->tocBackend().update(output_active, utype); 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); + shared_ptr child_toc = pair.second; + shared_ptr 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 + //having different document class and module selection between master + //and child). + for (pair const & name + : childbuffer->params().documentClass().outlinerNames()) + backend.addName(name.first, translateIfPossible(name.second)); } }