mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Collect the outliner names for the children's tocs
Fixes missing outliner names in various situations. Now if the warning "Missing outliner name" appears in the console, this correctly hints at an actual issue with the layout.
This commit is contained in:
parent
54f5100e74
commit
461fda9ca9
@ -1416,18 +1416,6 @@ bool TextClass::readOutlinerName(Lexer & lexrc)
|
||||
}
|
||||
|
||||
|
||||
docstring TextClass::outlinerName(std::string const & type) const
|
||||
{
|
||||
std::map<std::string,docstring>::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_, ',')) {
|
||||
|
@ -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<std::string, docstring> const &
|
||||
outlinerNames() const { return outliner_names_; }
|
||||
|
||||
protected:
|
||||
/// Protect construction
|
||||
TextClass();
|
||||
|
@ -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<string, docstring>::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<string, docstring> 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});
|
||||
}
|
||||
|
||||
|
||||
|
@ -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<std::string, unique_ptr<TocBuilder>> builders_;
|
||||
/// Stores localised outliner names from this buffer and its children
|
||||
std::map<std::string, docstring> outliner_names_;
|
||||
///
|
||||
Buffer const * buffer_;
|
||||
}; // TocBackend
|
||||
|
@ -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))
|
||||
|
@ -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);
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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<Toc> child_toc = pair.second;
|
||||
shared_ptr<Toc> toc = buffer().tocBackend().toc(type);
|
||||
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
|
||||
//having different document class and module selection between master
|
||||
//and child).
|
||||
for (pair<string, docstring> const & name
|
||||
: childbuffer->params().documentClass().outlinerNames())
|
||||
backend.addName(name.first, translateIfPossible(name.second));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user