]> git.lyx.org Git - lyx.git/blob - src/insets/insetfloatlist.C
Purely mechanical: move fragile into LatexRunParams.
[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 "LaTeXFeatures.h"
16 #include "lyxlex.h"
17 #include "BufferView.h"
18 #include "funcrequest.h"
19 #include "buffer.h"
20 #include "toc.h"
21 #include "gettext.h"
22 #include "debug.h"
23 #include "Lsstream.h"
24
25 #include "support/lstrings.h"
26
27 using std::ostream;
28 using std::endl;
29
30
31 InsetFloatList::InsetFloatList()
32         : InsetCommand(InsetCommandParams())
33 {}
34
35
36 InsetFloatList::InsetFloatList(string const & type)
37         : InsetCommand(InsetCommandParams())
38 {
39         setCmdName(type);
40 }
41
42
43 InsetFloatList::~InsetFloatList()
44 {
45         InsetCommandMailer mailer("toc", *this);
46         mailer.hideDialog();
47 }
48
49
50 string const InsetFloatList::getScreenLabel(Buffer const * buf) const
51 {
52         FloatList const & floats = buf->params.getLyXTextClass().floats();
53         FloatList::const_iterator it = floats[getCmdName()];
54         if (it != floats.end())
55                 return _(it->second.listName());
56         else
57                 return _("ERROR: Nonexistent float type!");
58 }
59
60
61 Inset::Code InsetFloatList::lyxCode() const
62 {
63         return Inset::FLOAT_LIST_CODE;
64 }
65
66
67 void InsetFloatList::write(Buffer const *, ostream & os) const
68 {
69         os << "FloatList " << getCmdName() << "\n";
70 }
71
72
73 void InsetFloatList::read(Buffer const * buf, LyXLex & lex)
74 {
75         FloatList const & floats = buf->params.getLyXTextClass().floats();
76         string token;
77
78         if (lex.eatLine()) {
79                 setCmdName(lex.getString());
80                 lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
81                 if (!floats.typeExist(getCmdName()))
82                         lex.printError("InsetFloatList: Unknown float type: `$$Token'");
83         } else
84                 lex.printError("InsetFloatList: Parse error: `$$Token'");
85         while (lex.isOK()) {
86                 lex.nextToken();
87                 token = lex.getString();
88                 if (token == "\\end_inset")
89                         break;
90         }
91         if (token != "\\end_inset") {
92                 lex.printError("Missing \\end_inset at this point. "
93                                "Read: `$$Token'");
94         }
95 }
96
97
98 dispatch_result InsetFloatList::localDispatch(FuncRequest const & cmd)
99 {
100         switch (cmd.action) {
101                 case LFUN_INSET_EDIT:
102                         InsetCommandMailer("toc", *this).showDialog(cmd.view());
103                         return DISPATCHED;
104                 default:
105                         return InsetCommand::localDispatch(cmd);
106         }
107 }
108
109
110 int InsetFloatList::latex(Buffer const * buf, ostream & os,
111                           LatexRunParams const &,
112                           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                 os << "%%\\listof{" << getCmdName() << "}{"
134                    << bformat(_("List of %1$s"), cit->second.name())
135                    << "}\n";
136         }
137         return 1;
138 }
139
140
141 int InsetFloatList::ascii(Buffer const * buffer, ostream & os, int) const
142 {
143         os << getScreenLabel(buffer) << "\n\n";
144
145         toc::asciiTocList(getCmdName(), buffer, os);
146
147         os << "\n";
148         return 0;
149 }
150
151
152 void InsetFloatList::validate(LaTeXFeatures & features) const
153 {
154         features.useFloat(getCmdName());
155 }