]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFloatList.cpp
rename InsetBase to Inset
[lyx.git] / src / insets / InsetFloatList.cpp
1 /**
2  * \file InsetFloatList.cpp
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 "Lexer.h"
25 #include "MetricsInfo.h"
26 #include "TocBackend.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         setParam("type", from_ascii(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[to_ascii(getParam("type"))];
56         if (it != floats.end())
57                 return buf.B_(it->second.listName());
58         else
59                 return _("ERROR: Nonexistent float type!");
60 }
61
62
63 Inset::Code InsetFloatList::lyxCode() const
64 {
65         return Inset::FLOAT_LIST_CODE;
66 }
67
68
69 void InsetFloatList::write(Buffer const &, ostream & os) const
70 {
71         os << "FloatList " << to_ascii(getParam("type")) << "\n";
72 }
73
74
75 void InsetFloatList::read(Buffer const & buf, Lexer & lex)
76 {
77         FloatList const & floats = buf.params().getLyXTextClass().floats();
78         string token;
79
80         if (lex.eatLine()) {
81                 setParam("type", lex.getDocString());
82                 LYXERR(Debug::INSETS) << "FloatList::float_type: "
83                                       << to_ascii(getParam("type")) << endl;
84                 if (!floats.typeExist(to_ascii(getParam("type"))))
85                         lex.printError("InsetFloatList: Unknown float type: `$$Token'");
86         } else
87                 lex.printError("InsetFloatList: Parse error: `$$Token'");
88         while (lex.isOK()) {
89                 lex.next();
90                 token = lex.getString();
91                 if (token == "\\end_inset")
92                         break;
93         }
94         if (token != "\\end_inset") {
95                 lex.printError("Missing \\end_inset at this point. "
96                                "Read: `$$Token'");
97         }
98 }
99
100
101 int InsetFloatList::latex(Buffer const & buf, odocstream & os,
102                           OutputParams const &) const
103 {
104         FloatList const & floats = buf.params().getLyXTextClass().floats();
105         FloatList::const_iterator cit = floats[to_ascii(getParam("type"))];
106
107         if (cit != floats.end()) {
108                 if (cit->second.builtin()) {
109                         // Only two different types allowed here:
110                         string const type = cit->second.type();
111                         if (type == "table") {
112                                 os << "\\listoftables\n";
113                         } else if (type == "figure") {
114                                 os << "\\listoffigures\n";
115                         } else {
116                                 os << "%% unknown builtin float\n";
117                         }
118                 } else {
119                         os << "\\listof{" << getParam("type") << "}{"
120                            << buf.B_(cit->second.listName()) << "}\n";
121                 }
122         } else {
123                 os << "%%\\listof{" << getParam("type") << "}{"
124                    << bformat(_("List of %1$s"), from_utf8(cit->second.name()))
125                    << "}\n";
126         }
127         return 1;
128 }
129
130
131 int InsetFloatList::plaintext(Buffer const & buffer, odocstream & os,
132                               OutputParams const &) const
133 {
134         os << getScreenLabel(buffer) << "\n\n";
135
136         buffer.tocBackend().writePlaintextTocList(to_ascii(getParam("type")), os);
137
138         return PLAINTEXT_NEWLINE;
139 }
140
141
142 void InsetFloatList::validate(LaTeXFeatures & features) const
143 {
144         features.useFloat(to_ascii(getParam("type")));
145 }
146
147
148 } // namespace lyx