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 #pragma implementation
16 #include "insetfloatlist.h"
17 #include "FloatList.h"
18 #include "LaTeXFeatures.h"
20 #include "frontends/Dialogs.h"
21 #include "frontends/LyXView.h"
22 #include "BufferView.h"
28 #include "BoostFormat.h"
34 InsetFloatList::InsetFloatList()
35 : InsetCommand(InsetCommandParams())
40 InsetFloatList::InsetFloatList(string const & type)
41 : InsetCommand(InsetCommandParams())
47 string const InsetFloatList::getScreenLabel(Buffer const * buf) const
49 FloatList const & floats = buf->params.getLyXTextClass().floats();
50 FloatList::const_iterator it = floats[getCmdName()];
51 if (it != floats.end())
52 return _(it->second.listName());
54 return _("ERROR: Nonexistent float type!");
58 Inset::Code InsetFloatList::lyxCode() const
60 return Inset::FLOAT_LIST_CODE;
64 void InsetFloatList::write(Buffer const *, ostream & os) const
66 os << "FloatList " << getCmdName() << "\n";
70 void InsetFloatList::read(Buffer const * buf, LyXLex & lex)
72 FloatList const & floats = buf->params.getLyXTextClass().floats();
76 setCmdName(lex.getString());
77 lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
78 if (!floats.typeExist(getCmdName()))
79 lex.printError("InsetFloatList: Unknown float type: `$$Token'");
81 lex.printError("InsetFloatList: Parse error: `$$Token'");
84 token = lex.getString();
85 if (token == "\\end_inset")
88 if (token != "\\end_inset") {
89 lex.printError("Missing \\end_inset at this point. "
95 void InsetFloatList::edit(BufferView * bv, int, int, mouse_button::state)
97 bv->owner()->getDialogs().showTOC(this);
101 void InsetFloatList::edit(BufferView * bv, bool)
103 edit(bv, 0, 0, mouse_button::none);
107 int InsetFloatList::latex(Buffer const * buf, ostream & os, bool, bool) const
109 FloatList const & floats = buf->params.getLyXTextClass().floats();
110 FloatList::const_iterator cit = floats[getCmdName()];
112 if (cit != floats.end()) {
113 if (cit->second.builtin()) {
114 // Only two different types allowed here:
115 string const type = cit->second.type();
116 if (type == "table") {
117 os << "\\listoftables\n";
118 } else if (type == "figure") {
119 os << "\\listoffigures\n";
121 os << "%% unknown builtin float\n";
124 os << "\\listof{" << getCmdName() << "}{"
125 << cit->second.listName() << "}\n";
131 << boost::format(_("List of %1$s")) % cit->second.name()
138 int InsetFloatList::ascii(Buffer const * buffer, ostream & os, int) const
140 os << getScreenLabel(buffer) << "\n\n";
142 toc::asciiTocList(getCmdName(), buffer, os);
149 void InsetFloatList::validate(LaTeXFeatures & features) const
151 features.useFloat(getCmdName());