]> git.lyx.org Git - lyx.git/blob - src/insets/insetlabel.C
a310f30d83d2fb6bfbac128e4f133939f61c1f29
[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 "support/lstrings.h"
19
20 #include "support/std_ostream.h"
21
22 using lyx::support::escape;
23
24 using std::string;
25 using std::ostream;
26
27
28 InsetLabel::InsetLabel(InsetCommandParams const & p)
29         : InsetCommand(p)
30 {}
31
32
33 InsetLabel::~InsetLabel()
34 {
35         InsetCommandMailer("label", *this).hideDialog();
36 }
37
38
39 void InsetLabel::getLabelList(Buffer const &, std::vector<string> & list) const
40 {
41         list.push_back(getContents());
42 }
43
44
45 dispatch_result InsetLabel::localDispatch(FuncRequest const & cmd)
46 {
47         switch (cmd.action) {
48
49         case LFUN_INSET_EDIT:
50                 InsetCommandMailer("label", *this).showDialog(cmd.view());
51                 return DISPATCHED;
52                 break;
53
54         case LFUN_INSET_MODIFY: {
55                 InsetCommandParams p;
56                 InsetCommandMailer::string2params(cmd.argument, p);
57                 if (p.getCmdName().empty())
58                         return UNDISPATCHED;
59
60                 bool clean = true;
61                 if (view() && p.getContents() != params().getContents()) {
62                         clean = view()->ChangeRefsIfUnique(params().getContents(),
63                                                            p.getContents());
64                 }
65
66                 setParams(p);
67                 cmd.view()->updateInset(this);
68                 return DISPATCHED;
69         }
70
71         default:
72                 return InsetCommand::localDispatch(cmd);
73         }
74 }
75
76
77 int InsetLabel::latex(Buffer const &, ostream & os,
78                       LatexRunParams const &) const
79 {
80         os << escape(getCommand());
81         return 0;
82 }
83
84
85 int InsetLabel::ascii(Buffer const &, ostream & os, int) const
86 {
87         os << '<' << getContents()  << '>';
88         return 0;
89 }
90
91
92 int InsetLabel::linuxdoc(Buffer const &, ostream & os) const
93 {
94         os << "<label id=\"" << getContents() << "\" >";
95         return 0;
96 }
97
98
99 int InsetLabel::docbook(Buffer const &, ostream & os, bool) const
100 {
101         os << "<anchor id=\"" << getContents() << "\">";
102         return 0;
103 }