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