]> git.lyx.org Git - lyx.git/blobdiff - src/LayoutModuleList.cpp
Fix another tooltip
[lyx.git] / src / LayoutModuleList.cpp
index b05fc120692602fef21330f404503717449dd7b9..b7da879253c4bdacf88ce05db85f1c99845f2fb6 100644 (file)
@@ -29,10 +29,10 @@ namespace lyx {
 
 // the previous document class may have loaded some modules that the
 // new one excludes, and the new class may provide, etc, some that
-// conflict with ones that were already loaded. So we need to go 
+// conflict with ones that were already loaded. So we need to go
 // through the list and fix everything. I suppose there are various
-// ways this could be done, but the following seems to work at the 
-// moment. (Thanks to Philippe Charpentier for helping work out all 
+// ways this could be done, but the following seems to work at the
+// moment. (Thanks to Philippe Charpentier for helping work out all
 // the bugs---rgh.)
 bool LayoutModuleList::adaptToBaseClass(LayoutFile const * const lay,
                std::list<string> const & removedModules)
@@ -53,24 +53,22 @@ bool LayoutModuleList::adaptToBaseClass(LayoutFile const * const lay,
 }
 
 
-bool LayoutModuleList::moduleCanBeAdded(string const & modName, 
+bool LayoutModuleList::moduleCanBeAdded(string const & modName,
                LayoutFile const * const lay) const
 {
        // Is the module already present?
        const_iterator it = begin();
        const_iterator const en = end();
-       for (; it != en; it++)
-               if (*it == modName) 
+       for (; it != en; ++it)
+               if (*it == modName)
                        return false;
 
-       LyXModule const * const lm = moduleList[modName];
+       LyXModule const * const lm = theModuleList[modName];
        if (!lm)
                return true;
 
-       // Is this module explicitly excluded by the document class?
-       const_iterator const exclmodstart = lay->excludedModules().begin();
-       const_iterator const exclmodend = lay->excludedModules().end();
-       if (find(exclmodstart, exclmodend, modName) != exclmodend)
+       // Does this module conflict with the document class or any loaded modules?
+       if (moduleConflicts(modName, lay))
                return false;
 
        // Is this module already provided by the document class?
@@ -79,31 +77,18 @@ bool LayoutModuleList::moduleCanBeAdded(string const & modName,
        if (find(provmodstart, provmodend, modName) != provmodend)
                return false;
 
-       // Check for conflicts with used modules
-       // first the provided modules...
-       const_iterator provmodit = provmodstart;
-       for (; provmodit != provmodend; ++provmodit) {
-               if (!LyXModule::areCompatible(modName, *provmodit))
-                       return false;
-       }
-       // and then the selected modules
-       const_iterator mit = begin();
-       const_iterator const men = end();
-       for (; mit != men; ++mit)
-               if (!LyXModule::areCompatible(modName, *mit))
-                       return false;
-
        // Check whether some required module is available
        vector<string> const reqs = lm->getRequiredModules();
        if (reqs.empty())
                return true;
 
-       mit = begin(); // reset
+       const_iterator mit = begin();
+       const_iterator const men = end();
        vector<string>::const_iterator rit = reqs.begin();
        vector<string>::const_iterator ren = reqs.end();
        bool foundone = false;
        for (; rit != ren; ++rit) {
-               if (find(mit, men, *rit) != men || 
+               if (find(mit, men, *rit) != men ||
                    find(provmodstart, provmodend, *rit) != provmodend) {
                        foundone = true;
                        break;
@@ -114,6 +99,32 @@ bool LayoutModuleList::moduleCanBeAdded(string const & modName,
 }
 
 
+bool LayoutModuleList::moduleConflicts(string const & modName,
+                                       LayoutFile const * const lay) const
+{
+       // Is this module explicitly excluded by the document class?
+       const_iterator const exclmodstart = lay->excludedModules().begin();
+       const_iterator const exclmodend = lay->excludedModules().end();
+       if (find(exclmodstart, exclmodend, modName) != exclmodend)
+               return true;
+       // Check for conflicts with used modules
+       // first the provided modules...
+       const_iterator provmodit = lay->providedModules().begin();
+       const_iterator const provmodend = lay->providedModules().end();
+       for (; provmodit != provmodend; ++provmodit) {
+               if (!LyXModule::areCompatible(modName, *provmodit))
+                       return true;
+       }
+       // and then the selected modules
+       const_iterator mit = begin();
+       const_iterator const men = end();
+       for (; mit != men; ++mit)
+               if (!LyXModule::areCompatible(modName, *mit))
+                       return true;
+       return false;
+}
+
+
 void LayoutModuleList::addDefaultModules(LayoutFile const * const lay,
                std::list<string> removedModules)
 {
@@ -131,12 +142,12 @@ void LayoutModuleList::addDefaultModules(LayoutFile const * const lay,
        iterator insertpos = begin();
        int numinserts = 0;
 
-       for (; mit != men; mit++) {
+       for (; mit != men; ++mit) {
                string const & modName = *mit;
                // make sure the user hasn't removed it
                if (find(removedModules.begin(), removedModules.end(), modName) !=
                    removedModules.end()) {
-                       LYXERR(Debug::TCLASS, "Default module `" << modName << 
+                       LYXERR(Debug::TCLASS, "Default module `" << modName <<
                                        "' not added because removed by user.");
                        continue;
                }
@@ -144,7 +155,7 @@ void LayoutModuleList::addDefaultModules(LayoutFile const * const lay,
                if (!moduleCanBeAdded(modName, lay)) {
                        // FIXME This could be because it's already present, so we should
                        // probably return something indicating that.
-                       LYXERR(Debug::TCLASS, "Default module `" << modName << 
+                       LYXERR(Debug::TCLASS, "Default module `" << modName <<
                                        "' could not be added.");
                        continue;
                }
@@ -191,8 +202,8 @@ bool LayoutModuleList::removeBadModules(LayoutFile const * const lay)
                bool excluded = false;
                for (; !excluded && pit != pen; ++pit) {
                        if (!LyXModule::areCompatible(modname, *pit)) {
-                               LYXERR0("Module " << modname << 
-                                               " dropped becuase it conflicts with provided module `" << *pit << "'.");
+                               LYXERR0("Module " << modname <<
+                                               " dropped because it conflicts with provided module `" << *pit << "'.");
                                consistent = false;
                                excluded = true;
                        }
@@ -208,7 +219,7 @@ bool LayoutModuleList::removeBadModules(LayoutFile const * const lay)
 // Perform a consistency check on the set of modules. We need to make
 // sure that none of the modules exclude each other and that requires
 // are satisfied.
-bool LayoutModuleList::checkModuleConsistency(LayoutFile const * const lay) 
+bool LayoutModuleList::checkModuleConsistency(LayoutFile const * const lay)
 {
        bool consistent = true;
        LayoutModuleList oldModules = *this;
@@ -225,7 +236,7 @@ bool LayoutModuleList::checkModuleConsistency(LayoutFile const * const lay)
                for (; !excluded && lit != len; ++lit) {
                        if (!LyXModule::areCompatible(modname, *lit)) {
                                consistent = false;
-                               LYXERR0("Module " << modname << 
+                               LYXERR0("Module " << modname <<
                                                " dropped because it is excluded by prior module " << *lit);
                                excluded = true;
                        }
@@ -236,13 +247,13 @@ bool LayoutModuleList::checkModuleConsistency(LayoutFile const * const lay)
 
                // determine whether some provided module or some prior module
                // satisfies our requirements
-               LyXModule const * const oldmod = moduleList[modname];
+               LyXModule const * const oldmod = theModuleList[modname];
                if (!oldmod) {
-                       LYXERR0("Default module " << modname << 
+                       LYXERR0("Default module " << modname <<
                                        " added although it is unavailable and can't check requirements.");
                        continue;
                }
-                       
+
                vector<string> const & reqs = oldmod->getRequiredModules();
                if (!reqs.empty()) {
                        // we now set excluded to true, meaning that we haven't
@@ -252,7 +263,7 @@ bool LayoutModuleList::checkModuleConsistency(LayoutFile const * const lay)
                        vector<string>::const_iterator const ren = reqs.end();
                        for (; rit != ren; ++rit) {
                                string const reqmod = *rit;
-                               if (find(provmods.begin(), provmods.end(), reqmod) != 
+                               if (find(provmods.begin(), provmods.end(), reqmod) !=
                                                provmods.end()) {
                                        excluded = false;
                                        break;