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