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