]> git.lyx.org Git - lyx.git/blob - src/insets/insetfloatlist.C
move floatlist to textclass
[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 "LaTeXFeatures.h"
10 #include "lyxlex.h"
11 #include "frontends/Dialogs.h"
12 #include "frontends/LyXView.h"
13 #include "BufferView.h"
14 #include "buffer.h"
15 #include "toc.h"
16 #include "gettext.h"
17 #include "debug.h"
18
19
20 using std::ostream;
21 using std::endl;
22
23
24 InsetFloatList::InsetFloatList()
25         : InsetCommand(InsetCommandParams())
26 {
27 }
28
29
30 InsetFloatList::InsetFloatList(string const & type)
31         : InsetCommand(InsetCommandParams())
32 {
33         setCmdName(type);
34 }
35
36
37 string const InsetFloatList::getScreenLabel(Buffer const * buf) const
38 {
39         FloatList const & floats = buf->params.getLyXTextClass().floats();
40         FloatList::const_iterator it = floats[getCmdName()];
41         if (it != floats.end())
42                 return _(it->second.listName());
43         else
44                 return _("ERROR: Nonexistent float type!");
45 }
46
47
48 Inset::Code InsetFloatList::lyxCode() const
49 {
50         return Inset::FLOAT_LIST_CODE;
51 }
52
53
54 void InsetFloatList::write(Buffer const *, ostream & os) const
55 {
56         os << "FloatList " << getCmdName() << "\n";
57 }
58
59
60 void InsetFloatList::read(Buffer const * buf, LyXLex & lex)
61 {
62         FloatList const & floats = buf->params.getLyXTextClass().floats();
63         string token;
64
65         if (lex.eatLine()) {
66                 setCmdName(lex.getString());
67                 lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
68                 if (!floats.typeExist(getCmdName()))
69                         lex.printError("InsetFloatList: Unknown float type: `$$Token'");
70         } else
71                 lex.printError("InsetFloatList: Parse error: `$$Token'");
72         while (lex.isOK()) {
73                 lex.nextToken();
74                 token = lex.getString();
75                 if (token == "\\end_inset")
76                         break;
77         }
78         if (token != "\\end_inset") {
79                 lex.printError("Missing \\end_inset at this point. "
80                                "Read: `$$Token'");
81         }
82 }
83
84
85 void InsetFloatList::edit(BufferView * bv, int, int, mouse_button::state)
86 {
87         bv->owner()->getDialogs().showTOC(this);
88 }
89
90
91 void InsetFloatList::edit(BufferView * bv, bool)
92 {
93         edit(bv, 0, 0, mouse_button::none);
94 }
95
96
97 int InsetFloatList::latex(Buffer const * buf, ostream & os, bool, bool) const
98 {
99         FloatList const & floats = buf->params.getLyXTextClass().floats();
100         FloatList::const_iterator cit = floats[getCmdName()];
101
102         if (cit != floats.end()) {
103                 if (cit->second.builtin()) {
104                         // Only two different types allowed here:
105                         string const type = cit->second.type();
106                         if (type == "table") {
107                                 os << "\\listoftables\n";
108                         } else if (type == "figure") {
109                                 os << "\\listoffigures\n";
110                         } else {
111                                 os << "%% unknown builtin float\n";
112                         }
113                 } else {
114                         os << "\\listof{" << getCmdName() << "}{"
115                            << cit->second.listName() << "}\n";
116                 }
117         } else {
118                 os << "%%\\listof{" << getCmdName() << "}{"
119                    << _("List of ") << cit->second.name() << "}\n";
120         }
121         return 1;
122 }
123
124
125 int InsetFloatList::ascii(Buffer const * buffer, ostream & os, int) const
126 {
127         os << getScreenLabel(buffer) << "\n\n";
128
129         toc::asciiTocList(getCmdName(), buffer, os);
130
131         os << "\n";
132         return 0;
133 }
134
135
136 void InsetFloatList::validate(LaTeXFeatures & features) const
137 {
138         features.useFloat(getCmdName());
139 }