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