]> git.lyx.org Git - lyx.git/blobdiff - src/ModuleList.cpp
reorder.
[lyx.git] / src / ModuleList.cpp
index 0b88a8e8f24d1fcb881a1682c0796f335b814a34..e2471ed5e5bbec2ca04e3e501f5acbae462c3493 100644 (file)
 
 #include "ModuleList.h"
 
-#include "support/debug.h"
 #include "LaTeXFeatures.h"
 #include "Lexer.h"
 
+#include "support/debug.h"
 #include "support/FileName.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
 
 #include <algorithm>
-#include <ostream>
        
 using namespace std;
 using namespace lyx::support;
@@ -34,16 +33,21 @@ namespace lyx {
 ModuleList moduleList;
 
 
-LyXModule::LyXModule(string const & n, string const & f
+LyXModule::LyXModule(string const & n, string const & i
                           string const & d, vector<string> const & p,
                           vector<string> const & r, vector<string> const & e):
-       name(n), filename(f), description(d), 
+       name(n), id(i), description(d), 
        packageList(p), requiredModules(r), excludedModules(e),
        checked(false)
-{}
+{
+       filename = id + ".module";
+}
 
 
 bool LyXModule::isAvailable() {
+#ifdef TEX2LYX
+       return true;
+#else
        if (packageList.empty())
                return true;
        if (checked)
@@ -60,9 +64,42 @@ bool LyXModule::isAvailable() {
        }
        available = true;
        return available;
+#endif
+}
+
+
+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(), id) != 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
 {
@@ -74,34 +111,30 @@ public:
 };
 
 
-//Much of this is borrowed from TextClassList::read()
-bool ModuleList::load()
+//Much of this is borrowed from LayoutFileList::read()
+bool ModuleList::read()
 {
        FileName const real_file = libFileSearch("", "lyxmodules.lst");
        LYXERR(Debug::TCLASS, "Reading modules from `" << real_file << '\'');
 
        if (real_file.empty()) {
-               lyxerr << "ModuleList::load(): unable to find "
-                               "modules file  `"
-                               << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
-                               << "'.\nNo modules will be available." << endl;
+               LYXERR0("unable to find modules file  `"
+                       << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
+                       << "'.\nNo modules will be available.");
                return false;
        }
 
-       Lexer lex(0, 0);
+       Lexer lex;
        if (!lex.setFile(real_file)) {
-               lyxerr << "ModuleList::load():"
-                               "lyxlex was not able to set file: "
-                               << real_file << ".\nNo modules will be available." << endl;
+               LYXERR0("lyxlex was not able to set file: "
+                       << real_file << ".\nNo modules will be available.");
                return false;
        }
 
        if (!lex.isOK()) {
-               lyxerr << "ModuleList::load():" <<
-                               "unable to open modules file  `"
-                               << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
-                               << "'\nNo modules will be available."
-                               << endl;
+               LYXERR0("unable to open modules file  `"
+                       << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
+                       << "'\nNo modules will be available.");
                return false;
        }
 
@@ -208,7 +241,7 @@ LyXModule * ModuleList::operator[](string const & str)
 {
        LyXModuleList::iterator it = modlist_.begin();
        for (; it != modlist_.end(); ++it)
-               if (it->getName() == str) {
+               if (it->getID() == str) {
                        LyXModule & mod = *it;
                        return &mod;
                }