]> git.lyx.org Git - lyx.git/blob - src/insets/insetfloatlist.C
toc support reorganization; changes to xform_helpers; aspect ratio patch from herbert
[lyx.git] / src / insets / insetfloatlist.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "insetfloatlist.h"
8 #include "FloatList.h"
9 #include "LaTeXFeatures.h"
10 #include "lyxlex.h"
11 #include "frontends/Dialogs.h"
12 #include "frontends/LyXView.h"
13 #include "BufferView.h"
14 #include "toc.h"
15 #include "gettext.h"
16 #include "debug.h"
17
18
19 using std::ostream;
20 using std::endl;
21
22
23 InsetFloatList::InsetFloatList()
24         : InsetCommand(InsetCommandParams())
25 {
26 }
27
28
29 InsetFloatList::InsetFloatList(string const & type)
30         : InsetCommand(InsetCommandParams())
31 {
32         setCmdName(type);
33 }
34
35
36 string const InsetFloatList::getScreenLabel(Buffer const *) const
37 {
38         FloatList::const_iterator it = floatList[getCmdName()];
39         if (it != floatList.end())
40                 return _(it->second.listName());
41         else
42                 return _("ERROR: Nonexistent float type!");
43 }
44
45
46 Inset::Code InsetFloatList::lyxCode() const
47 {
48         return Inset::FLOAT_LIST_CODE;
49 }
50
51
52 void InsetFloatList::write(Buffer const *, ostream & os) const
53 {
54         os << "FloatList " << getCmdName() << "\n";
55 }
56
57
58 void InsetFloatList::read(Buffer const *, LyXLex & lex)
59 {
60         string token;
61
62         if (lex.eatLine()) {
63                 setCmdName(lex.getString());
64                 lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
65                 if (!floatList.typeExist(getCmdName()))
66                         lex.printError("InsetFloatList: Unknown float type: `$$Token'");
67         } else
68                 lex.printError("InsetFloatList: Parse error: `$$Token'");
69         while (lex.isOK()) {
70                 lex.nextToken();
71                 token = lex.getString();
72                 if (token == "\\end_inset")
73                         break;
74         }
75         if (token != "\\end_inset") {
76                 lex.printError("Missing \\end_inset at this point. "
77                                "Read: `$$Token'");
78         }
79 }
80
81
82 void InsetFloatList::edit(BufferView * bv, int, int, mouse_button::state)
83 {
84         bv->owner()->getDialogs()->showTOC(this);
85 }
86
87
88 void InsetFloatList::edit(BufferView * bv, bool)
89 {
90         edit(bv, 0, 0, mouse_button::none);
91 }
92
93
94 int InsetFloatList::latex(Buffer const *, ostream & os, bool, bool) const
95 {
96         FloatList::const_iterator cit = floatList[getCmdName()];
97
98         if (cit != floatList.end()) {
99                 if (cit->second.builtin()) {
100                         // Only two different types allowed here:
101                         string const type = cit->second.type();
102                         if (type == "table") {
103                                 os << "\\listoftables\n";
104                         } else if (type == "figure") {
105                                 os << "\\listoffigures\n";
106                         } else {
107                                 os << "%% unknown builtin float\n";
108                         }
109                 } else {
110                         os << "\\listof{" << getCmdName() << "}{"
111                            << cit->second.listName() << "}\n";
112                 }
113         } else {
114                 os << "%%\\listof{" << getCmdName() << "}{"
115                    << _("List of ") << cit->second.name() << "}\n";
116         }
117         return 1;
118 }
119
120
121 int InsetFloatList::ascii(Buffer const * buffer, ostream & os, int) const
122 {
123         os << getScreenLabel(buffer) << "\n\n";
124
125         toc::asciiTocList(getCmdName(), buffer, os);
126
127         os << "\n";
128         return 0;
129 }
130
131
132 void InsetFloatList::validate(LaTeXFeatures & features) const
133 {
134         features.useFloat(getCmdName());
135 }