-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 1995 Matthias Ettrich
- * Copyright 1995-2001 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 <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
#include "insetlabel.h"
-#include "support/LOstream.h"
-#include "lyx_gui_misc.h" //askForText
-#include "support/lstrings.h" //frontStrip, strip
-#include "lyxtext.h"
#include "buffer.h"
-#include "gettext.h"
#include "BufferView.h"
+#include "funcrequest.h"
+#include "gettext.h"
+#include "lyxtext.h"
+
#include "support/lstrings.h"
+#include "support/LOstream.h"
+#include "support/lstrings.h" //frontStrip, strip
using std::ostream;
using std::vector;
using std::pair;
-/* Label. Used to insert a label automatically */
-
-InsetLabel::InsetLabel(InsetCommandParams const & p, bool)
+InsetLabel::InsetLabel(InsetCommandParams const & p)
: InsetCommand(p)
{}
+// InsetLabel::InsetLabel(InsetCommandParams const & p, bool)
+// : InsetCommand(p, false)
+// {}
+
+
+InsetLabel::~InsetLabel()
+{
+ InsetCommandMailer mailer("label", *this);
+ mailer.hideDialog();
+}
+
+
vector<string> const InsetLabel::getLabelList() const
{
return vector<string>(1, getContents());
}
-void InsetLabel::edit(BufferView * bv, int, int, unsigned int)
+dispatch_result InsetLabel::localDispatch(FuncRequest const & cmd)
{
- if (bv->buffer()->isReadonly()) {
- WarnReadonly(bv->buffer()->fileName());
- return;
- }
+ Inset::RESULT result = UNDISPATCHED;
+
+ switch (cmd.action) {
+
+ case LFUN_INSET_EDIT:
+ InsetCommandMailer("label", *this).showDialog(cmd.view());
+ result = DISPATCHED;
+ break;
- pair<bool, string> 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->ChangeRefsIfUnique(getContents(),
- new_contents);
- setContents(new_contents);
- bv->text->redoParagraph(bv);
- if (flag) {
- bv->redraw();
- bv->fitCursor();
- } else
- bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
+ 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);
+ }
-void InsetLabel::edit(BufferView * bv, bool)
-{
- edit(bv, 0, 0, 0);
+ return result;
}
int InsetLabel::latex(Buffer const *, ostream & os,
- bool /*fragile*/, bool /*fs*/) const
+ LatexRunParams const &) const
{
os << escape(getCommand());
return 0;
}
+
int InsetLabel::ascii(Buffer const *, ostream & os, int) const
{
- os << "<" << getContents() << ">";
+ os << '<' << getContents() << '>';
return 0;
}
}
-int InsetLabel::docbook(Buffer const *, ostream & os) const
+int InsetLabel::docbook(Buffer const *, ostream & os, bool) const
{
- os << "<anchor id=\"" << getContents() << "\" ></anchor>";
+ os << "<anchor id=\"" << getContents() << "\">";
return 0;
}