]> git.lyx.org Git - lyx.git/blob - src/insets/insetlabel.C
* src/LyXAction.C: mark goto-clear-bookmark as working without buffer
[lyx.git] / src / insets / insetlabel.C
1 /**
2  * \file insetlabel.C
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 "InsetList.h"
20 #include "lyxtext.h"
21 #include "paragraph.h"
22 #include "pariterator.h"
23 #include "sgml.h"
24
25 #include "support/lstrings.h"
26 #include "support/lyxalgo.h"
27 #include "support/std_ostream.h"
28
29
30 namespace lyx {
31
32 using support::escape;
33
34 using std::string;
35 using std::ostream;
36 using std::vector;
37
38
39 InsetLabel::InsetLabel(InsetCommandParams const & p)
40         : InsetCommand(p, "label")
41 {}
42
43
44 std::auto_ptr<InsetBase> InsetLabel::doClone() const
45 {
46         return std::auto_ptr<InsetBase>(new InsetLabel(params()));
47 }
48
49
50 void InsetLabel::getLabelList(Buffer const &, std::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(LCursor & cur, FuncRequest & cmd)
63 {
64         switch (cmd.action) {
65
66         case LFUN_INSET_MODIFY: {
67                 InsetCommandParams p("label");
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"], InsetBase::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 << escape(getCommand());
92         return 0;
93 }
94
95
96 int InsetLabel::plaintext(Buffer const &, odocstream & os,
97                       OutputParams const &) const
98 {
99         os << '<' << getParam("name") << '>';
100         return 0;
101 }
102
103
104 int InsetLabel::docbook(Buffer const & buf, odocstream & os,
105                         OutputParams const & runparams) const
106 {
107         os << "<!-- anchor id=\""
108            << sgml::cleanID(buf, runparams, getParam("name"))
109            << "\" -->";
110         return 0;
111 }
112
113
114 } // namespace lyx