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
This commit is contained in:
Richard Heck 2008-10-16 17:21:13 +00:00
parent 297d5d1f4e
commit a940cc3f6b
3 changed files with 44 additions and 38 deletions

View File

@ -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<string> 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();

View File

@ -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<std::string> 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 &);
///

View File

@ -316,28 +316,11 @@ void ModuleSelectionManager::updateAddPB()
return;
}
}
// Check whether any excluded module is being used...
vector<string> const excl = getExcludedList(modName);
if (!excl.empty()) {
vector<string>::const_iterator it = excl.begin();
vector<string>::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<string>::const_iterator selModIt = selModStart;
for (; selModIt != selModEnd; ++selModIt) {
string selMod = *selModIt;
vector<string> excMods = getExcludedList(selMod);
vector<string>::const_iterator const eit = excMods.begin();
vector<string>::const_iterator const een = excMods.end();
if (find(eit, een, modName) != een) {
// Check for conflicts with used modules
vector<string>::const_iterator selModIt = selModStart;
for (; selModIt != selModEnd; ++selModIt) {
if (!LyXModule::areCompatible(modName, *selModIt)) {
addPB->setEnabled(false);
return;
}