4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "ModuleList.h"
19 #include "support/filetools.h"
20 #include "support/lstrings.h"
31 using support::FileName;
32 using support::libFileSearch;
33 using support::makeDisplayPath;
35 //global variable: module list
36 ModuleList moduleList;
39 // used when sorting the module list.
43 int operator()(LyXModule const & lm1, LyXModule const & lm2) const
45 return lm1.name < lm2.name;
50 //Much of this is borrowed from TextClassList::read()
51 bool ModuleList::load()
53 support::FileName const real_file = libFileSearch("", "lyxmodules.lst");
54 LYXERR(Debug::TCLASS) << "Reading modules from `"
55 << real_file << '\'' << endl;
57 if (real_file.empty()) {
58 lyxerr << "ModuleList::load(): unable to find "
60 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
61 << "'.\nNo modules will be available." << endl;
66 if (!lex.setFile(real_file)) {
67 lyxerr << "ModuleList::load():"
68 "lyxlex was not able to set file: "
69 << real_file << ".\nNo modules will be available." << endl;
74 lyxerr << "ModuleList::load():" <<
75 "unable to open modules file `"
76 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
77 << "'\nNo modules will be available."
82 bool finished = false;
83 // Parse modules files
84 LYXERR(Debug::TCLASS) << "Starting parsing of lyxmodules.lst" << endl;
85 while (lex.isOK() && !finished) {
86 LYXERR(Debug::TCLASS) << "\tline by line" << endl;
92 string const modName = lex.getString();
93 LYXERR(Debug::TCLASS) << "Module name: " << modName << endl;
96 string const fname = lex.getString();
97 LYXERR(Debug::TCLASS) << "Filename: " << fname << endl;
100 string const desc = lex.getString();
101 LYXERR(Debug::TCLASS) << "Description: " << desc << endl;
105 string packages = lex.getString();
106 LYXERR(Debug::TCLASS) << "Packages: " << packages << endl;
108 while (!packages.empty()) {
110 packages = support::split(packages, p, ',');
113 // This code is run when we have
114 // modName, fname, desc, and pkgs
115 addLayoutModule(modName, fname, desc, pkgs);
119 LYXERR(Debug::TCLASS) << "End of parsing of lyxmodules.lst" << endl;
121 if (!moduleList.empty())
122 std::sort(moduleList.begin(), moduleList.end(), ModuleSorter());
127 void ModuleList::addLayoutModule(string const & moduleName,
128 string const & filename, string const & description,
129 vector<string> const & pkgs)
132 lm.name = moduleName;
133 lm.filename = filename;
134 lm.description = description;
135 lm.packageList = pkgs;
136 modlist_.push_back(lm);
140 LyXModuleList::const_iterator ModuleList::begin() const
142 return modlist_.begin();
146 LyXModuleList::iterator ModuleList::begin()
148 return modlist_.begin();
152 LyXModuleList::const_iterator ModuleList::end() const
154 return modlist_.end();
158 LyXModuleList::iterator ModuleList::end()
160 return modlist_.end();
164 LyXModule * ModuleList::operator[](string const & str)
166 LyXModuleList::iterator it = modlist_.begin();
167 for (; it != modlist_.end(); ++it)
168 if (it->name == str) {
169 LyXModule & mod = *it;