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 `" << real_file << '\'');
56 if (real_file.empty()) {
57 lyxerr << "ModuleList::load(): unable to find "
59 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
60 << "'.\nNo modules will be available." << endl;
65 if (!lex.setFile(real_file)) {
66 lyxerr << "ModuleList::load():"
67 "lyxlex was not able to set file: "
68 << real_file << ".\nNo modules will be available." << endl;
73 lyxerr << "ModuleList::load():" <<
74 "unable to open modules file `"
75 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
76 << "'\nNo modules will be available."
81 bool finished = false;
82 // Parse modules files
83 LYXERR(Debug::TCLASS, "Starting parsing of lyxmodules.lst");
84 while (lex.isOK() && !finished) {
85 LYXERR(Debug::TCLASS, "\tline by line");
91 string const modName = lex.getString();
92 LYXERR(Debug::TCLASS, "Module name: " << modName);
95 string const fname = lex.getString();
96 LYXERR(Debug::TCLASS, "Filename: " << fname);
99 string const desc = lex.getString();
100 LYXERR(Debug::TCLASS, "Description: " << desc);
104 string packages = lex.getString();
105 LYXERR(Debug::TCLASS, "Packages: " << packages);
107 while (!packages.empty()) {
109 packages = support::split(packages, p, ',');
112 // This code is run when we have
113 // modName, fname, desc, and pkgs
114 addLayoutModule(modName, fname, desc, pkgs);
118 LYXERR(Debug::TCLASS, "End of parsing of lyxmodules.lst");
120 if (!moduleList.empty())
121 std::sort(moduleList.begin(), moduleList.end(), ModuleSorter());
126 void ModuleList::addLayoutModule(string const & moduleName,
127 string const & filename, string const & description,
128 vector<string> const & pkgs)
131 lm.name = moduleName;
132 lm.filename = filename;
133 lm.description = description;
134 lm.packageList = pkgs;
135 modlist_.push_back(lm);
139 LyXModuleList::const_iterator ModuleList::begin() const
141 return modlist_.begin();
145 LyXModuleList::iterator ModuleList::begin()
147 return modlist_.begin();
151 LyXModuleList::const_iterator ModuleList::end() const
153 return modlist_.end();
157 LyXModuleList::iterator ModuleList::end()
159 return modlist_.end();
163 LyXModule * ModuleList::operator[](string const & str)
165 LyXModuleList::iterator it = modlist_.begin();
166 for (; it != modlist_.end(); ++it)
167 if (it->name == str) {
168 LyXModule & mod = *it;