]> git.lyx.org Git - lyx.git/blob - src/insets/insetfloatlist.C
Enable convertDefault.sh to run even if its executable bit is not set.
[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
11 #include <config.h>
12
13 #include "insetfloatlist.h"
14 #include "FloatList.h"
15 #include "metricsinfo.h"
16 #include "LaTeXFeatures.h"
17 #include "lyxlex.h"
18 #include "BufferView.h"
19 #include "funcrequest.h"
20 #include "buffer.h"
21 #include "toc.h"
22 #include "gettext.h"
23 #include "debug.h"
24 #include "Lsstream.h"
25
26 #include "support/lstrings.h"
27
28 using namespace lyx::support;
29
30 using std::ostream;
31 using std::endl;
32
33
34 InsetFloatList::InsetFloatList()
35         : InsetCommand(InsetCommandParams())
36 {}
37
38
39 InsetFloatList::InsetFloatList(string const & type)
40         : InsetCommand(InsetCommandParams())
41 {
42         setCmdName(type);
43 }
44
45
46 InsetFloatList::~InsetFloatList()
47 {
48         InsetCommandMailer mailer("toc", *this);
49         mailer.hideDialog();
50 }
51
52
53 string const InsetFloatList::getScreenLabel(Buffer const & buf) const
54 {
55         FloatList const & floats = buf.params.getLyXTextClass().floats();
56         FloatList::const_iterator it = floats[getCmdName()];
57         if (it != floats.end())
58                 return _(it->second.listName());
59         else
60                 return _("ERROR: Nonexistent float type!");
61 }
62
63
64 InsetOld::Code InsetFloatList::lyxCode() const
65 {
66         return InsetOld::FLOAT_LIST_CODE;
67 }
68
69
70 void InsetFloatList::write(Buffer const &, ostream & os) const
71 {
72         os << "FloatList " << getCmdName() << "\n";
73 }
74
75
76 void InsetFloatList::read(Buffer const & buf, LyXLex & lex)
77 {
78         FloatList const & floats = buf.params.getLyXTextClass().floats();
79         string token;
80
81         if (lex.eatLine()) {
82                 setCmdName(lex.getString());
83                 lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
84                 if (!floats.typeExist(getCmdName()))
85                         lex.printError("InsetFloatList: Unknown float type: `$$Token'");
86         } else
87                 lex.printError("InsetFloatList: Parse error: `$$Token'");
88         while (lex.isOK()) {
89                 lex.nextToken();
90                 token = lex.getString();
91                 if (token == "\\end_inset")
92                         break;
93         }
94         if (token != "\\end_inset") {
95                 lex.printError("Missing \\end_inset at this point. "
96                                "Read: `$$Token'");
97         }
98 }
99
100
101 void InsetFloatList::metrics(MetricsInfo & mi, Dimension & dim) const
102 {
103         InsetCommand::metrics(mi, dim);
104         center_indent_ = (mi.base.textwidth - dim.wid) / 2;
105         dim.wid = mi.base.textwidth;
106         dim_ = dim;
107 }
108
109
110 void InsetFloatList::draw(PainterInfo & pi, int x, int y) const
111 {
112         InsetCommand::draw(pi, x + center_indent_, y);
113 }
114
115
116 dispatch_result InsetFloatList::localDispatch(FuncRequest const & cmd)
117 {
118         switch (cmd.action) {
119                 case LFUN_INSET_EDIT:
120                         InsetCommandMailer("toc", *this).showDialog(cmd.view());
121                         return DISPATCHED;
122                 default:
123                         return InsetCommand::localDispatch(cmd);
124         }
125 }
126
127
128 int InsetFloatList::latex(Buffer const & buf, ostream & os,
129                           LatexRunParams const &) const
130 {
131         FloatList const & floats = buf.params.getLyXTextClass().floats();
132         FloatList::const_iterator cit = floats[getCmdName()];
133
134         if (cit != floats.end()) {
135                 if (cit->second.builtin()) {
136                         // Only two different types allowed here:
137                         string const type = cit->second.type();
138                         if (type == "table") {
139                                 os << "\\listoftables\n";
140                         } else if (type == "figure") {
141                                 os << "\\listoffigures\n";
142                         } else {
143                                 os << "%% unknown builtin float\n";
144                         }
145                 } else {
146                         os << "\\listof{" << getCmdName() << "}{"
147                            << cit->second.listName() << "}\n";
148                 }
149         } else {
150                 os << "%%\\listof{" << getCmdName() << "}{"
151                    << bformat(_("List of %1$s"), cit->second.name())
152                    << "}\n";
153         }
154         return 1;
155 }
156
157
158 int InsetFloatList::ascii(Buffer const & buffer, ostream & os, int) const
159 {
160         os << getScreenLabel(buffer) << "\n\n";
161
162         lyx::toc::asciiTocList(getCmdName(), buffer, os);
163
164         os << "\n";
165         return 0;
166 }
167
168
169 void InsetFloatList::validate(LaTeXFeatures & features) const
170 {
171         features.useFloat(getCmdName());
172 }