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