From fd355bbb2f3b192ccf92a59177eb68255449048f Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Thu, 11 Dec 2003 15:23:15 +0000 Subject: [PATCH] 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 --- src/ChangeLog | 5 ++ src/factory.C | 24 ++++++---- src/frontends/controllers/ChangeLog | 5 ++ src/frontends/controllers/ControlCommand.C | 4 +- src/insets/ChangeLog | 46 +++++++++++++++++++ src/insets/insetbibitem.C | 14 +----- src/insets/insetbibitem.h | 2 - src/insets/insetbibtex.C | 38 +--------------- src/insets/insetbibtex.h | 6 --- src/insets/insetbox.C | 16 +++---- src/insets/insetbranch.C | 3 +- src/insets/insetcite.C | 29 +----------- src/insets/insetcite.h | 7 --- src/insets/insetcommand.C | 53 +++++++++++++--------- src/insets/insetcommand.h | 11 +++-- src/insets/insetert.C | 9 ++-- src/insets/insetexternal.C | 27 ++++------- src/insets/insetfloat.C | 27 ++++------- src/insets/insetfloatlist.C | 48 +------------------- src/insets/insetfloatlist.h | 11 ----- src/insets/insetgraphics.C | 19 +++----- src/insets/insethfill.C | 2 +- src/insets/insetinclude.C | 31 +++++-------- src/insets/insetindex.C | 43 +----------------- src/insets/insetindex.h | 14 ------ src/insets/insetlabel.C | 14 +----- src/insets/insetlabel.h | 2 - src/insets/insetminipage.C | 27 ++++------- src/insets/insetnote.C | 15 +++--- src/insets/insetref.C | 11 +---- src/insets/insetref.h | 1 - src/insets/insettoc.C | 24 +--------- src/insets/insettoc.h | 7 --- src/insets/inseturl.C | 27 +---------- src/insets/inseturl.h | 7 --- src/insets/insetvspace.C | 11 +++-- src/insets/insetwrap.C | 27 ++++------- src/insets/mailinset.C | 12 +++++ src/insets/mailinset.h | 4 ++ 39 files changed, 231 insertions(+), 452 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 6571c28bdd..904f529447 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2003-12-11 Angus Leeming + + * factory.C (createInset): changes due to the changed interface to + InsetCommandMailer::string2params. + 2003-12-10 Angus Leeming * lyxfunc.C (dispatch): enable all inset dialogs to be opened with diff --git a/src/factory.C b/src/factory.C index f2b61dbd4c..20a85fbabd 100644 --- a/src/factory.C +++ b/src/factory.C @@ -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") { diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index aa7c868432..b34f9429d8 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,8 @@ +2003-12-11 Angus Leeming + + * ControlCommand.C (initialiseParams): changes due to the changed + interface to InsetCommandMailer::string2params. + 2003-12-10 Angus Leeming * ControlNote.[Ch] (note_gui_tokens): removed; no longer needed. diff --git a/src/frontends/controllers/ControlCommand.C b/src/frontends/controllers/ControlCommand.C index 2734b45d53..7812507f46 100644 --- a/src/frontends/controllers/ControlCommand.C +++ b/src/frontends/controllers/ControlCommand.C @@ -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; } diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index a13a90531a..fd2e2881cb 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,49 @@ +2003-12-11 Angus Leeming + + * 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 * insetexternal.[Ch]: add a draft option and respect it when diff --git a/src/insets/insetbibitem.C b/src/insets/insetbibitem.C index 3b18f09854..25ed6a6b53 100644 --- a/src/insets/insetbibitem.C +++ b/src/insets/insetbibitem.C @@ -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 InsetBibitem::clone() const { auto_ptr 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); diff --git a/src/insets/insetbibitem.h b/src/insets/insetbibitem.h index c71e9e26cc..96fe35a949 100644 --- a/src/insets/insetbibitem.h +++ b/src/insets/insetbibitem.h @@ -27,8 +27,6 @@ public: /// InsetBibitem(InsetCommandParams const &); /// - ~InsetBibitem(); - /// std::auto_ptr clone() const; /** Currently \bibitem is used as a LyX2.x command, so we need this method. diff --git a/src/insets/insetbibtex.C b/src/insets/insetbibtex.C index 3ec64011f1..028d1dfe71 100644 --- a/src/insets/insetbibtex.C +++ b/src/insets/insetbibtex.C @@ -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 InsetBibtex::clone() const { return std::auto_ptr(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); diff --git a/src/insets/insetbibtex.h b/src/insets/insetbibtex.h index 049c895279..f00f1ffb0a 100644 --- a/src/insets/insetbibtex.h +++ b/src/insets/insetbibtex.h @@ -23,14 +23,8 @@ public: /// InsetBibtex(InsetCommandParams const &); /// - ~InsetBibtex(); - /// std::auto_ptr 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; } diff --git a/src/insets/insetbox.C b/src/insets/insetbox.C index a1b0c57847..0b224108d1 100644 --- a/src/insets/insetbox.C +++ b/src/insets/insetbox.C @@ -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); } diff --git a/src/insets/insetbranch.C b/src/insets/insetbranch.C index e08702b2c2..9cc918f402 100644 --- a/src/insets/insetbranch.C +++ b/src/insets/insetbranch.C @@ -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: diff --git a/src/insets/insetcite.C b/src/insets/insetcite.C index c038e0424e..05d168c01e 100644 --- a/src/insets/insetcite.C +++ b/src/insets/insetcite.C @@ -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)) diff --git a/src/insets/insetcite.h b/src/insets/insetcite.h index 6cb9b5e2f1..7e28c061b8 100644 --- a/src/insets/insetcite.h +++ b/src/insets/insetcite.h @@ -23,8 +23,6 @@ public: /// InsetCitation(InsetCommandParams const &); /// - ~InsetCitation(); - /// std::auto_ptr clone() const { return std::auto_ptr(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 { /// diff --git a/src/insets/insetcommand.C b/src/insets/insetcommand.C index 713fbd3555..80d5ae8d12 100644 --- a/src/insets/insetcommand.C +++ b/src/insets/insetcommand.C @@ -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()) { - params.read(lex); - } + // 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; diff --git a/src/insets/insetcommand.h b/src/insets/insetcommand.h index 749d41579f..829db405bb 100644 --- a/src/insets/insetcommand.h +++ b/src/insets/insetcommand.h @@ -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,10 +111,11 @@ 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 &); + InsetCommandParams const &); private: /// std::string const name_; diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 1fe2feb33c..fbf577bbac 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -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; diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 62b77c891c..8840ebc5bf 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -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); - } + params.read(buffer, lex); } diff --git a/src/insets/insetfloat.C b/src/insets/insetfloat.C index aa45ba6d3c..46a7f1ac5c 100644 --- a/src/insets/insetfloat.C +++ b/src/insets/insetfloat.C @@ -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); - } + params.read(lex); } diff --git a/src/insets/insetfloatlist.C b/src/insets/insetfloatlist.C index 3699acd8e1..162df18570 100644 --- a/src/insets/insetfloatlist.C +++ b/src/insets/insetfloatlist.C @@ -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 { diff --git a/src/insets/insetfloatlist.h b/src/insets/insetfloatlist.h index 50dd2aba09..197b2dc182 100644 --- a/src/insets/insetfloatlist.h +++ b/src/insets/insetfloatlist.h @@ -24,16 +24,10 @@ public: /// InsetFloatList(std::string const & type); /// - ~InsetFloatList(); - /// virtual std::auto_ptr clone() const { return std::auto_ptr(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 diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 4a025357c9..257efeece2 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -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(); - } + InsetGraphics inset; + inset.readInsetGraphics(lex, buffer.filePath()); + params = inset.params(); } diff --git a/src/insets/insethfill.C b/src/insets/insethfill.C index 2fc778ced0..cb6c812707 100644 --- a/src/insets/insethfill.C +++ b/src/insets/insethfill.C @@ -18,7 +18,7 @@ using std::ostream; InsetHFill::InsetHFill() - : InsetCommand(InsetCommandParams("hfill")) + : InsetCommand(InsetCommandParams("hfill"), std::string()) {} diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 74579a2752..25b87afca7 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -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(); - } + InsetInclude inset(params); + inset.read(lex); + params = inset.params(); } diff --git a/src/insets/insetindex.C b/src/insets/insetindex.C index 1572347ac1..fa27b2440b 100644 --- a/src/insets/insetindex.C +++ b/src/insets/insetindex.C @@ -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"); diff --git a/src/insets/insetindex.h b/src/insets/insetindex.h index 34a634f143..997ec4a76a 100644 --- a/src/insets/insetindex.h +++ b/src/insets/insetindex.h @@ -24,8 +24,6 @@ public: /// InsetIndex(InsetCommandParams const &); /// - ~InsetIndex(); - /// virtual std::auto_ptr clone() const { return std::auto_ptr(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 clone() const { return std::auto_ptr(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 diff --git a/src/insets/insetlabel.C b/src/insets/insetlabel.C index 5f225ae608..6276c36194 100644 --- a/src/insets/insetlabel.C +++ b/src/insets/insetlabel.C @@ -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 InsetLabel::clone() const { return std::auto_ptr(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); diff --git a/src/insets/insetlabel.h b/src/insets/insetlabel.h index 15cf530839..d81f71556b 100644 --- a/src/insets/insetlabel.h +++ b/src/insets/insetlabel.h @@ -19,8 +19,6 @@ public: /// InsetLabel(InsetCommandParams const &); /// - ~InsetLabel(); - /// std::auto_ptr clone() const; /// std::string const getScreenLabel(Buffer const &) const; diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index eaf4b00bc5..3a4f2da379 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -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); - } + params.read(lex); } diff --git a/src/insets/insetnote.C b/src/insets/insetnote.C index 83888887c7..c2bd5767fa 100644 --- a/src/insets/insetnote.C +++ b/src/insets/insetnote.C @@ -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); } diff --git a/src/insets/insetref.C b/src/insets/insetref.C index e0ce44def7..af6c17cba2 100644 --- a/src/insets/insetref.C +++ b/src/insets/insetref.C @@ -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 diff --git a/src/insets/insetref.h b/src/insets/insetref.h index 13d32ce260..73ab89aa39 100644 --- a/src/insets/insetref.h +++ b/src/insets/insetref.h @@ -40,7 +40,6 @@ public: InsetRef(InsetRef const &); - ~InsetRef(); /// virtual std::auto_ptr clone() const { return std::auto_ptr(new InsetRef(*this)); diff --git a/src/insets/insettoc.C b/src/insets/insettoc.C index 5b5f3ec436..fa91fa2855 100644 --- a/src/insets/insettoc.C +++ b/src/insets/insettoc.C @@ -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 InsetTOC::clone() const { return std::auto_ptr(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 { diff --git a/src/insets/insettoc.h b/src/insets/insettoc.h index 1579655128..98813a7f1a 100644 --- a/src/insets/insettoc.h +++ b/src/insets/insettoc.h @@ -21,8 +21,6 @@ public: /// explicit InsetTOC(InsetCommandParams const &); /// - ~InsetTOC(); - /// std::auto_ptr 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 diff --git a/src/insets/inseturl.C b/src/insets/inseturl.C index 741dc0220a..0f052738d8 100644 --- a/src/insets/inseturl.C +++ b/src/insets/inseturl.C @@ -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; diff --git a/src/insets/inseturl.h b/src/insets/inseturl.h index 8555331683..3f30120b32 100644 --- a/src/insets/inseturl.h +++ b/src/insets/inseturl.h @@ -25,8 +25,6 @@ public: explicit InsetUrl(InsetCommandParams const &); /// - ~InsetUrl(); - /// virtual std::auto_ptr clone() const { return std::auto_ptr(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 diff --git a/src/insets/insetvspace.C b/src/insets/insetvspace.C index 595db97a73..7b7c9a3998 100644 --- a/src/insets/insetvspace.C +++ b/src/insets/insetvspace.C @@ -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); } diff --git a/src/insets/insetwrap.C b/src/insets/insetwrap.C index 6040f3779b..df42307e19 100644 --- a/src/insets/insetwrap.C +++ b/src/insets/insetwrap.C @@ -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); - } + params.read(lex); } diff --git a/src/insets/mailinset.C b/src/insets/mailinset.C index d9995ca2d7..48b2cf2b48 100644 --- a/src/insets/mailinset.C +++ b/src/insets/mailinset.C @@ -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; +} diff --git a/src/insets/mailinset.h b/src/insets/mailinset.h index 3e7622df20..4d5e6191f7 100644 --- a/src/insets/mailinset.h +++ b/src/insets/mailinset.h @@ -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 -- 2.39.2