From 28047741c2b106be146084e0e16b5cf485ec1048 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Thu, 16 Oct 2008 15:04:48 +0000 Subject: [PATCH] Fix a bug involving module conflicts. We need to check not only that we do not exclude some used module, but also that no used module excludes us. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26920 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/layouts/g-brief2.layout | 2 +- src/frontends/qt4/GuiDocument.cpp | 39 ++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/lib/layouts/g-brief2.layout b/lib/layouts/g-brief2.layout index ad42d4f3c8..237022d6e4 100644 --- a/lib/layouts/g-brief2.layout +++ b/lib/layouts/g-brief2.layout @@ -11,7 +11,7 @@ Input stdcounters.inc Input stdinsets.inc # General textclass parameters -Format 10 +Format 11 Columns 1 Sides 1 PageStyle Empty diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 5d126f5e35..e3132d7bef 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -274,30 +274,33 @@ void ModuleSelectionManager::updateAddPB() int const arows = availableModel->rowCount(); QModelIndexList const availSels = availableLV->selectionModel()->selectedIndexes(); - if (arows == 0 || availSels.isEmpty() || isSelected(availSels.first())) { + + // disable if there aren't any modules (?), if none of them is chosen + // in the dialog, or if the chosen one is already selected for use. + if (arows == 0 || availSels.isEmpty() || isSelected(availSels.first())) { addPB->setEnabled(false); return; } - + QModelIndex const & idx = availableLV->selectionModel()->currentIndex(); string const modName = getAvailableModel()->getIDString(idx.row()); - vector const reqs = getRequiredList(modName); - vector const excl = getExcludedList(modName); - - if (reqs.empty() && excl.empty()) { - addPB->setEnabled(true); - return; - } int const srows = selectedModel->rowCount(); + // if no modules are yet selected, there is no more to check. + if (srows == 0) { + addPB->setEnabled(true); + return; + } + vector selModList; for (int i = 0; i < srows; ++i) selModList.push_back(getSelectedModel()->getIDString(i)); vector::const_iterator const selModStart = selModList.begin(); vector::const_iterator const selModEnd = selModList.end(); - + // Check whether some required module is available + vector const reqs = getRequiredList(modName); if (!reqs.empty()) { bool foundOne = false; vector::const_iterator it = reqs.begin(); @@ -314,7 +317,8 @@ void ModuleSelectionManager::updateAddPB() } } - // Check whether any excluded module is being used + // 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(); @@ -326,6 +330,19 @@ void ModuleSelectionManager::updateAddPB() } } + // ...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) { + addPB->setEnabled(false); + return; + } + } + addPB->setEnabled(true); } -- 2.39.5