]> git.lyx.org Git - lyx.git/blob - src/insets/insetfloatlist.C
layout as string
[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 "frontends/Dialogs.h"
10 #include "LyXView.h"
11 #include "BufferView.h"
12 #include "buffer.h"
13 #include "gettext.h"
14 #include "debug.h"
15
16
17 using std::ostream;
18 using std::endl;
19
20
21 InsetFloatList::InsetFloatList()
22         : InsetCommand(InsetCommandParams())
23 {
24 }
25
26  
27 InsetFloatList::InsetFloatList(string const & type)
28         : InsetCommand(InsetCommandParams())
29 {
30         setCmdName(type);
31 }
32
33
34 string const InsetFloatList::getScreenLabel(Buffer const *) const 
35 {
36         string const guiName = floatList[getCmdName()]->second.name();
37         if (!guiName.empty()) {
38                 string const res = guiName + _(" List");
39                 return res;
40         }
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 << "FloatList::float_type: " << getCmdName() << endl;
64         } else
65                 lex.printError("InsetFloatList: Parse error: `$$Token'");
66         while (lex.isOK()) {
67                 lex.nextToken();
68                 token = lex.getString();
69                 if (token == "\\end_inset")
70                         break;
71         }
72         if (token != "\\end_inset") {
73                 lex.printError("Missing \\end_inset at this point. "
74                                "Read: `$$Token'");
75         }
76 }
77
78
79 void InsetFloatList::edit(BufferView * bv, int, int, unsigned int)
80 {
81         bv->owner()->getDialogs()->showTOC(this);
82 }
83
84
85 void InsetFloatList::edit(BufferView * bv, bool)
86 {
87         edit(bv, 0, 0, 0);
88 }
89
90
91 int InsetFloatList::latex(Buffer const *, ostream & os, bool, bool) const
92 {
93         FloatList::const_iterator cit = floatList[getCmdName()];
94
95         if (cit != floatList.end()) {
96                 if (cit->second.builtin()) {
97                         // Only two different types allowed here:
98                         string const type = cit->second.type();
99                         if (type == "table") {
100                                 os << "\\listoftables\n";
101                         } else if (type == "figure") {
102                                 os << "\\listoffigures\n";
103                         } else {
104                                 os << "%% unknown builtin float\n";
105                         }
106                 } else {
107                         os << "\\listof{" << getCmdName() << "}{"
108                            << _("List of ") << cit->second.name() << "}\n";
109                 }
110         } else {
111                 os << "%%\\listof{" << getCmdName() << "}{"
112                    << _("List of ") << cit->second.name() << "}\n";
113         }
114         return 1;
115 }
116
117
118 int InsetFloatList::ascii(Buffer const * buffer, ostream & os, int) const
119 {
120         os << getScreenLabel(buffer) << "\n\n";
121
122         Buffer::Lists const toc_list = buffer->getLists();
123         Buffer::Lists::const_iterator cit =
124                 toc_list.find(getCmdName());
125         if (cit != toc_list.end()) {
126                 Buffer::SingleList::const_iterator ccit = cit->second.begin();
127                 Buffer::SingleList::const_iterator end = cit->second.end();
128                 for (; ccit != end; ++ccit)
129                         os << string(4 * ccit->depth, ' ')
130                            << ccit->str << "\n";
131         }
132
133         os << "\n";
134         return 0;
135 }