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