]> git.lyx.org Git - features.git/commitdiff
Rationalize the handling of InsetLayout's preamble and requries. That is,
authorRichard Heck <rgheck@comcast.net>
Wed, 3 Jun 2009 23:44:31 +0000 (23:44 +0000)
committerRichard Heck <rgheck@comcast.net>
Wed, 3 Jun 2009 23:44:31 +0000 (23:44 +0000)
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
src/LaTeXFeatures.h
src/insets/InsetCollapsable.cpp
src/insets/InsetLayout.cpp
src/insets/InsetLayout.h

index cf26ea719b3c9efcc8109c2ab6ac26e42d3abafb..e64eb85cf1ace517ba7c579815b75d1b55a8fb45 100644 (file)
@@ -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();
 }
 
index 7f010b33ca94522ba397e4ff098683c600a7df1c..5fbadb4c76e763fd3cc915a23c61b9d7a0ec8836 100644 (file)
@@ -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<docstring> usedLayouts_;
-
+       ///
+       std::list<docstring> usedInsetLayouts_;
        /// The features that are needed by the document
        typedef std::set<std::string> Features;
        ///
index b13de0af26942fd13200e96ca9f9a73674cd3713..ac1bc3a8e9a9211a6ed3072efae03a869e46ab9b 100644 (file)
@@ -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);
 }
 
index 6a8258c54e648ccb93cf622f225c3a289fc0f73b..ca1429793b47e46d6cc6b26f5540f86a05ff6bd2 100644 (file)
@@ -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();
index ee5fccaba08835cdc988b865a50842be29f94947..886a6658851dd4edb7388df432b92cc6174fc6ee 100644 (file)
@@ -77,7 +77,7 @@ public:
        ///
        ColorCode bgcolor() const { return bgcolor_; };
        ///
-       std::string preamble() const { return preamble_; };
+       docstring preamble() const { return preamble_; };
        ///
        std::set<std::string> requires() const { return requires_; };
        ///
@@ -124,7 +124,7 @@ private:
        ///
        ColorCode bgcolor_;
        ///
-       std::string preamble_;
+       docstring preamble_;
        ///
        std::set<std::string> requires_;
        ///