]> git.lyx.org Git - lyx.git/commitdiff
Remove a whole heap of redundant functions from classes derived from
authorAngus Leeming <leeming@lyx.org>
Thu, 11 Dec 2003 15:23:15 +0000 (15:23 +0000)
committerAngus Leeming <leeming@lyx.org>
Thu, 11 Dec 2003 15:23:15 +0000 (15:23 +0000)
InsetCommand.
Clean-up many Mailer::string2params functions.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8233 a592a061-630c-0410-9148-cb99ea01b6c8

39 files changed:
src/ChangeLog
src/factory.C
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlCommand.C
src/insets/ChangeLog
src/insets/insetbibitem.C
src/insets/insetbibitem.h
src/insets/insetbibtex.C
src/insets/insetbibtex.h
src/insets/insetbox.C
src/insets/insetbranch.C
src/insets/insetcite.C
src/insets/insetcite.h
src/insets/insetcommand.C
src/insets/insetcommand.h
src/insets/insetert.C
src/insets/insetexternal.C
src/insets/insetfloat.C
src/insets/insetfloatlist.C
src/insets/insetfloatlist.h
src/insets/insetgraphics.C
src/insets/insethfill.C
src/insets/insetinclude.C
src/insets/insetindex.C
src/insets/insetindex.h
src/insets/insetlabel.C
src/insets/insetlabel.h
src/insets/insetminipage.C
src/insets/insetnote.C
src/insets/insetref.C
src/insets/insetref.h
src/insets/insettoc.C
src/insets/insettoc.h
src/insets/inseturl.C
src/insets/inseturl.h
src/insets/insetvspace.C
src/insets/insetwrap.C
src/insets/mailinset.C
src/insets/mailinset.h

index 6571c28bdd55d021ad24df870cc618f3d9b59151..904f5294471f9f0dcd5d1dc0a82b2beb456b359f 100644 (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
index f2b61dbd4c0b5c537a228c9aae56804fea8c3757..20a85fbabd4d6c0af9e73726f9690c91054a45ac 100644 (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") {
index aa7c8684320a964d078387398be634234f7af030..b34f9429d806fc6934aeba7aeacf1971613d8562 100644 (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.
index 2734b45d53a07af9eaf90b9f32c47d1bca5d3290..7812507f462e0abd9df36fc05b8ff2896de4144a 100644 (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;
 }
 
index a13a90531a74b505e6348a34fdf7afe2ad222804..fd2e2881cb619bf2fedcd55b156c30fd8486656d 100644 (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
index 3b18f098546527befba9f237da965e874af46e2b..25ed6a6b53e05c0d2986014f4a3eca0afe276d41 100644 (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);
index c71e9e26cc82e8253ffd1dd94d6793ceba4823ec..96fe35a949d8eb7379c5552e068bf0f3aa7d23f3 100644 (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.
index 3ec64011f1e639a0da1d66d21a2a8329012c3b23..028d1dfe718e2c2819dc1e6cc7675d30cf5fd3a6 100644 (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);
index 049c895279d7952974213040a40b979976379e9d..f00f1ffb0af824cdffb374fc80c8c6e534c85c11 100644 (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; }
index a1b0c57847604f1e47a067a9e22903048cc8b19d..0b224108d10ca0c46b966af7a788405300e919f3 100644 (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);
 }
index e08702b2c2fe7d721daa3fb3db58fc5e072d3c7c..9cc918f402d28f79cdd029f3aa0b486a28a9d5dd 100644 (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:
index c038e0424eaf80ad6875120fd4f0948df9da5830..05d168c01ef8647df42d72c196bccd3d767d19e9 100644 (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))
index 6cb9b5e2f10bdd19274d3cc7b0d1301e90955e80..7e28c061b8f13d9d3b955253afff44fe9588b5e8 100644 (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 {
                ///
index 713fbd35555880a7fe2f11a22300f6c281b34853..80d5ae8d12b2270f51ea265516f3ec5462b7685e 100644 (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()) {
-               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;
index 749d41579f34239a1042e883e020cea2395ca489..829db405bb9164fa0eecece0157febabdb18e1f8 100644 (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,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_;
index 1fe2feb33cf4528f02645b861618628a162fd858..fbf577bbac3df9663dac4e8c1bcff05cd8abe798 100644 (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;
index 62b77c891ce4dce91419472baa4655ec6a9b0995..8840ebc5bf82ba66133f00bb22d35b8da049d593 100644 (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);
-       }
+       params.read(buffer, lex);
 }
 
 
index aa45ba6d3c4a6a89939d6b18597732c4fc140d62..46a7f1ac5c1b3e1088919c725df2043bd6667025 100644 (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);
-       }
+       params.read(lex);
 }
 
 
index 3699acd8e11268375cd07ddd95d21e95ba4598ea..162df1857088dcd918fedf21d9bf3a8bd2eab5e5 100644 (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
 {
index 50dd2aba0948c10a84172db42321f4ee7fed07e0..197b2dc18285b1ff20f21d9289e91d8233d39f43 100644 (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
index 4a025357c98d4cc4bec63d749f64de4341e6cff4..257efeece25264d28ab3ba6d5136b2edb9c552dc 100644 (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();
-       }
+       InsetGraphics inset;
+       inset.readInsetGraphics(lex, buffer.filePath());
+       params = inset.params();
 }
 
 
index 2fc778ced0a447ed55cc8045a7004c82e9e506a5..cb6c8127075363ba3d52c629f52090745f431760 100644 (file)
@@ -18,7 +18,7 @@ using std::ostream;
 
 
 InsetHFill::InsetHFill()
-       : InsetCommand(InsetCommandParams("hfill"))
+       : InsetCommand(InsetCommandParams("hfill"), std::string())
 {}
 
 
index 74579a2752ece2656984b9f897c6b686a4c5ea26..25b87afca720178ba417e7d608371610758c327f 100644 (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();
-       }
+       InsetInclude inset(params);
+       inset.read(lex);
+       params = inset.params();
 }
 
 
index 1572347ac16c67b7a9e861b2730cd6634db3da4f..fa27b2440b5076d7bf40a13efa82e3e22aaf35c7 100644 (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");
index 34a634f143477703365c54d6ed3628f5eb326497..997ec4a76a4551a41b51ec7376f1c2f93129ec9b 100644 (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
index 5f225ae608180c68d9a9fcc47e4a183be1011351..6276c36194b56824109b9e92f429beb1e277ea23 100644 (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);
 
index 15cf530839633b1e3da46ba002014180dba0b307..d81f71556bc99a9412300fb00eb9434deb879bc4 100644 (file)
@@ -19,8 +19,6 @@ public:
        ///
        InsetLabel(InsetCommandParams const &);
        ///
-       ~InsetLabel();
-       ///
        std::auto_ptr<InsetBase> clone() const;
        ///
        std::string const getScreenLabel(Buffer const &) const;
index eaf4b00bc55c7f44173c57068c46bb5190570199..3a4f2da379e4c70e2eda9cd66524e7d2f3d32f3d 100644 (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);
-       }
+       params.read(lex);
 }
 
 
index 83888887c7afc3cf369d2bb3d34e568c73aae0f3..c2bd5767fa3c59854b06ee5746037e9ef29b7c7b 100644 (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);
 }
index e0ce44def7bd32eda67171b3a6055c8fa7802dca..af6c17cba2894e8df844345bfcff2aa93d465a94 100644 (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
index 13d32ce260598a194890baf4c7cff2e227a9f1d5..73ab89aa39ecc2f44c77bf5ac97269b0e49f0dd2 100644 (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));
index 5b5f3ec4367b67c0710e700d15c9af3b8d4bb36b..fa91fa2855a4c72efbe7d4cd3b2eaaa4fd9d0932 100644 (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
 {
index 15796551288046850bc6772240ffdea665e5c5dd..98813a7f1ad706e0d7254b91cbd59342f022a588 100644 (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
index 741dc0220a1a982a78cde6cae6581c178cc1ae4b..0f052738d8a104ec28abe54120f696a70d771b33 100644 (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;
index 8555331683ae7a367f85deaeb2b49f12c4ca6977..3f30120b32c75cd80054121c21168b58e40c1506 100644 (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
index 595db97a73eb406617b9757c27623a8fbcd3471b..7b7c9a3998676c577679669d3d477f2e59578a03 100644 (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);
 }
index 6040f3779b2f683f4cf91ade89cf3f0a5112cf01..df42307e19e98499499bdbd2d2571decd7226b97 100644 (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);
-       }
+       params.read(lex);
 }
 
 
index d9995ca2d71ffb99ceeea9dacf8026d0057ac709..48b2cf2b48958dca397b604f6948cef883fabc74 100644 (file)
 #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;
+}
index 3e7622df20b663ba230d0b71541284160772818a..4d5e6191f77506ae628f41d233d6ade534c34a66 100644 (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