From 658457b8474fcef68cc385ab7e3e88ca19b60aac Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Wed, 3 Jun 2009 23:44:31 +0000 Subject: [PATCH] Rationalize the handling of InsetLayout's preamble and requries. That is, bring it into line with the handing of Layout's preamble and requires. This will make information about used InsetLayout's avaiable elsewhere. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29914 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LaTeXFeatures.cpp | 32 ++++++++++++++++++++++++++++++++ src/LaTeXFeatures.h | 7 ++++++- src/insets/InsetCollapsable.cpp | 5 +---- src/insets/InsetLayout.cpp | 2 +- src/insets/InsetLayout.h | 4 ++-- 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index cf26ea719b..e64eb85cf1 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -29,6 +29,8 @@ #include "LyXRC.h" #include "TextClass.h" +#include "insets/InsetLayout.h" + #include "support/debug.h" #include "support/docstream.h" #include "support/FileName.h" @@ -357,6 +359,26 @@ void LaTeXFeatures::useLayout(docstring const & layoutname) } +void LaTeXFeatures::useInsetLayout(InsetLayout const & lay) +{ + docstring const & lname = lay.name(); + DocumentClass const & tclass = params_.documentClass(); + if (!tclass.hasInsetLayout(lname)) { + lyxerr << "LaTeXFeatures::useInsetLayout: layout `" + << to_utf8(lname) << "' does not exist in this class" + << endl; + return; + } + // Is this layout already in usedInsetLayouts? + if (find(usedInsetLayouts_.begin(), usedInsetLayouts_.end(), lname) + != usedInsetLayouts_.end()) + return; + + require(lay.requires()); + usedInsetLayouts_.push_back(lname); +} + + bool LaTeXFeatures::isRequired(string const & name) const { return features_.find(name) != features_.end(); @@ -895,6 +917,16 @@ docstring const LaTeXFeatures::getTClassPreamble() const for (; cit != end; ++cit) tcpreamble << tclass[*cit].preamble(); + cit = usedInsetLayouts_.begin(); + end = usedInsetLayouts_.end(); + TextClass::InsetLayouts const & ils = tclass.insetLayouts(); + for (; cit != end; ++cit) { + TextClass::InsetLayouts::const_iterator it = ils.find(*cit); + if (it == ils.end()) + continue; + tcpreamble << it->second.preamble(); + } + return tcpreamble.str(); } diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h index 7f010b33ca..5fbadb4c76 100644 --- a/src/LaTeXFeatures.h +++ b/src/LaTeXFeatures.h @@ -26,6 +26,7 @@ namespace lyx { class Buffer; class BufferParams; +class InsetLayout; class Language; /** The packages and commands that a buffer needs. This class @@ -98,6 +99,8 @@ public: /// void useLayout(docstring const & lyt); /// + void useInsetLayout(InsetLayout const & lay); + /// Buffer const & buffer() const; /// void setBuffer(Buffer const &); @@ -113,8 +116,10 @@ public: OutputParams const & runparams() const { return runparams_; } private: + /// std::list usedLayouts_; - + /// + std::list usedInsetLayouts_; /// The features that are needed by the document typedef std::set Features; /// diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index b13de0af26..ac1bc3a8e9 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -873,10 +873,7 @@ int InsetCollapsable::docbook(odocstream & os, OutputParams const & runparams) c void InsetCollapsable::validate(LaTeXFeatures & features) const { - string const preamble = getLayout().preamble(); - if (!preamble.empty()) - features.addPreambleSnippet(preamble); - features.require(getLayout().requires()); + features.useInsetLayout(getLayout()); InsetText::validate(features); } diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp index 6a8258c54e..ca1429793b 100644 --- a/src/insets/InsetLayout.cpp +++ b/src/insets/InsetLayout.cpp @@ -256,7 +256,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass) bgcolor_ = lcolor.getFromLyXName(tmp); break; case IL_PREAMBLE: - preamble_ = lex.getLongString("EndPreamble"); + preamble_ = from_utf8(lex.getLongString("EndPreamble")); break; case IL_REQUIRES: { lex.eatLine(); diff --git a/src/insets/InsetLayout.h b/src/insets/InsetLayout.h index ee5fccaba0..886a665885 100644 --- a/src/insets/InsetLayout.h +++ b/src/insets/InsetLayout.h @@ -77,7 +77,7 @@ public: /// ColorCode bgcolor() const { return bgcolor_; }; /// - std::string preamble() const { return preamble_; }; + docstring preamble() const { return preamble_; }; /// std::set requires() const { return requires_; }; /// @@ -124,7 +124,7 @@ private: /// ColorCode bgcolor_; /// - std::string preamble_; + docstring preamble_; /// std::set requires_; /// -- 2.39.2