]> git.lyx.org Git - lyx.git/blob - src/insets/insetfloatlist.C
Implemented Search/Replace functionality for Insets. Cleaned up a bit.
[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 *, 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 #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 void InsetFloatList::edit(BufferView * bv, bool)
72 {
73         edit(bv, 0, 0, 0);
74 }
75
76
77 int InsetFloatList::latex(Buffer const *, std::ostream & os, bool, bool) const
78 {
79         FloatList::const_iterator cit = floatList[float_type];
80
81         
82         if (cit != floatList.end()) {
83                 if (cit->second.builtin()) {
84                         // Only two different types allowed here:
85                         string const type = cit->second.type();
86                         if (type == "table") {
87                                 os << "\\listoftables\n";
88                         } else if (type == "figure") {
89                                 os << "\\listoffigures\n";
90                         } else {
91                                 os << "%% unknown builtin float\n";
92                         }
93                 } else {
94                         os << "\\listof{" << float_type << "}{"
95                            << _("List of ") << cit->second.name() << "}\n";
96                 }
97         } else {
98                 os << "%%\\listof{" << float_type << "}{"
99                    << _("List of ") << cit->second.name() << "}\n";
100         }
101         return 1;
102 }
103
104
105 int InsetFloatList::ascii(Buffer const * buffer, std::ostream & os, int) const
106 {
107         os << getScreenLabel() << "\n\n";
108
109         Buffer::Lists const toc_list = buffer->getLists();
110         Buffer::Lists::const_iterator cit =
111                 toc_list.find(float_type);
112         if (cit != toc_list.end()) {
113                 Buffer::SingleList::const_iterator ccit = cit->second.begin();
114                 Buffer::SingleList::const_iterator end = cit->second.end();
115                 for (; ccit != end; ++ccit)
116                         os << string(4 * ccit->depth, ' ')
117                            << ccit->str << "\n";
118         }
119
120         os << "\n";
121         return 0;
122 }