From a940cc3f6b46a21c2738e9ad409bfacbde5320e6 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Thu, 16 Oct 2008 17:21:13 +0000 Subject: [PATCH] The last bit of cleanup: Make checking for exclusions a bit easier. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26924 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ModuleList.cpp | 43 +++++++++++++++++++++++-------- src/ModuleList.h | 14 +++++----- src/frontends/qt4/GuiDocument.cpp | 25 +++--------------- 3 files changed, 44 insertions(+), 38 deletions(-) diff --git a/src/ModuleList.cpp b/src/ModuleList.cpp index e53af9b7e9..547f1f9220 100644 --- a/src/ModuleList.cpp +++ b/src/ModuleList.cpp @@ -64,6 +64,38 @@ bool LyXModule::isAvailable() { } +bool LyXModule::isCompatible(string const & modName) const +{ + // do we exclude it? + if (find(excludedModules.begin(), excludedModules.end(), modName) != + excludedModules.end()) + return false; + + LyXModule const * const lm = moduleList[modName]; + if (!lm) + return true; + + // does it exclude us? + vector const excMods = lm->getExcludedModules(); + if (find(excMods.begin(), excMods.end(), name) != excMods.end()) + return false; + + return true; +} + + +bool LyXModule::areCompatible(string const & mod1, string const & mod2) +{ + LyXModule const * const lm1 = moduleList[mod1]; + if (lm1) + return lm1->isCompatible(mod2); + LyXModule const * const lm2 = moduleList[mod2]; + if (lm2) + return lm2->isCompatible(mod1); + // Can't check it either way. + return true; +} + // used when sorting the module list. class ModuleSorter { @@ -201,17 +233,6 @@ LyXModuleList::iterator ModuleList::end() } -LyXModule * ModuleList::getModuleByName(string const & str) -{ - LyXModuleList::iterator it = modlist_.begin(); - for (; it != modlist_.end(); ++it) - if (it->getName() == str) { - LyXModule & mod = *it; - return &mod; - } - return 0; -} - LyXModule * ModuleList::operator[](string const & str) { LyXModuleList::iterator it = modlist_.begin(); diff --git a/src/ModuleList.h b/src/ModuleList.h index 804cce1dea..0ef152c069 100644 --- a/src/ModuleList.h +++ b/src/ModuleList.h @@ -24,7 +24,6 @@ namespace lyx { * a LaTeX package, where a layout file corresponds to a LaTeX class. */ -//FIXME Give us some access functions here. class LyXModule { public: /// @@ -51,7 +50,13 @@ public: /// Modules this one excludes: the list should be treated disjunctively std::vector const & getExcludedModules() const { return excludedModules; } - + /// \return true if the module is compatible with this one, i.e., + /// it does not exclude us and we do not exclude it. + /// this will also return true if modName is unknown and we do not + /// exclude it, since in that case we cannot check its exclusions. + bool isCompatible(std::string const & modName) const; + /// + static bool areCompatible(std::string const & mod1, std::string const & mod2); private: /// what appears in the ui std::string name; @@ -96,13 +101,10 @@ public: LyXModuleList::iterator end(); /// bool empty() const { return modlist_.empty(); } - /// Returns a pointer to the LyXModule with name str. - /// Returns a null pointer if no such module is found. - LyXModule * getModuleByName(std::string const & str); /// Returns a pointer to the LyXModule with filename str. /// Returns a null pointer if no such module is found. LyXModule * operator[](std::string const & str); - private: +private: /// noncopyable ModuleList(ModuleList const &); /// diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index e3132d7bef..9d0d74a4aa 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -316,28 +316,11 @@ void ModuleSelectionManager::updateAddPB() return; } } - - // Check whether any excluded module is being used... - vector const excl = getExcludedList(modName); - if (!excl.empty()) { - vector::const_iterator it = excl.begin(); - vector::const_iterator en = excl.end(); - for (; it != en; ++it) { - if (find(selModStart, selModEnd, *it) != selModEnd) { - addPB->setEnabled(false); - return; - } - } - } - // ...and whether any used module excludes us. - vector::const_iterator selModIt = selModStart; - for (; selModIt != selModEnd; ++selModIt) { - string selMod = *selModIt; - vector excMods = getExcludedList(selMod); - vector::const_iterator const eit = excMods.begin(); - vector::const_iterator const een = excMods.end(); - if (find(eit, een, modName) != een) { + // Check for conflicts with used modules + vector::const_iterator selModIt = selModStart; + for (; selModIt != selModEnd; ++selModIt) { + if (!LyXModule::areCompatible(modName, *selModIt)) { addPB->setEnabled(false); return; }