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