Fix final default-module-related bug reported by Philippe. The comments

in the code should explain what the problem was.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27313 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2008-11-06 14:59:14 +00:00
parent 225f7c6068
commit c573ab4976

View File

@ -1522,9 +1522,15 @@ void BufferParams::addDefaultModules()
list<string>::const_iterator mit = mods.begin(); list<string>::const_iterator mit = mods.begin();
list<string>::const_iterator men = mods.end(); list<string>::const_iterator men = mods.end();
// we want to add these to the front, but in the right order, // We want to insert the default modules at the beginning of
// so we collect them here first. // the list, but also to insert them in the correct order.
list<string> modulesToAdd; // The obvious thing to do would be to collect them and then
// insert them, but that doesn't work because a later default
// module may require an earlier one, and then the test below
// moduleCanBeAdded(modname)
// will fail. So we have to do it a more complicated way.
list<string>::iterator insertpos = layoutModules_.begin();
int numinserts = 0;
for (; mit != men; mit++) { for (; mit != men; mit++) {
string const & modName = *mit; string const & modName = *mit;
@ -1536,17 +1542,20 @@ void BufferParams::addDefaultModules()
continue; continue;
} }
if (moduleCanBeAdded(modName)) { if (!moduleCanBeAdded(modName)) {
LYXERR(Debug::TCLASS, "Default module `" << modName << "' added."); // FIXME This could be because it's already present, so we should
modulesToAdd.push_back(modName); // probably return something indicating that.
} else LYXERR(Debug::TCLASS, "Default module `" << modName <<
LYXERR(Debug::TCLASS, "' could not be added.");
"Default module `" << modName << "' could not be added."); continue;
}
LYXERR(Debug::TCLASS, "Default module `" << modName << "' added.");
layoutModules_.insert(insertpos, modName);
// now we reset insertpos
++numinserts;
insertpos = layoutModules_.begin();
advance(insertpos, numinserts);
} }
// OK, now we can add the default modules.
layoutModules_.insert(
layoutModules_.begin(), modulesToAdd.begin(), modulesToAdd.end());
} }