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"
28 extern string user_lyxdir;
31 // We have to have dummy default commands for security reasons!
33 ExternalTemplate::ExternalTemplate()
34 : viewCommand("true"), editCommand("true")
37 ExternalTemplate::FormatTemplate::FormatTemplate()
38 : updateCommand("true") {}
41 ExternalTemplateManager::ExternalTemplateManager()
43 // gimp gnuchess gnuplot ical netscape tetris xpaint
44 readTemplates(user_lyxdir);
51 dumpTemplate(std::ostream & o)
53 void operator()(ExternalTemplateManager::Templates::value_type const & vt) {
54 ExternalTemplate const & et = vt.second;
56 ost << "Template " << et.lyxName << "\n"
57 << "\tGuiName " << et.guiName << "\n"
61 << "\tFileFilter " << et.fileRegExp << "\n"
62 << "\tViewCommand " << et.viewCommand << "\n"
63 << "\tEditCommand " << et.editCommand << "\n"
64 << "\tAutomaticProduction " << et.automaticProduction << "\n";
66 ost << "TemplateEnd" << endl;
76 dumpFormat(ostream & o)
78 void operator()(ExternalTemplate::Formats::value_type const & vt) const{
79 ExternalTemplate::FormatTemplate const & ft = vt.second;
80 ost << "\tFormat " << vt.first << "\n"
81 << "\t\tProduct " << ft.product << "\n"
82 << "\t\tUpdateCommand " << ft.updateCommand << "\n"
83 << "\t\tRequirement " << ft.requirement << "\n"
86 << "\t\tPreambleEnd\n"
94 void ExternalTemplate::dumpFormats(ostream & os) const
96 for_each(formats.begin(), formats.end(), dumpFormat(os));
99 void ExternalTemplateManager::dumpTemplates() const
101 for_each(templates.begin(), templates.end(), dumpTemplate(lyxerr));
105 ExternalTemplateManager & ExternalTemplateManager::get()
107 static ExternalTemplateManager externalTemplateManager;
108 return externalTemplateManager;
112 ExternalTemplateManager::Templates &
113 ExternalTemplateManager::getTemplates()
119 ExternalTemplateManager::Templates const &
120 ExternalTemplateManager::getTemplates() const
126 void ExternalTemplateManager::readTemplates(string const & path)
135 keyword_item templatetags[] = {
136 { "template", TM_TEMPLATE },
137 { "templateend", TM_END }
140 LyXLex lex(templatetags, TM_END);
141 if (!lex.setFile("external_templates")) {
142 lyxerr << "No template file" << endl;
150 string temp = lex.GetString();
151 ExternalTemplate & tmp = templates[temp];
153 tmp.readTemplate(lex);
158 lyxerr << "TemplateEnd: " << lex.GetString() << endl;
159 lyxerr << "Warning: End outside Template." << endl;
166 void ExternalTemplate::readTemplate(LyXLex & lex)
168 enum TemplateOptionTags {
179 keyword_item templateoptiontags[] = {
180 { "automaticproduction", TO_AUTOMATIC },
181 { "editcommand", TO_EDITCMD },
182 { "filefilter", TO_FILTER },
183 { "format", TO_FORMAT },
184 { "guiname", TO_GUINAME },
185 { "helptext", TO_HELPTEXT },
186 { "templateend", TO_END },
187 { "viewcommand", TO_VIEWCMD }
190 pushpophelper pph(lex, templateoptiontags, TO_END);
196 guiName = lex.GetString();
200 helpText = lex.getLongString("HelpTextEnd");
205 fileRegExp = lex.GetString();
210 viewCommand = lex.GetString();
211 // For security reasons, a command may not be empty!
212 if (viewCommand.empty())
213 viewCommand = "true";
218 editCommand = lex.GetString();
219 // For security reasons, a command may not be empty!
220 if (editCommand.empty())
221 editCommand = "true";
226 automaticProduction = lex.GetBool();
231 formats[lex.GetString()].readFormat(lex);
238 lyxerr << "Default: " << lex.GetString() << endl;
246 void ExternalTemplate::FormatTemplate::readFormat(LyXLex & lex)
256 keyword_item formattags[] = {
257 { "formatend", FO_END },
258 { "preamble", FO_PREAMBLE },
259 { "product", FO_PRODUCT },
260 { "requirement", FO_REQUIREMENT },
261 { "updatecommand", FO_UPDATECMD }
264 pushpophelper pph(lex, formattags, FO_END);
270 product = lex.GetString();
275 updateCommand = lex.GetString();
276 // For security reasons, a command may not be empty!
277 if (updateCommand.empty())
278 updateCommand = "true";
283 requirement = lex.GetString();
287 preamble = lex.getLongString("preambleend");
291 lyxerr << "FormatEnd: " << lex.GetString() << endl;