]> git.lyx.org Git - features.git/commitdiff
Additional UI logic related to module requires and excludes.
authorRichard Heck <rgheck@comcast.net>
Thu, 10 Jan 2008 01:33:24 +0000 (01:33 +0000)
committerRichard Heck <rgheck@comcast.net>
Thu, 10 Jan 2008 01:33:24 +0000 (01:33 +0000)
The logic here is really kind of a mess. If anyone can make it
simpler, I'd be thrilled.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22458 a592a061-630c-0410-9148-cb99ea01b6c8

src/ModuleList.cpp
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiDocument.h
src/frontends/qt4/GuiSelectionManager.cpp

index bd035f49664600463b1c8601a8be54c6b61dfbef..0b88a8e8f24d1fcb881a1682c0796f335b814a34 100644 (file)
@@ -49,12 +49,14 @@ bool LyXModule::isAvailable() {
        if (checked)
                return available;
        checked = true;
+       //check whether all of the required packages are available
        vector<string>::const_iterator it  = packageList.begin();
        vector<string>::const_iterator end = packageList.end(); 
        for (; it != end; ++it) {
-               if (!LaTeXFeatures::isAvailable(*it))
+               if (!LaTeXFeatures::isAvailable(*it)) {
                        available = false;
                        return available;
+               }
        }
        available = true;
        return available;
index 4586ba197230780e268aaf9f626aee31975a763b..a2f2d67315b0cb12db7de0587ee6839f96b787c4 100644 (file)
@@ -42,6 +42,7 @@
 
 #include "insets/InsetListingsParams.h"
 
+//#include "support/debug.h"
 #include "support/FileName.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
@@ -197,7 +198,7 @@ GuiSelectionManager(availableLV, selectedLV, addPB, delPB,
        
 void ModuleSelMan::updateAddPB() 
 {
-       int const arows = availableLV->model()->rowCount();
+       int const arows = availableModel->stringList().size();
        QModelIndexList const availSels = 
                        availableLV->selectionModel()->selectedIndexes();
        if (arows == 0 || availSels.isEmpty()  || isSelected(availSels.first())) {
@@ -249,6 +250,163 @@ void ModuleSelMan::updateAddPB()
        addPB->setEnabled(true);
 }
 
+void ModuleSelMan::updateDownPB()
+{
+       int const srows = selectedModel->stringList().size();
+       if (srows == 0) {
+               downPB->setEnabled(false);
+               return;
+       }
+       QModelIndexList const selSels = 
+                       selectedLV->selectionModel()->selectedIndexes();
+       //disable if empty or last item is selected
+       if (selSels.empty() || selSels.first().row() == srows - 1) {
+               downPB->setEnabled(false);
+               return;
+       }
+       //determine whether immediately succeding element requires this one
+       QString const curModName = 
+               selectedLV->selectionModel()->currentIndex().data().toString();
+       QStringList const & qsl = selectedModel->stringList();
+       int const curIdx = qsl.indexOf(curModName);
+       if (curIdx < 0 || curIdx == srows - 1) { //this shouldn't happen...
+               downPB->setEnabled(false);
+               return;
+       }
+       string nextModName = fromqstr(qsl[curIdx + 1]);
+
+       vector<string> reqs = getRequiredList(nextModName);
+
+       //if it doesn't require anything....
+       if (reqs.empty()) {
+               downPB->setEnabled(true);
+               return;
+       }
+
+       //FIXME This should perhaps be more flexible and check whether, even 
+       //if this one is required, there is also an earlier one that is required.
+       //enable it if this module isn't required
+       downPB->setEnabled(
+                       find(reqs.begin(), reqs.end(), fromqstr(curModName)) == reqs.end());
+}
+
+void ModuleSelMan::updateUpPB() 
+{
+       int const srows = selectedModel->stringList().size();
+       if (srows == 0) {
+               upPB->setEnabled(false);
+               return;
+       }
+       QModelIndexList const selSels = 
+                       selectedLV->selectionModel()->selectedIndexes();
+       //disable if empty or first item is selected
+       if (selSels.empty() || selSels.first().row() == 0) {
+               upPB->setEnabled(false);
+               return;
+       }
+       //determine whether immediately preceding element is required by this one
+       QString const curModName = 
+               selectedLV->selectionModel()->currentIndex().data().toString();
+       vector<string> reqs = getRequiredList(fromqstr(curModName));
+       
+       //if this one doesn't require anything....
+       if (reqs.empty()) {
+               upPB->setEnabled(true);
+               return;
+       }
+
+       QStringList const & qsl = selectedModel->stringList();
+       int const curIdx = qsl.indexOf(curModName);
+       if (curIdx <= 0) { //this shouldn't happen...
+               upPB->setEnabled(false);
+               return;
+       }
+       string preModName = fromqstr(qsl[curIdx - 1]);
+
+       //NOTE This is less flexible than it might be. You could check whether, even 
+       //if this one is required, there is also an earlier one that is required.
+       //enable it if the preceding module isn't required
+       upPB->setEnabled(find(reqs.begin(), reqs.end(), preModName) == reqs.end());
+}
+
+void ModuleSelMan::updateDelPB() 
+{
+       int const srows = selectedModel->stringList().size();
+       if (srows == 0) {
+               deletePB->setEnabled(false);
+               return;
+       }
+       QModelIndexList const selSels = 
+                       selectedLV->selectionModel()->selectedIndexes();
+       if (selSels.empty() || selSels.first().row() < 0) {
+               deletePB->setEnabled(false);
+               return;
+       }
+       
+       //determine whether some LATER module requires this one
+       //NOTE Things are arranged so that this is the only way there
+       //can be a problem. At least, we hope so.
+       QString const curModName = 
+                       selectedLV->selectionModel()->currentIndex().data().toString();
+       QStringList const & qsl = selectedModel->stringList();
+       
+       //We're looking here for a reason NOT to enable the button. If we
+       //find one, we disable it and return. If we don't, we'll end up at
+       //the end of the function, and then we enable it.
+       QStringList::const_iterator it  = qsl.begin();
+       QStringList::const_iterator end = qsl.end();
+       bool found = false;
+       for (; it != end; ++it) {
+               //skip over the ones preceding this one
+               if (!found) {
+                       if (*it == curModName) {
+                               found = true;
+                       }
+                       continue;
+               }
+                       
+               string const mod = fromqstr(*it);
+               vector<string> reqs = getRequiredList(mod);
+               //does this one require us?
+               if (find(reqs.begin(), reqs.end(), fromqstr(curModName)) == reqs.end())
+                       //no...
+                       continue;
+
+               //OK, so there is a module that requires us
+               //is there an EARLIER module that satisfies the require?
+               //NOTE We demand that it be earlier to keep the list of modules
+               //consistent with the rule that a module must be proceeded by a
+               //required module. There would be more flexible ways to proceed,
+               //but that would be a lot more complicated, and the logic here is
+               //already complicated. (That's why I've left the debugging code.)
+               //lyxerr << "Testing " << mod << std::endl;
+               QStringList::const_iterator it2  = qsl.begin();
+               QStringList::const_iterator end2 = qsl.end();
+               for (; it2 != end2; ++it2) {
+                       //lyxerr << "In loop: Testing " << fromqstr(*it2) << std::endl;
+                       if (*it2 == curModName) { //EARLIER!!
+                               //no other module was found before this one, so...
+                               //lyxerr << "Reached the end of the loop." << std::endl;
+                               deletePB->setEnabled(false);
+                               return;
+                       }
+                       //do we satisfy the require? 
+                       if (find(reqs.begin(), reqs.end(), fromqstr(*it2)) != reqs.end()) {
+                               //lyxerr << fromqstr(*it2) << " does the trick." << std::endl;
+                               break;
+                       }
+               }
+               //did we reach the end of the list?
+               if (it2 == end2) {
+                       //lyxerr << "Reached end of list." << std::endl;
+                       deletePB->setEnabled(false);
+                       return;
+               }
+       }
+       //lyxerr << "All's well that ends well." << std::endl;  
+       deletePB->setEnabled(true);
+}
+
 
 /////////////////////////////////////////////////////////////////////
 //
index a0fd852563c41bd88098709618caba2728e5fb64..ac9dda04b07417b532d683a9a77ff05e60262b85 100644 (file)
@@ -82,6 +82,12 @@ public:
 private:
        ///
        virtual void updateAddPB();
+       ///
+       virtual void updateUpPB();
+       ///
+       virtual void updateDownPB();
+       ///
+       virtual void updateDelPB();
 };
 
 
index a762aad26babbb4de3f32be93e489bbc8bb32613..eea9d40edb0f492bd3eb23b040582f73186f29fb 100644 (file)
@@ -78,7 +78,7 @@ void GuiSelectionManager::update()
 
 void GuiSelectionManager::updateAddPB()
 {
-       int const arows = availableLV->model()->rowCount();
+       int const arows = availableModel->stringList().size();
        QModelIndexList const availSels = 
                availableLV->selectionModel()->selectedIndexes();
        addPB->setEnabled(arows > 0 &&
@@ -89,7 +89,7 @@ void GuiSelectionManager::updateAddPB()
 
 void GuiSelectionManager::updateDelPB()
 {
-       int const srows = selectedLV->model()->rowCount();
+       int const srows = selectedModel->stringList().size();
        if (srows == 0) {
                deletePB->setEnabled(false);
                return;
@@ -103,7 +103,7 @@ void GuiSelectionManager::updateDelPB()
 
 void GuiSelectionManager::updateUpPB()
 {
-       int const srows = selectedLV->model()->rowCount();
+       int const srows = selectedModel->stringList().size();
        if (srows == 0) {
                upPB->setEnabled(false);
                return;
@@ -117,7 +117,7 @@ void GuiSelectionManager::updateUpPB()
 
 void GuiSelectionManager::updateDownPB()
 {
-       int const srows = selectedLV->model()->rowCount();
+       int const srows = selectedModel->stringList().size();
        if (srows == 0) {
                downPB->setEnabled(false);
                return;