A real, LyX label dialog. Part 1.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6301 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-02-27 16:24:14 +00:00
parent 3e5ddbf850
commit 05a4c4d79f
12 changed files with 165 additions and 74 deletions

View 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));

View 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:

View 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);

View 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):

View File

@ -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")
{}

View File

@ -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

View File

@ -67,6 +67,8 @@ libcontrollers_la_SOURCES= \
ControlIndex.C \
ControlIndex.h \
ControlInset.h \
ControlLabel.C \
ControlLabel.h \
ControlLog.C \
ControlLog.h \
ControlMath.C \

View 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.

View File

@ -12,56 +12,78 @@
#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);
// }
// }
}

View 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; }

View 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();
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();
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;
}
pair<bool, string> result =
Alert::askForText(_("Enter new label to insert:"), text);
if (result.first) {
label = trim(result.second);
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;
}

View 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