dispatch_result InsetInclude::localDispatch(FuncRequest const & cmd)
{
- if (cmd.action != LFUN_INSET_MODIFY)
- return UNDISPATCHED;
+ dispatch_result result = UNDISPATCHED;
- InsetInclude::Params p;
- InsetIncludeMailer::string2params(cmd.argument, p);
- if (p.cparams.getCmdName().empty())
- return UNDISPATCHED;
+ switch (cmd.action) {
+ case LFUN_INSET_MODIFY: {
+ InsetInclude::Params p;
+ InsetIncludeMailer::string2params(cmd.argument, p);
+ if (p.cparams.getCmdName().empty())
+ break;
+
+ set(p);
+ params_.masterFilename_ = cmd.view()->buffer()->fileName();
+
+ cmd.view()->updateInset(this);
+ result = DISPATCHED;
+ }
+ break;
+
+ case LFUN_INSET_DIALOG_UPDATE: {
+ InsetIncludeMailer mailer(*this);
+ mailer.updateDialog(cmd.view());
+ }
+ break;
+
+ case LFUN_MOUSE_RELEASE:
+ edit(cmd.view(), cmd.x, cmd.y, cmd.button());
+ break;
- set(p);
- params_.masterFilename_ = cmd.view()->buffer()->fileName();
+ default:
+ break;
+ }
- cmd.view()->updateInset(this, true);
- return DISPATCHED;
+ return result;
}
}
-void InsetInclude::edit(BufferView *, int, int, mouse_button::state)
+void InsetInclude::edit(BufferView * bv, int, int, mouse_button::state)
{
InsetIncludeMailer mailer(*this);
- mailer.showDialog();
+ mailer.showDialog(bv);
}
void InsetInclude::draw(BufferView * bv, LyXFont const & font, int y,
- float & xx, bool b) const
+ float & xx) const
{
cache(bv);
if (!preview_->previewReady()) {
- InsetButton::draw(bv, font, y, xx, b);
+ InsetButton::draw(bv, font, y, xx);
return;
}
lyxerr << "restartLoading()" << std::endl;
removePreview();
if (view())
- view()->updateInset(&parent(), false);
+ view()->updateInset(&parent());
generatePreview();
}
+string const InsetIncludeMailer::name_("include");
+
InsetIncludeMailer::InsetIncludeMailer(InsetInclude & inset)
- : name_("include"), inset_(inset)
+ : inset_(inset)
{}
string const InsetIncludeMailer::inset2string() const
{
- return params2string(name(), inset_.params());
+ return params2string(inset_.params());
}
{
params = InsetInclude::Params();
- string name;
- string body = split(in, name, ' ');
+ istringstream data(in);
+ LyXLex lex(0,0);
+ lex.setStream(data);
- if (name != "include" || body.empty())
- return;
+ if (lex.isOK()) {
+ lex.next();
+ string const token = lex.getString();
+ if (token != name_)
+ return;
+ }
// This is part of the inset proper that is usually swallowed
// by Buffer::readInset
- body = split(body, name, ' ');
- if (name != "Include")
- return;
-
- istringstream data(body);
- LyXLex lex(0,0);
- lex.setStream(data);
+ if (lex.isOK()) {
+ lex.next();
+ string const token = lex.getString();
+ if (token != "Include")
+ return;
+ }
- InsetInclude inset(params);
- inset.read(0, lex);
- params = inset.params();
+ if (lex.isOK()) {
+ InsetInclude inset(params);
+ inset.read(0, lex);
+ params = inset.params();
+ }
}
string const
-InsetIncludeMailer::params2string(string const & name,
- InsetInclude::Params const & params)
+InsetIncludeMailer::params2string(InsetInclude::Params const & params)
{
InsetInclude inset(params);
inset.set(params);
ostringstream data;
- data << name << ' ';
+ data << name_ << ' ';
inset.write(0, data);
data << "\\end_inset\n";
return data.str();
}
-