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.
16 #include "ModuleList.h"
18 #include "support/docstring.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.
41 : public std::binary_function<LyXModule, LyXModule, int>
44 int operator()(LyXModule const & lm1,
45 LyXModule const & lm2) const
47 return (lm1.name < lm2.name);
52 //Much of this is borrowed from TextClassList::read()
53 bool ModuleList::load() {
54 support::FileName const real_file = libFileSearch("", "lyxmodules.lst");
55 LYXERR(Debug::TCLASS) << "Reading modules from `"
56 << real_file << '\'' << endl;
58 if (real_file.empty()) {
59 lyxerr << "ModuleList::load(): unable to find "
61 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
62 << "'.\nNo modules will be available." << endl;
67 if (!lex.setFile(real_file)) {
68 lyxerr << "ModuleList::load():"
69 "lyxlex was not able to set file: "
70 << real_file << ".\nNo modules will be available." << endl;
75 lyxerr << "ModuleList::load():" <<
76 "unable to open modules file `"
77 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
78 << "'\nNo modules will be available."
83 bool finished = false;
84 // Parse modules files
85 LYXERR(Debug::TCLASS) << "Starting parsing of lyxmodules.lst" << endl;
86 while (lex.isOK() && !finished) {
87 LYXERR(Debug::TCLASS) << "\tline by line" << endl;
93 string const modName = lex.getString();
94 LYXERR(Debug::TCLASS) << "Module name: " << modName << endl;
97 string const fname = lex.getString();
98 LYXERR(Debug::TCLASS) << "Filename: " << fname << endl;
101 string const desc = lex.getString();
102 LYXERR(Debug::TCLASS) << "Description: " << desc << endl;
106 string packages = lex.getString();
107 LYXERR(Debug::TCLASS) << "Packages: " << packages << endl;
109 while (!packages.empty()) {
111 packages = support::split(packages, p, ',');
114 // This code is run when we have
115 // modName, fname, desc, and pkgs
116 addLayoutModule(modName, fname, desc, pkgs);
120 LYXERR(Debug::TCLASS) << "End of parsing of lyxmodules.lst" << endl;
122 if (!moduleList.empty())
123 std::sort(moduleList.begin(), moduleList.end(), moduleSorter());
128 void ModuleList::addLayoutModule(string moduleName,
129 string filename, string description, vector<string> 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) {
164 LyXModuleList::iterator it = modlist_.begin();
165 for (; it != modlist_.end(); ++it)
166 if (it->name == str) {
167 LyXModule & mod = *it;