]> git.lyx.org Git - lyx.git/blob - src/insets/insetlabel.C
Remove a whole heap of redundant functions from classes derived from
[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, "label")
33 {}
34
35
36 std::auto_ptr<InsetBase> InsetLabel::clone() const
37 {
38         return std::auto_ptr<InsetBase>(new InsetLabel(params()));
39 }
40
41
42 void InsetLabel::getLabelList(Buffer const &, std::vector<string> & list) const
43 {
44         list.push_back(getContents());
45 }
46
47
48 string const InsetLabel::getScreenLabel(Buffer const &) const
49 {
50         return getContents();
51 }
52
53
54 DispatchResult
55 InsetLabel::priv_dispatch(FuncRequest const & cmd,
56                           idx_type & idx, pos_type & pos)
57 {
58         BOOST_ASSERT(cmd.view());
59         BufferView * const bv = cmd.view();
60
61         switch (cmd.action) {
62
63         case LFUN_INSET_MODIFY: {
64                 InsetCommandParams p;
65                 InsetCommandMailer::string2params("label", cmd.argument, p);
66                 if (p.getCmdName().empty())
67                         return DispatchResult(false);
68
69                 bool clean = true;
70                 if (bv && p.getContents() != params().getContents()) {
71                         clean = bv->ChangeRefsIfUnique(params().getContents(),
72                                                        p.getContents());
73                 }
74
75                 setParams(p);
76                 bv->update();
77                 return DispatchResult(true, true);
78         }
79
80         default:
81                 return InsetCommand::priv_dispatch(cmd, idx, pos);
82         }
83 }
84
85
86 int InsetLabel::latex(Buffer const &, ostream & os,
87                       OutputParams const &) const
88 {
89         os << escape(getCommand());
90         return 0;
91 }
92
93
94 int InsetLabel::plaintext(Buffer const &, ostream & os,
95                       OutputParams const &) const
96 {
97         os << '<' << getContents()  << '>';
98         return 0;
99 }
100
101
102 int InsetLabel::linuxdoc(Buffer const &, ostream & os,
103                          OutputParams const &) const
104 {
105         os << "<label id=\"" << getContents() << "\" >";
106         return 0;
107 }
108
109
110 int InsetLabel::docbook(Buffer const &, ostream & os,
111                         OutputParams const &) const
112 {
113         os << "<anchor id=\"" << getContents() << "\">";
114         return 0;
115 }