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"
27 extern string user_lyxdir;
30 // We have to have dummy default commands for security reasons!
32 ExternalTemplate::ExternalTemplate()
33 : viewCommand("true"), editCommand("true")
36 ExternalTemplate::FormatTemplate::FormatTemplate()
37 : updateCommand("true") {}
40 ExternalTemplateManager::ExternalTemplateManager()
42 // gimp gnuchess gnuplot ical netscape tetris xpaint
43 readTemplates(user_lyxdir);
50 dumpTemplate(std::ostream & o)
52 void operator()(ExternalTemplateManager::Templates::value_type const & vt) {
53 ExternalTemplate const & et = vt.second;
55 ost << "Template " << et.lyxName << "\n"
56 << "\tGuiName " << et.guiName << "\n"
60 << "\tFileFilter " << et.fileRegExp << "\n"
61 << "\tViewCommand " << et.viewCommand << "\n"
62 << "\tEditCommand " << et.editCommand << "\n"
63 << "\tAutomaticProduction " << et.automaticProduction << "\n";
65 ost << "TemplateEnd" << endl;
75 dumpFormat(ostream & o)
77 void operator()(ExternalTemplate::Formats::value_type const & vt) const{
78 ExternalTemplate::FormatTemplate const & ft = vt.second;
79 ost << "\tFormat " << vt.first << "\n"
80 << "\t\tProduct " << ft.product << "\n"
81 << "\t\tUpdateCommand " << ft.updateCommand << "\n"
82 << "\t\tRequirement " << ft.requirement << "\n"
85 << "\t\tPreambleEnd\n"
93 void ExternalTemplate::dumpFormats(ostream & os) const
95 for_each(formats.begin(), formats.end(), dumpFormat(os));
98 void ExternalTemplateManager::dumpTemplates() const
100 for_each(templates.begin(), templates.end(), dumpTemplate(lyxerr));
104 ExternalTemplateManager & ExternalTemplateManager::get()
106 static ExternalTemplateManager externalTemplateManager;
107 return externalTemplateManager;
111 ExternalTemplateManager::Templates &
112 ExternalTemplateManager::getTemplates()
118 ExternalTemplateManager::Templates const &
119 ExternalTemplateManager::getTemplates() const
125 void ExternalTemplateManager::readTemplates(string const & path)
134 keyword_item templatetags[] = {
135 { "template", TM_TEMPLATE },
136 { "templateend", TM_END }
139 LyXLex lex(templatetags, TM_END);
140 if (!lex.setFile("external_templates")) {
141 lyxerr << "No template file" << endl;
149 string temp = lex.GetString();
150 ExternalTemplate & tmp = templates[temp];
152 tmp.readTemplate(lex);
157 lyxerr << "TemplateEnd: " << lex.GetString() << endl;
158 lyxerr << "Warning: End outside Template." << endl;
165 void ExternalTemplate::readTemplate(LyXLex & lex)
167 enum TemplateOptionTags {
178 keyword_item templateoptiontags[] = {
179 { "automaticproduction", TO_AUTOMATIC },
180 { "editcommand", TO_EDITCMD },
181 { "filefilter", TO_FILTER },
182 { "format", TO_FORMAT },
183 { "guiname", TO_GUINAME },
184 { "helptext", TO_HELPTEXT },
185 { "templateend", TO_END },
186 { "viewcommand", TO_VIEWCMD }
189 pushpophelper pph(lex, templateoptiontags, TO_END);
195 guiName = lex.GetString();
199 helpText = lex.getLongString("HelpTextEnd");
204 fileRegExp = lex.GetString();
209 viewCommand = lex.GetString();
210 // For security reasons, a command may not be empty!
211 if (viewCommand.empty())
212 viewCommand = "true";
217 editCommand = lex.GetString();
218 // For security reasons, a command may not be empty!
219 if (editCommand.empty())
220 editCommand = "true";
225 automaticProduction = lex.GetBool();
230 formats[lex.GetString()].readFormat(lex);
237 lyxerr << "Default: " << lex.GetString() << endl;
245 void ExternalTemplate::FormatTemplate::readFormat(LyXLex & lex)
255 keyword_item formattags[] = {
256 { "formatend", FO_END },
257 { "preamble", FO_PREAMBLE },
258 { "product", FO_PRODUCT },
259 { "requirement", FO_REQUIREMENT },
260 { "updatecommand", FO_UPDATECMD }
263 pushpophelper pph(lex, formattags, FO_END);
269 product = lex.GetString();
274 updateCommand = lex.GetString();
275 // For security reasons, a command may not be empty!
276 if (updateCommand.empty())
277 updateCommand = "true";
282 requirement = lex.GetString();
286 preamble = lex.getLongString("preambleend");
290 lyxerr << "FormatEnd: " << lex.GetString() << endl;