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));
+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:
#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"
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);
+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):
--- /dev/null
+/**
+ * \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")
+{}
--- /dev/null
+// -*- 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
ControlIndex.C \
ControlIndex.h \
ControlInset.h \
+ ControlLabel.C \
+ ControlLabel.h \
ControlLog.C \
ControlLog.h \
ControlMath.C \
~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.
#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);
+// }
+// }
}
///
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; }
}
-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;
}
///
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