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