]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetcommand.C
fix #832
[lyx.git] / src / insets / insetcommand.C
index b0be308fea1a60821c05e0d18573bb4cd1a09096..7edcececf5560d74d63bcfbcbe8d165dfc024a55 100644 (file)
@@ -67,21 +67,33 @@ int InsetCommand::docbook(Buffer const *, ostream &, bool) const
 
 dispatch_result InsetCommand::localDispatch(FuncRequest const & cmd)
 {
-       if (cmd.action != LFUN_INSET_MODIFY)
+       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;
+       }
 
-       InsetCommandParams p;
-       InsetCommandMailer::string2params(cmd.argument, p);
-       if (p.getCmdName().empty())
-               return UNDISPATCHED;
-
-       setParams(p);
-       if (view())
-               view()->updateInset(this, true);
-
-       return DISPATCHED;
 }
 
+
 InsetCommandMailer::InsetCommandMailer(string const & name,
                                       InsetCommand & inset)
        : name_(name), inset_(inset)
@@ -101,28 +113,38 @@ void InsetCommandMailer::string2params(string const & in,
        params.setContents(string());
        params.setOptions(string());
 
-       string name;
-       string body = split(in, name, ' ');
-
-       if (body.empty())
+       if (in.empty())
                return;
-
-       istringstream data(body);
+       
+       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(string const & name,
+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());
 }