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