+ && tocdepth == tclass.tocdepth();
+}
+
+
+DocumentClass const & BufferParams::documentClass() const
+{
+ return *doc_class_;
+}
+
+
+DocumentClass const * BufferParams::documentClassPtr() const {
+ return doc_class_;
+}
+
+
+void BufferParams::setDocumentClass(DocumentClass const * const tc) {
+ // evil, but this function is evil
+ doc_class_ = const_cast<DocumentClass *>(tc);
+}
+
+
+bool BufferParams::setBaseClass(string const & classname)
+{
+ LYXERR(Debug::TCLASS, "setBaseClass: " << classname);
+ LayoutFileList & bcl = LayoutFileList::get();
+ if (!bcl.haveClass(classname)) {
+ docstring s =
+ bformat(_("The document class %1$s could not be found. "
+ "A default textclass with default layouts will be used. "
+ "LyX might not be able to produce output unless a correct "
+ "textclass is selected from the document settings dialog."),
+ from_utf8(classname));
+ frontend::Alert::error(_("Document class not found"), s);
+ bcl.addEmptyClass(classname);
+ }
+
+ bool const success = bcl[classname].load();
+ if (!success) {
+ docstring s =
+ bformat(_("The document class %1$s could not be loaded."),
+ from_utf8(classname));
+ frontend::Alert::error(_("Could not load class"), s);
+ return false;
+ }
+
+ pimpl_->baseClass_ = classname;
+
+ // add any required modules not already in use
+ set<string> const & mods = baseClass()->defaultModules();
+ set<string>::const_iterator mit = mods.begin();
+ set<string>::const_iterator men = mods.end();
+ for (; mit != men; mit++) {
+ string const & modName = *mit;
+ // see if we're already in use
+ if (find(layoutModules_.begin(), layoutModules_.end(), modName) !=
+ layoutModules_.end()) {
+ LYXERR(Debug::TCLASS, "Default module `" << modName <<
+ "' not added because already used.");
+ continue;
+ }
+ // make sure the user hasn't removed it
+ if (find(removedModules_.begin(), removedModules_.end(), modName) !=
+ removedModules_.end()) {
+ LYXERR(Debug::TCLASS, "Default module `" << modName <<
+ "' not added because removed by user.");
+ continue;
+ }
+ // Now we want to check the list of selected modules to see if any of them
+ // exclude this one.
+ bool foundit = false;
+ // so iterate over the selected modules...
+ LayoutModuleList::const_iterator lit = layoutModules_.begin();
+ LayoutModuleList::const_iterator len = layoutModules_.end();
+ for (; lit != len; lit++) {
+ LyXModule * lm = moduleList[*lit];
+ if (!lm)
+ continue;
+ vector<string> const & exc = lm->getExcludedModules();
+ // ...and see if this one excludes us.
+ if (find(exc.begin(), exc.end(), modName) != exc.end()) {
+ foundit = true;
+ LYXERR(Debug::TCLASS, "Default module `" << modName <<
+ "' not added because excluded by loaded module `" <<
+ *lit << "'.");
+ break;
+ }
+ }
+ if (!foundit) {
+ LYXERR(Debug::TCLASS, "Default module `" << modName << "' added.");
+ layoutModules_.push_back(modName);
+ }
+ }
+ return true;
+}
+
+
+LayoutFile const * BufferParams::baseClass() const
+{
+ if (LayoutFileList::get().haveClass(pimpl_->baseClass_))
+ return &(LayoutFileList::get()[pimpl_->baseClass_]);
+ else
+ return 0;
+}
+
+
+LayoutFileIndex const & BufferParams::baseClassID() const
+{
+ return pimpl_->baseClass_;
+}
+
+
+void BufferParams::makeDocumentClass()
+{
+ 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
+ // doing a check in InsetInclude.
+ LayoutModuleList::const_iterator it = layoutModules_.begin();
+ for (; it != layoutModules_.end(); it++) {
+ string const modName = *it;
+ LyXModule * lm = moduleList[modName];
+ if (!lm) {
+ docstring const msg =
+ bformat(_("The module %1$s has been requested by\n"
+ "this document but has not been found in the list of\n"
+ "available modules. If you recently installed it, you\n"
+ "probably need to reconfigure LyX.\n"), from_utf8(modName));
+ frontend::Alert::warning(_("Module not available"),
+ msg + _("Some layouts may not be available."));
+ LYXERR0("BufferParams::makeDocumentClass(): Module " <<
+ modName << " requested but not found in module list.");
+ continue;
+ }
+ if (!lm->isAvailable()) {
+ docstring const msg =
+ bformat(_("The module %1$s requires a package that is\n"
+ "not available in your LaTeX installation. LaTeX output\n"
+ "may not be possible.\n"), from_utf8(modName));
+ frontend::Alert::warning(_("Package not available"), msg);
+ }
+ FileName layout_file = libFileSearch("layouts", lm->getFilename());
+ 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);
+ }
+ }
+ if (!local_layout.empty()) {
+ if (!doc_class_->read(local_layout, TextClass::MODULE)) {
+ docstring const msg = _("Error reading internal layout information");
+ frontend::Alert::warning(_("Read Error"), msg);
+ }
+ }