X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsetexternal.C;h=fd5fe30017f1c40deb2e1380df6d4912eb95d9e1;hb=26f1a5bfcae4b7fd7b946a1884c396d842b24925;hp=ed22c53cdff5a5b10c2cea610b1ad35c4114ce7e;hpb=527b60ce383d4f22f3cbcadc32989d372d7ec091;p=lyx.git diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index ed22c53cdf..fd5fe30017 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -10,21 +10,19 @@ #include -#ifdef __GNUG__ -#pragma implementation -#endif #include "insetexternal.h" #include "ExternalTemplate.h" #include "BufferView.h" #include "buffer.h" -#include "frontends/LyXView.h" +#include "funcrequest.h" #include "lyx_main.h" #include "LaTeXFeatures.h" #include "gettext.h" #include "debug.h" #include "lyxlex.h" +#include "frontends/LyXView.h" #include "frontends/Dialogs.h" #include "support/filetools.h" @@ -53,16 +51,52 @@ InsetExternal::InsetExternal() InsetExternal::~InsetExternal() { lyx::unlink(tempname_); - hideDialog(); + InsetExternalMailer mailer(*this); + mailer.hideDialog(); } -InsetExternal::Params InsetExternal::params() const +InsetExternal::Params const & InsetExternal::params() const { return params_; } +dispatch_result InsetExternal::localDispatch(FuncRequest const & cmd) +{ + dispatch_result result = UNDISPATCHED; + + switch (cmd.action) { + case LFUN_INSET_MODIFY: { + InsetExternal::Params p; + InsetExternalMailer::string2params(cmd.argument, p); + if (p.filename.empty()) + break; + + setFromParams(p); + cmd.view()->updateInset(this); + result = DISPATCHED; + } + break; + + case LFUN_INSET_DIALOG_UPDATE: { + InsetExternalMailer mailer(*this); + mailer.updateDialog(cmd.view()); + } + break; + + case LFUN_MOUSE_RELEASE: + edit(cmd.view(), cmd.x, cmd.y, cmd.button()); + break; + + default: + break; + } + + return result; +} + + void InsetExternal::setFromParams(Params const & p) { params_.filename = p.filename; @@ -77,11 +111,10 @@ string const InsetExternal::editMessage() const } -void InsetExternal::edit(BufferView * bv, - int /*x*/, int /*y*/, mouse_button::state) +void InsetExternal::edit(BufferView * bv, int, int, mouse_button::state) { - view_ = bv; - view_->owner()->getDialogs().showExternal(this); + InsetExternalMailer mailer(*this); + mailer.showDialog(bv); } @@ -122,15 +155,15 @@ void InsetExternal::read(Buffer const *, LyXLex & lex) } // Parse string format... - string::size_type const pos1 = format.find(","); + string::size_type const pos1 = format.find(','); params_.templ = ExternalTemplateManager::get().getTemplateByName(format.substr(0, pos1)); string::size_type const pos2 = format.find("\",\"", pos1); params_.filename = format.substr(pos1 + 2, pos2 - (pos1 + 2)); params_.parameters = format.substr(pos2 + 3, format.length() - (pos2 + 4)); lyxerr[Debug::INFO] << "InsetExternal::Read: " << params_.templ.lyxName - << " " << params_.filename - << " " << params_.parameters << endl; + << ' ' << params_.filename + << ' ' << params_.parameters << endl; } @@ -224,7 +257,7 @@ void InsetExternal::executeCommand(string const & s, Systemcall one; if (lyxerr.debugging()) { lyxerr << "Executing '" << s << "' in '" - << buffer->filePath() << "'" << endl; + << buffer->filePath() << '\'' << endl; } one.startscript(Systemcall::Wait, s); } @@ -330,17 +363,61 @@ void InsetExternal::editExternal() const } -bool operator==(InsetExternal::Params const & left, - InsetExternal::Params const & right) +string const InsetExternalMailer::name_("external"); + +InsetExternalMailer::InsetExternalMailer(InsetExternal & inset) + : inset_(inset) +{} + + +string const InsetExternalMailer::inset2string() const +{ + return params2string(inset_.params()); +} + + +void InsetExternalMailer::string2params(string const & in, + InsetExternal::Params & params) { - return ((left.filename == right.filename) && - (left.parameters == right.parameters) && - (left.templ.lyxName == right.templ.lyxName)); + params = InsetExternal::Params(); + + istringstream data(in); + LyXLex lex(0,0); + lex.setStream(data); + + 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 + if (lex.isOK()) { + lex.next(); + string const token = lex.getString(); + if (token != "External") + return; + } + + if (lex.isOK()) { + InsetExternal inset; + inset.read(0, lex); + params = inset.params(); + } } -bool operator!=(InsetExternal::Params const & left, - InsetExternal::Params const & right) +string const +InsetExternalMailer::params2string(InsetExternal::Params const & params) { - return !(left == right); + InsetExternal inset; + inset.setFromParams(params); + ostringstream data; + data << name_ << ' '; + inset.write(0, data); + data << "\\end_inset\n"; + + return data.str(); }