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