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"
14 #include "FloatList.h"
15 #include "LaTeXFeatures.h"
17 #include "BufferView.h"
18 #include "funcrequest.h"
25 #include "support/lstrings.h"
31 InsetFloatList::InsetFloatList()
32 : InsetCommand(InsetCommandParams())
36 InsetFloatList::InsetFloatList(string const & type)
37 : InsetCommand(InsetCommandParams())
43 InsetFloatList::~InsetFloatList()
45 InsetCommandMailer mailer("toc", *this);
50 string const InsetFloatList::getScreenLabel(Buffer const * buf) const
52 FloatList const & floats = buf->params.getLyXTextClass().floats();
53 FloatList::const_iterator it = floats[getCmdName()];
54 if (it != floats.end())
55 return _(it->second.listName());
57 return _("ERROR: Nonexistent float type!");
61 Inset::Code InsetFloatList::lyxCode() const
63 return Inset::FLOAT_LIST_CODE;
67 void InsetFloatList::write(Buffer const *, ostream & os) const
69 os << "FloatList " << getCmdName() << "\n";
73 void InsetFloatList::read(Buffer const * buf, LyXLex & lex)
75 FloatList const & floats = buf->params.getLyXTextClass().floats();
79 setCmdName(lex.getString());
80 lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
81 if (!floats.typeExist(getCmdName()))
82 lex.printError("InsetFloatList: Unknown float type: `$$Token'");
84 lex.printError("InsetFloatList: Parse error: `$$Token'");
87 token = lex.getString();
88 if (token == "\\end_inset")
91 if (token != "\\end_inset") {
92 lex.printError("Missing \\end_inset at this point. "
98 dispatch_result InsetFloatList::localDispatch(FuncRequest const & cmd)
100 switch (cmd.action) {
101 case LFUN_INSET_EDIT:
102 InsetCommandMailer("toc", *this).showDialog(cmd.view());
105 return InsetCommand::localDispatch(cmd);
110 int InsetFloatList::latex(Buffer const * buf, ostream & os,
111 LatexRunParams const &) const
113 FloatList const & floats = buf->params.getLyXTextClass().floats();
114 FloatList::const_iterator cit = floats[getCmdName()];
116 if (cit != floats.end()) {
117 if (cit->second.builtin()) {
118 // Only two different types allowed here:
119 string const type = cit->second.type();
120 if (type == "table") {
121 os << "\\listoftables\n";
122 } else if (type == "figure") {
123 os << "\\listoffigures\n";
125 os << "%% unknown builtin float\n";
128 os << "\\listof{" << getCmdName() << "}{"
129 << cit->second.listName() << "}\n";
132 os << "%%\\listof{" << getCmdName() << "}{"
133 << bformat(_("List of %1$s"), cit->second.name())
140 int InsetFloatList::ascii(Buffer const * buffer, ostream & os, int) const
142 os << getScreenLabel(buffer) << "\n\n";
144 toc::asciiTocList(getCmdName(), buffer, os);
151 void InsetFloatList::validate(LaTeXFeatures & features) const
153 features.useFloat(getCmdName());