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