]> git.lyx.org Git - lyx.git/blob - src/insets/insetfloatlist.C
Adjust InsetFloatList to the new InsetCommand syntax.
[lyx.git] / src / insets / insetfloatlist.C
1 /**
2  * \file insetfloatlist.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "insetfloatlist.h"
14
15 #include "buffer.h"
16 #include "bufferparams.h"
17 #include "debug.h"
18 #include "dispatchresult.h"
19 #include "Floating.h"
20 #include "FloatList.h"
21 #include "funcrequest.h"
22 #include "gettext.h"
23 #include "LaTeXFeatures.h"
24 #include "lyxlex.h"
25 #include "metricsinfo.h"
26 #include "toc.h"
27
28 #include "support/lstrings.h"
29
30 using lyx::docstring;
31 using lyx::support::bformat;
32
33 using std::endl;
34 using std::string;
35 using std::ostream;
36
37
38 InsetFloatList::InsetFloatList()
39         : InsetCommand(InsetCommandParams("floatlist"), "toc")
40 {}
41
42
43 InsetFloatList::InsetFloatList(string const & type)
44         : InsetCommand(InsetCommandParams("floatlist"), "toc")
45 {
46         setCmdName(type);
47 }
48
49
50 docstring const InsetFloatList::getScreenLabel(Buffer const & buf) const
51 {
52         FloatList const & floats = buf.params().getLyXTextClass().floats();
53         FloatList::const_iterator it = floats[getCmdName()];
54         if (it != floats.end())
55                 return buf.B_(it->second.listName());
56         else
57                 return _("ERROR: Nonexistent float type!");
58 }
59
60
61 InsetBase::Code InsetFloatList::lyxCode() const
62 {
63         return InsetBase::FLOAT_LIST_CODE;
64 }
65
66
67 void InsetFloatList::write(Buffer const &, ostream & os) const
68 {
69         os << "FloatList " << getCmdName() << "\n";
70 }
71
72
73 void InsetFloatList::read(Buffer const & buf, LyXLex & lex)
74 {
75         InsetCommand::read(buf, lex);
76         lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
77         if (!buf.params().getLyXTextClass().floats().typeExist(getCmdName()))
78                 lex.printError("InsetFloatList: Unknown float type: `$$Token'");
79 }
80
81
82 int InsetFloatList::latex(Buffer const & buf, ostream & os,
83                           OutputParams const &) const
84 {
85         FloatList const & floats = buf.params().getLyXTextClass().floats();
86         FloatList::const_iterator cit = floats[getCmdName()];
87
88         if (cit != floats.end()) {
89                 if (cit->second.builtin()) {
90                         // Only two different types allowed here:
91                         string const type = cit->second.type();
92                         if (type == "table") {
93                                 os << "\\listoftables\n";
94                         } else if (type == "figure") {
95                                 os << "\\listoffigures\n";
96                         } else {
97                                 os << "%% unknown builtin float\n";
98                         }
99                 } else {
100                         // FIXME UNICODE
101                         os << "\\listof{" << getCmdName() << "}{"
102                            << lyx::to_utf8(buf.B_(cit->second.listName())) << "}\n";
103                 }
104         } else {
105                 // FIXME UNICODE
106                 os << "%%\\listof{" << getCmdName() << "}{"
107                    << lyx::to_utf8(bformat(_("List of %1$s"), lyx::from_utf8(cit->second.name())))
108                    << "}\n";
109         }
110         return 1;
111 }
112
113
114 int InsetFloatList::plaintext(Buffer const & buffer, lyx::odocstream & os,
115                               OutputParams const &) const
116 {
117         os << getScreenLabel(buffer) << "\n\n";
118
119         lyx::toc::asciiTocList(getCmdName(), buffer, os);
120
121         os << "\n";
122         return 0;
123 }
124
125
126 void InsetFloatList::validate(LaTeXFeatures & features) const
127 {
128         features.useFloat(getCmdName());
129 }