X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FExternalTemplate.cpp;h=6bd02ac47a603b84803a2377c1a95b5744a9bc10;hb=3588f2f69675df8dbf829800b0ed6e4a455c68b4;hp=f3884f91d6acf8d5237420bd91e4b10ad6074f73;hpb=2012beb58e62d04b9c2fc2bc0bc3d60fa095e03e;p=lyx.git diff --git a/src/insets/ExternalTemplate.cpp b/src/insets/ExternalTemplate.cpp index f3884f91d6..6bd02ac47a 100644 --- a/src/insets/ExternalTemplate.cpp +++ b/src/insets/ExternalTemplate.cpp @@ -20,6 +20,7 @@ #include "support/lstrings.h" #include "support/Package.h" #include "support/Path.h" +#include "support/Translator.h" #include @@ -50,7 +51,7 @@ static TransformIDTranslator const & transformIDTranslator() // We have to have dummy default commands for security reasons! Template::Template() - : inputFormat("*") + : inputFormat("*"), automaticProduction(false), preview_mode(PREVIEW_OFF) {} @@ -73,16 +74,16 @@ class DumpPreambleDef { public: typedef TemplateManager::PreambleDefs::value_type value_type; - DumpPreambleDef(ostream & o) : ost(o) {} + DumpPreambleDef(ostream & os) : os_(os) {} void operator()(value_type const & vt) { - ost << "PreambleDef " << vt.first << '\n' + os_ << "PreambleDef " << vt.first << '\n' << vt.second << "PreambleDefEnd" << endl; } private: - ostream & ost; + ostream & os_; }; @@ -90,46 +91,57 @@ class DumpTemplate { public: typedef TemplateManager::Templates::value_type value_type; - DumpTemplate(ostream & o) : ost(o) {} + DumpTemplate(ostream & os) : os_(os) {} void operator()(value_type const & vt) { Template const & et = vt.second; - ost << "Template " << et.lyxName << '\n' + os_ << "Template " << et.lyxName << '\n' << "\tGuiName " << et.guiName << '\n' << "\tHelpText\n" << et.helpText << "\tHelpTextEnd\n" << "\tInputFormat " << et.inputFormat << '\n' << "\tFileFilter " << et.fileRegExp << '\n' - << "\tAutomaticProduction " << et.automaticProduction << '\n'; - + << "\tAutomaticProduction " << et.automaticProduction << '\n' + << "\tPreview "; + switch (et.preview_mode) { + case PREVIEW_OFF: + os_ << "Off\n"; + break; + case PREVIEW_GRAPHICS: + os_ << "Graphics\n"; + break; + case PREVIEW_INSTANT: + os_ << "InstantPreview\n"; + break; + } typedef vector IDs; IDs::const_iterator it = et.transformIds.begin(); IDs::const_iterator end = et.transformIds.end(); for (; it != end; ++it) { - ost << "\tTransform " + os_ << "\tTransform " << transformIDTranslator().find(*it) << '\n'; } - et.dumpFormats(ost); - ost << "TemplateEnd" << endl; + et.dumpFormats(os_); + os_ << "TemplateEnd" << endl; } private: - ostream & ost; + ostream & os_; }; class DumpFormat { public: typedef Template::Formats::value_type value_type; - DumpFormat(ostream & o) : ost(o) {} + DumpFormat(ostream & o) : os_(o) {} void operator()(value_type const & vt) const { Template::Format const & ft = vt.second; - ost << "\tFormat " << vt.first << '\n' + os_ << "\tFormat " << vt.first << '\n' << "\t\tProduct " << ft.product << '\n' << "\t\tUpdateFormat " << ft.updateFormat << '\n' << "\t\tUpdateResult " << ft.updateResult << '\n'; @@ -138,14 +150,14 @@ public: vector::const_iterator qend = ft.requirements.end(); for (; qit != qend; ++qit) { lyxerr << "req:" << *qit << endl; - ost << "\t\tRequirement " << *qit << '\n'; + os_ << "\t\tRequirement " << *qit << '\n'; } typedef vector Options; Options::const_iterator oit = ft.options.begin(); Options::const_iterator oend = ft.options.end(); for (; oit != oend; ++oit) { - ost << "\t\tOption " + os_ << "\t\tOption " << oit->name << ": " << oit->option @@ -155,7 +167,7 @@ public: vector::const_iterator pit = ft.preambleNames.begin(); vector::const_iterator pend = ft.preambleNames.end(); for (; pit != pend; ++pit) { - ost << "\t\tPreamble " << *pit << '\n'; + os_ << "\t\tPreamble " << *pit << '\n'; } typedef Template::Format::FileMap FileMap; @@ -165,15 +177,15 @@ public: vector::const_iterator fit = rit->second.begin(); vector::const_iterator fend = rit->second.end(); for (; fit != fend; ++fit) { - ost << "\t\tReferencedFile " << rit->first + os_ << "\t\tReferencedFile " << rit->first << " \"" << *fit << "\"\n"; } } - ost << "\tFormatEnd\n"; + os_ << "\tFormatEnd\n"; } private: - ostream & ost; + ostream & os_; }; @@ -202,8 +214,7 @@ TemplateManager & TemplateManager::get() } -TemplateManager::Templates const & -TemplateManager::getTemplates() const +TemplateManager::Templates const & TemplateManager::getTemplates() const { return templates; } @@ -236,21 +247,21 @@ void TemplateManager::readTemplates(FileName const & path) { PathChanger p(path); - enum TemplateTags { + enum { TM_PREAMBLEDEF = 1, TM_PREAMBLEDEF_END, TM_TEMPLATE, TM_TEMPLATE_END }; - keyword_item templatetags[] = { + LexerKeyword templatetags[] = { { "preambledef", TM_PREAMBLEDEF }, { "preambledefend", TM_PREAMBLEDEF_END }, { "template", TM_TEMPLATE }, { "templateend", TM_TEMPLATE_END } }; - Lexer lex(templatetags, TM_TEMPLATE_END); + Lexer lex(templatetags); FileName const filename = libFileSearch("", "external_templates"); if (filename.empty() || !lex.setFile(filename)) { @@ -292,49 +303,36 @@ void TemplateManager::readTemplates(FileName const & path) } -namespace { - -void add(vector & ids, string const & name) -{ - TransformID id = transformIDTranslator().find(name); - if (int(id) == -1) { - lyxerr << "external::Template::readTemplate\n" - << "Transform " << name << " is not recognized" - << endl; - } else { - ids.push_back(id); - } -} - -} // namespace anon - - void Template::readTemplate(Lexer & lex) { - enum TemplateOptionTags { + enum { TO_GUINAME = 1, TO_HELPTEXT, TO_INPUTFORMAT, TO_FILTER, TO_AUTOMATIC, + TO_PREVIEW, TO_TRANSFORM, TO_FORMAT, TO_END }; - keyword_item templateoptiontags[] = { + LexerKeyword templateoptiontags[] = { { "automaticproduction", TO_AUTOMATIC }, { "filefilter", TO_FILTER }, { "format", TO_FORMAT }, { "guiname", TO_GUINAME }, { "helptext", TO_HELPTEXT }, { "inputformat", TO_INPUTFORMAT }, + { "preview", TO_PREVIEW }, { "templateend", TO_END }, { "transform", TO_TRANSFORM } }; - PushPopHelper pph(lex, templateoptiontags, TO_END); + PushPopHelper pph(lex, templateoptiontags); + lex.setContext("Template::readTemplate"); + string token; while (lex.isOK()) { switch (lex.lex()) { case TO_GUINAME: @@ -361,11 +359,26 @@ void Template::readTemplate(Lexer & lex) automaticProduction = lex.getBool(); break; - case TO_TRANSFORM: - lex.next(true); - add(transformIds, lex.getString()); + case TO_PREVIEW: + lex >> token; + if (token == "InstantPreview") + preview_mode = PREVIEW_INSTANT; + else if (token == "Graphics") + preview_mode = PREVIEW_GRAPHICS; + else + preview_mode = PREVIEW_OFF; break; + case TO_TRANSFORM: { + lex >> token; + TransformID id = transformIDTranslator().find(token); + if (int(id) == -1) + LYXERR0("Transform " << token << " is not recognized"); + else + transformIds.push_back(id); + break; + } + case TO_FORMAT: lex.next(true); formats[lex.getString()].readFormat(lex); @@ -377,7 +390,7 @@ void Template::readTemplate(Lexer & lex) default: lex.printError("external::Template::readTemplate: " "Wrong tag: $$Token"); - BOOST_ASSERT(false); + LASSERT(false, /**/); break; } } @@ -467,7 +480,7 @@ void setOptionFactory(Template::Format & format, string const & transform, void Template::Format::readFormat(Lexer & lex) { - enum FormatTags { + enum { FO_PRODUCT = 1, FO_UPDATEFORMAT, FO_UPDATERESULT, @@ -480,7 +493,7 @@ void Template::Format::readFormat(Lexer & lex) FO_END }; - keyword_item formattags[] = { + LexerKeyword formattags[] = { { "formatend", FO_END }, { "option", FO_OPTION }, { "preamble", FO_PREAMBLE }, @@ -493,7 +506,7 @@ void Template::Format::readFormat(Lexer & lex) { "updateresult", FO_UPDATERESULT } }; - PushPopHelper pph(lex, formattags, FO_END); + PushPopHelper pph(lex, formattags); while (lex.isOK()) { switch (lex.lex()) { @@ -564,6 +577,3 @@ void Template::Format::readFormat(Lexer & lex) } // namespace external } // namespace lyx - - -