]> git.lyx.org Git - lyx.git/blob - src/insets/insetfloatlist.C
bf262dbab301e597735bd7a7f59039c088273c44
[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
31 namespace lyx {
32
33 using support::bformat;
34
35 using std::endl;
36 using std::string;
37 using std::ostream;
38
39
40 InsetFloatList::InsetFloatList()
41         : InsetCommand(InsetCommandParams("floatlist"), "toc")
42 {}
43
44
45 InsetFloatList::InsetFloatList(string const & type)
46         : InsetCommand(InsetCommandParams("floatlist"), "toc")
47 {
48         setCmdName(type);
49 }
50
51
52 docstring const InsetFloatList::getScreenLabel(Buffer const & buf) const
53 {
54         FloatList const & floats = buf.params().getLyXTextClass().floats();
55         FloatList::const_iterator it = floats[getCmdName()];
56         if (it != floats.end())
57                 return buf.B_(it->second.listName());
58         else
59                 return _("ERROR: Nonexistent float type!");
60 }
61
62
63 InsetBase::Code InsetFloatList::lyxCode() const
64 {
65         return InsetBase::FLOAT_LIST_CODE;
66 }
67
68
69 void InsetFloatList::write(Buffer const &, ostream & os) const
70 {
71         os << "FloatList " << getCmdName() << "\n";
72 }
73
74
75 void InsetFloatList::read(Buffer const & buf, LyXLex & lex)
76 {
77         InsetCommand::read(buf, lex);
78         lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
79         if (!buf.params().getLyXTextClass().floats().typeExist(getCmdName()))
80                 lex.printError("InsetFloatList: Unknown float type: `$$Token'");
81 }
82
83
84 int InsetFloatList::latex(Buffer const & buf, odocstream & os,
85                           OutputParams const &) const
86 {
87         FloatList const & floats = buf.params().getLyXTextClass().floats();
88         FloatList::const_iterator cit = floats[getCmdName()];
89
90         if (cit != floats.end()) {
91                 if (cit->second.builtin()) {
92                         // Only two different types allowed here:
93                         string const type = cit->second.type();
94                         if (type == "table") {
95                                 os << "\\listoftables\n";
96                         } else if (type == "figure") {
97                                 os << "\\listoffigures\n";
98                         } else {
99                                 os << "%% unknown builtin float\n";
100                         }
101                 } else {
102                         // FIXME UNICODE
103                         os << "\\listof{" << from_ascii(getCmdName()) << "}{"
104                            << buf.B_(cit->second.listName()) << "}\n";
105                 }
106         } else {
107                 // FIXME UNICODE
108                 os << "%%\\listof{" << from_ascii(getCmdName()) << "}{"
109                    << bformat(_("List of %1$s"), from_utf8(cit->second.name()))
110                    << "}\n";
111         }
112         return 1;
113 }
114
115
116 int InsetFloatList::plaintext(Buffer const & buffer, odocstream & os,
117                               OutputParams const &) const
118 {
119         os << getScreenLabel(buffer) << "\n\n";
120
121         toc::asciiTocList(getCmdName(), buffer, os);
122
123         os << "\n";
124         return 0;
125 }
126
127
128 void InsetFloatList::validate(LaTeXFeatures & features) const
129 {
130         features.useFloat(getCmdName());
131 }
132
133
134 } // namespace lyx