]> git.lyx.org Git - lyx.git/blob - src/insets/insetlabel.C
Collapse all those LFUN_XYZ_APPLY to a single LFUN_INSET_APPLY.
[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 "support/LOstream.h"
16 #include "frontends/Alert.h"
17 #include "support/lstrings.h" //frontStrip, strip
18 #include "lyxtext.h"
19 #include "buffer.h"
20 #include "gettext.h"
21 #include "BufferView.h"
22 #include "support/lstrings.h"
23
24 using std::ostream;
25 using std::vector;
26 using std::pair;
27
28 /* Label. Used to insert a label automatically */
29
30
31 InsetLabel::InsetLabel(InsetCommandParams const & p, bool)
32         : InsetCommand(p)
33 {}
34
35
36 vector<string> const InsetLabel::getLabelList() const
37 {
38         return vector<string>(1, getContents());
39 }
40
41
42 void InsetLabel::edit(BufferView * bv, int, int, mouse_button::state)
43 {
44         pair<bool, string> result = Alert::askForText(_("Enter label:"), getContents());
45         if (result.first) {
46                 string new_contents = trim(result.second);
47                 if (!new_contents.empty() &&
48                     getContents() != new_contents) {
49                         bv->buffer()->markDirty();
50                         bool flag = bv->ChangeRefsIfUnique(getContents(),
51                                                            new_contents);
52                         setContents(new_contents);
53 #if 0
54                         bv->text->redoParagraph(bv);
55                         if (flag) {
56                                 bv->redraw();
57                                 bv->fitCursor();
58                         } else
59                                 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
60 #else
61                         bv->updateInset(this, !flag);
62 #endif
63                 }
64         }
65 }
66
67
68 void InsetLabel::edit(BufferView * bv, bool)
69 {
70         edit(bv, 0, 0, mouse_button::none);
71 }
72
73
74 int InsetLabel::latex(Buffer const *, ostream & os,
75                       bool /*fragile*/, bool /*fs*/) const
76 {
77         os << escape(getCommand());
78         return 0;
79 }
80
81 int InsetLabel::ascii(Buffer const *, ostream & os, int) const
82 {
83         os << '<' << getContents()  << '>';
84         return 0;
85 }
86
87
88 int InsetLabel::linuxdoc(Buffer const *, ostream & os) const
89 {
90         os << "<label id=\"" << getContents() << "\" >";
91         return 0;
92 }
93
94
95 int InsetLabel::docbook(Buffer const *, ostream & os, bool) const
96 {
97         os << "<anchor id=\"" << getContents() << "\">";
98         return 0;
99 }