Richard Heck wrote:

The attached patch moves some things around, so that module info can be made available to tex2lyx. Comments welcome.

I think the only other thing that needs doing is for moduleCanBeAdded to be moved. Maybe some other routines could be moved, too, but they don't need to be, I don't think, for this purpose.

JMarc: ModuleList::load() is what is used to populate the global module list, moduleList. I guess we need some routine that, given a previously unknown layout, will try to find a module that provides it?

This time with the patch.

rh

Index: src/BufferParams.h
===================================================================
--- src/BufferParams.h	(revision 28447)
+++ src/BufferParams.h	(working copy)
@@ -15,8 +15,9 @@
 #ifndef BUFFERPARAMS_H
 #define BUFFERPARAMS_H
 
-#include "Font.h"
 #include "Citation.h"
+#include "Font.h"
+#include "LayoutModuleList.h"
 #include "paper.h"
 
 #include "insets/InsetQuotes.h"
@@ -54,8 +55,6 @@
 class BufferParams {
 public:
 	///
-	typedef std::list<std::string> LayoutModuleList;
-	///
 	enum ParagraphSeparation {
 		///
 		ParagraphIndentSeparation,
Index: src/BufferParams.cpp
===================================================================
--- src/BufferParams.cpp	(revision 28447)
+++ src/BufferParams.cpp	(working copy)
@@ -1708,41 +1708,8 @@
 	if (!baseClass())
 		return;
 
-	doc_class_ = &(DocumentClassBundle::get().newClass(*baseClass()));
+	doc_class_ = &(DocumentClassBundle::get().makeDocumentClass(*baseClass(), layoutModules_));
 
-	// 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");
Index: src/LayoutModuleList.h
===================================================================
--- src/LayoutModuleList.h	(revision 0)
+++ src/LayoutModuleList.h	(revision 0)
@@ -0,0 +1,22 @@
+// -*- C++ -*-
+/**
+ * \file ModuleList.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Richard Heck
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef LAYOUTMODULELIST_H
+#define LAYOUTMODULELIST_H
+
+#include <list>
+#include <string>
+
+namespace lyx {
+///
+typedef std::list<std::string> LayoutModuleList;
+}
+#endif
Index: src/TextClass.h
===================================================================
--- src/TextClass.h	(revision 28447)
+++ src/TextClass.h	(working copy)
@@ -16,6 +16,7 @@
 #include "FontInfo.h"
 #include "Layout.h"
 #include "LayoutEnums.h"
+#include "LayoutModuleList.h"
 
 #include "insets/InsetLayout.h"
 
@@ -429,15 +430,19 @@
 /// DocumentClassBundle::get().
 class DocumentClassBundle : boost::noncopyable {
 public:
-	/// \return Pointer to a new class equal to baseClass
-	DocumentClass & newClass(LayoutFile const & baseClass);
 	/// \return The sole instance of this class.
 	static DocumentClassBundle & get();
+	/// \return A new DocumentClass based on baseClass, with info added
+	/// from the modules in modlist.
+	DocumentClass & makeDocumentClass(LayoutFile const & baseClass, 
+			LayoutModuleList const & modlist);
 private:
 	/// control instantiation
 	DocumentClassBundle() {}
 	/// clean up
 	~DocumentClassBundle();
+	/// \return Reference to a new DocumentClass equal to baseClass
+	DocumentClass & newClass(LayoutFile const & baseClass);
 	///
 	std::vector<DocumentClass *> documentClasses_;
 };
Index: src/TextClass.cpp
===================================================================
--- src/TextClass.cpp	(revision 28447)
+++ src/TextClass.cpp	(working copy)
@@ -24,6 +24,7 @@
 #include "Layout.h"
 #include "Lexer.h"
 #include "Font.h"
+#include "ModuleList.h"
 
 #include "frontends/alert.h"
 
@@ -1105,6 +1106,52 @@
 }
 
 
+DocumentClass & DocumentClassBundle::makeDocumentClass(
+		LayoutFile const & baseClass, LayoutModuleList const & modlist)
+{
+	DocumentClass & doc_class = newClass(baseClass);
+	LayoutModuleList::const_iterator it = modlist.begin();
+	LayoutModuleList::const_iterator en = modlist.end();
+	for (; it != en; it++) {
+		string const modName = *it;
+		LyXModule * lm = moduleList[modName];
+#ifndef TEX2LYX
+		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("DocumentClassBundle::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);
+		}
+#else
+		if (!lm)
+			continue;
+#endif
+		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));
+#ifndef TEX2LYX
+			frontend::Alert::warning(_("Read Error"), msg);
+#endif
+		}
+	}
+	return doc_class;
+}
+
+
 /////////////////////////////////////////////////////////////////////////
 //
 // DocumentClass
Index: src/ModuleList.cpp
===================================================================
--- src/ModuleList.cpp	(revision 28447)
+++ src/ModuleList.cpp	(working copy)
@@ -45,6 +45,9 @@
 
 
 bool LyXModule::isAvailable() {
+#ifdef TEX2LYX
+	return true;
+#else
 	if (packageList.empty())
 		return true;
 	if (checked)
@@ -61,6 +64,7 @@
 	}
 	available = true;
 	return available;
+#endif
 }
 
 
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision 28447)
+++ src/Makefile.am	(working copy)
@@ -219,6 +219,7 @@
 	Layout.h \
 	LayoutEnums.h \
 	LayoutFile.h \
+	LayoutModuleList.h \
 	Length.h \
 	Lexer.h \
 	LyXAction.h \
Index: src/tex2lyx/Makefile.am
===================================================================
--- src/tex2lyx/Makefile.am	(revision 28447)
+++ src/tex2lyx/Makefile.am	(working copy)
@@ -36,6 +36,9 @@
 	../LayoutFile.h \
 	../Layout.h \
 	../Layout.cpp \
+	../LayoutModuleList.h \
+	../ModuleList.h \
+	../ModuleList.cpp \
 	../TextClass.cpp \
 	../TextClass.h \
 	../Lexer.cpp \

Reply via email to