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
This commit is contained in:
Richard Heck 2009-06-03 23:44:31 +00:00
parent d3ff1d16e3
commit 658457b847
5 changed files with 42 additions and 8 deletions

View 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();
}

View 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;
///

View 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);
}

View 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();

View 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_;
///