X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FExternalTemplate.cpp;h=ae9148b4e859a4fe8aba5e3e4ca0188f059ea995;hb=639aa354448188f45e69d6bd1e0ef3dfcc938c5f;hp=64f31343a67d13817daa093e40e5b6dfbd5c2d5c;hpb=1f945177b9628b213c60872df88f2d155c3d6c54;p=lyx.git diff --git a/src/insets/ExternalTemplate.cpp b/src/insets/ExternalTemplate.cpp index 64f31343a6..ae9148b4e8 100644 --- a/src/insets/ExternalTemplate.cpp +++ b/src/insets/ExternalTemplate.cpp @@ -260,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 << '\''); + + if (real_file.empty()) { + LYXERR0("unable to find external templates file `xtemplates.lst'.\n" + << "No external templates will be available."); + return; + } - FileName const filename = libFileSearch("", "external_templates"); - if (filename.empty() || !lex.setFile(filename)) { - lex.printError("external::TemplateManager::readTemplates: " - "No template file"); + Lexer tlex; + if (!tlex.setFile(real_file)) { + LYXERR0("lyxlex was not able to set file: " + << real_file << ".\nNo external templates will be available."); return; } - char const * const preamble_end_tag = - templatetags[TM_PREAMBLEDEF_END-1].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; + } - 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)); + 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; + } } } } @@ -468,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)