]> git.lyx.org Git - lyx.git/blob - src/insets/insetlabel.C
Don't remove cell selections after fontchange.
[lyx.git] / src / insets / insetlabel.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1995 Matthias Ettrich
7  *          Copyright 1995-2001 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "insetlabel.h"
18 #include "support/LOstream.h"
19 #include "frontends/Alert.h"
20 #include "support/lstrings.h" //frontStrip, strip
21 #include "lyxtext.h"
22 #include "buffer.h"
23 #include "gettext.h"
24 #include "BufferView.h"
25 #include "support/lstrings.h"
26
27 using std::ostream;
28 using std::vector;
29 using std::pair;
30
31 /* Label. Used to insert a label automatically */
32
33
34 InsetLabel::InsetLabel(InsetCommandParams const & p, bool)
35         : InsetCommand(p)
36 {}
37
38
39 vector<string> const InsetLabel::getLabelList() const
40 {
41         return vector<string>(1, getContents());
42 }
43
44
45 void InsetLabel::edit(BufferView * bv, int, int, unsigned int)
46 {
47         pair<bool, string> result = Alert::askForText(_("Enter label:"), getContents());
48         if (result.first) {
49                 string new_contents = frontStrip(strip(result.second));
50                 if (!new_contents.empty() &&
51                     getContents() != new_contents) {
52                         bv->buffer()->markDirty();
53                         bool flag = bv->ChangeRefsIfUnique(getContents(),
54                                                            new_contents);
55                         setContents(new_contents);
56                         bv->text->redoParagraph(bv);
57                         if (flag) {
58                                 bv->redraw();
59                                 bv->fitCursor();
60                         } else
61                                 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
62                 }
63         }
64 }
65
66
67 void InsetLabel::edit(BufferView * bv, bool)
68 {
69         edit(bv, 0, 0, 0);
70 }
71
72
73 int InsetLabel::latex(Buffer const *, ostream & os,
74                       bool /*fragile*/, bool /*fs*/) const
75 {
76         os << escape(getCommand());
77         return 0;
78 }
79
80 int InsetLabel::ascii(Buffer const *, ostream & os, int) const
81 {
82         os << "<" << getContents()  << ">";
83         return 0;
84 }
85
86
87 int InsetLabel::linuxdoc(Buffer const *, ostream & os) const
88 {
89         os << "<label id=\"" << getContents() << "\" >";
90         return 0;
91 }
92
93
94 int InsetLabel::docbook(Buffer const *, ostream & os) const
95 {
96         os << "<anchor id=\"" << getContents() << "\" ></anchor>";
97         return 0;
98 }