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