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 "support/debug.h"
18 #include "DispatchResult.h"
20 #include "FloatList.h"
21 #include "FuncRequest.h"
22 #include "support/gettext.h"
23 #include "LaTeXFeatures.h"
25 #include "MetricsInfo.h"
26 #include "TocBackend.h"
27 #include "TextClass.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 CommandInfo const * InsetFloatList::findInfo(std::string const & /* cmdName */)
53 static const char * const paramnames[] = {"type", ""};
54 static const bool isoptional[] = {false};
55 static const CommandInfo info = {1, paramnames, isoptional};
61 bool InsetFloatList::isCompatibleCommand(std::string const & s)
63 std::string str = s.substr(0, 6);
64 return str == "listof";
68 docstring const InsetFloatList::getScreenLabel(Buffer const & buf) const
70 FloatList const & floats = buf.params().getTextClass().floats();
71 FloatList::const_iterator it = floats[to_ascii(getParam("type"))];
72 if (it != floats.end())
73 return buf.B_(it->second.listName());
75 return _("ERROR: Nonexistent float type!");
79 void InsetFloatList::write(Buffer const &, std::ostream & os) const
81 os << "FloatList " << to_ascii(getParam("type")) << "\n";
85 void InsetFloatList::read(Buffer const & buf, Lexer & lex)
87 FloatList const & floats = buf.params().getTextClass().floats();
91 setParam("type", lex.getDocString());
92 LYXERR(Debug::INSETS, "FloatList::float_type: "
93 << to_ascii(getParam("type")));
94 if (!floats.typeExist(to_ascii(getParam("type"))))
95 lex.printError("InsetFloatList: Unknown float type: `$$Token'");
97 lex.printError("InsetFloatList: Parse error: `$$Token'");
102 token = lex.getString();
103 if (token == "\\end_inset")
106 if (token != "\\end_inset") {
107 lex.printError("Missing \\end_inset at this point. "
113 int InsetFloatList::latex(Buffer const & buf, odocstream & os,
114 OutputParams const &) const
116 FloatList const & floats = buf.params().getTextClass().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 << buf.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(Buffer const & buffer, odocstream & os,
144 OutputParams const &) const
146 os << getScreenLabel(buffer) << "\n\n";
148 buffer.tocBackend().writePlaintextTocList(to_ascii(getParam("type")), os);
150 return PLAINTEXT_NEWLINE;
154 void InsetFloatList::validate(LaTeXFeatures & features) const
156 features.useFloat(to_ascii(getParam("type")));