From 56a35c2c61401f1855e91c11142a5389bfc5572c Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Fri, 25 Jul 2008 15:51:27 +0000 Subject: [PATCH] Add UseModule tag for layout files. This allows the AMS files, in particular, to "require" the theorems-ams module, which is what most users will want. A later commit will allow users also to "exclude" this module, in case they wanted to do that. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25880 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/layouts/amsart.layout | 1 + lib/layouts/amsbook.layout | 1 + lib/scripts/layout2layout.py | 5 ++++- src/BufferParams.cpp | 41 +++++++++++++++++++++++++++++++++--- src/LayoutFile.h | 4 ++++ src/TextClass.cpp | 15 ++++++++++--- src/TextClass.h | 2 ++ 7 files changed, 62 insertions(+), 7 deletions(-) diff --git a/lib/layouts/amsart.layout b/lib/layouts/amsart.layout index f25010695f..38bf20e903 100644 --- a/lib/layouts/amsart.layout +++ b/lib/layouts/amsart.layout @@ -19,6 +19,7 @@ ClassOptions FontSize 8|9|10|11|12 End +UseModule theorems-ams Style Standard Category MainText diff --git a/lib/layouts/amsbook.layout b/lib/layouts/amsbook.layout index 80f39ef083..bbc63708a5 100644 --- a/lib/layouts/amsbook.layout +++ b/lib/layouts/amsbook.layout @@ -20,6 +20,7 @@ ClassOptions FontSize 8|9|10|11|12 End +UseModule theorems-ams Style Standard Category MainText diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py index e628a300fd..01222291c9 100644 --- a/lib/scripts/layout2layout.py +++ b/lib/scripts/layout2layout.py @@ -25,7 +25,10 @@ import os, re, string, sys # Incremented to format 7, 24 March 2008 by rgh # AddToPreamble tag added to layout files -currentFormat = 7 + +# Incremented to format 8, 25 July 2008 by rgh +# UseModule tag added to layout files +currentFormat = 8 def usage(prog_name): diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 9c6a0e2926..bc818c39dd 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -1462,10 +1462,45 @@ void BufferParams::makeDocumentClass() return; doc_class_ = &(DocumentClassBundle::get().newClass(*baseClass())); + + // add any required modules not already in use + set const & mods = baseClass()->defaultModules(); + set::const_iterator mit = mods.begin(); + set::const_iterator men = mods.end(); + for (; mit != men; mit++) { + string const & modName = *mit; + LayoutModuleList::const_iterator const fit = + find(layoutModules_.begin(), layoutModules_.end(), modName); + if (fit == layoutModules_.end()) { + // We need to make sure there's no module chosen that excludes this one + LayoutModuleList::const_iterator lit = layoutModules_.begin(); + LayoutModuleList::const_iterator len = layoutModules_.end(); + bool foundit = false; + // so iterate over the selected modules... + for (; lit != len; lit++) { + LyXModule * lm = moduleList[*lit]; + if (!lm) + continue; + vector const & exc = lm->getExcludedModules(); + // ...and see if one of them 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); + } + } + } - //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. + // 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; diff --git a/src/LayoutFile.h b/src/LayoutFile.h index 5f18117ffa..04c4a38228 100644 --- a/src/LayoutFile.h +++ b/src/LayoutFile.h @@ -18,6 +18,8 @@ #include +#include +#include #include @@ -61,6 +63,8 @@ class LayoutFile : public TextClass, boost::noncopyable { public: /// check whether the TeX class is available bool isTeXClassAvailable() const { return texClassAvail_; } + /// + std::set const & defaultModules() const { return usemod_; } private: /// Construct a layout with default values. Actual values loaded later. explicit LayoutFile(std::string const & filename, diff --git a/src/TextClass.cpp b/src/TextClass.cpp index 3f756bdd49..8205704e4e 100644 --- a/src/TextClass.cpp +++ b/src/TextClass.cpp @@ -61,7 +61,7 @@ private: }; -int const FORMAT = 7; +int const FORMAT = 8; bool layout2layout(FileName const & filename, FileName const & tempfile) @@ -182,7 +182,8 @@ enum TextClassTags { TC_TITLELATEXNAME, TC_TITLELATEXTYPE, TC_FORMAT, - TC_ADDTOPREAMBLE + TC_ADDTOPREAMBLE, + TC_USEMODULE }; @@ -213,7 +214,8 @@ namespace { { "style", TC_STYLE }, { "titlelatexname", TC_TITLELATEXNAME }, { "titlelatextype", TC_TITLELATEXTYPE }, - { "tocdepth", TC_TOCDEPTH } + { "tocdepth", TC_TOCDEPTH }, + { "usemodule", TC_USEMODULE } }; } //namespace anon @@ -491,6 +493,13 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt) break; } + case TC_USEMODULE: { + lexrc.next(); + string const module = lexrc.getString(); + usemod_.insert(module); + break; + } + case TC_LEFTMARGIN: // left margin type if (lexrc.next()) leftmargin_ = lexrc.getDocString(); diff --git a/src/TextClass.h b/src/TextClass.h index 254ee586fe..847612a4d4 100644 --- a/src/TextClass.h +++ b/src/TextClass.h @@ -246,6 +246,8 @@ protected: std::set provides_; /// latex packages requested by document class. std::set requires_; + /// modules wanted by document class + std::set usemod_; /// unsigned int columns_; ///