#include "BufferParams.h"
#include "Author.h"
+#include "BaseClassList.h"
#include "BranchList.h"
#include "buffer_funcs.h"
#include "Bullet.h"
#include "Font.h"
#include "Lexer.h"
#include "LyXRC.h"
-#include "TextClassList.h"
#include "OutputParams.h"
#include "Spacing.h"
#include "TexRow.h"
*/
VSpace defskip;
PDFOptions pdfoptions;
-
- /// the base TextClass associated with the document
- TextClassIndex baseClass_;
- /// the possibly modular TextClass actually in use
- TextClassIndex textClass_;
+ LayoutFileIndex baseClass_;
};
BufferParams::Impl::Impl()
- : defskip(VSpace::MEDSKIP), baseClass_(0), textClass_(0)
+ : defskip(VSpace::MEDSKIP), baseClass_(string(""))
{
// set initial author
// FIXME UNICODE
BufferParams::BufferParams()
: pimpl_(new Impl)
{
- setBaseClass(defaultTextclass());
- makeTextClass();
+ setBaseClass(defaultBaseclass());
+ makeDocumentClass();
paragraph_separation = PARSEP_INDENT;
quotes_language = InsetQuotes::EnglishQ;
fontsize = "default";
string const classname = lex.getString();
// if there exists a local layout file, ignore the system one
// NOTE: in this case, the textclass (.cls file) is assumed to be available.
- pair<bool, TextClassIndex> pp =
- make_pair(false, TextClassIndex(0));
+ string tcp;
+ BaseClassList & bcl = BaseClassList::get();
if (!filepath.empty())
- pp = textclasslist.addTextClass(
- classname, filepath.absFilename());
- if (pp.first)
- setBaseClass(pp.second);
- else {
- pp = textclasslist.numberOfClass(classname);
- if (pp.first)
- setBaseClass(pp.second);
- else {
- // a warning will be given for unknown class
- setBaseClass(defaultTextclass());
- return classname;
- }
+ tcp = bcl.addLayoutFile(classname, filepath.absFilename());
+ if (!tcp.empty())
+ setBaseClass(tcp);
+ else if (bcl.haveClass(classname)) {
+ setBaseClass(classname);
+ } else {
+ // a warning will be given for unknown class
+ setBaseClass(defaultBaseclass());
+ return classname;
}
// FIXME: this warning will be given even if there exists a local .cls
// file. Even worse, the .lyx file can not be compiled or exported
// because the textclass is marked as unavilable.
- if (!textClass().isTeXClassAvailable()) {
+ if (!baseClass()->isTeXClassAvailable()) {
docstring const msg =
bformat(_("The layout file requested by this document,\n"
"%1$s.layout,\n"
// Prints out the buffer info into the .lyx file given by file
// the textclass
- os << "\\textclass " << textClass().name() << '\n';
+ os << "\\textclass " << baseClass()->name() << '\n';
// then the preamble
if (!preamble.empty()) {
void BufferParams::validate(LaTeXFeatures & features) const
{
- features.require(textClass().requires());
+ features.require(documentClass().requires());
if (outputChanges) {
bool dvipost = LaTeXFeatures::isAvailable("dvipost");
features.require("float");
// AMS Style is at document level
- if (use_amsmath == package_on || textClass().provides("amsmath"))
+ if (use_amsmath == package_on
+ || documentClass().provides("amsmath"))
features.require("amsmath");
if (use_esint == package_on)
features.require("esint");
{
os << "\\documentclass";
- TextClass const & tclass = textClass();
+ DocumentClass const & tclass = documentClass();
+
ostringstream clsoptions; // the document class options.
if (tokenPos(tclass.opt_fontsize(),
// hyperref, see
// http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html
if (language->lang() == "japanese-plain" &&
- !textClass().provides("japanese")) {
+ !documentClass().provides("japanese")) {
//load babel in case it was not loaded due to an empty language list
if (language_options.str().empty())
lyxpreamble += "\\usepackage{babel}\n";
// use hyperref explicitely when it is required
if (features.isRequired("hyperref")) {
odocstringstream oss;
- pdfoptions().writeLaTeX(oss, textClass().provides("hyperref"));
+ pdfoptions().writeLaTeX(oss, documentClass().provides("hyperref"));
lyxpreamble += oss.str();
}
void BufferParams::useClassDefaults()
{
- TextClass const & tclass = textclasslist[pimpl_->baseClass_];
+ DocumentClass const & tclass = documentClass();
sides = tclass.sides();
columns = tclass.columns();
bool BufferParams::hasClassDefaults() const
{
- TextClass const & tclass = textclasslist[pimpl_->baseClass_];
+ DocumentClass const & tclass = documentClass();
return sides == tclass.sides()
&& columns == tclass.columns()
}
-TextClass const & BufferParams::textClass() const
+DocumentClass const & BufferParams::documentClass() const
{
- return textclasslist[pimpl_->textClass_];
+ return *doc_class_;
}
-TextClassIndex BufferParams::textClassIndex() const
-{
- return pimpl_->textClass_;
+DocumentClass * BufferParams::documentClassPtr() const {
+ return doc_class_;
}
-void BufferParams::setTextClass(TextClassIndex const & tc)
-{
- pimpl_->textClass_ = tc;
+void BufferParams::setDocumentClass(DocumentClass const * const tc) {
+ // evil, but this function is evil
+ doc_class_ = const_cast<DocumentClass *>(tc);
}
-bool BufferParams::setBaseClass(TextClassIndex const & tc)
+bool BufferParams::setBaseClass(string const & classname)
{
- if (textclasslist[tc].load()) {
- pimpl_->baseClass_ = tc;
+ LYXERR(Debug::TCLASS, "setBaseClass: " << classname);
+ BaseClassList const & bcl = BaseClassList::get();
+ if (!bcl.haveClass(classname)) {
+ docstring s =
+ bformat(_("The document class %1$s could not be found."),
+ from_utf8(classname));
+ frontend::Alert::error(_("Class not found"), s);
+ return false;
+ }
+
+ if (bcl[classname].load()) {
+ pimpl_->baseClass_ = classname;
return true;
}
docstring s =
bformat(_("The document class %1$s could not be loaded."),
- from_utf8(textclasslist[tc].name()));
+ from_utf8(classname));
frontend::Alert::error(_("Could not load class"), s);
return false;
}
-TextClassIndex BufferParams::baseClass() const
+LayoutFile const * BufferParams::baseClass() const
+{
+ if (BaseClassList::get().haveClass(pimpl_->baseClass_))
+ return &(BaseClassList::get()[pimpl_->baseClass_]);
+ else
+ return 0;
+}
+
+
+LayoutFileIndex const & BufferParams::baseClassID() const
{
return pimpl_->baseClass_;
}
-void BufferParams::makeTextClass()
+void BufferParams::makeDocumentClass()
{
- pimpl_->textClass_ = baseClass();
+ if (!baseClass())
+ return;
+
+ doc_class_ = &(DocumentClassBundle::get().newClass(*baseClass()));
//FIXME It might be worth loading the children's modules here,
//just as we load their bibliographies and such, instead of just
"probably need to reconfigure LyX.\n"), from_utf8(modName));
frontend::Alert::warning(_("Module not available"),
msg + _("Some layouts may not be available."));
- lyxerr << "BufferParams::makeTextClass(): Module " <<
+ lyxerr << "BufferParams::makeDocumentClass(): Module " <<
modName << " requested but not found in module list." <<
endl;
continue;
frontend::Alert::warning(_("Package not available"), msg);
}
FileName layout_file = libFileSearch("layouts", lm->getFilename());
- if (!textclasslist.at(pimpl_->textClass_).read(layout_file, TextClass::MODULE)) {
+ if (!doc_class_->read(layout_file, TextClass::MODULE)) {
docstring const msg =
bformat(_("Error reading module %1$s\n"), from_utf8(modName));
frontend::Alert::warning(_("Read Error"), msg);
}
-vector<string> const & BufferParams::getModules() const
+vector<string> const & BufferParams::getModules() const
{
return layoutModules_;
}
-bool BufferParams::addLayoutModule(string const & modName)
+bool BufferParams::addLayoutModule(string const & modName)
{
LayoutModuleList::const_iterator it = layoutModules_.begin();
LayoutModuleList::const_iterator end = layoutModules_.end();
}
-void BufferParams::clearLayoutModules()
+void BufferParams::clearLayoutModules()
{
layoutModules_.clear();
}
Font const BufferParams::getFont() const
{
- FontInfo f = textClass().defaultfont();
+ FontInfo f = documentClass().defaultfont();
if (fontsDefaultFamily == "rmdefault")
f.setFamily(ROMAN_FAMILY);
else if (fontsDefaultFamily == "sfdefault")
void BufferParams::readGraphicsDriver(Lexer & lex)
{
- if (!lex.next())
+ if (!lex.next())
return;
string const tmptok = lex.getString();
void BufferParams::readBullets(Lexer & lex)
{
- if (!lex.next())
+ if (!lex.next())
return;
int const index = lex.getInteger();
void BufferParams::readBulletsLaTeX(Lexer & lex)
{
// The bullet class should be able to read this.
- if (!lex.next())
+ if (!lex.next())
return;
int const index = lex.getInteger();
lex.next(true);
{
// FIXME the class should provide the numerical/
// authoryear choice
- if (textClass().provides("natbib")
+ if (documentClass().provides("natbib")
&& cite_engine_ != biblio::ENGINE_NATBIB_NUMERICAL)
return biblio::ENGINE_NATBIB_AUTHORYEAR;
return cite_engine_;