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