2 * \file insetfloatlist.C
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"
28 #include "support/lstrings.h"
33 using support::bformat;
40 InsetFloatList::InsetFloatList()
41 : InsetCommand(InsetCommandParams("floatlist"), "toc")
45 InsetFloatList::InsetFloatList(string const & type)
46 : InsetCommand(InsetCommandParams("floatlist"), "toc")
48 setParam("type", from_ascii(type));
52 docstring const InsetFloatList::getScreenLabel(Buffer const & buf) const
54 FloatList const & floats = buf.params().getLyXTextClass().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 InsetBase::Code InsetFloatList::lyxCode() const
65 return InsetBase::FLOAT_LIST_CODE;
69 void InsetFloatList::write(Buffer const &, ostream & os) const
71 os << "FloatList " << to_ascii(getParam("type")) << "\n";
75 void InsetFloatList::read(Buffer const & buf, LyXLex & lex)
77 FloatList const & floats = buf.params().getLyXTextClass().floats();
81 setParam("type", lex.getDocString());
82 lyxerr[Debug::INSETS] << "FloatList::float_type: "
83 << to_ascii(getParam("type")) << endl;
84 if (!floats.typeExist(to_ascii(getParam("type"))))
85 lex.printError("InsetFloatList: Unknown float type: `$$Token'");
87 lex.printError("InsetFloatList: Parse error: `$$Token'");
90 token = lex.getString();
91 if (token == "\\end_inset")
94 if (token != "\\end_inset") {
95 lex.printError("Missing \\end_inset at this point. "
101 int InsetFloatList::latex(Buffer const & buf, odocstream & os,
102 OutputParams const &) const
104 FloatList const & floats = buf.params().getLyXTextClass().floats();
105 FloatList::const_iterator cit = floats[to_ascii(getParam("type"))];
107 if (cit != floats.end()) {
108 if (cit->second.builtin()) {
109 // Only two different types allowed here:
110 string const type = cit->second.type();
111 if (type == "table") {
112 os << "\\listoftables\n";
113 } else if (type == "figure") {
114 os << "\\listoffigures\n";
116 os << "%% unknown builtin float\n";
119 os << "\\listof{" << getParam("type") << "}{"
120 << buf.B_(cit->second.listName()) << "}\n";
123 os << "%%\\listof{" << getParam("type") << "}{"
124 << bformat(_("List of %1$s"), from_utf8(cit->second.name()))
131 int InsetFloatList::plaintext(Buffer const & buffer, odocstream & os,
132 OutputParams const &) const
134 os << getScreenLabel(buffer) << "\n\n";
136 toc::asciiTocList(to_ascii(getParam("type")), buffer, os);
143 void InsetFloatList::validate(LaTeXFeatures & features) const
145 features.useFloat(to_ascii(getParam("type")));