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 string filename = LibFileSearch("", "external_templates");
142 if (filename.empty()) {
143 lyxerr << "No template file" << endl;
147 LyXLex lex(templatetags, TM_END);
148 if (!lex.setFile(filename)) {
149 lyxerr << "No template file" << endl;
157 string temp = lex.GetString();
158 ExternalTemplate & tmp = templates[temp];
160 tmp.readTemplate(lex);
165 lyxerr << "TemplateEnd: " << lex.GetString() << endl;
166 lyxerr << "Warning: End outside Template." << endl;
173 void ExternalTemplate::readTemplate(LyXLex & lex)
175 enum TemplateOptionTags {
186 keyword_item templateoptiontags[] = {
187 { "automaticproduction", TO_AUTOMATIC },
188 { "editcommand", TO_EDITCMD },
189 { "filefilter", TO_FILTER },
190 { "format", TO_FORMAT },
191 { "guiname", TO_GUINAME },
192 { "helptext", TO_HELPTEXT },
193 { "templateend", TO_END },
194 { "viewcommand", TO_VIEWCMD }
197 pushpophelper pph(lex, templateoptiontags, TO_END);
203 guiName = lex.GetString();
207 helpText = lex.getLongString("HelpTextEnd");
212 fileRegExp = lex.GetString();
217 viewCommand = lex.GetString();
218 // For security reasons, a command may not be empty!
219 if (viewCommand.empty())
220 viewCommand = "true";
225 editCommand = lex.GetString();
226 // For security reasons, a command may not be empty!
227 if (editCommand.empty())
228 editCommand = "true";
233 automaticProduction = lex.GetBool();
238 formats[lex.GetString()].readFormat(lex);
245 lyxerr << "Default: " << lex.GetString() << endl;
253 void ExternalTemplate::FormatTemplate::readFormat(LyXLex & lex)
263 keyword_item formattags[] = {
264 { "formatend", FO_END },
265 { "preamble", FO_PREAMBLE },
266 { "product", FO_PRODUCT },
267 { "requirement", FO_REQUIREMENT },
268 { "updatecommand", FO_UPDATECMD }
271 pushpophelper pph(lex, formattags, FO_END);
277 product = lex.GetString();
282 updateCommand = lex.GetString();
283 // For security reasons, a command may not be empty!
284 if (updateCommand.empty())
285 updateCommand = "true";
290 requirement = lex.GetString();
294 preamble = lex.getLongString("preambleend");
298 lyxerr << "FormatEnd: " << lex.GetString() << endl;