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 #ifndef CXX_GLOBAL_CSTD
36 using lyx::textclass_type;
44 // Gets textclass number from name
45 pair<bool, textclass_type> const
46 LyXTextClassList::NumberOfClass(string const & textclass) const
48 ClassList::const_iterator cit =
49 find_if(classlist.begin(), classlist.end(),
50 lyx::compare_memfun(&LyXTextClass::name, textclass));
51 return cit != classlist.end() ?
52 make_pair(true, textclass_type(cit - classlist.begin())) :
53 make_pair(false, textclass_type(0));
57 // Gets a textclass structure from number
59 LyXTextClassList::operator[](textclass_type textclass) const
61 classlist[textclass].load();
62 if (textclass < classlist.size())
63 return classlist[textclass];
69 void LyXTextClassList::Add(LyXTextClass const & t)
71 classlist.push_back(t);
75 // used when sorting the textclass list.
76 class less_textclass_desc {
78 int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
79 return tc1.description() < tc2.description();
84 // Reads LyX textclass definitions according to textclass config file
85 bool LyXTextClassList::Read ()
88 string real_file = LibFileSearch("", "textclass.lst");
89 lyxerr[Debug::TCLASS] << "Reading textclasses from `"
90 << real_file << "'" << endl;
92 if (real_file.empty()) {
93 lyxerr << "LyXTextClassList::Read: unable to find "
94 "textclass file `" << MakeDisplayPath(real_file, 1000)
95 << "'. Exiting." << endl;
97 Alert::alert(_("LyX wasn't able to find its layout descriptions!"),
98 _("Check that the file \"textclass.lst\""),
99 _("is installed correctly. Sorry, has to exit :-("));
101 // This causes LyX to end... Not a desirable behaviour. Lgb
102 // What do you propose? That the user gets a file dialog
103 // and is allowed to hunt for the file? (Asger)
104 // more that we have a layout for minimal.cls statically
105 // compiled in... (Lgb)
108 if (!lex.setFile(real_file)) {
109 lyxerr << "LyXTextClassList::Read: "
110 "lyxlex was not able to set file: "
111 << real_file << endl;
115 lyxerr << "LyXTextClassList::Read: unable to open "
116 "textclass file `" << MakeDisplayPath(real_file, 1000)
117 << "'\nCheck your installation. LyX can't continue."
122 bool finished = false;
124 lyxerr[Debug::TCLASS] << "Starting parsing of textclass.lst" << endl;
125 while (lex.isOK() && !finished) {
126 lyxerr[Debug::TCLASS] << "\tline by line" << endl;
128 case LyXLex::LEX_FEOF:
132 string const fname = lex.getString();
133 lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
135 string const clname = lex.getString();
136 lyxerr[Debug::TCLASS] << "Clname: " << clname << endl;
138 string const desc = lex.getString();
139 lyxerr[Debug::TCLASS] << "Desc: " << desc << endl;
140 // This code is run when we have
141 // fname, clname and desc
142 LyXTextClass tmpl(fname, clname, desc);
143 if (lyxerr.debugging(Debug::TCLASS)) {
151 lyxerr[Debug::TCLASS] << "End of parsing of textclass.lst" << endl;
153 if (classlist.empty()) {
154 lyxerr << "LyXTextClassList::Read: no textclasses found!"
156 Alert::alert(_("LyX wasn't able to find any layout description!"),
157 _("Check the contents of the file \"textclass.lst\""),
158 _("Sorry, has to exit :-("));
161 // Ok everything loaded ok, now sort the list.
162 sort(classlist.begin(), classlist.end(), less_textclass_desc());
167 // Global variable: textclass table.
168 LyXTextClassList textclasslist;
170 // Reads the style files
173 lyxerr[Debug::TCLASS] << "LyXSetStyle: parsing configuration...\n";
175 if (!textclasslist.Read()) {
176 lyxerr[Debug::TCLASS] << "LyXSetStyle: an error occured "
177 "during parsing.\n Exiting." << endl;
181 lyxerr[Debug::TCLASS] << "LyXSetStyle: configuration parsed." << endl;