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"
27 using namespace lyx::support;
33 InsetFloatList::InsetFloatList()
34 : InsetCommand(InsetCommandParams())
38 InsetFloatList::InsetFloatList(string const & type)
39 : InsetCommand(InsetCommandParams())
45 InsetFloatList::~InsetFloatList()
47 InsetCommandMailer mailer("toc", *this);
52 string const InsetFloatList::getScreenLabel(Buffer const * buf) const
54 FloatList const & floats = buf->params.getLyXTextClass().floats();
55 FloatList::const_iterator it = floats[getCmdName()];
56 if (it != floats.end())
57 return _(it->second.listName());
59 return _("ERROR: Nonexistent float type!");
63 InsetOld::Code InsetFloatList::lyxCode() const
65 return InsetOld::FLOAT_LIST_CODE;
69 void InsetFloatList::write(Buffer const *, ostream & os) const
71 os << "FloatList " << getCmdName() << "\n";
75 void InsetFloatList::read(Buffer const * buf, LyXLex & lex)
77 FloatList const & floats = buf->params.getLyXTextClass().floats();
81 setCmdName(lex.getString());
82 lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
83 if (!floats.typeExist(getCmdName()))
84 lex.printError("InsetFloatList: Unknown float type: `$$Token'");
86 lex.printError("InsetFloatList: Parse error: `$$Token'");
89 token = lex.getString();
90 if (token == "\\end_inset")
93 if (token != "\\end_inset") {
94 lex.printError("Missing \\end_inset at this point. "
100 dispatch_result InsetFloatList::localDispatch(FuncRequest const & cmd)
102 switch (cmd.action) {
103 case LFUN_INSET_EDIT:
104 InsetCommandMailer("toc", *this).showDialog(cmd.view());
107 return InsetCommand::localDispatch(cmd);
112 int InsetFloatList::latex(Buffer const * buf, ostream & os,
113 LatexRunParams const &) const
115 FloatList const & floats = buf->params.getLyXTextClass().floats();
116 FloatList::const_iterator cit = floats[getCmdName()];
118 if (cit != floats.end()) {
119 if (cit->second.builtin()) {
120 // Only two different types allowed here:
121 string const type = cit->second.type();
122 if (type == "table") {
123 os << "\\listoftables\n";
124 } else if (type == "figure") {
125 os << "\\listoffigures\n";
127 os << "%% unknown builtin float\n";
130 os << "\\listof{" << getCmdName() << "}{"
131 << cit->second.listName() << "}\n";
134 os << "%%\\listof{" << getCmdName() << "}{"
135 << bformat(_("List of %1$s"), cit->second.name())
142 int InsetFloatList::ascii(Buffer const * buffer, ostream & os, int) const
144 os << getScreenLabel(buffer) << "\n\n";
146 toc::asciiTocList(getCmdName(), buffer, os);
153 void InsetFloatList::validate(LaTeXFeatures & features) const
155 features.useFloat(getCmdName());