]> git.lyx.org Git - lyx.git/blob - src/insets/insetfloatlist.C
outstanding changes
[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 "buffer.h"
10 #include "gettext.h"
11 #include "debug.h"
12
13 using std::endl;
14
15 string const InsetFloatList::getScreenLabel(Buffer const *) const 
16 {
17         string const guiName = floatList[float_type]->second.name();
18         if (!guiName.empty()) {
19                 string const res = guiName + _(" List");
20                 return res;
21         }
22         return _("ERROR nonexistant float type!");
23 }
24
25
26 Inset::Code InsetFloatList::lyxCode() const
27 {
28         return Inset::FLOAT_LIST_CODE;
29 }
30
31
32 void InsetFloatList::write(Buffer const *, std::ostream & os) const
33 {
34         os << "FloatList " << float_type << "\n";
35 }
36
37
38 void InsetFloatList::read(Buffer const *, LyXLex & lex) 
39 {
40         string token;
41
42         if (lex.eatLine()) {
43                 float_type = lex.getString();
44                 lyxerr << "FloatList::float_type: " << float_type << endl;
45         } else
46                 lex.printError("InsetFloatList: Parse error: `$$Token'");
47         while (lex.isOK()) {
48                 lex.nextToken();
49                 token = lex.getString();
50                 if (token == "\\end_inset")
51                         break;
52         }
53         if (token != "\\end_inset") {
54                 lex.printError("Missing \\end_inset at this point. "
55                                "Read: `$$Token'");
56         }
57 }
58
59
60 void InsetFloatList::edit(BufferView *, int, int, unsigned int)
61 {
62         // FIX: Implement me please.
63 #if 0
64         bv->owner()->getDialogs()->showFloatList(this);
65 #endif
66 }
67
68
69 void InsetFloatList::edit(BufferView * bv, bool)
70 {
71         edit(bv, 0, 0, 0);
72 }
73
74
75 int InsetFloatList::latex(Buffer const *, std::ostream & os, bool, bool) const
76 {
77         FloatList::const_iterator cit = floatList[float_type];
78
79         
80         if (cit != floatList.end()) {
81                 if (cit->second.builtin()) {
82                         // Only two different types allowed here:
83                         string const type = cit->second.type();
84                         if (type == "table") {
85                                 os << "\\listoftables\n";
86                         } else if (type == "figure") {
87                                 os << "\\listoffigures\n";
88                         } else {
89                                 os << "%% unknown builtin float\n";
90                         }
91                 } else {
92                         os << "\\listof{" << float_type << "}{"
93                            << _("List of ") << cit->second.name() << "}\n";
94                 }
95         } else {
96                 os << "%%\\listof{" << float_type << "}{"
97                    << _("List of ") << cit->second.name() << "}\n";
98         }
99         return 1;
100 }
101
102
103 int InsetFloatList::ascii(Buffer const * buffer, std::ostream & os, int) const
104 {
105         os << getScreenLabel(buffer) << "\n\n";
106
107         Buffer::Lists const toc_list = buffer->getLists();
108         Buffer::Lists::const_iterator cit =
109                 toc_list.find(float_type);
110         if (cit != toc_list.end()) {
111                 Buffer::SingleList::const_iterator ccit = cit->second.begin();
112                 Buffer::SingleList::const_iterator end = cit->second.end();
113                 for (; ccit != end; ++ccit)
114                         os << string(4 * ccit->depth, ' ')
115                            << ccit->str << "\n";
116         }
117
118         os << "\n";
119         return 0;
120 }