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