]> git.lyx.org Git - lyx.git/blob - src/insets/insetlabel.C
Fix working of the spellchecker dialog with ispell when there are no
[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 "lyx_gui_misc.h"     //askForText
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         if (bv->buffer()->isReadonly()) {
48                 WarnReadonly(bv->buffer()->fileName());
49                 return;
50         }
51
52         pair<bool, string> result = askForText(_("Enter label:"), getContents());
53         if (result.first) {
54                 string new_contents = frontStrip(strip(result.second));
55                 if (!new_contents.empty() &&
56                     getContents() != new_contents) {
57                         bv->buffer()->markDirty();
58                         bool flag = bv->ChangeRefsIfUnique(getContents(),
59                                                            new_contents);
60                         setContents(new_contents);
61                         bv->text->redoParagraph(bv);
62                         if (flag) {
63                                 bv->redraw();
64                                 bv->fitCursor();
65                         } else
66                                 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
67                 }
68         }
69 }
70
71
72 void InsetLabel::edit(BufferView * bv, bool)
73 {
74         edit(bv, 0, 0, 0);
75 }
76
77
78 int InsetLabel::latex(Buffer const *, ostream & os,
79                       bool /*fragile*/, bool /*fs*/) const
80 {
81         os << escape(getCommand());
82         return 0;
83 }
84
85 int InsetLabel::ascii(Buffer const *, ostream & os, int) const
86 {
87         os << "<" << getContents()  << ">";
88         return 0;
89 }
90
91
92 int InsetLabel::linuxdoc(Buffer const *, ostream & os) const
93 {
94         os << "<label id=\"" << getContents() << "\" >";
95         return 0;
96 }
97
98
99 int InsetLabel::docbook(Buffer const *, ostream & os) const
100 {
101         os << "<anchor id=\"" << getContents() << "\" ></anchor>";
102         return 0;
103 }