#include "lyxlex.h"
#include "metricsinfo.h"
-#include "support/std_sstream.h"
+#include <sstream>
using std::string;
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_) {
void InsetCommand::draw(PainterInfo & pi, int x, int y) const
{
+ setPosCache(pi, x, y);
button_.draw(pi, x, y);
}
}
-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, 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, true);
-
- case LFUN_MOUSE_RELEASE:
- edit(cmd.view(), true);
- return DispatchResult(true);
+ 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;
}
}
}
-void InsetCommandMailer::string2params(string const & in,
+void InsetCommandMailer::string2params(string const & name,
+ string const & in,
InsetCommandParams & params)
{
params = InsetCommandParams();
-
if (in.empty())
return;
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;