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> 2003-12-10 Angus Leeming <leeming@lyx.org>
* lyxfunc.C (dispatch): enable all inset dialogs to be opened with * 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") { if (name == "bibitem") {
InsetCommandParams icp; InsetCommandParams icp;
InsetCommandMailer::string2params(cmd.argument, icp); InsetCommandMailer::string2params(name, cmd.argument,
icp);
return new InsetBibitem(icp); return new InsetBibitem(icp);
} else if (name == "bibtex") { } else if (name == "bibtex") {
InsetCommandParams icp; InsetCommandParams icp;
InsetCommandMailer::string2params(cmd.argument, icp); InsetCommandMailer::string2params(name, cmd.argument,
icp);
return new InsetBibtex(icp); return new InsetBibtex(icp);
} else if (name == "citation") { } else if (name == "citation") {
InsetCommandParams icp; InsetCommandParams icp;
InsetCommandMailer::string2params(cmd.argument, icp); InsetCommandMailer::string2params(name, cmd.argument,
icp);
return new InsetCitation(icp); return new InsetCitation(icp);
} else if (name == "ert") { } else if (name == "ert") {
@ -260,27 +263,32 @@ InsetOld * createInset(FuncRequest const & cmd)
} else if (name == "index") { } else if (name == "index") {
InsetCommandParams icp; InsetCommandParams icp;
InsetCommandMailer::string2params(cmd.argument, icp); InsetCommandMailer::string2params(name, cmd.argument,
icp);
return new InsetIndex(icp); return new InsetIndex(icp);
} else if (name == "label") { } else if (name == "label") {
InsetCommandParams icp; InsetCommandParams icp;
InsetCommandMailer::string2params(cmd.argument, icp); InsetCommandMailer::string2params(name, cmd.argument,
icp);
return new InsetLabel(icp); return new InsetLabel(icp);
} else if (name == "ref") { } else if (name == "ref") {
InsetCommandParams icp; InsetCommandParams icp;
InsetCommandMailer::string2params(cmd.argument, icp); InsetCommandMailer::string2params(name, cmd.argument,
icp);
return new InsetRef(icp, *bv->buffer()); return new InsetRef(icp, *bv->buffer());
} else if (name == "toc") { } else if (name == "toc") {
InsetCommandParams icp; InsetCommandParams icp;
InsetCommandMailer::string2params(cmd.argument, icp); InsetCommandMailer::string2params(name, cmd.argument,
icp);
return new InsetTOC(icp); return new InsetTOC(icp);
} else if (name == "url") { } else if (name == "url") {
InsetCommandParams icp; InsetCommandParams icp;
InsetCommandMailer::string2params(cmd.argument, icp); InsetCommandMailer::string2params(name, cmd.argument,
icp);
return new InsetUrl(icp); return new InsetUrl(icp);
} else if (name == "vspace") { } 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> 2003-12-10 Angus Leeming <leeming@lyx.org>
* ControlNote.[Ch] (note_gui_tokens): removed; no longer needed. * 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) 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; 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> 2003-12-10 Angus Leeming <leeming@lyx.org>
* insetexternal.[Ch]: add a draft option and respect it when * 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) InsetBibitem::InsetBibitem(InsetCommandParams const & p)
: InsetCommand(p), counter(1) : InsetCommand(p, "bibitem"), counter(1)
{ {
if (getContents().empty()) if (getContents().empty())
setContents(key_prefix + tostr(++key_counter)); setContents(key_prefix + tostr(++key_counter));
} }
InsetBibitem::~InsetBibitem()
{
InsetCommandMailer("bibitem", *this).hideDialog();
}
auto_ptr<InsetBase> InsetBibitem::clone() const auto_ptr<InsetBase> InsetBibitem::clone() const
{ {
auto_ptr<InsetBibitem> b(new InsetBibitem(params())); auto_ptr<InsetBibitem> b(new InsetBibitem(params()));
@ -65,13 +59,9 @@ InsetBibitem::priv_dispatch(FuncRequest const & cmd,
{ {
switch (cmd.action) { switch (cmd.action) {
case LFUN_MOUSE_PRESS:
InsetCommandMailer("bibitem", *this).showDialog(cmd.view());
return DispatchResult(true, true);
case LFUN_INSET_MODIFY: { case LFUN_INSET_MODIFY: {
InsetCommandParams p; InsetCommandParams p;
InsetCommandMailer::string2params(cmd.argument, p); InsetCommandMailer::string2params("bibitem", cmd.argument, p);
if (p.getCmdName().empty()) if (p.getCmdName().empty())
return DispatchResult(true, true); return DispatchResult(true, true);
setParams(p); setParams(p);

View File

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

View File

@ -55,39 +55,16 @@ using std::vector;
InsetBibtex::InsetBibtex(InsetCommandParams const & p) InsetBibtex::InsetBibtex(InsetCommandParams const & p)
: InsetCommand(p) : InsetCommand(p, "bibtex")
{} {}
InsetBibtex::~InsetBibtex()
{
InsetCommandMailer("bibtex", *this).hideDialog();
}
std::auto_ptr<InsetBase> InsetBibtex::clone() const std::auto_ptr<InsetBase> InsetBibtex::clone() const
{ {
return std::auto_ptr<InsetBase>(new InsetBibtex(*this)); 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 DispatchResult
InsetBibtex::priv_dispatch(FuncRequest const & cmd, InsetBibtex::priv_dispatch(FuncRequest const & cmd,
idx_type & idx, pos_type & pos) idx_type & idx, pos_type & pos)
@ -96,20 +73,9 @@ InsetBibtex::priv_dispatch(FuncRequest const & cmd,
switch (cmd.action) { 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: { case LFUN_INSET_MODIFY: {
InsetCommandParams p; InsetCommandParams p;
InsetCommandMailer::string2params(cmd.argument, p); InsetCommandMailer::string2params("bibtex", cmd.argument, p);
if (!p.getCmdName().empty()) if (!p.getCmdName().empty())
setParams(p); setParams(p);
result.dispatched(true); result.dispatched(true);

View File

@ -23,14 +23,8 @@ public:
/// ///
InsetBibtex(InsetCommandParams const &); InsetBibtex(InsetCommandParams const &);
/// ///
~InsetBibtex();
///
std::auto_ptr<InsetBase> clone() const; 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; std::string const getScreenLabel(Buffer const &) const;
/// ///
EDITABLE editable() const { return IS_EDITABLE; } EDITABLE editable() const { return IS_EDITABLE; }

View File

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

View File

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

View File

@ -215,21 +215,10 @@ string const getBasicLabel(string const & keyList, string const & after)
InsetCitation::InsetCitation(InsetCommandParams const & p) 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 InsetCitation::generateLabel(Buffer const & buffer) const
{ {
string const before = string(); 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 int InsetCitation::plaintext(Buffer const & buffer, ostream & os, int) const
{ {
if (cache.params == params() && cache.style == getStyle(buffer)) if (cache.params == params() && cache.style == getStyle(buffer))

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -35,23 +35,17 @@ using std::ostream;
InsetFloatList::InsetFloatList() InsetFloatList::InsetFloatList()
: InsetCommand(InsetCommandParams()) : InsetCommand(InsetCommandParams(), "toc")
{} {}
InsetFloatList::InsetFloatList(string const & type) InsetFloatList::InsetFloatList(string const & type)
: InsetCommand(InsetCommandParams()) : InsetCommand(InsetCommandParams(), "toc")
{ {
setCmdName(type); setCmdName(type);
} }
InsetFloatList::~InsetFloatList()
{
InsetCommandMailer("toc", *this).hideDialog();
}
string const InsetFloatList::getScreenLabel(Buffer const & buf) const string const InsetFloatList::getScreenLabel(Buffer const & buf) const
{ {
FloatList const & floats = buf.params().getLyXTextClass().floats(); 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, int InsetFloatList::latex(Buffer const & buf, ostream & os,
OutputParams const &) const OutputParams const &) const
{ {

View File

@ -24,16 +24,10 @@ public:
/// ///
InsetFloatList(std::string const & type); InsetFloatList(std::string const & type);
/// ///
~InsetFloatList();
///
virtual std::auto_ptr<InsetBase> clone() const { virtual std::auto_ptr<InsetBase> clone() const {
return std::auto_ptr<InsetBase>(new InsetFloatList(getCmdName())); 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; std::string const getScreenLabel(Buffer const &) const;
/// ///
EDITABLE editable() const { return IS_EDITABLE; } EDITABLE editable() const { return IS_EDITABLE; }
@ -59,11 +53,6 @@ public:
OutputParams const & runparams) const; OutputParams const & runparams) const;
/// ///
void validate(LaTeXFeatures & features) const; void validate(LaTeXFeatures & features) const;
protected:
///
virtual
DispatchResult
priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &);
}; };
#endif #endif

View File

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

View File

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

View File

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

View File

@ -24,7 +24,7 @@ using std::ostream;
InsetIndex::InsetIndex(InsetCommandParams const & p) 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 string const InsetIndex::getScreenLabel(Buffer const &) const
{ {
return _("Idx"); 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, int InsetIndex::docbook(Buffer const &, ostream & os,
OutputParams const &) const OutputParams const &) const
{ {
@ -91,7 +56,7 @@ InsetOld::Code InsetIndex::lyxCode() const
InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p) 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 string const InsetPrintIndex::getScreenLabel(Buffer const &) const
{ {
return _("Index"); return _("Index");

View File

@ -24,8 +24,6 @@ public:
/// ///
InsetIndex(InsetCommandParams const &); InsetIndex(InsetCommandParams const &);
/// ///
~InsetIndex();
///
virtual std::auto_ptr<InsetBase> clone() const { virtual std::auto_ptr<InsetBase> clone() const {
return std::auto_ptr<InsetBase>(new InsetIndex(params())); return std::auto_ptr<InsetBase>(new InsetIndex(params()));
} }
@ -38,9 +36,6 @@ public:
/// ///
int docbook(Buffer const &, std::ostream &, int docbook(Buffer const &, std::ostream &,
OutputParams const &) const; OutputParams const &) const;
///
DispatchResult priv_dispatch(FuncRequest const & cmd,
idx_type & idx, pos_type & pos);
}; };
@ -49,8 +44,6 @@ public:
/// ///
InsetPrintIndex(InsetCommandParams const &); InsetPrintIndex(InsetCommandParams const &);
/// ///
~InsetPrintIndex();
///
virtual std::auto_ptr<InsetBase> clone() const { virtual std::auto_ptr<InsetBase> clone() const {
return std::auto_ptr<InsetBase>(new InsetPrintIndex(params())); return std::auto_ptr<InsetBase>(new InsetPrintIndex(params()));
} }
@ -64,13 +57,6 @@ public:
bool display() const { return true; } bool display() const { return true; }
/// ///
std::string const getScreenLabel(Buffer const &) const; 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 #endif

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -26,16 +26,10 @@ using std::ostream;
InsetTOC::InsetTOC(InsetCommandParams const & p) InsetTOC::InsetTOC(InsetCommandParams const & p)
: InsetCommand(p) : InsetCommand(p, "toc")
{} {}
InsetTOC::~InsetTOC()
{
InsetCommandMailer("toc", *this).hideDialog();
}
std::auto_ptr<InsetBase> InsetTOC::clone() const std::auto_ptr<InsetBase> InsetTOC::clone() const
{ {
return std::auto_ptr<InsetBase>(new InsetTOC(*this)); 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, int InsetTOC::plaintext(Buffer const & buffer, ostream & os,
OutputParams const &) const OutputParams const &) const
{ {

View File

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

View File

@ -29,35 +29,10 @@ using std::ostream;
InsetUrl::InsetUrl(InsetCommandParams const & p) 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 const InsetUrl::getScreenLabel(Buffer const &) const
{ {
string temp; string temp;

View File

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

View File

@ -239,15 +239,20 @@ string const InsetVSpaceMailer::inset2string(Buffer const &) const
void InsetVSpaceMailer::string2params(string const & in, VSpace & vspace) void InsetVSpaceMailer::string2params(string const & in, VSpace & vspace)
{ {
vspace = VSpace(); vspace = VSpace();
if (in.empty()) if (in.empty())
return; return;
istringstream data(in); istringstream data(in);
LyXLex lex(0,0); LyXLex lex(0,0);
lex.setStream(data); 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) if (lex)
vspace = VSpace(vsp); vspace = VSpace(vsp);
} }

View File

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

View File

@ -13,10 +13,13 @@
#include "mailinset.h" #include "mailinset.h"
#include "BufferView.h" #include "BufferView.h"
#include "debug.h"
#include "frontends/Dialogs.h" #include "frontends/Dialogs.h"
#include "frontends/LyXView.h" #include "frontends/LyXView.h"
using std::string;
void MailInset::showDialog(BufferView * bv) const void MailInset::showDialog(BufferView * bv) const
{ {
@ -39,3 +42,12 @@ void MailInset::hideDialog() const
{ {
Dialogs::hide(name(), &inset()); 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; 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 #endif // MAILINSET_H