Am Mittwoch, dem 07.01.2026 um 14:05 -0500 schrieb Richard Kimberly
Heck:
> It would be easy enough to check here if the cite engine exists. But
> perhaps the better thing to do would be to create a 'dummy' cite
> engine file when we initially notice that the requested cite engine
> does not exist? I'm not familiar enough with this code to know what
> is best.
See attached patch. This falls back to basic if we need a cite engine
(in the document dialog which would otherwise crash as well on
opening).
Citations do look odd, but this is intentional, as basic is in many
cases not the correct cite engine (since we do not know whether the
missing one is bibntex or biblatex, we cannot guess here).
--
Jürgen
diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 2fdafa1db8..f0207ad711 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -4474,7 +4474,9 @@ string const BufferParams::bibtexCommand(bool const warn) const
bool BufferParams::useBiblatex() const
{
- return theCiteEnginesList[citeEngine()]->getCiteFramework() == "biblatex";
+ return theCiteEnginesList[citeEngine()]
+ ? theCiteEnginesList[citeEngine()]->getCiteFramework() == "biblatex"
+ : false;
}
diff --git a/src/CiteEnginesList.cpp b/src/CiteEnginesList.cpp
index 7006356ece..15b89c60bc 100644
--- a/src/CiteEnginesList.cpp
+++ b/src/CiteEnginesList.cpp
@@ -310,4 +310,20 @@ LyXCiteEngine * CiteEnginesList::operator[](string const & str)
return nullptr;
}
+
+LyXCiteEngine const * CiteEnginesList::getCiteEngine(string const & str) const
+{
+ LyXCiteEngine * fallback = nullptr;
+ for (auto & eng : englist_) {
+ if (eng.getID() == str)
+ return ŋ
+ else if (eng.getID() == "basic")
+ fallback = const_cast<LyXCiteEngine *>(&eng);
+ }
+ if (!fallback)
+ LYXERR0("Basic cite engine not found! Your installation is corrupted.");
+
+ return fallback;
+}
+
} // namespace lyx
diff --git a/src/CiteEnginesList.h b/src/CiteEnginesList.h
index 2979f004bc..dde6e02968 100644
--- a/src/CiteEnginesList.h
+++ b/src/CiteEnginesList.h
@@ -140,6 +140,9 @@ public:
LyXCiteEngine const * operator[](std::string const & str) const;
///
LyXCiteEngine * operator[](std::string const & str);
+ /// Returns a pointer to the LyXCiteEngine with filename str.
+ /// Returns a pointer to basic citeengine if no such engine is found.
+ LyXCiteEngine const * getCiteEngine(std::string const & str) const;
private:
/// noncopyable
CiteEnginesList(CiteEnginesList const &);
diff --git a/src/frontends/qt/GuiDocument.cpp b/src/frontends/qt/GuiDocument.cpp
index 48cb00ef4d..71b9f60790 100644
--- a/src/frontends/qt/GuiDocument.cpp
+++ b/src/frontends/qt/GuiDocument.cpp
@@ -3226,7 +3226,7 @@ void GuiDocument::resetDefaultBibfile(string const & which)
CiteEngineType(biblioModule->citeStyleCO->itemData(
biblioModule->citeStyleCO->currentIndex()).toInt());
- updateDefaultBiblio(theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet), which);
+ updateDefaultBiblio(theCiteEnginesList.getCiteEngine(fromqstr(engine))->getDefaultBiblio(cet), which);
}
@@ -3248,7 +3248,7 @@ void GuiDocument::citeEngineChanged(int n)
biblioModule->citeEngineCO->itemData(n).toString();
vector<string> const engs =
- theCiteEnginesList[fromqstr(engine)]->getEngineType();
+ theCiteEnginesList.getCiteEngine(fromqstr(engine))->getEngineType();
updateCiteStyles(engs);
updateEngineDependends();
@@ -3263,7 +3263,7 @@ void GuiDocument::updateEngineDependends()
QString const engine =
biblioModule->citeEngineCO->itemData(
biblioModule->citeEngineCO->currentIndex()).toString();
- LyXCiteEngine const * ce = theCiteEnginesList[fromqstr(engine)];
+ LyXCiteEngine const * ce = theCiteEnginesList.getCiteEngine(fromqstr(engine));
bool const biblatex = isBiblatex();
bool const citepack = biblatex
@@ -3299,7 +3299,8 @@ void GuiDocument::citeStyleChanged()
QString const currentDef = isBiblatex() ?
biblioModule->biblatexBbxCO->currentText()
: biblioModule->defaultBiblioCO->currentText();
- if (theCiteEnginesList[fromqstr(engine)]->isDefaultBiblio(fromqstr(currentDef)))
+ if (theCiteEnginesList[fromqstr(engine)]
+ && theCiteEnginesList[fromqstr(engine)]->isDefaultBiblio(fromqstr(currentDef)))
resetDefaultBibfile();
biblioChanged();
@@ -3679,7 +3680,8 @@ void GuiDocument::applyView()
CiteEngineType const style = CiteEngineType(biblioModule->citeStyleCO->itemData(
biblioModule->citeStyleCO->currentIndex()).toInt());
- if (theCiteEnginesList[engine]->hasEngineType(style))
+ if (theCiteEnginesList[engine]
+ && theCiteEnginesList[engine]->hasEngineType(style))
bp_.setCiteEngineType(style);
else
bp_.setCiteEngineType(ENGINE_TYPE_DEFAULT);
@@ -5004,8 +5006,8 @@ bool GuiDocument::isBiblatex() const
// this can happen if the cite engine is unknown, which can happen
// if one is using a file that came from someone else, etc. in that
// case, we crash if we proceed.
- if (engine.isEmpty())
- return false;
+ if (engine.isEmpty() || !theCiteEnginesList[fromqstr(engine)])
+ return false;
return theCiteEnginesList[fromqstr(engine)]->getCiteFramework() == "biblatex";
}
@@ -5128,7 +5130,7 @@ void GuiDocument::updateResetDefaultBiblio()
CiteEngineType(biblioModule->citeStyleCO->itemData(
biblioModule->citeStyleCO->currentIndex()).toInt());
- string const defbib = theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet);
+ string const defbib = theCiteEnginesList.getCiteEngine(fromqstr(engine))->getDefaultBiblio(cet);
if (isBiblatex()) {
QString const bbx = biblioModule->biblatexBbxCO->currentText();
QString const cbx = biblioModule->biblatexCbxCO->currentText();
--
lyx-devel mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-devel