From 0aeeb78f3cd9b93da1b81c911a8d2f3915533336 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sun, 20 May 2018 12:27:03 +0200 Subject: [PATCH] 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. --- src/BufferParams.cpp | 73 +++---------------------------- src/BufferParams.h | 19 ++------ src/BufferView.cpp | 8 ++-- src/TextClass.cpp | 53 ++++++++++------------ src/TextClass.h | 4 +- src/frontends/qt4/GuiDocument.cpp | 2 +- src/tex2lyx/tex2lyx.cpp | 3 +- 7 files changed, 42 insertions(+), 120 deletions(-) diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 76a2c62231..634f99f0b4 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -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 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 const & engine) -{ - vector::const_iterator it = engine.begin(); - vector::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 const & engine) -{ - clearCiteEngine(); - addCiteEngine(engine); -} - - vector 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"; } diff --git a/src/BufferParams.h b/src/BufferParams.h index 21c6cff557..d5e17d1118 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -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 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 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 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 diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 5096b9acc3..a3d0804381 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -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(); } diff --git a/src/TextClass.cpp b/src/TextClass.cpp index c8a5301f13..22141bcf0f 100644 --- a/src/TextClass.cpp +++ b/src/TextClass.cpp @@ -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); } } diff --git a/src/TextClass.h b/src/TextClass.h index 570e67f8d4..6ec7d13304 100644 --- a/src/TextClass.h +++ b/src/TextClass.h @@ -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 diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 0bf578f2a4..3ed61c8b1b 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -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))); diff --git a/src/tex2lyx/tex2lyx.cpp b/src/tex2lyx/tex2lyx.cpp index 1079087a2c..8ae6073e01 100644 --- a/src/tex2lyx/tex2lyx.cpp +++ b/src/tex2lyx/tex2lyx.cpp @@ -284,11 +284,10 @@ void initModules() for (; it != end; ++it) { string const module = it->getID(); LayoutModuleList m; - LayoutModuleList c; vector v; if (!addModule(module, baseClass, m, v)) continue; - modules[module] = getDocumentClass(baseClass, m, c); + modules[module] = getDocumentClass(baseClass, m); } init = false; } -- 2.39.5