]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFloatList.cpp
getting rid of superfluous std:: statements.
[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 "support/debug.h"
18 #include "DispatchResult.h"
19 #include "Floating.h"
20 #include "FloatList.h"
21 #include "FuncRequest.h"
22 #include "support/gettext.h"
23 #include "LaTeXFeatures.h"
24 #include "Lexer.h"
25 #include "MetricsInfo.h"
26 #include "TocBackend.h"
27 #include "TextClass.h"
28
29 #include "support/lstrings.h"
30
31 #include <ostream>
32
33 using namespace std;
34 using namespace lyx::support;
35
36 namespace lyx {
37
38
39 InsetFloatList::InsetFloatList()
40         : InsetCommand(InsetCommandParams(FLOAT_LIST_CODE), "toc")
41 {}
42
43
44 InsetFloatList::InsetFloatList(string const & type)
45         : InsetCommand(InsetCommandParams(FLOAT_LIST_CODE), "toc")
46 {
47         setParam("type", from_ascii(type));
48 }
49
50
51 CommandInfo const * InsetFloatList::findInfo(string const & /* cmdName */)
52 {
53         static const char * const paramnames[] = {"type", ""};
54         static const bool isoptional[] = {false};
55         static const CommandInfo info = {1, paramnames, isoptional};
56         return &info;
57 }
58
59
60 //HACK
61 bool InsetFloatList::isCompatibleCommand(string const & s)
62 {
63         string str = s.substr(0, 6);
64         return str == "listof";
65 }
66
67
68 docstring const InsetFloatList::getScreenLabel(Buffer const & buf) const
69 {
70         FloatList const & floats = buf.params().getTextClass().floats();
71         FloatList::const_iterator it = floats[to_ascii(getParam("type"))];
72         if (it != floats.end())
73                 return buf.B_(it->second.listName());
74         else
75                 return _("ERROR: Nonexistent float type!");
76 }
77
78
79 void InsetFloatList::write(Buffer const &, ostream & os) const
80 {
81         os << "FloatList " << to_ascii(getParam("type")) << "\n";
82 }
83
84
85 void InsetFloatList::read(Buffer const & buf, Lexer & lex)
86 {
87         FloatList const & floats = buf.params().getTextClass().floats();
88         string token;
89
90         if (lex.eatLine()) {
91                 setParam("type", lex.getDocString());
92                 LYXERR(Debug::INSETS, "FloatList::float_type: "
93                                       << to_ascii(getParam("type")));
94                 if (!floats.typeExist(to_ascii(getParam("type"))))
95                         lex.printError("InsetFloatList: Unknown float type: `$$Token'");
96         } else {
97                 lex.printError("InsetFloatList: Parse error: `$$Token'");
98         }
99
100         while (lex.isOK()) {
101                 lex.next();
102                 token = lex.getString();
103                 if (token == "\\end_inset")
104                         break;
105         }
106         if (token != "\\end_inset") {
107                 lex.printError("Missing \\end_inset at this point. "
108                                "Read: `$$Token'");
109         }
110 }
111
112
113 int InsetFloatList::latex(Buffer const & buf, odocstream & os,
114                           OutputParams const &) const
115 {
116         FloatList const & floats = buf.params().getTextClass().floats();
117         FloatList::const_iterator cit = floats[to_ascii(getParam("type"))];
118
119         if (cit != floats.end()) {
120                 if (cit->second.builtin()) {
121                         // Only two different types allowed here:
122                         string const type = cit->second.type();
123                         if (type == "table") {
124                                 os << "\\listoftables\n";
125                         } else if (type == "figure") {
126                                 os << "\\listoffigures\n";
127                         } else {
128                                 os << "%% unknown builtin float\n";
129                         }
130                 } else {
131                         os << "\\listof{" << getParam("type") << "}{"
132                            << buf.B_(cit->second.listName()) << "}\n";
133                 }
134         } else {
135                 os << "%%\\listof{" << getParam("type") << "}{"
136                    << bformat(_("List of %1$s"), from_utf8(cit->second.name()))
137                    << "}\n";
138         }
139         return 1;
140 }
141
142
143 int InsetFloatList::plaintext(Buffer const & buffer, odocstream & os,
144                               OutputParams const &) const
145 {
146         os << getScreenLabel(buffer) << "\n\n";
147
148         buffer.tocBackend().writePlaintextTocList(to_ascii(getParam("type")), os);
149
150         return PLAINTEXT_NEWLINE;
151 }
152
153
154 void InsetFloatList::validate(LaTeXFeatures & features) const
155 {
156         features.useFloat(to_ascii(getParam("type")));
157 }
158
159
160 } // namespace lyx