]> git.lyx.org Git - lyx.git/blob - src/insets/insetlabel.C
layout as string
[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 #if 0
57                         bv->text->redoParagraph(bv);
58                         if (flag) {
59                                 bv->redraw();
60                                 bv->fitCursor();
61                         } else
62                                 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
63 #else
64                         bv->updateInset(this, !flag);
65 #endif
66                 }
67         }
68 }
69
70
71 void InsetLabel::edit(BufferView * bv, bool)
72 {
73         edit(bv, 0, 0, 0);
74 }
75
76
77 int InsetLabel::latex(Buffer const *, ostream & os,
78                       bool /*fragile*/, bool /*fs*/) const
79 {
80         os << escape(getCommand());
81         return 0;
82 }
83
84 int InsetLabel::ascii(Buffer const *, ostream & os, int) const
85 {
86         os << "<" << getContents()  << ">";
87         return 0;
88 }
89
90
91 int InsetLabel::linuxdoc(Buffer const *, ostream & os) const
92 {
93         os << "<label id=\"" << getContents() << "\" >";
94         return 0;
95 }
96
97
98 int InsetLabel::docbook(Buffer const *, ostream & os) const
99 {
100         os << "<anchor id=\"" << getContents() << "\" ></anchor>";
101         return 0;
102 }