]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetcommand.C
Enable the external inset to handle unknown templates gracefully.
[lyx.git] / src / insets / insetcommand.C
index dadb444486cddd52ad01ae944988605936ee3742..9b2e873ee470ddc7c84728cdfaddc728e083bb2c 100644 (file)
 using std::ostream;
 
 
-InsetCommand::InsetCommand(InsetCommandParams const & p, bool)
+InsetCommand::InsetCommand(InsetCommandParams const & p)
        : p_(p.getCmdName(), p.getContents(), p.getOptions())
 {}
 
 
+InsetCommand::InsetCommand(InsetCommand const & ic)
+       : p_(ic.p_)
+{
+}
+
+
 void InsetCommand::setParams(InsetCommandParams const & p)
 {
        p_.setCmdName(p.getCmdName());
@@ -40,7 +46,7 @@ void InsetCommand::setParams(InsetCommandParams const & p)
 
 
 int InsetCommand::latex(Buffer const *, ostream & os,
-                       bool /*fragile*/, bool/*fs*/) const
+                       LatexRunParams const &) const
 {
        os << getCommand();
        return 0;
@@ -67,34 +73,32 @@ int InsetCommand::docbook(Buffer const *, ostream &, bool) const
 
 dispatch_result InsetCommand::localDispatch(FuncRequest const & cmd)
 {
-       dispatch_result result = UNDISPATCHED;
-
        switch (cmd.action) {
        case LFUN_INSET_MODIFY: {
                InsetCommandParams p;
                InsetCommandMailer::string2params(cmd.argument, p);
                if (p.getCmdName().empty())
-                       break;
+                       return UNDISPATCHED;
 
                setParams(p);
-               cmd.view()->updateInset(this, true);
-               result = DISPATCHED;
+               cmd.view()->updateInset(this);
+               return DISPATCHED;
        }
-       break;
 
-       case LFUN_INSET_DIALOG_UPDATE: {
-               InsetCommandMailer mailer(cmd.argument, *this);
-               mailer.updateDialog();
-       }
-       break;
+       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:
-               break;
+               return UNDISPATCHED;
        }
 
-       return result;
 }
 
+
 InsetCommandMailer::InsetCommandMailer(string const & name,
                                       InsetCommand & inset)
        : name_(name), inset_(inset)
@@ -114,7 +118,10 @@ void InsetCommandMailer::string2params(string const & in,
        params.setContents(string());
        params.setOptions(string());
 
-       istringstream data(in);
+       if (in.empty())
+               return;
+
+       istringstream data(STRCONV(in));
        LyXLex lex(0,0);
        lex.setStream(data);
 
@@ -123,18 +130,26 @@ void InsetCommandMailer::string2params(string const & in,
                string const name = lex.getString();
        }
 
-       params.read(lex);
+       // 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());
 }