1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ======================================================
15 #pragma implementation
18 #include "lyxtextclasslist.h"
19 #include "lyxtextclass.h"
24 #include "frontends/Alert.h"
26 #include "support/lyxfunctional.h"
27 #include "support/LAssert.h"
28 #include "support/filetools.h"
32 using lyx::textclass_type;
40 // Gets textclass number from name
41 pair<bool, textclass_type> const
42 LyXTextClassList::NumberOfClass(string const & textclass) const
44 ClassList::const_iterator cit =
45 find_if(classlist.begin(), classlist.end(),
46 lyx::compare_memfun(&LyXTextClass::name, textclass));
47 return cit != classlist.end() ?
48 make_pair(true, textclass_type(cit - classlist.begin())) :
49 make_pair(false, textclass_type(0));
53 // Gets a textclass structure from number
55 LyXTextClassList::operator[](textclass_type textclass) const
57 classlist[textclass].load();
58 if (textclass < classlist.size())
59 return classlist[textclass];
65 void LyXTextClassList::Add(LyXTextClass const & t)
67 classlist.push_back(t);
71 // used when sorting the textclass list.
72 class less_textclass_desc {
74 int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
75 return tc1.description() < tc2.description();
80 // Reads LyX textclass definitions according to textclass config file
81 bool LyXTextClassList::Read ()
84 string real_file = LibFileSearch("", "textclass.lst");
85 lyxerr[Debug::TCLASS] << "Reading textclasses from `"
86 << real_file << "'" << endl;
88 if (real_file.empty()) {
89 lyxerr << "LyXTextClassList::Read: unable to find "
90 "textclass file `" << MakeDisplayPath(real_file, 1000)
91 << "'. Exiting." << endl;
93 Alert::alert(_("LyX wasn't able to find its layout descriptions!"),
94 _("Check that the file \"textclass.lst\""),
95 _("is installed correctly. Sorry, has to exit :-("));
97 // This causes LyX to end... Not a desirable behaviour. Lgb
98 // What do you propose? That the user gets a file dialog
99 // and is allowed to hunt for the file? (Asger)
100 // more that we have a layout for minimal.cls statically
101 // compiled in... (Lgb)
104 if (!lex.setFile(real_file)) {
105 lyxerr << "LyXTextClassList::Read: "
106 "lyxlex was not able to set file: "
107 << real_file << endl;
111 lyxerr << "LyXTextClassList::Read: unable to open "
112 "textclass file `" << MakeDisplayPath(real_file, 1000)
113 << "'\nCheck your installation. LyX can't continue."
118 bool finished = false;
120 lyxerr[Debug::TCLASS] << "Starting parsing of textclass.lst" << endl;
121 while (lex.isOK() && !finished) {
122 lyxerr[Debug::TCLASS] << "\tline by line" << endl;
124 case LyXLex::LEX_FEOF:
128 string const fname = lex.getString();
129 lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
131 string const clname = lex.getString();
132 lyxerr[Debug::TCLASS]
133 << "Clname: " << clname << endl;
135 string const desc = lex.getString();
136 lyxerr[Debug::TCLASS]
137 << "Desc: " << desc << endl;
138 // This code is run when we have
139 // fname, clname and desc
140 LyXTextClass tmpl(fname,
144 debugging(Debug::TCLASS)) {
152 lyxerr[Debug::TCLASS] << "End of parsing of textclass.lst" << endl;
154 if (classlist.empty()) {
155 lyxerr << "LyXTextClassList::Read: no textclasses found!"
157 Alert::alert(_("LyX wasn't able to find any layout description!"),
158 _("Check the contents of the file \"textclass.lst\""),
159 _("Sorry, has to exit :-("));
162 // Ok everything loaded ok, now sort the list.
163 sort(classlist.begin(), classlist.end(), less_textclass_desc());
168 // Global variable: textclass table.
169 LyXTextClassList textclasslist;
171 // Reads the style files
174 lyxerr[Debug::TCLASS] << "LyXSetStyle: parsing configuration...\n";
176 if (!textclasslist.Read()) {
177 lyxerr[Debug::TCLASS] << "LyXSetStyle: an error occured "
178 "during parsing.\n Exiting." << endl;
182 lyxerr[Debug::TCLASS] << "LyXSetStyle: configuration parsed." << endl;