]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetinclude.C
The markDirty() and fitCursor() changes
[lyx.git] / src / insets / insetinclude.C
index 9cafae74d5e3d669087b366e1fde0499cf1a73b8..ab4d2dc727a31fa045ade32f578ebf5598a7a84c 100644 (file)
@@ -115,19 +115,38 @@ InsetInclude::~InsetInclude()
 
 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;
 }
 
 
@@ -193,10 +212,10 @@ Inset * InsetInclude::clone(Buffer const & buffer, bool) const
 }
 
 
-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);
 }
 
 
@@ -538,11 +557,11 @@ int InsetInclude::width(BufferView * bv, LyXFont const & font) const
 
 
 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;
        }
 
@@ -605,19 +624,21 @@ void InsetInclude::PreviewImpl::restartLoading()
        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());
 }
 
 
@@ -626,36 +647,41 @@ void InsetIncludeMailer::string2params(string const & in,
 {
        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";