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"
16 #include "support/debug.h"
19 #include "support/filetools.h"
20 #include "support/lstrings.h"
26 using namespace lyx::support;
31 //global variable: module list
32 ModuleList moduleList;
35 // used when sorting the module list.
39 int operator()(LyXModule const & lm1, LyXModule const & lm2) const
41 return lm1.name < lm2.name;
46 //Much of this is borrowed from TextClassList::read()
47 bool ModuleList::load()
49 FileName const real_file = libFileSearch("", "lyxmodules.lst");
50 LYXERR(Debug::TCLASS, "Reading modules from `" << real_file << '\'');
52 if (real_file.empty()) {
53 lyxerr << "ModuleList::load(): unable to find "
55 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
56 << "'.\nNo modules will be available." << endl;
61 if (!lex.setFile(real_file)) {
62 lyxerr << "ModuleList::load():"
63 "lyxlex was not able to set file: "
64 << real_file << ".\nNo modules will be available." << endl;
69 lyxerr << "ModuleList::load():" <<
70 "unable to open modules file `"
71 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
72 << "'\nNo modules will be available."
77 bool finished = false;
78 // Parse modules files
79 LYXERR(Debug::TCLASS, "Starting parsing of lyxmodules.lst");
80 while (lex.isOK() && !finished) {
81 LYXERR(Debug::TCLASS, "\tline by line");
87 string const modName = lex.getString();
88 LYXERR(Debug::TCLASS, "Module name: " << modName);
91 string const fname = lex.getString();
92 LYXERR(Debug::TCLASS, "Filename: " << fname);
95 string const desc = lex.getString();
96 LYXERR(Debug::TCLASS, "Description: " << desc);
100 string packages = lex.getString();
101 LYXERR(Debug::TCLASS, "Packages: " << packages);
103 while (!packages.empty()) {
105 packages = split(packages, p, ',');
108 // This code is run when we have
109 // modName, fname, desc, and pkgs
110 addLayoutModule(modName, fname, desc, pkgs);
114 LYXERR(Debug::TCLASS, "End of parsing of lyxmodules.lst");
116 if (!moduleList.empty())
117 sort(moduleList.begin(), moduleList.end(), ModuleSorter());
122 void ModuleList::addLayoutModule(string const & moduleName,
123 string const & filename, string const & description,
124 vector<string> const & pkgs)
127 lm.name = moduleName;
128 lm.filename = filename;
129 lm.description = description;
130 lm.packageList = pkgs;
131 modlist_.push_back(lm);
135 LyXModuleList::const_iterator ModuleList::begin() const
137 return modlist_.begin();
141 LyXModuleList::iterator ModuleList::begin()
143 return modlist_.begin();
147 LyXModuleList::const_iterator ModuleList::end() const
149 return modlist_.end();
153 LyXModuleList::iterator ModuleList::end()
155 return modlist_.end();
159 LyXModule * ModuleList::operator[](string const & str)
161 LyXModuleList::iterator it = modlist_.begin();
162 for (; it != modlist_.end(); ++it)
163 if (it->name == str) {
164 LyXModule & mod = *it;