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 * ====================================================== */
14 #pragma implementation
19 #include "ExternalTemplate.h"
23 #include "support/path.h"
24 #include "support/LAssert.h"
25 #include "support/filetools.h"
31 extern string user_lyxdir;
34 // We have to have dummy default commands for security reasons!
36 ExternalTemplate::ExternalTemplate()
40 ExternalTemplate::FormatTemplate::FormatTemplate()
44 ExternalTemplateManager::ExternalTemplateManager()
46 // gimp gnuchess gnuplot ical netscape tetris xpaint
47 readTemplates(user_lyxdir);
48 if (lyxerr.debugging())
55 dumpTemplate(std::ostream & o)
57 void operator()(ExternalTemplateManager::Templates::value_type const & vt) {
58 ExternalTemplate const & et = vt.second;
60 ost << "Template " << et.lyxName << "\n"
61 << "\tGuiName " << et.guiName << "\n"
65 << "\tFileFilter " << et.fileRegExp << "\n"
66 << "\tViewCommand " << et.viewCommand << "\n"
67 << "\tEditCommand " << et.editCommand << "\n"
68 << "\tAutomaticProduction " << et.automaticProduction << "\n";
70 ost << "TemplateEnd" << endl;
80 dumpFormat(ostream & o)
82 void operator()(ExternalTemplate::Formats::value_type const & vt) const{
83 ExternalTemplate::FormatTemplate const & ft = vt.second;
84 ost << "\tFormat " << vt.first << "\n"
85 << "\t\tProduct " << ft.product << "\n"
86 << "\t\tUpdateCommand " << ft.updateCommand << "\n"
87 << "\t\tUpdateResult " << ft.updateResult << "\n"
88 << "\t\tRequirement " << ft.requirement << "\n"
91 << "\t\tPreambleEnd\n"
99 void ExternalTemplate::dumpFormats(ostream & os) const
101 for_each(formats.begin(), formats.end(), dumpFormat(os));
105 void ExternalTemplateManager::dumpTemplates() const
107 for_each(templates.begin(), templates.end(), dumpTemplate(lyxerr));
111 ExternalTemplateManager & ExternalTemplateManager::get()
113 static ExternalTemplateManager externalTemplateManager;
114 return externalTemplateManager;
118 ExternalTemplateManager::Templates &
119 ExternalTemplateManager::getTemplates()
125 ExternalTemplateManager::Templates const &
126 ExternalTemplateManager::getTemplates() const
132 ExternalTemplate const & ExternalTemplateManager::getTemplateByName(string const & name)
134 return templates[name];
138 void ExternalTemplateManager::readTemplates(string const & path)
147 keyword_item templatetags[] = {
148 { "template", TM_TEMPLATE },
149 { "templateend", TM_END }
152 string filename = LibFileSearch("", "external_templates");
153 if (filename.empty()) {
154 lyxerr << "ExternalTemplateManager::readTemplates: "
155 "No template file" << endl;
159 LyXLex lex(templatetags, TM_END);
160 if (!lex.setFile(filename)) {
161 lyxerr << "ExternalTemplateManager::readTemplates: "
162 "No template file" << endl;
170 string const temp = lex.getString();
171 ExternalTemplate & tmp = templates[temp];
173 tmp.readTemplate(lex);
178 lex.printError("Warning: End outside Template.");
185 void ExternalTemplate::readTemplate(LyXLex & lex)
187 enum TemplateOptionTags {
198 keyword_item templateoptiontags[] = {
199 { "automaticproduction", TO_AUTOMATIC },
200 { "editcommand", TO_EDITCMD },
201 { "filefilter", TO_FILTER },
202 { "format", TO_FORMAT },
203 { "guiname", TO_GUINAME },
204 { "helptext", TO_HELPTEXT },
205 { "templateend", TO_END },
206 { "viewcommand", TO_VIEWCMD }
209 pushpophelper pph(lex, templateoptiontags, TO_END);
215 guiName = lex.getString();
219 helpText = lex.getLongString("HelpTextEnd");
224 fileRegExp = lex.getString();
229 viewCommand = lex.getString();
234 editCommand = lex.getString();
239 automaticProduction = lex.getBool();
244 formats[lex.getString()].readFormat(lex);
251 lex.printError("ExternalTemplate::readTemplate: "
252 "Wrong tag: $$Token");
260 void ExternalTemplate::FormatTemplate::readFormat(LyXLex & lex)
271 keyword_item formattags[] = {
272 { "formatend", FO_END },
273 { "preamble", FO_PREAMBLE },
274 { "product", FO_PRODUCT },
275 { "requirement", FO_REQUIREMENT },
276 { "updatecommand", FO_UPDATECMD },
277 { "updateresult", FO_UPDATERESULT }
280 pushpophelper pph(lex, formattags, FO_END);
286 product = lex.getString();
291 updateCommand = lex.getString();
294 case FO_UPDATERESULT:
296 updateResult = lex.getString();
301 requirement = lex.getString();
305 preamble = lex.getLongString("preambleend");
309 if (lyxerr.debugging())
310 lex.printError("FormatEnd");