]> git.lyx.org Git - lyx.git/blob - src/insets/insetlabel.C
b96d27ef4d8361820cb2f53a65b90a6a63341629
[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_INSET_EDIT:
70                 InsetCommandMailer("label", *this).showDialog(bv);
71                 return DispatchResult(true, true);
72                 break;
73
74         case LFUN_INSET_MODIFY: {
75                 InsetCommandParams p;
76                 InsetCommandMailer::string2params(cmd.argument, p);
77                 if (p.getCmdName().empty())
78                         return DispatchResult(false);
79
80                 bool clean = true;
81                 if (bv && p.getContents() != params().getContents()) {
82                         clean = bv->ChangeRefsIfUnique(params().getContents(),
83                                                        p.getContents());
84                 }
85
86                 setParams(p);
87                 bv->updateInset(this);
88                 return DispatchResult(true, true);
89         }
90
91         default:
92                 return InsetCommand::priv_dispatch(cmd, idx, pos);
93         }
94 }
95
96
97 int InsetLabel::latex(Buffer const &, ostream & os,
98                       LatexRunParams const &) const
99 {
100         os << escape(getCommand());
101         return 0;
102 }
103
104
105 int InsetLabel::ascii(Buffer const &, ostream & os,
106                       LatexRunParams const &) const
107 {
108         os << '<' << getContents()  << '>';
109         return 0;
110 }
111
112
113 int InsetLabel::linuxdoc(Buffer const &, ostream & os,
114                          LatexRunParams const &) const
115 {
116         os << "<label id=\"" << getContents() << "\" >";
117         return 0;
118 }
119
120
121 int InsetLabel::docbook(Buffer const &, ostream & os,
122                         LatexRunParams const &) const
123 {
124         os << "<anchor id=\"" << getContents() << "\">";
125         return 0;
126 }