1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
17 #include "insetlabel.h"
18 #include "support/LOstream.h"
19 #include "lyx_gui_misc.h" //askForText
20 #include "support/lstrings.h" //frontStrip, strip
24 #include "BufferView.h"
25 #include "support/lstrings.h"
31 /* Label. Used to insert a label automatically */
34 InsetLabel::InsetLabel(InsetCommandParams const & p, bool)
39 vector<string> const InsetLabel::getLabelList() const
41 return vector<string>(1, getContents());
45 void InsetLabel::edit(BufferView * bv, int, int, unsigned int)
47 if (bv->buffer()->isReadonly()) {
48 WarnReadonly(bv->buffer()->fileName());
52 pair<bool, string> result = askForText(_("Enter label:"), getContents());
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(),
60 setContents(new_contents);
61 bv->text->redoParagraph(bv);
66 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
72 void InsetLabel::edit(BufferView * bv, bool)
78 int InsetLabel::latex(Buffer const *, ostream & os,
79 bool /*fragile*/, bool /*fs*/) const
81 os << escape(getCommand());
85 int InsetLabel::ascii(Buffer const *, ostream & os, int) const
87 os << "<" << getContents() << ">";
92 int InsetLabel::linuxdoc(Buffer const *, ostream & os) const
94 os << "<label id=\"" << getContents() << "\" >";
99 int InsetLabel::docBook(Buffer const *, ostream & os) const
101 os << "<anchor id=\"" << getContents() << "\" ></anchor>";