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