Remove a whole heap of redundant functions from classes derived from

InsetCommand.
Clean-up many Mailer::string2params functions.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8233 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-12-11 15:23:15 +00:00
parent 559c84c370
commit fd355bbb2f
39 changed files with 231 additions and 452 deletions

View File

@ -1,3 +1,8 @@
2003-12-11 Angus Leeming <leeming@lyx.org>
* factory.C (createInset): changes due to the changed interface to
InsetCommandMailer::string2params.
2003-12-10 Angus Leeming <leeming@lyx.org>
* lyxfunc.C (dispatch): enable all inset dialogs to be opened with

View File

@ -217,17 +217,20 @@ InsetOld * createInset(FuncRequest const & cmd)
if (name == "bibitem") {
InsetCommandParams icp;
InsetCommandMailer::string2params(cmd.argument, icp);
InsetCommandMailer::string2params(name, cmd.argument,
icp);
return new InsetBibitem(icp);
} else if (name == "bibtex") {
InsetCommandParams icp;
InsetCommandMailer::string2params(cmd.argument, icp);
InsetCommandMailer::string2params(name, cmd.argument,
icp);
return new InsetBibtex(icp);
} else if (name == "citation") {
InsetCommandParams icp;
InsetCommandMailer::string2params(cmd.argument, icp);
InsetCommandMailer::string2params(name, cmd.argument,
icp);
return new InsetCitation(icp);
} else if (name == "ert") {
@ -260,27 +263,32 @@ InsetOld * createInset(FuncRequest const & cmd)
} else if (name == "index") {
InsetCommandParams icp;
InsetCommandMailer::string2params(cmd.argument, icp);
InsetCommandMailer::string2params(name, cmd.argument,
icp);
return new InsetIndex(icp);
} else if (name == "label") {
InsetCommandParams icp;
InsetCommandMailer::string2params(cmd.argument, icp);
InsetCommandMailer::string2params(name, cmd.argument,
icp);
return new InsetLabel(icp);
} else if (name == "ref") {
InsetCommandParams icp;
InsetCommandMailer::string2params(cmd.argument, icp);
InsetCommandMailer::string2params(name, cmd.argument,
icp);
return new InsetRef(icp, *bv->buffer());
} else if (name == "toc") {
InsetCommandParams icp;
InsetCommandMailer::string2params(cmd.argument, icp);
InsetCommandMailer::string2params(name, cmd.argument,
icp);
return new InsetTOC(icp);
} else if (name == "url") {
InsetCommandParams icp;
InsetCommandMailer::string2params(cmd.argument, icp);
InsetCommandMailer::string2params(name, cmd.argument,
icp);
return new InsetUrl(icp);
} else if (name == "vspace") {

View File

@ -1,3 +1,8 @@
2003-12-11 Angus Leeming <leeming@lyx.org>
* ControlCommand.C (initialiseParams): changes due to the changed
interface to InsetCommandMailer::string2params.
2003-12-10 Angus Leeming <leeming@lyx.org>
* ControlNote.[Ch] (note_gui_tokens): removed; no longer needed.

View File

@ -27,7 +27,9 @@ ControlCommand::ControlCommand(Dialog & dialog, string const & lfun_name)
bool ControlCommand::initialiseParams(string const & data)
{
InsetCommandMailer::string2params(data, params_);
// The name passed with LFUN_INSET_APPLY is also the name
// used to identify the mailer.
InsetCommandMailer::string2params(lfun_name_, data, params_);
return true;
}

View File

@ -1,3 +1,49 @@
2003-12-11 Angus Leeming <leeming@lyx.org>
* mailinset.[Ch] (print_mailer_error): new helper function.
* insetcommand.[Ch]: add a mailer_name_ variable and use it when
calling InsetCommandMailer.
(InsetCommandMailer::string2params): pass the name of the dialog.
* insetbibitem.[Ch] (d-tor):
* insetbibtex.[Ch] (d-tor):
* insetcite.[Ch] (d-tor):
* insetfloatlist.[Ch] (d-tor):
* insetindex.[Ch] (d-tor):
* insetlabel.[Ch] (d-tor):
* insetref.[Ch] (d-tor):
* insettoc.[Ch] (d-tor):
* inseturl.[Ch] (d-tor): removed.
Hiding the dialog is handled by InsetCommand.
* insetbibtex.[Ch] (draw, metrics):
* insetfloatlist.[Ch] (draw, metrics):
* insetindex.[Ch] (draw, metrics): removed.
Drawing is handled by InsetCommand.
* insetbibitem.[Ch] (priv_dispatch):
* insetbibtex.[Ch] (priv_dispatch):
* insetcite.[Ch] (priv_dispatch):
* insetfloatlist.[Ch] (priv_dispatch):
* insetindex.[Ch] (priv_dispatch):
* insetlabel.[Ch] (priv_dispatch):
* insettoc.[Ch] (priv_dispatch):
* inseturl.[Ch] (priv_dispatch): removed or simplified.
let InsetCommand handle LFUN_MOUSE_PRESS, LFUN_MOUSE_RELEASE,
LFUN_INSET_DIALOG_SHOW.
* insetbox.C (string2params):
* insetbranch.C (string2params):
* insetert.C (string2params):
* insetexternal.C (string2params):
* insetfloat.C (string2params):
* insetinclude.C (string2params):
* insetminipage.C (string2params):
* insetnote.C (string2params):
* insetvspace.C (string2params):
* insetwrap.C (string2params): over-hauled.
2003-12-10 Angus Leeming <leeming@lyx.org>
* insetexternal.[Ch]: add a draft option and respect it when

View File

@ -38,19 +38,13 @@ string const key_prefix = "key-";
InsetBibitem::InsetBibitem(InsetCommandParams const & p)
: InsetCommand(p), counter(1)
: InsetCommand(p, "bibitem"), counter(1)
{
if (getContents().empty())
setContents(key_prefix + tostr(++key_counter));
}
InsetBibitem::~InsetBibitem()
{
InsetCommandMailer("bibitem", *this).hideDialog();
}
auto_ptr<InsetBase> InsetBibitem::clone() const
{
auto_ptr<InsetBibitem> b(new InsetBibitem(params()));
@ -65,13 +59,9 @@ InsetBibitem::priv_dispatch(FuncRequest const & cmd,
{
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
InsetCommandMailer("bibitem", *this).showDialog(cmd.view());
return DispatchResult(true, true);
case LFUN_INSET_MODIFY: {
InsetCommandParams p;
InsetCommandMailer::string2params(cmd.argument, p);
InsetCommandMailer::string2params("bibitem", cmd.argument, p);
if (p.getCmdName().empty())
return DispatchResult(true, true);
setParams(p);

View File

@ -27,8 +27,6 @@ public:
///
InsetBibitem(InsetCommandParams const &);
///
~InsetBibitem();
///
std::auto_ptr<InsetBase> clone() const;
/** Currently \bibitem is used as a LyX2.x command,
so we need this method.

View File

@ -55,39 +55,16 @@ using std::vector;
InsetBibtex::InsetBibtex(InsetCommandParams const & p)
: InsetCommand(p)
: InsetCommand(p, "bibtex")
{}
InsetBibtex::~InsetBibtex()
{
InsetCommandMailer("bibtex", *this).hideDialog();
}
std::auto_ptr<InsetBase> InsetBibtex::clone() const
{
return std::auto_ptr<InsetBase>(new InsetBibtex(*this));
}
void InsetBibtex::metrics(MetricsInfo & mi, Dimension & dim) const
{
InsetCommand::metrics(mi, dim);
int center_indent = (mi.base.textwidth - dim.wid) / 2;
Box b(center_indent, center_indent + dim.wid, -dim.asc, dim.des);
button().setBox(b);
dim.wid = mi.base.textwidth;
dim_ = dim;
}
void InsetBibtex::draw(PainterInfo & pi, int x, int y) const
{
InsetCommand::draw(pi, x + button().box().x1, y);
}
DispatchResult
InsetBibtex::priv_dispatch(FuncRequest const & cmd,
idx_type & idx, pos_type & pos)
@ -96,20 +73,9 @@ InsetBibtex::priv_dispatch(FuncRequest const & cmd,
switch (cmd.action) {
case LFUN_INSET_DIALOG_SHOW:
InsetCommandMailer("bibtex", *this).showDialog(cmd.view());
result.dispatched(true);
break;
case LFUN_MOUSE_RELEASE:
if (button().box().contains(cmd.x, cmd.y))
InsetCommandMailer("bibtex", *this).showDialog(cmd.view());
result.dispatched(true);
break;
case LFUN_INSET_MODIFY: {
InsetCommandParams p;
InsetCommandMailer::string2params(cmd.argument, p);
InsetCommandMailer::string2params("bibtex", cmd.argument, p);
if (!p.getCmdName().empty())
setParams(p);
result.dispatched(true);

View File

@ -23,14 +23,8 @@ public:
///
InsetBibtex(InsetCommandParams const &);
///
~InsetBibtex();
///
std::auto_ptr<InsetBase> clone() const;
///
void metrics(MetricsInfo &, Dimension &) const;
///
void draw(PainterInfo & pi, int x, int y) const;
///
std::string const getScreenLabel(Buffer const &) const;
///
EDITABLE editable() const { return IS_EDITABLE; }

View File

@ -424,7 +424,6 @@ void InsetBoxMailer::string2params(string const & in,
InsetBoxParams & params)
{
params = InsetBoxParams(string());
if (in.empty())
return;
@ -434,18 +433,15 @@ void InsetBoxMailer::string2params(string const & in,
string name;
lex >> name;
if (!lex || name != name_) {
lyxerr << "InsetBoxMailer::string2params(" << in << ")\n"
<< "Missing identifier \"" << name_ << '"' << std::endl;
return;
}
if (!lex || name != name_)
return print_mailer_error("InsetBoxMailer", in, 1, name_);
// This is part of the inset proper that is usually swallowed
// by LyXText::readInset
string inset_id;
lex >> inset_id;
if (!lex || inset_id != "Box")
return;
string id;
lex >> id;
if (!lex || id != "Box")
return print_mailer_error("InsetBoxMailer", in, 2, "Box");
params.read(lex);
}

View File

@ -231,7 +231,6 @@ void InsetBranchMailer::string2params(string const & in,
InsetBranchParams & params)
{
params = InsetBranchParams();
if (in.empty())
return;
@ -242,7 +241,7 @@ void InsetBranchMailer::string2params(string const & in,
string name;
lex >> name;
if (name != name_)
return;
return print_mailer_error("InsetBranchMailer", in, 1, name_);
params.read(lex);
// Process all_branches here:

View File

@ -215,21 +215,10 @@ string const getBasicLabel(string const & keyList, string const & after)
InsetCitation::InsetCitation(InsetCommandParams const & p)
: InsetCommand(p)
: InsetCommand(p, "citation")
{}
// InsetCitation::InsetCitation(InsetCommandParams const & p, bool)
// : InsetCommand(p, false)
// {}
InsetCitation::~InsetCitation()
{
InsetCommandMailer("citation", *this).hideDialog();
}
string const InsetCitation::generateLabel(Buffer const & buffer) const
{
string const before = string();
@ -308,22 +297,6 @@ string const InsetCitation::getScreenLabel(Buffer const & buffer) const
}
DispatchResult
InsetCitation::priv_dispatch(FuncRequest const & cmd,
idx_type & idx, pos_type & pos)
{
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
InsetCommandMailer("citation", *this).showDialog(cmd.view());
return DispatchResult(true, true);
default:
return InsetCommand::priv_dispatch(cmd, idx, pos);
}
}
int InsetCitation::plaintext(Buffer const & buffer, ostream & os, int) const
{
if (cache.params == params() && cache.style == getStyle(buffer))

View File

@ -23,8 +23,6 @@ public:
///
InsetCitation(InsetCommandParams const &);
///
~InsetCitation();
///
std::auto_ptr<InsetBase> clone() const {
return std::auto_ptr<InsetBase>(new InsetCitation(params()));
}
@ -41,11 +39,6 @@ public:
OutputParams const &) const;
///
void validate(LaTeXFeatures &) const;
protected:
///
virtual
DispatchResult
priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &);
private:
struct Cache {
///

View File

@ -28,12 +28,21 @@ using std::ostream;
using std::ostringstream;
InsetCommand::InsetCommand(InsetCommandParams const & p)
InsetCommand::InsetCommand(InsetCommandParams const & p,
string const & mailer_name)
: p_(p.getCmdName(), p.getContents(), p.getOptions()),
mailer_name_(mailer_name),
set_label_(false)
{}
InsetCommand::~InsetCommand()
{
if (!mailer_name_.empty())
InsetCommandMailer(mailer_name_, *this).hideDialog();
}
void InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const
{
if (!set_label_) {
@ -96,7 +105,7 @@ InsetCommand::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
InsetCommandParams p;
InsetCommandMailer::string2params(cmd.argument, p);
InsetCommandMailer::string2params(mailer_name_, cmd.argument, p);
if (p.getCmdName().empty())
return DispatchResult(false);
@ -109,9 +118,13 @@ InsetCommand::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
InsetCommandMailer(cmd.argument, *this).updateDialog(cmd.view());
return DispatchResult(true, true);
case LFUN_MOUSE_RELEASE:
edit(cmd.view(), true);
case LFUN_INSET_DIALOG_SHOW:
case LFUN_MOUSE_RELEASE: {
if (!mailer_name_.empty())
InsetCommandMailer(mailer_name_, *this).
showDialog(cmd.view());
return DispatchResult(true);
}
default:
return DispatchResult(false);
@ -132,11 +145,11 @@ string const InsetCommandMailer::inset2string(Buffer const &) const
}
void InsetCommandMailer::string2params(string const & in,
void InsetCommandMailer::string2params(string const & name,
string const & in,
InsetCommandParams & params)
{
params = InsetCommandParams();
if (in.empty())
return;
@ -144,26 +157,24 @@ void InsetCommandMailer::string2params(string const & in,
LyXLex lex(0,0);
lex.setStream(data);
if (lex.isOK()) {
lex.next();
string const name = lex.getString();
}
string n;
lex >> n;
if (!lex || n != name)
return print_mailer_error("InsetCommandMailer", in, 1, name);
// This is part of the inset proper that is usually swallowed
// by Buffer::readInset
if (lex.isOK()) {
lex.next();
string const token = lex.getString();
if (token != "LatexCommand")
return;
}
if (lex.isOK()) {
// by LyXText::readInset
string id;
lex >> id;
if (!lex || id != "LatexCommand")
return print_mailer_error("InsetCommandMailer", in, 2, "LatexCommand");
params.read(lex);
}
}
string const InsetCommandMailer::params2string(string const & name,
string const
InsetCommandMailer::params2string(string const & name,
InsetCommandParams const & params)
{
ostringstream data;

View File

@ -31,7 +31,10 @@ class InsetCommand : public InsetOld {
public:
///
explicit
InsetCommand(InsetCommandParams const &);
InsetCommand(InsetCommandParams const &,
std::string const & mailer_name);
///
~InsetCommand();
///
void metrics(MetricsInfo &, Dimension &) const;
///
@ -91,6 +94,7 @@ protected:
private:
///
InsetCommandParams p_;
std::string mailer_name_;
mutable bool set_label_;
mutable RenderButton button_;
};
@ -107,7 +111,8 @@ public:
///
virtual std::string const inset2string(Buffer const &) const;
///
static void string2params(std::string const &, InsetCommandParams &);
static void string2params(std::string const &, std::string const & name,
InsetCommandParams &);
///
static std::string const params2string(std::string const & name,
InsetCommandParams const &);

View File

@ -482,6 +482,8 @@ void InsetERTMailer::string2params(string const & in,
InsetCollapsable::CollapseStatus & status)
{
status = InsetCollapsable::Collapsed;
if (in.empty())
return;
istringstream data(in);
LyXLex lex(0,0);
@ -489,11 +491,8 @@ void InsetERTMailer::string2params(string const & in,
string name;
lex >> name;
if (name != name_) {
lyxerr << "InsetERTMailer::string2params(" << in << ")\n"
<< "Missing identifier \"" << name_ << '"' << std::endl;
return;
}
if (name != name_)
return print_mailer_error("InsetERTMailer", in, 1, name_);
int s;
lex >> s;

View File

@ -836,7 +836,6 @@ void InsetExternalMailer::string2params(string const & in,
InsetExternalParams & params)
{
params = InsetExternalParams();
if (in.empty())
return;
@ -844,25 +843,19 @@ void InsetExternalMailer::string2params(string const & in,
LyXLex lex(0,0);
lex.setStream(data);
if (lex.isOK()) {
lex.next();
string const token = lex.getString();
if (token != name_)
return;
}
string name;
lex >> name;
if (!lex || name != name_)
return print_mailer_error("InsetExternalMailer", in, 1, name_);
// This is part of the inset proper that is usually swallowed
// by Buffer::readInset
if (lex.isOK()) {
lex.next();
string const token = lex.getString();
if (token != "External")
return;
}
// by LyXText::readInset
string id;
lex >> id;
if (!lex || id != "External")
return print_mailer_error("InsetBoxMailer", in, 2, "External");
if (lex.isOK()) {
params.read(buffer, lex);
}
}

View File

@ -418,7 +418,6 @@ void InsetFloatMailer::string2params(string const & in,
InsetFloatParams & params)
{
params = InsetFloatParams();
if (in.empty())
return;
@ -426,25 +425,19 @@ void InsetFloatMailer::string2params(string const & in,
LyXLex lex(0,0);
lex.setStream(data);
if (lex.isOK()) {
lex.next();
string const token = lex.getString();
if (token != name_)
return;
}
string name;
lex >> name;
if (!lex || name != name_)
return print_mailer_error("InsetFloatMailer", in, 1, name_);
// This is part of the inset proper that is usually swallowed
// by Buffer::readInset
if (lex.isOK()) {
lex.next();
string const token = lex.getString();
if (token != "Float" || !lex.eatLine())
return;
}
// by LyXText::readInset
string id;
lex >> id;
if (!lex || id != "Float")
return print_mailer_error("InsetBoxMailer", in, 2, "Float");
if (lex.isOK()) {
params.read(lex);
}
}

View File

@ -35,23 +35,17 @@ using std::ostream;
InsetFloatList::InsetFloatList()
: InsetCommand(InsetCommandParams())
: InsetCommand(InsetCommandParams(), "toc")
{}
InsetFloatList::InsetFloatList(string const & type)
: InsetCommand(InsetCommandParams())
: InsetCommand(InsetCommandParams(), "toc")
{
setCmdName(type);
}
InsetFloatList::~InsetFloatList()
{
InsetCommandMailer("toc", *this).hideDialog();
}
string const InsetFloatList::getScreenLabel(Buffer const & buf) const
{
FloatList const & floats = buf.params().getLyXTextClass().floats();
@ -100,44 +94,6 @@ void InsetFloatList::read(Buffer const & buf, LyXLex & lex)
}
void InsetFloatList::metrics(MetricsInfo & mi, Dimension & dim) const
{
InsetCommand::metrics(mi, dim);
int center_indent = (mi.base.textwidth - dim.wid) / 2;
Box b(center_indent, center_indent + dim.wid, -dim.asc, dim.des);
button().setBox(b);
dim.wid = mi.base.textwidth;
dim_ = dim;
}
void InsetFloatList::draw(PainterInfo & pi, int x, int y) const
{
InsetCommand::draw(pi, x + button().box().x1, y);
}
DispatchResult
InsetFloatList::priv_dispatch(FuncRequest const & cmd,
idx_type & idx, pos_type & pos)
{
switch (cmd.action) {
case LFUN_MOUSE_RELEASE:
if (button().box().contains(cmd.x, cmd.y))
InsetCommandMailer("toc", *this).showDialog(cmd.view());
return DispatchResult(true, true);
case LFUN_INSET_DIALOG_SHOW:
InsetCommandMailer("toc", *this).showDialog(cmd.view());
return DispatchResult(true, true);
default:
return InsetCommand::priv_dispatch(cmd, idx, pos);
}
}
int InsetFloatList::latex(Buffer const & buf, ostream & os,
OutputParams const &) const
{

View File

@ -24,16 +24,10 @@ public:
///
InsetFloatList(std::string const & type);
///
~InsetFloatList();
///
virtual std::auto_ptr<InsetBase> clone() const {
return std::auto_ptr<InsetBase>(new InsetFloatList(getCmdName()));
}
///
void metrics(MetricsInfo &, Dimension &) const;
///
void draw(PainterInfo & pi, int x, int y) const;
///
std::string const getScreenLabel(Buffer const &) const;
///
EDITABLE editable() const { return IS_EDITABLE; }
@ -59,11 +53,6 @@ public:
OutputParams const & runparams) const;
///
void validate(LaTeXFeatures & features) const;
protected:
///
virtual
DispatchResult
priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &);
};
#endif

View File

@ -716,7 +716,6 @@ void InsetGraphicsMailer::string2params(string const & in,
InsetGraphicsParams & params)
{
params = InsetGraphicsParams();
if (in.empty())
return;
@ -724,18 +723,14 @@ void InsetGraphicsMailer::string2params(string const & in,
LyXLex lex(0,0);
lex.setStream(data);
if (lex.isOK()) {
lex.next();
string const token = lex.getString();
if (token != name_)
return;
}
string name;
lex >> name;
if (!lex || name != name_)
return print_mailer_error("InsetGraphicsMailer", in, 1, name_);
if (lex.isOK()) {
InsetGraphics inset;
inset.readInsetGraphics(lex, buffer.filePath());
params = inset.params();
}
}

View File

@ -18,7 +18,7 @@ using std::ostream;
InsetHFill::InsetHFill()
: InsetCommand(InsetCommandParams("hfill"))
: InsetCommand(InsetCommandParams("hfill"), std::string())
{}

View File

@ -644,7 +644,6 @@ void InsetIncludeMailer::string2params(string const & in,
InsetCommandParams & params)
{
params = InsetCommandParams();
if (in.empty())
return;
@ -652,27 +651,21 @@ void InsetIncludeMailer::string2params(string const & in,
LyXLex lex(0,0);
lex.setStream(data);
if (lex.isOK()) {
lex.next();
string const token = lex.getString();
if (token != name_)
return;
}
string name;
lex >> name;
if (!lex || name != name_)
return print_mailer_error("InsetIncludeMailer", in, 1, name_);
// This is part of the inset proper that is usually swallowed
// by Buffer::readInset
if (lex.isOK()) {
lex.next();
string const token = lex.getString();
if (token != "Include")
return;
}
// by LyXText::readInset
string id;
lex >> id;
if (!lex || id != "Include")
return print_mailer_error("InsetBoxMailer", in, 2, "Include");
if (lex.isOK()) {
InsetInclude inset(params);
inset.read(lex);
params = inset.params();
}
}

View File

@ -24,7 +24,7 @@ using std::ostream;
InsetIndex::InsetIndex(InsetCommandParams const & p)
: InsetCommand(p)
: InsetCommand(p, "index")
{}
@ -33,47 +33,12 @@ InsetIndex::InsetIndex(InsetCommandParams const & p)
// {}
InsetIndex::~InsetIndex()
{
InsetCommandMailer("index", *this).hideDialog();
}
string const InsetIndex::getScreenLabel(Buffer const &) const
{
return _("Idx");
}
void InsetPrintIndex::metrics(MetricsInfo & mi, Dimension & dim) const
{
InsetCommand::metrics(mi, dim);
center_indent_ = (mi.base.textwidth - dim.wid) / 2;
dim.wid = mi.base.textwidth;
dim_ = dim;
}
void InsetPrintIndex::draw(PainterInfo & pi, int x, int y) const
{
InsetCommand::draw(pi, x + center_indent_, y);
}
DispatchResult InsetIndex::priv_dispatch(FuncRequest const & cmd,
idx_type & idx, pos_type & pos)
{
switch (cmd.action) {
case LFUN_MOUSE_RELEASE:
InsetCommandMailer("index", *this).showDialog(cmd.view());
return DispatchResult(true, true);
default:
return InsetCommand::priv_dispatch(cmd, idx, pos);
}
}
int InsetIndex::docbook(Buffer const &, ostream & os,
OutputParams const &) const
{
@ -91,7 +56,7 @@ InsetOld::Code InsetIndex::lyxCode() const
InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
: InsetCommand(p)
: InsetCommand(p, string())
{}
@ -100,10 +65,6 @@ InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
// {}
InsetPrintIndex::~InsetPrintIndex()
{}
string const InsetPrintIndex::getScreenLabel(Buffer const &) const
{
return _("Index");

View File

@ -24,8 +24,6 @@ public:
///
InsetIndex(InsetCommandParams const &);
///
~InsetIndex();
///
virtual std::auto_ptr<InsetBase> clone() const {
return std::auto_ptr<InsetBase>(new InsetIndex(params()));
}
@ -38,9 +36,6 @@ public:
///
int docbook(Buffer const &, std::ostream &,
OutputParams const &) const;
///
DispatchResult priv_dispatch(FuncRequest const & cmd,
idx_type & idx, pos_type & pos);
};
@ -49,8 +44,6 @@ public:
///
InsetPrintIndex(InsetCommandParams const &);
///
~InsetPrintIndex();
///
virtual std::auto_ptr<InsetBase> clone() const {
return std::auto_ptr<InsetBase>(new InsetPrintIndex(params()));
}
@ -64,13 +57,6 @@ public:
bool display() const { return true; }
///
std::string const getScreenLabel(Buffer const &) const;
///
void metrics(MetricsInfo &, Dimension &) const;
///
void draw(PainterInfo & pi, int x, int y) const;
private:
///
mutable unsigned int center_indent_;
};
#endif

View File

@ -29,16 +29,10 @@ using std::ostream;
InsetLabel::InsetLabel(InsetCommandParams const & p)
: InsetCommand(p)
: InsetCommand(p, "label")
{}
InsetLabel::~InsetLabel()
{
InsetCommandMailer("label", *this).hideDialog();
}
std::auto_ptr<InsetBase> InsetLabel::clone() const
{
return std::auto_ptr<InsetBase>(new InsetLabel(params()));
@ -66,13 +60,9 @@ InsetLabel::priv_dispatch(FuncRequest const & cmd,
switch (cmd.action) {
case LFUN_MOUSE_RELEASE:
InsetCommandMailer("label", *this).showDialog(bv);
return DispatchResult(true, true);
case LFUN_INSET_MODIFY: {
InsetCommandParams p;
InsetCommandMailer::string2params(cmd.argument, p);
InsetCommandMailer::string2params("label", cmd.argument, p);
if (p.getCmdName().empty())
return DispatchResult(false);

View File

@ -19,8 +19,6 @@ public:
///
InsetLabel(InsetCommandParams const &);
///
~InsetLabel();
///
std::auto_ptr<InsetBase> clone() const;
///
std::string const getScreenLabel(Buffer const &) const;

View File

@ -303,7 +303,6 @@ void InsetMinipageMailer::string2params(string const & in,
InsetMinipage::Params & params)
{
params = InsetMinipage::Params();
if (in.empty())
return;
@ -311,25 +310,19 @@ void InsetMinipageMailer::string2params(string const & in,
LyXLex lex(0, 0);
lex.setStream(data);
if (lex.isOK()) {
lex.next();
string const token = lex.getString();
if (token != "minipage")
return;
}
string name;
lex >> name;
if (!lex || name != name_)
return print_mailer_error("InsetMinipageMailer", in, 1, name_);
// This is part of the inset proper that is usually swallowed
// by Buffer::readInset
if (lex.isOK()) {
lex.next();
string const token = lex.getString();
if (token != "Minipage")
return;
}
// by LyXText::readInset
string id;
lex >> id;
if (!lex || id != "Minipage")
return print_mailer_error("InsetBoxMailer", in, 2, "Minipage");
if (lex.isOK()) {
params.read(lex);
}
}

View File

@ -351,18 +351,15 @@ void InsetNoteMailer::string2params(string const & in,
string name;
lex >> name;
if (!lex || name != name_) {
lyxerr << "InsetNoteMailer::string2params(" << in << ")\n"
<< "Missing identifier \"" << name_ << '"' << std::endl;
return;
}
if (!lex || name != name_)
return print_mailer_error("InsetNoteMailer", in, 1, name_);
// This is part of the inset proper that is usually swallowed
// by LyXText::readInset
string inset_id;
lex >> inset_id;
if (!lex || inset_id != "Note")
return;
string id;
lex >> id;
if (!lex || id != "Note")
return print_mailer_error("InsetBoxMailer", in, 2, "Note");
params.read(lex);
}

View File

@ -30,20 +30,13 @@ using std::ostream;
InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
: InsetCommand(p), isLatex(buf.isLatex())
: InsetCommand(p, "ref"), isLatex(buf.isLatex())
{}
InsetRef::InsetRef(InsetRef const & ir)
: InsetCommand(ir), isLatex(ir.isLatex)
{
}
InsetRef::~InsetRef()
{
InsetCommandMailer("ref", *this).hideDialog();
}
{}
DispatchResult

View File

@ -40,7 +40,6 @@ public:
InsetRef(InsetRef const &);
~InsetRef();
///
virtual std::auto_ptr<InsetBase> clone() const {
return std::auto_ptr<InsetBase>(new InsetRef(*this));

View File

@ -26,16 +26,10 @@ using std::ostream;
InsetTOC::InsetTOC(InsetCommandParams const & p)
: InsetCommand(p)
: InsetCommand(p, "toc")
{}
InsetTOC::~InsetTOC()
{
InsetCommandMailer("toc", *this).hideDialog();
}
std::auto_ptr<InsetBase> InsetTOC::clone() const
{
return std::auto_ptr<InsetBase>(new InsetTOC(*this));
@ -58,22 +52,6 @@ InsetOld::Code InsetTOC::lyxCode() const
}
DispatchResult
InsetTOC::priv_dispatch(FuncRequest const & cmd,
idx_type & idx, pos_type & pos)
{
switch (cmd.action) {
case LFUN_MOUSE_RELEASE:
case LFUN_INSET_DIALOG_SHOW:
InsetCommandMailer("toc", *this).showDialog(cmd.view());
return DispatchResult(true, true);
default:
return InsetCommand::priv_dispatch(cmd, idx, pos);
}
}
int InsetTOC::plaintext(Buffer const & buffer, ostream & os,
OutputParams const &) const
{

View File

@ -21,8 +21,6 @@ public:
///
explicit InsetTOC(InsetCommandParams const &);
///
~InsetTOC();
///
std::auto_ptr<InsetBase> clone() const;
///
std::string const getScreenLabel(Buffer const &) const;
@ -41,11 +39,6 @@ public:
///
int docbook(Buffer const &, std::ostream &,
OutputParams const &) const;
protected:
///
virtual
DispatchResult
priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &);
};
#endif

View File

@ -29,35 +29,10 @@ using std::ostream;
InsetUrl::InsetUrl(InsetCommandParams const & p)
: InsetCommand(p)
: InsetCommand(p, "url")
{}
// InsetUrl::InsetUrl(InsetCommandParams const & p, bool)
// : InsetCommand(p, false)
// {}
InsetUrl::~InsetUrl()
{
InsetCommandMailer("url", *this).hideDialog();
}
DispatchResult
InsetUrl::priv_dispatch(FuncRequest const & cmd,
idx_type & idx, pos_type & pos)
{
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
InsetCommandMailer("url", *this).showDialog(cmd.view());
return DispatchResult(true, true);
default:
return InsetCommand::priv_dispatch(cmd, idx, pos);
}
}
string const InsetUrl::getScreenLabel(Buffer const &) const
{
string temp;

View File

@ -25,8 +25,6 @@ public:
explicit
InsetUrl(InsetCommandParams const &);
///
~InsetUrl();
///
virtual std::auto_ptr<InsetBase> clone() const {
return std::auto_ptr<InsetBase>(new InsetUrl(params()));
}
@ -52,11 +50,6 @@ public:
///
int docbook(Buffer const &, std::ostream &,
OutputParams const &) const;
protected:
///
virtual
DispatchResult
priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &);
};
#endif

View File

@ -239,15 +239,20 @@ string const InsetVSpaceMailer::inset2string(Buffer const &) const
void InsetVSpaceMailer::string2params(string const & in, VSpace & vspace)
{
vspace = VSpace();
if (in.empty())
return;
istringstream data(in);
LyXLex lex(0,0);
lex.setStream(data);
string name, vsp;
lex >> name >> vsp;
string name;
lex >> name;
if (!lex || name != name_)
return print_mailer_error("InsetVSpaceMailer", in, 1, name_);
string vsp;
lex >> vsp;
if (lex)
vspace = VSpace(vsp);
}

View File

@ -261,7 +261,6 @@ string const InsetWrapMailer::inset2string(Buffer const &) const
void InsetWrapMailer::string2params(string const & in, InsetWrapParams & params)
{
params = InsetWrapParams();
if (in.empty())
return;
@ -269,25 +268,19 @@ void InsetWrapMailer::string2params(string const & in, InsetWrapParams & params)
LyXLex lex(0,0);
lex.setStream(data);
if (lex.isOK()) {
lex.next();
string const token = lex.getString();
if (token != name_)
return;
}
string name;
lex >> name;
if (!lex || name != name_)
return print_mailer_error("InsetWrapMailer", in, 1, name_);
// This is part of the inset proper that is usually swallowed
// by Buffer::readInset
if (lex.isOK()) {
lex.next();
string const token = lex.getString();
if (token != "Wrap" || !lex.eatLine())
return;
}
// by LyXText::readInset
string id;
lex >> id;
if (!lex || id != "Wrap")
return print_mailer_error("InsetBoxMailer", in, 2, "Wrap");
if (lex.isOK()) {
params.read(lex);
}
}

View File

@ -13,10 +13,13 @@
#include "mailinset.h"
#include "BufferView.h"
#include "debug.h"
#include "frontends/Dialogs.h"
#include "frontends/LyXView.h"
using std::string;
void MailInset::showDialog(BufferView * bv) const
{
@ -39,3 +42,12 @@ void MailInset::hideDialog() const
{
Dialogs::hide(name(), &inset());
}
void print_mailer_error(string const & class_name,
string const & data, int arg_id, string const & arg)
{
lyxerr << class_name << "::string2params(" << data << ")\n"
<< "Expected arg " << arg_id << "to be \"" << arg << '"'
<< std::endl;
}

View File

@ -40,5 +40,9 @@ protected:
virtual std::string const & name() const = 0;
};
void print_mailer_error(std::string const & class_name,
std::string const & data,
int arg_id, std::string const & arg);
#endif // MAILINSET_H