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"
30 using lyx::support::bformat;
37 InsetFloatList::InsetFloatList()
38 : InsetCommand(InsetCommandParams(), "toc")
42 InsetFloatList::InsetFloatList(string const & type)
43 : InsetCommand(InsetCommandParams(), "toc")
49 string const InsetFloatList::getScreenLabel(Buffer const & buf) const
51 FloatList const & floats = buf.params().getLyXTextClass().floats();
52 FloatList::const_iterator it = floats[getCmdName()];
53 if (it != floats.end())
55 return lyx::to_utf8(buf.B_(it->second.listName()));
58 return lyx::to_utf8(_("ERROR: Nonexistent float type!"));
62 InsetBase::Code InsetFloatList::lyxCode() const
64 return InsetBase::FLOAT_LIST_CODE;
68 void InsetFloatList::write(Buffer const &, ostream & os) const
70 os << "FloatList " << getCmdName() << "\n";
74 void InsetFloatList::read(Buffer const & buf, LyXLex & lex)
76 FloatList const & floats = buf.params().getLyXTextClass().floats();
80 setCmdName(lex.getString());
81 lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
82 if (!floats.typeExist(getCmdName()))
83 lex.printError("InsetFloatList: Unknown float type: `$$Token'");
85 lex.printError("InsetFloatList: Parse error: `$$Token'");
88 token = lex.getString();
89 if (token == "\\end_inset")
92 if (token != "\\end_inset") {
93 lex.printError("Missing \\end_inset at this point. "
99 int InsetFloatList::latex(Buffer const & buf, ostream & os,
100 OutputParams const &) const
102 FloatList const & floats = buf.params().getLyXTextClass().floats();
103 FloatList::const_iterator cit = floats[getCmdName()];
105 if (cit != floats.end()) {
106 if (cit->second.builtin()) {
107 // Only two different types allowed here:
108 string const type = cit->second.type();
109 if (type == "table") {
110 os << "\\listoftables\n";
111 } else if (type == "figure") {
112 os << "\\listoffigures\n";
114 os << "%% unknown builtin float\n";
118 os << "\\listof{" << getCmdName() << "}{"
119 << lyx::to_utf8(buf.B_(cit->second.listName())) << "}\n";
123 os << "%%\\listof{" << getCmdName() << "}{"
124 << lyx::to_utf8(bformat(_("List of %1$s"), lyx::from_utf8(cit->second.name())))
131 int InsetFloatList::plaintext(Buffer const & buffer, ostream & os, OutputParams const &) const
133 os << getScreenLabel(buffer) << "\n\n";
135 lyx::toc::asciiTocList(getCmdName(), buffer, os);
142 void InsetFloatList::validate(LaTeXFeatures & features) const
144 features.useFloat(getCmdName());