X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsetlabel.C;h=66963db35005b0d03398cbd7e78de312fdfb6f78;hb=6ce86e2bfe0a403e0e811b66fdddb2d56cfe0f83;hp=72376e442799d187d9bd33e806d268403534e55f;hpb=74a46e047411135aa83e77fe5be9e9f320cc9b7b;p=lyx.git diff --git a/src/insets/insetlabel.C b/src/insets/insetlabel.C index 72376e4427..66963db350 100644 --- a/src/insets/insetlabel.C +++ b/src/insets/insetlabel.C @@ -1,113 +1,118 @@ -/* This file is part of - * ====================================================== - * - * LyX, The Document Processor - * - * Copyright 1995 Matthias Ettrich - * Copyright 1995-2000 The LyX Team. +/** + * \file insetlabel.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. * - * ====================================================== */ + * \author Lars Gullik Bjønnes + * + * Full author contact details are available in file CREDITS + */ #include -#ifdef __GNUG__ -#pragma implementation -#endif #include "insetlabel.h" +#include "buffer.h" +#include "BufferView.h" +#include "funcrequest.h" +#include "gettext.h" +#include "lyxtext.h" + +#include "support/lstrings.h" #include "support/LOstream.h" -#include "lyx_gui_misc.h" //askForText #include "support/lstrings.h" //frontStrip, strip -#include "lyxtext.h" -#include "buffer.h" using std::ostream; using std::vector; using std::pair; -/* Label. Used to insert a label automatically */ - -InsetLabel::InsetLabel(InsetCommandParams const & p) +InsetLabel::InsetLabel(InsetCommandParams const & p, bool) : InsetCommand(p) {} +InsetLabel::~InsetLabel() +{ + InsetCommandMailer mailer("label", *this); + mailer.hideDialog(); +} + + vector const InsetLabel::getLabelList() const { - return vector(1,getContents()); + return vector(1, getContents()); } -void InsetLabel::Edit(BufferView * bv, int, int, unsigned int) +void InsetLabel::edit(BufferView * bv, int, int, mouse_button::state) { - if (bv->buffer()->isReadonly()) { - WarnReadonly(bv->buffer()->fileName()); - return; - } + InsetCommandMailer mailer("label", *this); + mailer.showDialog(bv); +} + - pair result = askForText(_("Enter label:"), getContents()); - if (result.first) { - string new_contents = frontStrip(strip(result.second)); - if (!new_contents.empty() && - getContents() != new_contents) { - bv->buffer()->markDirty(); - bool flag = bv->ChangeRefs(getContents(),new_contents); - setContents( new_contents ); - bv->text->RedoParagraph(bv); - if (flag) { - bv->redraw(); - bv->fitCursor(getLyXText(bv)); - } else - bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); +dispatch_result InsetLabel::localDispatch(FuncRequest const & cmd) +{ + Inset::RESULT result = UNDISPATCHED; + + switch (cmd.action) { + case LFUN_INSET_MODIFY: { + InsetCommandParams p; + InsetCommandMailer::string2params(cmd.argument, p); + if (p.getCmdName().empty()) + return UNDISPATCHED; + + bool clean = true; + if (view() && p.getContents() != params().getContents()) { + clean = view()->ChangeRefsIfUnique(params().getContents(), + p.getContents()); } + + setParams(p); + cmd.view()->updateInset(this); + result = DISPATCHED; + } + break; + + default: + result = InsetCommand::localDispatch(cmd); } + + return result; +} + + +void InsetLabel::edit(BufferView * bv, bool) +{ + edit(bv, 0, 0, mouse_button::none); } -int InsetLabel::Latex(Buffer const *, ostream & os, +int InsetLabel::latex(Buffer const *, ostream & os, bool /*fragile*/, bool /*fs*/) const { os << escape(getCommand()); return 0; } -int InsetLabel::Ascii(Buffer const *, ostream & os, int) const + +int InsetLabel::ascii(Buffer const *, ostream & os, int) const { - os << "<" << getContents() << ">"; + os << '<' << getContents() << '>'; return 0; } -int InsetLabel::Linuxdoc(Buffer const *, ostream & os) const +int InsetLabel::linuxdoc(Buffer const *, ostream & os) const { os << "