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.
15 #include "ModuleList.h"
16 #include "support/filetools.h"
17 #include "support/docstring.h"
26 using support::FileName;
27 using support::libFileSearch;
28 using support::makeDisplayPath;
30 //global variable: module list
31 ModuleList moduleList;
34 // used when sorting the module list.
36 : public std::binary_function<LyXModule, LyXModule, int>
39 int operator()(LyXModule const & lm1,
40 LyXModule const & lm2) const
42 return (lm1.name < lm2.name);
47 //Much of this is borrowed from TextClassList::read()
48 bool ModuleList::load() {
49 support::FileName const real_file = libFileSearch("", "lyxmodules.lst");
50 LYXERR(Debug::TCLASS) << "Reading modules from `"
51 << real_file << '\'' << endl;
53 if (real_file.empty()) {
54 lyxerr << "ModuleList::load(): unable to find "
56 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
57 << "'.\nNo modules will be available." << endl;
62 if (!lex.setFile(real_file)) {
63 lyxerr << "ModuleList::load():"
64 "lyxlex was not able to set file: "
65 << real_file << ".\nNo modules will be available." << endl;
70 lyxerr << "ModuleList::load():" <<
71 "unable to open modules file `"
72 << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
73 << "'\nNo modules will be available."
78 bool finished = false;
79 // Parse modules files
80 LYXERR(Debug::TCLASS) << "Starting parsing of lyxmodules.lst" << endl;
81 while (lex.isOK() && !finished) {
82 LYXERR(Debug::TCLASS) << "\tline by line" << endl;
88 string const modName = lex.getString();
89 LYXERR(Debug::TCLASS) << "Module name: " << modName << endl;
91 string const fname = lex.getString();
92 LYXERR(Debug::TCLASS) << "Filename: " << fname << endl;
94 string const desc = lex.getString();
95 LYXERR(Debug::TCLASS) << "Description: " << desc << endl;
96 //FIXME Add package read, and availability
97 // This code is run when we have
98 // modName, fname, and desc
99 addLayoutModule(modName, fname, desc);
105 LYXERR(Debug::TCLASS) << "End of parsing of lyxmodules.lst" << endl;
107 if (!moduleList.empty())
108 sort(moduleList.begin(), moduleList.end(), moduleSorter());
113 void ModuleList::addLayoutModule(string moduleName,
114 string filename, string description) {
116 lm.name = moduleName;
117 lm.filename = filename;
118 lm.description = description;
119 modlist_.push_back(lm);
123 LyXModuleList::const_iterator ModuleList::begin() const
125 return modlist_.begin();
129 LyXModuleList::iterator ModuleList::begin()
131 return modlist_.begin();
135 LyXModuleList::const_iterator ModuleList::end() const
137 return modlist_.end();
141 LyXModuleList::iterator ModuleList::end()
143 return modlist_.end();
147 LyXModule * ModuleList::operator[](string const str) {
148 LyXModuleList::iterator it = modlist_.begin();
149 for (; it != modlist_.end(); ++it)
150 if (it->name == str) {
151 LyXModule & mod = *it;