]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetlabel.C
parlist-a-1.diff
[lyx.git] / src / insets / insetlabel.C
index d83a9263366e4221cfa9482c0378f5a865ef24b0..66963db35005b0d03398cbd7e78de312fdfb6f78 100644 (file)
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
 
 #include "insetlabel.h"
-#include "support/LOstream.h"
-#include "frontends/Alert.h"
-#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)
        : InsetCommand(p)
 {}
 
 
+InsetLabel::~InsetLabel()
+{
+       InsetCommandMailer mailer("label", *this);
+       mailer.hideDialog();
+}
+
+
 vector<string> const InsetLabel::getLabelList() const
 {
        return vector<string>(1, getContents());
@@ -44,27 +47,39 @@ vector<string> const InsetLabel::getLabelList() const
 
 void InsetLabel::edit(BufferView * bv, int, int, mouse_button::state)
 {
-       pair<bool, string> result = Alert::askForText(_("Enter label:"), getContents());
-       if (result.first) {
-               string new_contents = trim(result.second);
-               if (!new_contents.empty() &&
-                   getContents() != new_contents) {
-                       bv->buffer()->markDirty();
-                       bool flag = bv->ChangeRefsIfUnique(getContents(),
-                                                          new_contents);
-                       setContents(new_contents);
-#if 0
-                       bv->text->redoParagraph(bv);
-                       if (flag) {
-                               bv->redraw();
-                               bv->fitCursor();
-                       } else
-                               bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
-#else
-                       bv->updateInset(this, !flag);
-#endif
+       InsetCommandMailer mailer("label", *this);
+       mailer.showDialog(bv);
+}
+
+
+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;
 }
 
 
@@ -81,6 +96,7 @@ int InsetLabel::latex(Buffer const *, ostream & os,
        return 0;
 }
 
+
 int InsetLabel::ascii(Buffer const *, ostream & os, int) const
 {
        os << '<' << getContents()  << '>';