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"
27 #include "TextClass.h"
29 #include "support/lstrings.h"
34 using support::bformat;
41 InsetFloatList::InsetFloatList()
42 : InsetCommand(InsetCommandParams(FLOAT_LIST_CODE), "toc")
46 InsetFloatList::InsetFloatList(string const & type)
47 : InsetCommand(InsetCommandParams(FLOAT_LIST_CODE), "toc")
49 setParam("type", from_ascii(type));
53 CommandInfo const * InsetFloatList::findInfo(std::string const & /* cmdName */)
55 static const char * const paramnames[] = {"type", ""};
56 static const bool isoptional[] = {false};
57 static const CommandInfo info = {1, paramnames, isoptional};
63 bool InsetFloatList::isCompatibleCommand(std::string const & s) {
64 std::string str = s.substr(0, 6);
65 return str == "listof";
69 docstring const InsetFloatList::getScreenLabel(Buffer const & buf) const
71 FloatList const & floats = buf.params().getTextClass().floats();
72 FloatList::const_iterator it = floats[to_ascii(getParam("type"))];
73 if (it != floats.end())
74 return buf.B_(it->second.listName());
76 return _("ERROR: Nonexistent float type!");
80 void InsetFloatList::write(Buffer const &, ostream & os) const
82 os << "FloatList " << to_ascii(getParam("type")) << "\n";
86 void InsetFloatList::read(Buffer const & buf, Lexer & lex)
88 FloatList const & floats = buf.params().getTextClass().floats();
92 setParam("type", lex.getDocString());
93 LYXERR(Debug::INSETS) << "FloatList::float_type: "
94 << to_ascii(getParam("type")) << endl;
95 if (!floats.typeExist(to_ascii(getParam("type"))))
96 lex.printError("InsetFloatList: Unknown float type: `$$Token'");
98 lex.printError("InsetFloatList: Parse error: `$$Token'");
101 token = lex.getString();
102 if (token == "\\end_inset")
105 if (token != "\\end_inset") {
106 lex.printError("Missing \\end_inset at this point. "
112 int InsetFloatList::latex(Buffer const & buf, odocstream & os,
113 OutputParams const &) const
115 FloatList const & floats = buf.params().getTextClass().floats();
116 FloatList::const_iterator cit = floats[to_ascii(getParam("type"))];
118 if (cit != floats.end()) {
119 if (cit->second.builtin()) {
120 // Only two different types allowed here:
121 string const type = cit->second.type();
122 if (type == "table") {
123 os << "\\listoftables\n";
124 } else if (type == "figure") {
125 os << "\\listoffigures\n";
127 os << "%% unknown builtin float\n";
130 os << "\\listof{" << getParam("type") << "}{"
131 << buf.B_(cit->second.listName()) << "}\n";
134 os << "%%\\listof{" << getParam("type") << "}{"
135 << bformat(_("List of %1$s"), from_utf8(cit->second.name()))
142 int InsetFloatList::plaintext(Buffer const & buffer, odocstream & os,
143 OutputParams const &) const
145 os << getScreenLabel(buffer) << "\n\n";
147 buffer.tocBackend().writePlaintextTocList(to_ascii(getParam("type")), os);
149 return PLAINTEXT_NEWLINE;
153 void InsetFloatList::validate(LaTeXFeatures & features) const
155 features.useFloat(to_ascii(getParam("type")));