]> git.lyx.org Git - lyx.git/blob - src/insets/insetlabel.C
the update/updateInset merge
[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 "dispatchresult.h"
17 #include "funcrequest.h"
18
19 #include "frontends/LyXView.h"
20
21 #include "support/lstrings.h"
22
23 #include "support/std_ostream.h"
24
25 using lyx::support::escape;
26
27 using std::string;
28 using std::ostream;
29
30
31 InsetLabel::InsetLabel(InsetCommandParams const & p)
32         : InsetCommand(p)
33 {}
34
35
36 InsetLabel::~InsetLabel()
37 {
38         InsetCommandMailer("label", *this).hideDialog();
39 }
40
41
42 std::auto_ptr<InsetBase> InsetLabel::clone() const
43 {
44         return std::auto_ptr<InsetBase>(new InsetLabel(params()));
45 }
46
47
48 void InsetLabel::getLabelList(Buffer const &, std::vector<string> & list) const
49 {
50         list.push_back(getContents());
51 }
52
53
54 string const InsetLabel::getScreenLabel(Buffer const &) const
55 {
56         return getContents();
57 }
58
59
60 DispatchResult
61 InsetLabel::priv_dispatch(FuncRequest const & cmd,
62                           idx_type & idx, pos_type & pos)
63 {
64         BOOST_ASSERT(cmd.view());
65         BufferView * const bv = cmd.view();
66
67         switch (cmd.action) {
68
69         case LFUN_MOUSE_RELEASE:
70                 InsetCommandMailer("label", *this).showDialog(bv);
71                 return DispatchResult(true, true);
72
73         case LFUN_INSET_MODIFY: {
74                 InsetCommandParams p;
75                 InsetCommandMailer::string2params(cmd.argument, p);
76                 if (p.getCmdName().empty())
77                         return DispatchResult(false);
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->update();
87                 return DispatchResult(true, true);
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                       OutputParams const &) const
98 {
99         os << escape(getCommand());
100         return 0;
101 }
102
103
104 int InsetLabel::plaintext(Buffer const &, ostream & os,
105                       OutputParams const &) const
106 {
107         os << '<' << getContents()  << '>';
108         return 0;
109 }
110
111
112 int InsetLabel::linuxdoc(Buffer const &, ostream & os,
113                          OutputParams const &) const
114 {
115         os << "<label id=\"" << getContents() << "\" >";
116         return 0;
117 }
118
119
120 int InsetLabel::docbook(Buffer const &, ostream & os,
121                         OutputParams const &) const
122 {
123         os << "<anchor id=\"" << getContents() << "\">";
124         return 0;
125 }