X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FExternalTemplate.cpp;h=ae9148b4e859a4fe8aba5e3e4ca0188f059ea995;hb=e5c79a43ee78192f45a9ab34873f8bb426b5f37e;hp=db12e68b8cb56c1ed97c283706cc2bc76cfad264;hpb=1b1f8dd235ba8e168348cd23c824063f2595a0c5;p=lyx.git diff --git a/src/insets/ExternalTemplate.cpp b/src/insets/ExternalTemplate.cpp index db12e68b8c..ae9148b4e8 100644 --- a/src/insets/ExternalTemplate.cpp +++ b/src/insets/ExternalTemplate.cpp @@ -78,7 +78,7 @@ public: void operator()(value_type const & vt) { os_ << "PreambleDef " << vt.first << '\n' - << vt.second + << to_utf8(vt.second) << "PreambleDefEnd" << endl; } @@ -99,7 +99,7 @@ public: os_ << "Template " << et.lyxName << '\n' << "\tGuiName " << et.guiName << '\n' << "\tHelpText\n" - << et.helpText + << to_utf8(et.helpText) << "\tHelpTextEnd\n" << "\tInputFormat " << et.inputFormat << '\n' << "\tFileFilter " << et.fileRegExp << '\n' @@ -228,16 +228,15 @@ TemplateManager::getTemplateByName(string const & name) const } -string const -TemplateManager::getPreambleDefByName(string const & name) const +docstring TemplateManager::getPreambleDefByName(string const & name) const { string const trimmed_name = trim(name); if (trimmed_name.empty()) - return string(); + return docstring(); PreambleDefs::const_iterator it = preambledefs.find(trimmed_name); if (it == preambledefs.end()) - return string(); + return docstring(); return it->second; } @@ -261,43 +260,91 @@ void TemplateManager::readTemplates(FileName const & path) { "templateend", TM_TEMPLATE_END } }; - Lexer lex(templatetags); + // Read the templates list + vector templateslist; + FileName const real_file = libFileSearch("", "xtemplates.lst"); + LYXERR(Debug::EXTERNAL, "Reading external templates from `" << real_file << '\''); - FileName const filename = libFileSearch("", "external_templates"); - if (filename.empty() || !lex.setFile(filename)) { - lex.printError("external::TemplateManager::readTemplates: " - "No template file"); + if (real_file.empty()) { + LYXERR0("unable to find external templates file `xtemplates.lst'.\n" + << "No external templates will be available."); return; } - char const * const preamble_end_tag = - templatetags[TM_PREAMBLEDEF_END-1].tag; + Lexer tlex; + if (!tlex.setFile(real_file)) { + LYXERR0("lyxlex was not able to set file: " + << real_file << ".\nNo external templates will be available."); + return; + } - while (lex.isOK()) { - switch (lex.lex()) { - case TM_PREAMBLEDEF: { - lex.next(); - string const name = lex.getString(); - preambledefs[name] = lex.getLongString(preamble_end_tag); + if (!tlex.isOK()) { + LYXERR0("unable to open external templates file `" + << to_utf8(makeDisplayPath(real_file.absFileName(), 1000)) + << "'\nNo external templates will be available."); + return; + } + + bool finished = false; + // Parse external templates files + LYXERR(Debug::EXTERNAL, "Starting parsing of xtemplates.lst"); + while (tlex.isOK() && !finished) { + LYXERR(Debug::EXTERNAL, "\tline by line"); + switch (tlex.lex()) { + case Lexer::LEX_FEOF: + finished = true; + break; + default: + string const name = tlex.getString(); + LYXERR(Debug::EXTERNAL, "Template name: " << name); + templateslist.push_back(name); + break; } - break; + } - case TM_TEMPLATE: { - lex.next(); - string const name = lex.getString(); - Template & tmp = templates[name]; - tmp.lyxName = name; - tmp.readTemplate(lex); + LYXERR(Debug::EXTERNAL, "End of parsing of xtemplates.lst"); + + for (vector::const_iterator it = templateslist.begin(); it != templateslist.end(); ++it) { + FileName const filename = libFileSearch("xtemplates", *it); + LYXERR(Debug::EXTERNAL, "Reading template file " << filename.absFileName()); + Lexer lex(templatetags); + if (filename.empty() || !lex.setFile(filename)) { + lex.printError("external::TemplateManager::readTemplates: " + "No template file"); + return; } - break; - case TM_TEMPLATE_END: - lex.printError("Warning: End outside Template."); - break; + char const * const preamble_end_tag = + templatetags[TM_PREAMBLEDEF_END-1].tag; - case TM_PREAMBLEDEF_END: - lex.printError("Warning: End outside PreambleDef."); - break; + while (lex.isOK()) { + switch (lex.lex()) { + case TM_PREAMBLEDEF: { + lex.next(); + string const name = lex.getString(); + preambledefs[name] = lex.getLongString(from_ascii(preamble_end_tag)); + break; + } + + case TM_TEMPLATE: { + lex.next(); + string const name = lex.getString(); + Template & tmp = templates[name]; + tmp.lyxName = name; + tmp.readTemplate(lex); + break; + } + + case TM_TEMPLATE_END: + lex.printError("Warning: End outside Template."); + break; + + case TM_PREAMBLEDEF_END: + lex.printError("Warning: End outside PreambleDef."); + break; + default: + break; + } } } } @@ -341,7 +388,7 @@ void Template::readTemplate(Lexer & lex) break; case TO_HELPTEXT: - helpText = lex.getLongString("HelpTextEnd"); + helpText = lex.getLongString(from_ascii("HelpTextEnd")); break; case TO_INPUTFORMAT: @@ -469,7 +516,7 @@ void setOptionFactory(Template::Format & format, string const & transform, transform_class_not_found(lyxerr, transformer_class); } -} // namespace anon +} // namespace void Template::Format::readFormat(Lexer & lex)