]> git.lyx.org Git - lyx.git/blob - src/insets/insetlabel.C
ac056649d781e79c458a62d6fc7e3d19bbf6955b
[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 InsetLabel::localDispatch(FuncRequest const & cmd)
60 {
61         BOOST_ASSERT(cmd.view());
62         BufferView * const bv = cmd.view();
63
64         switch (cmd.action) {
65
66         case LFUN_INSET_EDIT:
67                 InsetCommandMailer("label", *this).showDialog(bv);
68                 return DISPATCHED;
69                 break;
70
71         case LFUN_INSET_MODIFY: {
72                 InsetCommandParams p;
73                 InsetCommandMailer::string2params(cmd.argument, p);
74                 if (p.getCmdName().empty())
75                         return UNDISPATCHED;
76
77                 bool clean = true;
78                 if (bv && p.getContents() != params().getContents()) {
79                         clean = bv->ChangeRefsIfUnique(params().getContents(),
80                                                        p.getContents());
81                 }
82
83                 setParams(p);
84                 bv->updateInset(this);
85                 return DISPATCHED;
86         }
87
88         default:
89                 return InsetCommand::localDispatch(cmd);
90         }
91 }
92
93
94 int InsetLabel::latex(Buffer const &, ostream & os,
95                       LatexRunParams const &) const
96 {
97         os << escape(getCommand());
98         return 0;
99 }
100
101
102 int InsetLabel::ascii(Buffer const &, ostream & os, int) const
103 {
104         os << '<' << getContents()  << '>';
105         return 0;
106 }
107
108
109 int InsetLabel::linuxdoc(Buffer const &, ostream & os) const
110 {
111         os << "<label id=\"" << getContents() << "\" >";
112         return 0;
113 }
114
115
116 int InsetLabel::docbook(Buffer const &, ostream & os, bool) const
117 {
118         os << "<anchor id=\"" << getContents() << "\">";
119         return 0;
120 }