mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-06 00:10:59 +00:00
Simplify cite engines code
As opposed to modules (from which the framework was initially borrowed), we only allow one cite engine per document. Thus, we don't need to fiddle with lists.
This commit is contained in:
parent
17ea71b31c
commit
0aeeb78f3c
@ -380,7 +380,7 @@ BufferParams::BufferParams()
|
||||
: pimpl_(new Impl)
|
||||
{
|
||||
setBaseClass(defaultBaseclass());
|
||||
cite_engine_.push_back("basic");
|
||||
cite_engine_ = "basic";
|
||||
cite_engine_type_ = ENGINE_TYPE_DEFAULT;
|
||||
makeDocumentClass();
|
||||
paragraph_separation = ParagraphIndentSeparation;
|
||||
@ -901,8 +901,7 @@ string BufferParams::readToken(Lexer & lex, string const & token,
|
||||
use_package(package, packagetranslator().find(use));
|
||||
} else if (token == "\\cite_engine") {
|
||||
lex.eatLine();
|
||||
vector<string> engine = getVectorFromString(lex.getString());
|
||||
setCiteEngine(engine);
|
||||
cite_engine_ = lex.getString();
|
||||
} else if (token == "\\cite_engine_type") {
|
||||
string engine_type;
|
||||
lex >> engine_type;
|
||||
@ -1282,17 +1281,10 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
|
||||
|
||||
os << "\n\\cite_engine ";
|
||||
|
||||
if (!cite_engine_.empty()) {
|
||||
LayoutModuleList::const_iterator be = cite_engine_.begin();
|
||||
LayoutModuleList::const_iterator en = cite_engine_.end();
|
||||
for (LayoutModuleList::const_iterator it = be; it != en; ++it) {
|
||||
if (it != be)
|
||||
os << ',';
|
||||
os << *it;
|
||||
}
|
||||
} else {
|
||||
if (!cite_engine_.empty())
|
||||
os << cite_engine_;
|
||||
else
|
||||
os << "basic";
|
||||
}
|
||||
|
||||
os << "\n\\cite_engine_type " << theCiteEnginesList.getTypeAsString(cite_engine_type_);
|
||||
|
||||
@ -2493,18 +2485,12 @@ void BufferParams::makeDocumentClass(bool const clone)
|
||||
|
||||
invalidateConverterCache();
|
||||
LayoutModuleList mods;
|
||||
LayoutModuleList ces;
|
||||
LayoutModuleList::iterator it = layout_modules_.begin();
|
||||
LayoutModuleList::iterator en = layout_modules_.end();
|
||||
for (; it != en; ++it)
|
||||
mods.push_back(*it);
|
||||
|
||||
it = cite_engine_.begin();
|
||||
en = cite_engine_.end();
|
||||
for (; it != en; ++it)
|
||||
ces.push_back(*it);
|
||||
|
||||
doc_class_ = getDocumentClass(*baseClass(), mods, ces, clone);
|
||||
doc_class_ = getDocumentClass(*baseClass(), mods, cite_engine_, clone);
|
||||
|
||||
TextClass::ReturnValues success = TextClass::OK;
|
||||
if (!forced_local_layout_.empty())
|
||||
@ -2526,12 +2512,6 @@ bool BufferParams::layoutModuleCanBeAdded(string const & modName) const
|
||||
}
|
||||
|
||||
|
||||
bool BufferParams::citationModuleCanBeAdded(string const & modName) const
|
||||
{
|
||||
return cite_engine_.moduleCanBeAdded(modName, baseClass());
|
||||
}
|
||||
|
||||
|
||||
docstring BufferParams::getLocalLayout(bool forced) const
|
||||
{
|
||||
if (forced)
|
||||
@ -3408,30 +3388,6 @@ Encoding const & BufferParams::encoding() const
|
||||
}
|
||||
|
||||
|
||||
bool BufferParams::addCiteEngine(string const & engine)
|
||||
{
|
||||
LayoutModuleList::const_iterator it = cite_engine_.begin();
|
||||
LayoutModuleList::const_iterator en = cite_engine_.end();
|
||||
for (; it != en; ++it)
|
||||
if (*it == engine)
|
||||
return false;
|
||||
cite_engine_.push_back(engine);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool BufferParams::addCiteEngine(vector<string> const & engine)
|
||||
{
|
||||
vector<string>::const_iterator it = engine.begin();
|
||||
vector<string>::const_iterator en = engine.end();
|
||||
bool ret = true;
|
||||
for (; it != en; ++it)
|
||||
if (!addCiteEngine(*it))
|
||||
ret = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
string const & BufferParams::defaultBiblioStyle() const
|
||||
{
|
||||
if (!biblio_style.empty())
|
||||
@ -3466,20 +3422,6 @@ string BufferParams::getCiteAlias(string const & s) const
|
||||
}
|
||||
|
||||
|
||||
void BufferParams::setCiteEngine(string const & engine)
|
||||
{
|
||||
clearCiteEngine();
|
||||
addCiteEngine(engine);
|
||||
}
|
||||
|
||||
|
||||
void BufferParams::setCiteEngine(vector<string> const & engine)
|
||||
{
|
||||
clearCiteEngine();
|
||||
addCiteEngine(engine);
|
||||
}
|
||||
|
||||
|
||||
vector<string> BufferParams::citeCommands() const
|
||||
{
|
||||
static CitationStyle const default_style;
|
||||
@ -3543,8 +3485,7 @@ string const BufferParams::bibtexCommand() const
|
||||
|
||||
bool BufferParams::useBiblatex() const
|
||||
{
|
||||
return theCiteEnginesList[citeEngine().list().front()]
|
||||
->getCiteFramework() == "biblatex";
|
||||
return theCiteEnginesList[citeEngine()]->getCiteFramework() == "biblatex";
|
||||
}
|
||||
|
||||
|
||||
|
@ -168,8 +168,6 @@ public:
|
||||
/// checks to make sure module's requriements are satisfied, that it does
|
||||
/// not conflict with already-present modules, isn't already loaded, etc.
|
||||
bool layoutModuleCanBeAdded(std::string const & modName) const;
|
||||
/// same, but for citaton modules.
|
||||
bool citationModuleCanBeAdded(std::string const & modName) const;
|
||||
///
|
||||
void addRemovedModule(std::string const & modName)
|
||||
{ removed_modules_.push_back(modName); }
|
||||
@ -465,21 +463,12 @@ public:
|
||||
std::string const loadFonts(LaTeXFeatures & features) const;
|
||||
|
||||
/// the cite engine modules
|
||||
LayoutModuleList const & citeEngine() const
|
||||
{ return cite_engine_; }
|
||||
std::string const & citeEngine() const { return cite_engine_; }
|
||||
/// the type of cite engine (authoryear or numerical)
|
||||
CiteEngineType const & citeEngineType() const
|
||||
{ return cite_engine_type_; }
|
||||
/// add the module to the cite engine modules
|
||||
bool addCiteEngine(std::string const &);
|
||||
/// add the modules to the cite engine modules
|
||||
bool addCiteEngine(std::vector<std::string> const &);
|
||||
/// clear the list of cite engine modules
|
||||
void clearCiteEngine() { cite_engine_.clear(); }
|
||||
/// set the cite engine module
|
||||
void setCiteEngine(std::string const &);
|
||||
/// set the cite engine modules
|
||||
void setCiteEngine(std::vector<std::string> const &);
|
||||
void setCiteEngine(std::string const & eng) { cite_engine_ = eng; }
|
||||
/// set the cite engine type
|
||||
void setCiteEngineType(CiteEngineType const & engine_type)
|
||||
{ cite_engine_type_ = engine_type; }
|
||||
@ -577,8 +566,8 @@ private:
|
||||
typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
|
||||
///
|
||||
mutable DefaultFlavorCache default_flavors_;
|
||||
/// the cite engine modules
|
||||
LayoutModuleList cite_engine_;
|
||||
/// the cite engine
|
||||
std::string cite_engine_;
|
||||
/// the type of cite engine (authoryear or numerical)
|
||||
CiteEngineType cite_engine_type_;
|
||||
/// the default BibTeX style file for the document
|
||||
|
@ -1395,14 +1395,14 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
// We need to find out if the bibliography information
|
||||
// has changed. See bug #11055.
|
||||
// So these should not be references...
|
||||
LayoutModuleList const engines = buffer().params().citeEngine();
|
||||
string const engine = buffer().params().citeEngine();
|
||||
CiteEngineType const enginetype = buffer().params().citeEngineType();
|
||||
if (!cur.textUndo())
|
||||
dr.setMessage(_("No further undo information"));
|
||||
else {
|
||||
dr.screenUpdate(Update::Force | Update::FitCursor);
|
||||
dr.forceBufferUpdate();
|
||||
if (buffer().params().citeEngine() != engines ||
|
||||
if (buffer().params().citeEngine() != engine ||
|
||||
buffer().params().citeEngineType() != enginetype)
|
||||
buffer().invalidateCiteLabels();
|
||||
}
|
||||
@ -1415,14 +1415,14 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
// We need to find out if the bibliography information
|
||||
// has changed. See bug #11055.
|
||||
// So these should not be references...
|
||||
LayoutModuleList const engines = buffer().params().citeEngine();
|
||||
string const engine = buffer().params().citeEngine();
|
||||
CiteEngineType const enginetype = buffer().params().citeEngineType();
|
||||
if (!cur.textRedo())
|
||||
dr.setMessage(_("No further redo information"));
|
||||
else {
|
||||
dr.screenUpdate(Update::Force | Update::FitCursor);
|
||||
dr.forceBufferUpdate();
|
||||
if (buffer().params().citeEngine() != engines ||
|
||||
if (buffer().params().citeEngine() != engine ||
|
||||
buffer().params().citeEngineType() != enginetype)
|
||||
buffer().invalidateCiteLabels();
|
||||
}
|
||||
|
@ -1666,8 +1666,7 @@ Layout TextClass::createBasicLayout(docstring const & name, bool unknown) const
|
||||
|
||||
DocumentClassPtr getDocumentClass(
|
||||
LayoutFile const & baseClass, LayoutModuleList const & modlist,
|
||||
LayoutModuleList const & celist,
|
||||
bool const clone)
|
||||
string const & cengine, bool const clone)
|
||||
{
|
||||
DocumentClassPtr doc_class =
|
||||
DocumentClassPtr(new DocumentClass(baseClass));
|
||||
@ -1706,37 +1705,31 @@ DocumentClassPtr getDocumentClass(
|
||||
}
|
||||
}
|
||||
|
||||
LayoutModuleList::const_iterator cit = celist.begin();
|
||||
LayoutModuleList::const_iterator cen = celist.end();
|
||||
for (; cit != cen; ++cit) {
|
||||
string const ceName = *cit;
|
||||
LyXCiteEngine * ce = theCiteEnginesList[ceName];
|
||||
if (!ce) {
|
||||
docstring const msg =
|
||||
bformat(_("The cite engine %1$s has been requested by\n"
|
||||
"this document but has not been found in the list of\n"
|
||||
"available engines. If you recently installed it, you\n"
|
||||
"probably need to reconfigure LyX.\n"), from_utf8(ceName));
|
||||
if (!clone)
|
||||
frontend::Alert::warning(_("Cite Engine not available"), msg);
|
||||
continue;
|
||||
}
|
||||
if (!ce->isAvailable() && !clone) {
|
||||
docstring const prereqs = from_utf8(getStringFromVector(ce->prerequisites(), "\n\t"));
|
||||
docstring const msg =
|
||||
bformat(_("The cite engine %1$s requires a package that is not\n"
|
||||
"available in your LaTeX installation, or a converter that\n"
|
||||
"you have not installed. LaTeX output may not be possible.\n"
|
||||
"Missing prerequisites:\n"
|
||||
"\t%2$s\n"
|
||||
"See section 3.1.2.3 (Modules) of the User's Guide for more information."),
|
||||
from_utf8(ceName), prereqs);
|
||||
frontend::Alert::warning(_("Package not available"), msg, true);
|
||||
}
|
||||
LyXCiteEngine * ce = theCiteEnginesList[cengine];
|
||||
if (!ce) {
|
||||
docstring const msg =
|
||||
bformat(_("The cite engine %1$s has been requested by\n"
|
||||
"this document but has not been found in the list of\n"
|
||||
"available engines. If you recently installed it, you\n"
|
||||
"probably need to reconfigure LyX.\n"), from_utf8(cengine));
|
||||
if (!clone)
|
||||
frontend::Alert::warning(_("Cite Engine not available"), msg);
|
||||
} else if (!ce->isAvailable() && !clone) {
|
||||
docstring const prereqs = from_utf8(getStringFromVector(ce->prerequisites(), "\n\t"));
|
||||
docstring const msg =
|
||||
bformat(_("The cite engine %1$s requires a package that is not\n"
|
||||
"available in your LaTeX installation, or a converter that\n"
|
||||
"you have not installed. LaTeX output may not be possible.\n"
|
||||
"Missing prerequisites:\n"
|
||||
"\t%2$s\n"
|
||||
"See section 3.1.2.3 (Modules) of the User's Guide for more information."),
|
||||
from_utf8(cengine), prereqs);
|
||||
frontend::Alert::warning(_("Package not available"), msg, true);
|
||||
} else {
|
||||
FileName layout_file = libFileSearch("citeengines", ce->getFilename());
|
||||
if (!doc_class->read(layout_file, TextClass::CITE_ENGINE)) {
|
||||
docstring const msg =
|
||||
bformat(_("Error reading cite engine %1$s\n"), from_utf8(ceName));
|
||||
bformat(_("Error reading cite engine %1$s\n"), from_utf8(cengine));
|
||||
frontend::Alert::warning(_("Read Error"), msg);
|
||||
}
|
||||
}
|
||||
|
@ -524,7 +524,7 @@ private:
|
||||
/// The only way to make a DocumentClass is to call this function.
|
||||
friend DocumentClassPtr
|
||||
getDocumentClass(LayoutFile const &, LayoutModuleList const &,
|
||||
LayoutModuleList const &,
|
||||
std::string const &,
|
||||
bool const clone);
|
||||
};
|
||||
|
||||
@ -535,7 +535,7 @@ private:
|
||||
/// on the CutStack.
|
||||
DocumentClassPtr getDocumentClass(LayoutFile const & baseClass,
|
||||
LayoutModuleList const & modlist,
|
||||
LayoutModuleList const & celist,
|
||||
std::string const & cengine = std::string(),
|
||||
bool const clone = false);
|
||||
|
||||
/// convert page sides option to text 1 or 2
|
||||
|
@ -3399,7 +3399,7 @@ void GuiDocument::paramsToDialog()
|
||||
latexModule->refstyleCB->setChecked(bp_.use_refstyle);
|
||||
|
||||
// biblio
|
||||
string const cite_engine = bp_.citeEngine().list().front();
|
||||
string const cite_engine = bp_.citeEngine();
|
||||
|
||||
biblioModule->citeEngineCO->setCurrentIndex(
|
||||
biblioModule->citeEngineCO->findData(toqstr(cite_engine)));
|
||||
|
@ -284,11 +284,10 @@ void initModules()
|
||||
for (; it != end; ++it) {
|
||||
string const module = it->getID();
|
||||
LayoutModuleList m;
|
||||
LayoutModuleList c;
|
||||
vector<string> v;
|
||||
if (!addModule(module, baseClass, m, v))
|
||||
continue;
|
||||
modules[module] = getDocumentClass(baseClass, m, c);
|
||||
modules[module] = getDocumentClass(baseClass, m);
|
||||
}
|
||||
init = false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user