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