- BufferParams const & bp = cur.buffer().params();
- LayoutPtr const layout =
- bp.getTextClass().emptyLayout();
- //lyxerr << "\nInsetERT::doDispatch (begin): cmd: " << cmd << endl;
- switch (cmd.action) {
-
- case LFUN_MOUSE_PRESS:
- if (cmd.button() != mouse_button::button3)
- InsetCollapsable::doDispatch(cur, cmd);
- else
- // This makes the cursor leave the
- // inset when it collapses on mouse-3
- cur.undispatched();
- break;
-
- case LFUN_QUOTE_INSERT: {
- // We need to bypass the fancy quotes in Text
- FuncRequest f(LFUN_SELF_INSERT, "\"");
- dispatch(cur, f);
+ switch (cmd.action()) {
+ case LFUN_INSET_EDIT: {
+ cur.push(*this);
+ text().selectAll(cur);
+ string const format =
+ cur.buffer()->params().documentClass().outputFormat();
+ string const ext = theFormats().extension(format);
+ tempfile_.reset(new TempFile("ert_editXXXXXX." + ext));
+ FileName const tempfilename = tempfile_->name();
+ string const name = tempfilename.toFilesystemEncoding();
+ ofdocstream os(name.c_str());
+ os << cur.selectionAsString(false);
+ os.close();
+ // Since we lock the inset while the external file is edited,
+ // we need to move the cursor outside and clear any selection inside
+ cur.clearSelection();
+ cur.pop();
+ cur.leaveInset(*this);
+ theFormats().edit(buffer(), tempfilename, format);