]> git.lyx.org Git - lyx.git/blob - src/insets/insetfloatlist.C
Revert this change as it sneaked in and wasn't discussed yet.
[lyx.git] / src / insets / insetfloatlist.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "insetfloatlist.h"
8 #include "FloatList.h"
9 #include "LaTeXFeatures.h"
10 #include "frontends/Dialogs.h"
11 #include "LyXView.h"
12 #include "BufferView.h"
13 #include "buffer.h"
14 #include "gettext.h"
15 #include "debug.h"
16
17
18 using std::ostream;
19 using std::endl;
20
21
22 InsetFloatList::InsetFloatList()
23         : InsetCommand(InsetCommandParams())
24 {
25 }
26
27
28 InsetFloatList::InsetFloatList(string const & type)
29         : InsetCommand(InsetCommandParams())
30 {
31         setCmdName(type);
32 }
33
34
35 string const InsetFloatList::getScreenLabel(Buffer const *) const
36 {
37         FloatList::const_iterator it = floatList[getCmdName()];
38         if (it != floatList.end())
39                 return _(it->second.listName());
40         else
41                 return _("ERROR: Nonexistent float type!");
42 }
43
44
45 Inset::Code InsetFloatList::lyxCode() const
46 {
47         return Inset::FLOAT_LIST_CODE;
48 }
49
50
51 void InsetFloatList::write(Buffer const *, ostream & os) const
52 {
53         os << "FloatList " << getCmdName() << "\n";
54 }
55
56
57 void InsetFloatList::read(Buffer const *, LyXLex & lex)
58 {
59         string token;
60
61         if (lex.eatLine()) {
62                 setCmdName(lex.getString());
63                 lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
64                 if (!floatList.typeExist(getCmdName()))
65                         lex.printError("InsetFloatList: Unknown float type: `$$Token'");
66         } else
67                 lex.printError("InsetFloatList: Parse error: `$$Token'");
68         while (lex.isOK()) {
69                 lex.nextToken();
70                 token = lex.getString();
71                 if (token == "\\end_inset")
72                         break;
73         }
74         if (token != "\\end_inset") {
75                 lex.printError("Missing \\end_inset at this point. "
76                                "Read: `$$Token'");
77         }
78 }
79
80
81 void InsetFloatList::edit(BufferView * bv, int, int, unsigned int)
82 {
83         bv->owner()->getDialogs()->showTOC(this);
84 }
85
86
87 void InsetFloatList::edit(BufferView * bv, bool)
88 {
89         edit(bv, 0, 0, 0);
90 }
91
92
93 int InsetFloatList::latex(Buffer const *, ostream & os, bool, bool) const
94 {
95         FloatList::const_iterator cit = floatList[getCmdName()];
96
97         if (cit != floatList.end()) {
98                 if (cit->second.builtin()) {
99                         // Only two different types allowed here:
100                         string const type = cit->second.type();
101                         if (type == "table") {
102                                 os << "\\listoftables\n";
103                         } else if (type == "figure") {
104                                 os << "\\listoffigures\n";
105                         } else {
106                                 os << "%% unknown builtin float\n";
107                         }
108                 } else {
109                         os << "\\listof{" << getCmdName() << "}{"
110                            << cit->second.listName() << "}\n";
111                 }
112         } else {
113                 os << "%%\\listof{" << getCmdName() << "}{"
114                    << _("List of ") << cit->second.name() << "}\n";
115         }
116         return 1;
117 }
118
119
120 int InsetFloatList::ascii(Buffer const * buffer, ostream & os, int) const
121 {
122         os << getScreenLabel(buffer) << "\n\n";
123
124         Buffer::Lists const toc_list = buffer->getLists();
125         Buffer::Lists::const_iterator cit =
126                 toc_list.find(getCmdName());
127         if (cit != toc_list.end()) {
128                 Buffer::SingleList::const_iterator ccit = cit->second.begin();
129                 Buffer::SingleList::const_iterator end = cit->second.end();
130                 for (; ccit != end; ++ccit)
131                         os << string(4 * ccit->depth, ' ')
132                            << ccit->str << "\n";
133         }
134
135         os << "\n";
136         return 0;
137 }
138
139
140 void InsetFloatList::validate(LaTeXFeatures & features) const
141 {
142         features.useFloat(getCmdName());
143 }