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())
54 return buf.B_(it->second.listName());
56 return _("ERROR: Nonexistent float type!");
60 InsetOld::Code InsetFloatList::lyxCode() const
62 return InsetOld::FLOAT_LIST_CODE;
66 void InsetFloatList::write(Buffer const &, ostream & os) const
68 os << "FloatList " << getCmdName() << "\n";
72 void InsetFloatList::read(Buffer const & buf, LyXLex & lex)
74 FloatList const & floats = buf.params().getLyXTextClass().floats();
78 setCmdName(lex.getString());
79 lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
80 if (!floats.typeExist(getCmdName()))
81 lex.printError("InsetFloatList: Unknown float type: `$$Token'");
83 lex.printError("InsetFloatList: Parse error: `$$Token'");
86 token = lex.getString();
87 if (token == "\\end_inset")
90 if (token != "\\end_inset") {
91 lex.printError("Missing \\end_inset at this point. "
97 int InsetFloatList::latex(Buffer const & buf, ostream & os,
98 OutputParams const &) const
100 FloatList const & floats = buf.params().getLyXTextClass().floats();
101 FloatList::const_iterator cit = floats[getCmdName()];
103 if (cit != floats.end()) {
104 if (cit->second.builtin()) {
105 // Only two different types allowed here:
106 string const type = cit->second.type();
107 if (type == "table") {
108 os << "\\listoftables\n";
109 } else if (type == "figure") {
110 os << "\\listoffigures\n";
112 os << "%% unknown builtin float\n";
115 os << "\\listof{" << getCmdName() << "}{"
116 << buf.B_(cit->second.listName()) << "}\n";
119 os << "%%\\listof{" << getCmdName() << "}{"
120 << bformat(_("List of %1$s"), cit->second.name())
127 int InsetFloatList::plaintext(Buffer const & buffer, ostream & os, OutputParams const &) const
129 os << getScreenLabel(buffer) << "\n\n";
131 lyx::toc::asciiTocList(getCmdName(), buffer, os);
138 void InsetFloatList::validate(LaTeXFeatures & features) const
140 features.useFloat(getCmdName());