]> git.lyx.org Git - lyx.git/blob - src/insets/insetfloatlist.C
The speed patch: redraw only rows that have changed
[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
15 #include "buffer.h"
16 #include "bufferparams.h"
17 #include "debug.h"
18 #include "dispatchresult.h"
19 #include "Floating.h"
20 #include "FloatList.h"
21 #include "funcrequest.h"
22 #include "gettext.h"
23 #include "LaTeXFeatures.h"
24 #include "lyxlex.h"
25 #include "metricsinfo.h"
26 #include "toc.h"
27
28 #include "support/lstrings.h"
29
30 using lyx::support::bformat;
31
32 using std::endl;
33 using std::string;
34 using std::ostream;
35
36
37 InsetFloatList::InsetFloatList()
38         : InsetCommand(InsetCommandParams(), "toc")
39 {}
40
41
42 InsetFloatList::InsetFloatList(string const & type)
43         : InsetCommand(InsetCommandParams(), "toc")
44 {
45         setCmdName(type);
46 }
47
48
49 string const InsetFloatList::getScreenLabel(Buffer const & buf) const
50 {
51         FloatList const & floats = buf.params().getLyXTextClass().floats();
52         FloatList::const_iterator it = floats[getCmdName()];
53         if (it != floats.end())
54                 return buf.B_(it->second.listName());
55         else
56                 return _("ERROR: Nonexistent float type!");
57 }
58
59
60 InsetBase::Code InsetFloatList::lyxCode() const
61 {
62         return InsetBase::FLOAT_LIST_CODE;
63 }
64
65
66 void InsetFloatList::write(Buffer const &, ostream & os) const
67 {
68         os << "FloatList " << getCmdName() << "\n";
69 }
70
71
72 void InsetFloatList::read(Buffer const & buf, LyXLex & lex)
73 {
74         FloatList const & floats = buf.params().getLyXTextClass().floats();
75         string token;
76
77         if (lex.eatLine()) {
78                 setCmdName(lex.getString());
79                 lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
80                 if (!floats.typeExist(getCmdName()))
81                         lex.printError("InsetFloatList: Unknown float type: `$$Token'");
82         } else
83                 lex.printError("InsetFloatList: Parse error: `$$Token'");
84         while (lex.isOK()) {
85                 lex.next();
86                 token = lex.getString();
87                 if (token == "\\end_inset")
88                         break;
89         }
90         if (token != "\\end_inset") {
91                 lex.printError("Missing \\end_inset at this point. "
92                                "Read: `$$Token'");
93         }
94 }
95
96
97 int InsetFloatList::latex(Buffer const & buf, ostream & os,
98                           OutputParams const &) const
99 {
100         FloatList const & floats = buf.params().getLyXTextClass().floats();
101         FloatList::const_iterator cit = floats[getCmdName()];
102
103         if (cit != floats.end()) {
104                 if (cit->second.builtin()) {
105                         // Only two different types allowed here:
106                         string const type = cit->second.type();
107                         if (type == "table") {
108                                 os << "\\listoftables\n";
109                         } else if (type == "figure") {
110                                 os << "\\listoffigures\n";
111                         } else {
112                                 os << "%% unknown builtin float\n";
113                         }
114                 } else {
115                         os << "\\listof{" << getCmdName() << "}{"
116                            << buf.B_(cit->second.listName()) << "}\n";
117                 }
118         } else {
119                 os << "%%\\listof{" << getCmdName() << "}{"
120                    << bformat(_("List of %1$s"), cit->second.name())
121                    << "}\n";
122         }
123         return 1;
124 }
125
126
127 int InsetFloatList::plaintext(Buffer const & buffer, ostream & os, OutputParams const &) const
128 {
129         os << getScreenLabel(buffer) << "\n\n";
130
131         lyx::toc::asciiTocList(getCmdName(), buffer, os);
132
133         os << "\n";
134         return 0;
135 }
136
137
138 void InsetFloatList::validate(LaTeXFeatures & features) const
139 {
140         features.useFloat(getCmdName());
141 }