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