]> git.lyx.org Git - lyx.git/blob - src/insets/insetlabel.C
3e9ca9ad8fd9406d1bc314147736ce27e0a15725
[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 "BufferView.h"
16 #include "funcrequest.h"
17
18 #include "frontends/LyXView.h"
19
20 #include "support/lstrings.h"
21
22 #include "support/std_ostream.h"
23
24 using lyx::support::escape;
25
26 using std::string;
27 using std::ostream;
28
29
30 InsetLabel::InsetLabel(InsetCommandParams const & p)
31         : InsetCommand(p)
32 {}
33
34
35 InsetLabel::~InsetLabel()
36 {
37         InsetCommandMailer("label", *this).hideDialog();
38 }
39
40
41 std::auto_ptr<InsetBase> InsetLabel::clone() 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 dispatch_result
60 InsetLabel::priv_dispatch(FuncRequest const & cmd,
61                           idx_type & idx, pos_type & pos)
62 {
63         BOOST_ASSERT(cmd.view());
64         BufferView * const bv = cmd.view();
65
66         switch (cmd.action) {
67
68         case LFUN_INSET_EDIT:
69                 InsetCommandMailer("label", *this).showDialog(bv);
70                 return DISPATCHED;
71                 break;
72
73         case LFUN_INSET_MODIFY: {
74                 InsetCommandParams p;
75                 InsetCommandMailer::string2params(cmd.argument, p);
76                 if (p.getCmdName().empty())
77                         return UNDISPATCHED;
78
79                 bool clean = true;
80                 if (bv && p.getContents() != params().getContents()) {
81                         clean = bv->ChangeRefsIfUnique(params().getContents(),
82                                                        p.getContents());
83                 }
84
85                 setParams(p);
86                 bv->updateInset(this);
87                 return DISPATCHED;
88         }
89
90         default:
91                 return InsetCommand::priv_dispatch(cmd, idx, pos);
92         }
93 }
94
95
96 int InsetLabel::latex(Buffer const &, ostream & os,
97                       LatexRunParams const &) const
98 {
99         os << escape(getCommand());
100         return 0;
101 }
102
103
104 int InsetLabel::ascii(Buffer const &, ostream & os, int) const
105 {
106         os << '<' << getContents()  << '>';
107         return 0;
108 }
109
110
111 int InsetLabel::linuxdoc(Buffer const &, ostream & os) const
112 {
113         os << "<label id=\"" << getContents() << "\" >";
114         return 0;
115 }
116
117
118 int InsetLabel::docbook(Buffer const &, ostream & os, bool) const
119 {
120         os << "<anchor id=\"" << getContents() << "\">";
121         return 0;
122 }