]> git.lyx.org Git - features.git/commitdiff
A real, LyX label dialog. Part 1.
authorAngus Leeming <leeming@lyx.org>
Thu, 27 Feb 2003 16:24:14 +0000 (16:24 +0000)
committerAngus Leeming <leeming@lyx.org>
Thu, 27 Feb 2003 16:24:14 +0000 (16:24 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6301 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
src/BufferView_pimpl.C
src/ChangeLog
src/factory.C
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlLabel.C [new file with mode: 0644]
src/frontends/controllers/ControlLabel.h [new file with mode: 0644]
src/frontends/controllers/Makefile.am
src/insets/insetbibitem.h
src/insets/insetlabel.C
src/insets/insetlabel.h
src/lyx_cb.C
src/lyx_cb.h

index f29895c2ab0a428873f2fcc97bbe959b53455343..6bfa31a50242eaa4fd570d4e4f034f6665f12ddb 100644 (file)
@@ -1090,9 +1090,15 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
                owner_->getLyXFunc().setMessage(currentState(bv_));
                break;
 
-       case LFUN_INSERT_LABEL:
-               MenuInsertLabel(bv_, ev.argument);
-               break;
+       case LFUN_INSERT_LABEL: {
+               // Try and generate a valid label
+               string const contents = ev.argument.empty() ?
+                       getPossibleLabel(*bv_) : ev.argument;
+               InsetCommandParams icp("label", contents);
+               string data = InsetCommandMailer::params2string("label", icp);
+               owner_->getDialogs().show("label", data, 0);
+       }
+       break;
 
        case LFUN_BOOKMARK_SAVE:
                savePosition(strToUnsignedInt(ev.argument));
index 82df282882b5243ce640b9367cfb9a3f4d9b99e6..348358d1d59e680e130c582b47e5e6a0fd35d0d9 100644 (file)
@@ -1,3 +1,13 @@
+2003-02-27  Angus Leeming  <leeming@lyx.org>
+
+       * BufferView_pimpl.C (dispatch): call a real, LyX dialog to insert
+       a label.
+
+       * factory.C (createInset): add "label" to the factory.
+
+       * lyx_cb.[Ch] (getPossibleLabel): rewrite MenuInsertLabel to return the
+       string and do no more.
+
 2003-02-27  Angus Leeming  <leeming@lyx.org>
 
        * commandtags.h:
index 288aa0e15043192bde889bc9e3142ab6ab6855e3..31ccbb68b31e49a64382df2d301789c645a71d3c 100644 (file)
@@ -27,6 +27,7 @@
 #include "insets/insetfloat.h"
 #include "insets/insetfoot.h"
 #include "insets/insetindex.h"
+#include "insets/insetlabel.h"
 #include "insets/insetmarginal.h"
 #include "insets/insetminipage.h"
 #include "insets/insetnote.h"
@@ -198,6 +199,11 @@ Inset * createInset(FuncRequest const & cmd)
                        InsetCommandMailer::string2params(cmd.argument, icp);
                        return new InsetIndex(icp);
 
+               } else if (name == "label") {
+                       InsetCommandParams icp;
+                       InsetCommandMailer::string2params(cmd.argument, icp);
+                       return new InsetLabel(icp);
+
                } else if (name == "ref") {
                        InsetCommandParams icp;
                        InsetCommandMailer::string2params(cmd.argument, icp);
index eeaa7ff1c530eab1615934bcfa9d13d4f70a6dd6..d0f18f792bcff1d565219e3cbf57774607c99ffd 100644 (file)
@@ -1,3 +1,9 @@
+2003-02-27  Angus Leeming  <leeming@lyx.org>
+
+       * ControlLabel.[Ch]: new files. A controller for the Label dialog.
+
+       * Makefile.am: add the new files.
+
 2003-02-27  Angus Leeming  <leeming@lyx.org>
 
        * ControlBibitem.C (c-tor):
diff --git a/src/frontends/controllers/ControlLabel.C b/src/frontends/controllers/ControlLabel.C
new file mode 100644 (file)
index 0000000..ba842e1
--- /dev/null
@@ -0,0 +1,19 @@
+/**
+ * \file ControlLabel.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#include <config.h>
+
+
+#include "ControlLabel.h"
+
+
+ControlLabel::ControlLabel(Dialog & d)
+       : ControlCommand(d, "label")
+{}
diff --git a/src/frontends/controllers/ControlLabel.h b/src/frontends/controllers/ControlLabel.h
new file mode 100644 (file)
index 0000000..bd06578
--- /dev/null
@@ -0,0 +1,26 @@
+// -*- C++ -*-
+/**
+ * \file ControlLabel.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#ifndef CONTROLLABEL_H
+#define CONTROLLABEL_H
+
+
+#include "ControlCommand.h"
+
+/** A controller for Label dialogs.
+ */
+class ControlLabel : public ControlCommand {
+public:
+       ///
+       ControlLabel(Dialog &);
+};
+
+#endif // CONTROLLABEL_H
index de72b274989a9fc42ad8c3cd026447717e1f5b5f..073eb54a63da1b3eab7ead3d70c0642265e9442f 100644 (file)
@@ -67,6 +67,8 @@ libcontrollers_la_SOURCES= \
        ControlIndex.C \
        ControlIndex.h \
        ControlInset.h \
+       ControlLabel.C \
+       ControlLabel.h \
        ControlLog.C \
        ControlLog.h \
        ControlMath.C \
index 1d0444057c9d1be2ab6b911f0b0ce4c0da17f311..8156b1ca7e8719c4e70976358d745fd2bf3058e4 100644 (file)
@@ -30,7 +30,7 @@ public:
        ~InsetBibitem();
        ///
        Inset * clone(Buffer const &, bool same_id = false) const;
-       /// small wrapper for the time being
+       ///
        virtual dispatch_result localDispatch(FuncRequest const & cmd);
        /** Currently \bibitem is used as a LyX2.x command,
            so we need this method.
index 537b85b312a02adafab4bcd4864592e60e35c3c4..459699b8958f666e1c8f7ff0ec66c5a32ddab274 100644 (file)
 
 
 #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());
 }
 
 
-void InsetLabel::edit(BufferView * bv, int, int, mouse_button::state)
+void InsetLabel::edit(BufferView *, 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();
+}
+
+
+dispatch_result InsetLabel::localDispatch(FuncRequest const & cmd)
+{
+       if (cmd.action != LFUN_INSET_APPLY)
+               return UNDISPATCHED;
+
+       InsetCommandParams p;
+       InsetCommandMailer::string2params(cmd.argument, p);
+       if (p.getCmdName().empty())
+               return UNDISPATCHED;
+
+       bool clean = true;
+       if (view() && p.getContents() != params().getContents()) {
+               clean = view()->ChangeCitationsIfUnique(params().getContents(),
+                                                       p.getContents());
        }
+
+       setParams(p);
+       if (view())
+               view()->updateInset(this, !clean);
+
+       return DISPATCHED;
+//     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);
+//                     bv->updateInset(this, !flag);
+//             }
+//     }
 }
 
 
index 4cb3b2657d8b261ec543285f70bc65269fe35564..b4478c3d82c099206c864ddb4536d1a0fbb186f5 100644 (file)
@@ -20,10 +20,14 @@ public:
        ///
        InsetLabel(InsetCommandParams const &, bool same_id = false);
        ///
+       ~InsetLabel();
+       ///
        virtual Inset * clone(Buffer const &, bool same_id = false) const {
                return new InsetLabel(params(), same_id);
        }
        ///
+       virtual dispatch_result localDispatch(FuncRequest const & cmd);
+       ///
        string const getScreenLabel(Buffer const *) const { return getContents(); }
        ///
        EDITABLE editable() const { return IS_EDITABLE; }
index e3578314111db3cc6f221767fdd4d4196ab0cddb..c1ea6d4fdd01fac12511c51e949ef36bd037cd81 100644 (file)
@@ -469,53 +469,43 @@ string getContentsOfAsciiFile(BufferView * bv, string const & f, bool asParagrap
 }
 
 
-void MenuInsertLabel(BufferView * bv, string const & arg)
+string const getPossibleLabel(BufferView const & bv)
 {
-       string label = arg;
-       if (label.empty()) {
-               Paragraph * par = bv->getLyXText()->cursor.par();
-               LyXLayout_ptr layout = par->layout();
-               if (layout->latextype == LATEX_PARAGRAPH && par->previous()) {
-                       Paragraph * par2 = par->previous();
-
-                       LyXLayout_ptr const & layout2 = par2->layout();
-
-                       if (layout2->latextype != LATEX_PARAGRAPH) {
-                               par = par2;
-                               layout = layout2;
-                       }
-               }
-               string text = layout->latexname().substr(0, 3);
-               if (layout->latexname() == "theorem")
-                       text = "thm"; // Create a correct prefix for prettyref
-
-               text += ':';
-               if (layout->latextype == LATEX_PARAGRAPH ||
-                   lyxrc.label_init_length < 0)
-                       text.erase();
-               string par_text = par->asString(bv->buffer(), false);
-               for (int i = 0; i < lyxrc.label_init_length; ++i) {
-                       if (par_text.empty())
-                               break;
-                       string head;
-                       par_text = split(par_text, head, ' ');
-                       if (i > 0)
-                               text += '-'; // Is it legal to use spaces in
-                                            // labels ?
-                       text += head;
-               }
+       Paragraph * par = bv.getLyXText()->cursor.par();
+       LyXLayout_ptr layout = par->layout();
+       if (layout->latextype == LATEX_PARAGRAPH && par->previous()) {
+               Paragraph * par2 = par->previous();
 
-               pair<bool, string> result =
-                       Alert::askForText(_("Enter new label to insert:"), text);
-               if (result.first) {
-                       label = trim(result.second);
+               LyXLayout_ptr const & layout2 = par2->layout();
+
+               if (layout2->latextype != LATEX_PARAGRAPH) {
+                       par = par2;
+                       layout = layout2;
                }
        }
-       if (!label.empty()) {
-               InsetCommandParams p("label", label);
-               InsetLabel * inset = new InsetLabel(p);
-               bv->insertInset(inset);
+
+       string text = layout->latexname().substr(0, 3);
+       if (layout->latexname() == "theorem")
+               text = "thm"; // Create a correct prefix for prettyref
+
+       text += ':';
+       if (layout->latextype == LATEX_PARAGRAPH ||
+           lyxrc.label_init_length < 0)
+               text.erase();
+
+       string par_text = par->asString(bv.buffer(), false);
+       for (int i = 0; i < lyxrc.label_init_length; ++i) {
+               if (par_text.empty())
+                       break;
+               string head;
+               par_text = split(par_text, head, ' ');
+               if (i > 0)
+                       text += '-'; // Is it legal to use spaces in
+               // labels ?
+               text += head;
        }
+
+       return text;
 }
 
 
index 5db5524967b7d090a47577aee8ef1d8bc077045e..ce4220728beda1ecae5b47d8e5f9e13639cb2d43 100644 (file)
@@ -33,7 +33,7 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph);
 ///
 string getContentsOfAsciiFile(BufferView * bv, string const & f, bool asParagraph);
 ///
-void MenuInsertLabel(BufferView * bv, string const & arg);
+string const getPossibleLabel(BufferView const & bv);
 ///
 void Reconfigure(BufferView * bv);
 #endif