1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
19 #include "ExternalTemplate.h"
22 #include "support/path.h"
23 #include "support/LAssert.h"
29 extern string user_lyxdir;
32 // We have to have dummy default commands for security reasons!
34 ExternalTemplate::ExternalTemplate()
35 : viewCommand("true"), editCommand("true")
38 ExternalTemplate::FormatTemplate::FormatTemplate()
39 : updateCommand("true") {}
42 ExternalTemplateManager::ExternalTemplateManager()
44 // gimp gnuchess gnuplot ical netscape tetris xpaint
45 readTemplates(user_lyxdir);
52 dumpTemplate(std::ostream & o)
54 void operator()(ExternalTemplateManager::Templates::value_type const & vt) {
55 ExternalTemplate const & et = vt.second;
57 ost << "Template " << et.lyxName << "\n"
58 << "\tGuiName " << et.guiName << "\n"
62 << "\tFileFilter " << et.fileRegExp << "\n"
63 << "\tViewCommand " << et.viewCommand << "\n"
64 << "\tEditCommand " << et.editCommand << "\n"
65 << "\tAutomaticProduction " << et.automaticProduction << "\n";
67 ost << "TemplateEnd" << endl;
77 dumpFormat(ostream & o)
79 void operator()(ExternalTemplate::Formats::value_type const & vt) const{
80 ExternalTemplate::FormatTemplate const & ft = vt.second;
81 ost << "\tFormat " << vt.first << "\n"
82 << "\t\tProduct " << ft.product << "\n"
83 << "\t\tUpdateCommand " << ft.updateCommand << "\n"
84 << "\t\tRequirement " << ft.requirement << "\n"
87 << "\t\tPreambleEnd\n"
95 void ExternalTemplate::dumpFormats(ostream & os) const
97 for_each(formats.begin(), formats.end(), dumpFormat(os));
100 void ExternalTemplateManager::dumpTemplates() const
102 for_each(templates.begin(), templates.end(), dumpTemplate(lyxerr));
106 ExternalTemplateManager & ExternalTemplateManager::get()
108 static ExternalTemplateManager externalTemplateManager;
109 return externalTemplateManager;
113 ExternalTemplateManager::Templates &
114 ExternalTemplateManager::getTemplates()
120 ExternalTemplateManager::Templates const &
121 ExternalTemplateManager::getTemplates() const
127 void ExternalTemplateManager::readTemplates(string const & path)
136 keyword_item templatetags[] = {
137 { "template", TM_TEMPLATE },
138 { "templateend", TM_END }
141 LyXLex lex(templatetags, TM_END);
142 if (!lex.setFile("external_templates")) {
143 lyxerr << "No template file" << endl;
151 string temp = lex.GetString();
152 ExternalTemplate & tmp = templates[temp];
154 tmp.readTemplate(lex);
159 lyxerr << "TemplateEnd: " << lex.GetString() << endl;
160 lyxerr << "Warning: End outside Template." << endl;
167 void ExternalTemplate::readTemplate(LyXLex & lex)
169 enum TemplateOptionTags {
180 keyword_item templateoptiontags[] = {
181 { "automaticproduction", TO_AUTOMATIC },
182 { "editcommand", TO_EDITCMD },
183 { "filefilter", TO_FILTER },
184 { "format", TO_FORMAT },
185 { "guiname", TO_GUINAME },
186 { "helptext", TO_HELPTEXT },
187 { "templateend", TO_END },
188 { "viewcommand", TO_VIEWCMD }
191 pushpophelper pph(lex, templateoptiontags, TO_END);
197 guiName = lex.GetString();
201 helpText = lex.getLongString("HelpTextEnd");
206 fileRegExp = lex.GetString();
211 viewCommand = lex.GetString();
212 // For security reasons, a command may not be empty!
213 if (viewCommand.empty())
214 viewCommand = "true";
219 editCommand = lex.GetString();
220 // For security reasons, a command may not be empty!
221 if (editCommand.empty())
222 editCommand = "true";
227 automaticProduction = lex.GetBool();
232 formats[lex.GetString()].readFormat(lex);
239 lyxerr << "Default: " << lex.GetString() << endl;
247 void ExternalTemplate::FormatTemplate::readFormat(LyXLex & lex)
257 keyword_item formattags[] = {
258 { "formatend", FO_END },
259 { "preamble", FO_PREAMBLE },
260 { "product", FO_PRODUCT },
261 { "requirement", FO_REQUIREMENT },
262 { "updatecommand", FO_UPDATECMD }
265 pushpophelper pph(lex, formattags, FO_END);
271 product = lex.GetString();
276 updateCommand = lex.GetString();
277 // For security reasons, a command may not be empty!
278 if (updateCommand.empty())
279 updateCommand = "true";
284 requirement = lex.GetString();
288 preamble = lex.getLongString("preambleend");
292 lyxerr << "FormatEnd: " << lex.GetString() << endl;