]> git.lyx.org Git - features.git/blobdiff - src/insets/insetcommand.C
change "support/std_sstream.h" to <sstream>
[features.git] / src / insets / insetcommand.C
index d8576148ed46f024e2d90703a503569a8f5e0bc5..77a357b05eec3321777c47dfed2bf7bf1fa9bed6 100644 (file)
@@ -19,7 +19,7 @@
 #include "lyxlex.h"
 #include "metricsinfo.h"
 
-#include "support/std_sstream.h"
+#include <sstream>
 
 
 using std::string;
@@ -28,12 +28,21 @@ using std::ostream;
 using std::ostringstream;
 
 
-InsetCommand::InsetCommand(InsetCommandParams const & p)
-       : p_(p.getCmdName(), p.getContents(), p.getOptions()),
+InsetCommand::InsetCommand(InsetCommandParams const & p,
+                          string const & mailer_name)
+       : p_(p.getCmdName(), p.getContents(), p.getOptions(), p.getSecOptions()),
+         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_) {
@@ -48,6 +57,7 @@ void InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void InsetCommand::draw(PainterInfo & pi, int x, int y) const
 {
+       setPosCache(pi, x, y);
        button_.draw(pi, x, y);
 }
 
@@ -60,58 +70,67 @@ void InsetCommand::setParams(InsetCommandParams const & p)
 
 
 int InsetCommand::latex(Buffer const &, ostream & os,
-                       LatexRunParams const &) const
+                       OutputParams const &) const
 {
        os << getCommand();
        return 0;
 }
 
 
-int InsetCommand::ascii(Buffer const &, ostream &,
-                       LatexRunParams const &) const
+int InsetCommand::plaintext(Buffer const &, ostream &,
+                       OutputParams const &) const
 {
        return 0;
 }
 
 
 int InsetCommand::linuxdoc(Buffer const &, ostream &,
-                          LatexRunParams const &) const
+                          OutputParams const &) const
 {
        return 0;
 }
 
 
 int InsetCommand::docbook(Buffer const &, ostream &,
-                         LatexRunParams const &) const
+                         OutputParams const &) const
 {
        return 0;
 }
 
 
-DispatchResult
-InsetCommand::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
+void InsetCommand::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
+       case LFUN_INSET_REFRESH:
+               set_label_ = false;
+               break;
+
        case LFUN_INSET_MODIFY: {
                InsetCommandParams p;
-               InsetCommandMailer::string2params(cmd.argument, p);
-               if (p.getCmdName().empty())
-                       return DispatchResult(false);
-
-               setParams(p);
-               cmd.view()->updateInset(this);
-               return DispatchResult(true);
+               InsetCommandMailer::string2params(mailer_name_, cmd.argument, p);
+               if (p.getCmdName().empty()) {
+                       cur.undispatched();
+               } else {
+                       setParams(p);
+                       cur.bv().update();
+               }
+               break;
        }
 
        case LFUN_INSET_DIALOG_UPDATE:
-               InsetCommandMailer(cmd.argument, *this).updateDialog(cmd.view());
-               return DispatchResult(true);
-
-       case LFUN_MOUSE_RELEASE:
-               return dispatch(FuncRequest(cmd.view(), LFUN_INSET_EDIT));
+               InsetCommandMailer(cmd.argument, *this).updateDialog(&cur.bv());
+               break;
+
+       case LFUN_INSET_DIALOG_SHOW:
+       case LFUN_MOUSE_RELEASE: {
+               if (!mailer_name_.empty())
+                       InsetCommandMailer(mailer_name_, *this).showDialog(&cur.bv());
+               break;
+       }
 
        default:
-               return DispatchResult(false);
+               InsetOld::priv_dispatch(cur, cmd);
+               break;
        }
 
 }
@@ -129,11 +148,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;
 
@@ -141,26 +160,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;