]> git.lyx.org Git - features.git/blobdiff - src/LaTeXFeatures.cpp
Rationalize the handling of InsetLayout's preamble and requries. That is,
[features.git] / src / LaTeXFeatures.cpp
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();
 }