]> git.lyx.org Git - lyx.git/blob - src/insets/InsetLabel.cpp
header cleanup.
[lyx.git] / src / insets / InsetLabel.cpp
1 /**
2  * \file InsetLabel.cpp
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 "InsetLabel.h"
14
15 #include "Buffer.h"
16 #include "BufferView.h"
17 #include "DispatchResult.h"
18 #include "FuncRequest.h"
19 #include "Text.h"
20 #include "sgml.h"
21
22 #include "support/lstrings.h"
23 #include "support/lyxalgo.h"
24
25
26 namespace lyx {
27
28 using support::escape;
29
30 using std::string;
31 using std::vector;
32
33
34 InsetLabel::InsetLabel(InsetCommandParams const & p)
35         : InsetCommand(p, "label")
36 {}
37
38
39 std::auto_ptr<Inset> InsetLabel::doClone() const
40 {
41         return std::auto_ptr<Inset>(new InsetLabel(params()));
42 }
43
44
45 void InsetLabel::getLabelList(Buffer const &, std::vector<docstring> & list) const
46 {
47         list.push_back(getParam("name"));
48 }
49
50
51 docstring const InsetLabel::getScreenLabel(Buffer const &) const
52 {
53         return getParam("name");
54 }
55
56
57 void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
58 {
59         switch (cmd.action) {
60
61         case LFUN_INSET_MODIFY: {
62                 InsetCommandParams p("label");
63                 // FIXME UNICODE
64                 InsetCommandMailer::string2params("label", to_utf8(cmd.argument()), p);
65                 if (p.getCmdName().empty()) {
66                         cur.noUpdate();
67                         break;
68                 }
69                 if (p["name"] != params()["name"])
70                         cur.bv().buffer()->changeRefsIfUnique(params()["name"],
71                                         p["name"], Inset::REF_CODE);
72                 setParams(p);
73                 break;
74         }
75
76         default:
77                 InsetCommand::doDispatch(cur, cmd);
78                 break;
79         }
80 }
81
82
83 int InsetLabel::latex(Buffer const &, odocstream & os,
84                       OutputParams const &) const
85 {
86         os << escape(getCommand());
87         return 0;
88 }
89
90
91 int InsetLabel::plaintext(Buffer const &, odocstream & os,
92                           OutputParams const &) const
93 {
94         docstring const str = getParam("name");
95         os << '<' << str << '>';
96         return 2 + str.size();
97 }
98
99
100 int InsetLabel::docbook(Buffer const & buf, odocstream & os,
101                         OutputParams const & runparams) const
102 {
103         os << "<!-- anchor id=\""
104            << sgml::cleanID(buf, runparams, getParam("name"))
105            << "\" -->";
106         return 0;
107 }
108
109
110 } // namespace lyx