]> git.lyx.org Git - lyx.git/blob - src/insets/insetfloatlist.C
some reindentation, revert workarea xpos++, constify, remove all traces of LyXParagra...
[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() const 
16 {
17         string const guiName = floatList[float_type]->second.name();
18         if (!guiName.empty()) {
19                 string const res = _("List of ") + guiName;
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 *, 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 #ifdef WITH_WARNINGS
63 #warning Implement me please.
64 #endif
65 #if 0
66         bv->owner()->getDialogs()->showFloatList(this);
67 #endif
68 }
69
70
71 int InsetFloatList::Latex(Buffer const *, ostream & os, bool, bool) const
72 {
73         FloatList::const_iterator cit = floatList[float_type];
74
75         
76         if (cit != floatList.end()) {
77                 if (cit->second.builtin()) {
78                         // Only two different types allowed here:
79                         string const type = cit->second.type();
80                         if (type == "table") {
81                                 os << "\\listoftables\n";
82                         } else if (type == "figure") {
83                                 os << "\\listoffigures\n";
84                         } else {
85                                 os << "%% unknown builtin float\n";
86                         }
87                 } else {
88                         os << "\\listof{" << float_type << "}{"
89                            << _("List of ") << cit->second.name() << "}\n";
90                 }
91         } else {
92                 os << "%%\\listof{" << float_type << "}{"
93                    << _("List of ") << cit->second.name() << "}\n";
94         }
95         return 1;
96 }
97
98
99 int InsetFloatList::Ascii(Buffer const * buffer, std::ostream & os, int) const
100 {
101         os << getScreenLabel() << "\n\n";
102
103         Buffer::Lists const toc_list = buffer->getLists();
104         Buffer::Lists::const_iterator cit =
105                 toc_list.find(float_type);
106         if (cit != toc_list.end()) {
107                 Buffer::SingleList::const_iterator ccit = cit->second.begin();
108                 Buffer::SingleList::const_iterator end = cit->second.end();
109                 for (; ccit != end; ++ccit)
110                         os << string(4 * ccit->depth, ' ')
111                            << ccit->str << "\n";
112         }
113
114         os << "\n";
115         return 0;
116 }