]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetcommand.C
fix #832
[lyx.git] / src / insets / insetcommand.C
index 7c291d23afba654edf978df9b79e0dd660ef1369..7edcececf5560d74d63bcfbcbe8d165dfc024a55 100644 (file)
 
 #include "frontends/Painter.h"
 
+#include "support/lstrings.h"
+
 #include "Lsstream.h"
 
 using std::ostream;
-using std::endl;
 
 
 InsetCommand::InsetCommand(InsetCommandParams const & p, bool)
@@ -66,18 +67,33 @@ int InsetCommand::docbook(Buffer const *, ostream &, bool) const
 
 dispatch_result InsetCommand::localDispatch(FuncRequest const & cmd)
 {
-       InsetCommandParams p;
-       InsetCommandMailer::string2params(cmd.argument, p);
-       if (p.getCmdName().empty())
+       lyxerr << "InsetCommand::localDispatch: " << cmd.action << "\n";
+       switch (cmd.action) {
+       case LFUN_INSET_MODIFY: {
+               InsetCommandParams p;
+               InsetCommandMailer::string2params(cmd.argument, p);
+               if (p.getCmdName().empty())
+                       return UNDISPATCHED;
+
+               setParams(p);
+               cmd.view()->updateInset(this);
+               return DISPATCHED;
+       }
+
+       case LFUN_INSET_DIALOG_UPDATE:
+               InsetCommandMailer(cmd.argument, *this).updateDialog(cmd.view());
+               return DISPATCHED;
+
+       case LFUN_MOUSE_RELEASE:
+               return localDispatch(FuncRequest(cmd.view(), LFUN_INSET_EDIT));
+
+       default:
                return UNDISPATCHED;
+       }
 
-       setParams(p);
-       if (view())
-               view()->updateInset(this, true);
-
-       return DISPATCHED;
 }
 
+
 InsetCommandMailer::InsetCommandMailer(string const & name,
                                       InsetCommand & inset)
        : name_(name), inset_(inset)
@@ -86,7 +102,7 @@ InsetCommandMailer::InsetCommandMailer(string const & name,
 
 string const InsetCommandMailer::inset2string() const
 {
-       return params2string(inset_.params());
+       return params2string(name(), inset_.params());
 }
 
 
@@ -99,21 +115,36 @@ void InsetCommandMailer::string2params(string const & in,
 
        if (in.empty())
                return;
-
-       istringstream data(in);
+       
+       istringstream data(STRCONV(in));
        LyXLex lex(0,0);
        lex.setStream(data);
 
-       params.read(lex);
+       if (lex.isOK()) {
+               lex.next();
+               string const name = lex.getString();
+       }
+
+       // 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);
+       }
 }
 
 
-string const
-InsetCommandMailer::params2string(InsetCommandParams const & params)
+string const InsetCommandMailer::params2string(string const & name,
+                                 InsetCommandParams const & params)
 {
        ostringstream data;
+       data << name << ' ';
        params.write(data);
        data << "\\end_inset\n";
-
-       return data.str();
+       return STRCONV(data.str());
 }