]> git.lyx.org Git - lyx.git/blob - src/insets/insetlabel.C
*** empty log message ***
[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 void InsetLabel::edit(BufferView *, int, int, mouse_button::state)
49 {
50         InsetCommandMailer mailer("label", *this);
51         mailer.showDialog();
52 }
53
54
55 dispatch_result InsetLabel::localDispatch(FuncRequest const & cmd)
56 {
57         if (cmd.action != LFUN_INSET_APPLY)
58                 return UNDISPATCHED;
59
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()->ChangeCitationsIfUnique(params().getContents(),
68                                                         p.getContents());
69         }
70
71         setParams(p);
72         if (view())
73                 view()->updateInset(this, !clean);
74
75         return DISPATCHED;
76 //      if (result.first) {
77 //              string new_contents = trim(result.second);
78 //              if (!new_contents.empty() &&
79 //                  getContents() != new_contents) {
80 //                      bv->buffer()->markDirty();
81 //                      bool flag = bv->ChangeRefsIfUnique(getContents(),
82 //                                                         new_contents);
83 //                      setContents(new_contents);
84 //                      bv->updateInset(this, !flag);
85 //              }
86 //      }
87 }
88
89
90 void InsetLabel::edit(BufferView * bv, bool)
91 {
92         edit(bv, 0, 0, mouse_button::none);
93 }
94
95
96 int InsetLabel::latex(Buffer const *, ostream & os,
97                       bool /*fragile*/, bool /*fs*/) const
98 {
99         os << escape(getCommand());
100         return 0;
101 }
102
103 int InsetLabel::ascii(Buffer const *, ostream & os, int) const
104 {
105         os << '<' << getContents()  << '>';
106         return 0;
107 }
108
109
110 int InsetLabel::linuxdoc(Buffer const *, ostream & os) const
111 {
112         os << "<label id=\"" << getContents() << "\" >";
113         return 0;
114 }
115
116
117 int InsetLabel::docbook(Buffer const *, ostream & os, bool) const
118 {
119         os << "<anchor id=\"" << getContents() << "\">";
120         return 0;
121 }