X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FLayoutFile.cpp;h=88a4cf63f57a26e56807702fced1997823b38fb4;hb=d61f81f188cba8a592879d9df9e775806787fea1;hp=8b4bba35532f5ad543bf4657cda73c689237e185;hpb=f854295dabdbef460da4f839eb82d4c0cad0fbb9;p=lyx.git diff --git a/src/LayoutFile.cpp b/src/LayoutFile.cpp index 8b4bba3553..88a4cf63f5 100644 --- a/src/LayoutFile.cpp +++ b/src/LayoutFile.cpp @@ -3,7 +3,7 @@ * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * - * \author Lars Gullik Bjønnes + * \author Lars Gullik Bjønnes * \author John Levon * * Full author contact details are available in file CREDITS. @@ -18,11 +18,14 @@ #include "Lexer.h" #include "TextClass.h" -#include "support/lassert.h" +#include "frontends/alert.h" + #include "support/debug.h" #include "support/FileName.h" #include "support/filetools.h" #include "support/gettext.h" +#include "support/lassert.h" +#include "support/lstrings.h" #include #include @@ -82,8 +85,7 @@ LayoutFile const & LayoutFileList::operator[](string const & classname) const } -LayoutFile & - LayoutFileList::operator[](string const & classname) +LayoutFile & LayoutFileList::operator[](string const & classname) { LASSERT(haveClass(classname), /**/); return *classmap_[classname]; @@ -137,27 +139,27 @@ bool LayoutFileList::read() default: string const fname = lex.getString(); LYXERR(Debug::TCLASS, "Fname: " << fname); - if (lex.next()) { - string const clname = lex.getString(); - LYXERR(Debug::TCLASS, "Clname: " << clname); - if (lex.next()) { - string const desc = lex.getString(); - LYXERR(Debug::TCLASS, "Desc: " << desc); - if (lex.next()) { - bool avail = lex.getBool(); - LYXERR(Debug::TCLASS, "Avail: " << avail); - // This code is run when we have - // fname, clname, desc, and avail - LayoutFile * tmpl = new LayoutFile(fname, clname, desc, avail); - if (lyxerr.debugging(Debug::TCLASS)) { - // only system layout files are loaded here so no - // buffer path is needed. - tmpl->load(); - } - classmap_[fname] = tmpl; - } - } + if (!lex.next()) + break; + string const clname = lex.getString(); + LYXERR(Debug::TCLASS, "Clname: " << clname); + if (!lex.next()) + break; + string const desc = lex.getString(); + LYXERR(Debug::TCLASS, "Desc: " << desc); + if (!lex.next()) + break; + bool avail = lex.getBool(); + LYXERR(Debug::TCLASS, "Avail: " << avail); + // This code is run when we have + // fname, clname, desc, and avail + LayoutFile * tmpl = new LayoutFile(fname, clname, desc, avail); + if (lyxerr.debugging(Debug::TCLASS)) { + // only system layout files are loaded here so no + // buffer path is needed. + tmpl->load(); } + classmap_[fname] = tmpl; } } LYXERR(Debug::TCLASS, "End of parsing of textclass.lst"); @@ -227,10 +229,11 @@ LayoutFileIndex LayoutFileList::addEmptyClass(string const & textclass) // the last parameter to true will suppress a warning message about missing // tex class. LayoutFile * tc = new LayoutFile(textclass, textclass, "Unknown text class " + textclass, true); - if (!tc->load(tempLayout.absFilename())) + if (!tc->load(tempLayout.absFilename())) { // The only way this happens is because the hardcoded layout file above // is wrong. LASSERT(false, /**/); + } classmap_[textclass] = tc; return textclass; } @@ -275,7 +278,7 @@ LayoutFileIndex // There will be only one textclass with this name, even if different // layout files are loaded from different directories. if (haveClass(textclass)) { - LYXERR0("Exisint textclass " << textclass << " is redefined by " << fullName); + LYXERR0("Existing textclass " << textclass << " is redefined by " << fullName); delete classmap_[textclass]; } classmap_[textclass] = tmpl; @@ -288,6 +291,24 @@ LayoutFileIndex } +bool LayoutFileList::load(string const & name, string const & buf_path) +{ + if (!haveClass(name)) { + LYXERR0("Document class \"" << name << "\" does not exist."); + return false; + } + + LayoutFile * tc = classmap_[name]; + if (!tc->load(buf_path)) { + docstring s = bformat(_("The document class %1$s " + "could not be loaded."), from_utf8(name)); + frontend::Alert::error(_("Could not load class"), s); + return false; + } + return true; +} + + LayoutFileIndex defaultBaseclass() { if (LayoutFileList::get().haveClass("article"))