2 * \file InsetFloatList.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS.
13 #include "InsetFloatList.h"
16 #include "BufferParams.h"
18 #include "DispatchResult.h"
20 #include "FloatList.h"
21 #include "FuncRequest.h"
23 #include "LaTeXFeatures.h"
25 #include "MetricsInfo.h"
26 #include "TocBackend.h"
28 #include "support/lstrings.h"
33 using support::bformat;
40 InsetFloatList::InsetFloatList()
41 : InsetCommand(InsetCommandParams(FLOAT_LIST_CODE), "toc")
45 InsetFloatList::InsetFloatList(string const & type)
46 : InsetCommand(InsetCommandParams(FLOAT_LIST_CODE), "toc")
48 setParam("type", from_ascii(type));
52 docstring const InsetFloatList::getScreenLabel(Buffer const & buf) const
54 FloatList const & floats = buf.params().getTextClass().floats();
55 FloatList::const_iterator it = floats[to_ascii(getParam("type"))];
56 if (it != floats.end())
57 return buf.B_(it->second.listName());
59 return _("ERROR: Nonexistent float type!");
63 void InsetFloatList::write(Buffer const &, ostream & os) const
65 os << "FloatList " << to_ascii(getParam("type")) << "\n";
69 void InsetFloatList::read(Buffer const & buf, Lexer & lex)
71 FloatList const & floats = buf.params().getTextClass().floats();
75 setParam("type", lex.getDocString());
76 LYXERR(Debug::INSETS) << "FloatList::float_type: "
77 << to_ascii(getParam("type")) << endl;
78 if (!floats.typeExist(to_ascii(getParam("type"))))
79 lex.printError("InsetFloatList: Unknown float type: `$$Token'");
81 lex.printError("InsetFloatList: Parse error: `$$Token'");
84 token = lex.getString();
85 if (token == "\\end_inset")
88 if (token != "\\end_inset") {
89 lex.printError("Missing \\end_inset at this point. "
95 int InsetFloatList::latex(Buffer const & buf, odocstream & os,
96 OutputParams const &) const
98 FloatList const & floats = buf.params().getTextClass().floats();
99 FloatList::const_iterator cit = floats[to_ascii(getParam("type"))];
101 if (cit != floats.end()) {
102 if (cit->second.builtin()) {
103 // Only two different types allowed here:
104 string const type = cit->second.type();
105 if (type == "table") {
106 os << "\\listoftables\n";
107 } else if (type == "figure") {
108 os << "\\listoffigures\n";
110 os << "%% unknown builtin float\n";
113 os << "\\listof{" << getParam("type") << "}{"
114 << buf.B_(cit->second.listName()) << "}\n";
117 os << "%%\\listof{" << getParam("type") << "}{"
118 << bformat(_("List of %1$s"), from_utf8(cit->second.name()))
125 int InsetFloatList::plaintext(Buffer const & buffer, odocstream & os,
126 OutputParams const &) const
128 os << getScreenLabel(buffer) << "\n\n";
130 buffer.tocBackend().writePlaintextTocList(to_ascii(getParam("type")), os);
132 return PLAINTEXT_NEWLINE;
136 void InsetFloatList::validate(LaTeXFeatures & features) const
138 features.useFloat(to_ascii(getParam("type")));