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