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"
17 #include "DispatchResult.h"
19 #include "FloatList.h"
20 #include "FuncRequest.h"
21 #include "LaTeXFeatures.h"
23 #include "MetricsInfo.h"
24 #include "TextClass.h"
25 #include "TocBackend.h"
27 #include "support/debug.h"
28 #include "support/gettext.h"
29 #include "support/lstrings.h"
34 using namespace lyx::support;
39 InsetFloatList::InsetFloatList()
40 : InsetCommand(InsetCommandParams(FLOAT_LIST_CODE), "toc")
44 InsetFloatList::InsetFloatList(string const & type)
45 : InsetCommand(InsetCommandParams(FLOAT_LIST_CODE), "toc")
47 setParam("type", from_ascii(type));
51 ParamInfo const & InsetFloatList::findInfo(string const & /* cmdName */)
53 static ParamInfo param_info_;
54 if (param_info_.empty()) {
55 param_info_.add("type", ParamInfo::LATEX_REQUIRED);
62 bool InsetFloatList::isCompatibleCommand(string const & s)
64 string str = s.substr(0, 6);
65 return str == "listof";
69 docstring InsetFloatList::screenLabel() const
71 FloatList const & floats = buffer().params().documentClass().floats();
72 FloatList::const_iterator it = floats[to_ascii(getParam("type"))];
73 if (it != floats.end())
74 return buffer().B_(it->second.listName());
76 return _("ERROR: Nonexistent float type!");
80 void InsetFloatList::write(ostream & os) const
82 os << "FloatList " << to_ascii(getParam("type")) << "\n";
86 void InsetFloatList::read(Lexer & lex)
88 lex.setContext("InsetFloatList::read");
89 FloatList const & floats = buffer().params().documentClass().floats();
93 setParam("type", lex.getDocString());
94 LYXERR(Debug::INSETS, "FloatList::float_type: "
95 << to_ascii(getParam("type")));
96 if (!floats.typeExist(to_ascii(getParam("type"))))
97 lex.printError("Unknown float type");
99 lex.printError("Parse error");
104 token = lex.getString();
105 if (token == "\\end_inset")
108 if (token != "\\end_inset") {
109 lex.printError("Missing \\end_inset at this point.");
114 int InsetFloatList::latex(odocstream & os, OutputParams const &) const
116 FloatList const & floats = buffer().params().documentClass().floats();
117 FloatList::const_iterator cit = floats[to_ascii(getParam("type"))];
119 if (cit != floats.end()) {
120 if (cit->second.builtin()) {
121 // Only two different types allowed here:
122 string const type = cit->second.type();
123 if (type == "table") {
124 os << "\\listoftables\n";
125 } else if (type == "figure") {
126 os << "\\listoffigures\n";
128 os << "%% unknown builtin float\n";
131 os << "\\listof{" << getParam("type") << "}{"
132 << buffer().B_(cit->second.listName()) << "}\n";
135 os << "%%\\listof{" << getParam("type") << "}{"
136 << bformat(_("List of %1$s"), from_utf8(cit->second.name()))
143 int InsetFloatList::plaintext(odocstream & os, OutputParams const &) const
145 os << screenLabel() << "\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")));