#include <config.h>
-
#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 "Lsstream.h"
+#include "frontends/LyXView.h"
#include "frontends/Dialogs.h"
#include "support/filetools.h"
#include <cstdio>
#include <utility>
-
using std::ostream;
using std::endl;
InsetExternal::~InsetExternal()
{
lyx::unlink(tempname_);
- hideDialog();
+ InsetExternalMailer mailer(*this);
+ mailer.hideDialog();
}
-InsetExternal::Params InsetExternal::params() const
+InsetExternal::Params const & InsetExternal::params() const
{
return params_;
}
-void InsetExternal::setFromParams(Params const & p)
+dispatch_result InsetExternal::localDispatch(FuncRequest const & cmd)
{
- params_.filename = p.filename;
- params_.parameters = p.parameters;
- params_.templ = p.templ;
-}
+ switch (cmd.action) {
+
+ case LFUN_INSET_MODIFY: {
+ InsetExternal::Params p;
+ InsetExternalMailer::string2params(cmd.argument, p);
+ if (!p.filename.empty()) {
+ setFromParams(p);
+ cmd.view()->updateInset(this);
+ }
+ return DISPATCHED;
+ }
+ case LFUN_INSET_DIALOG_UPDATE:
+ InsetExternalMailer(*this).updateDialog(cmd.view());
+ return DISPATCHED;
-string const InsetExternal::editMessage() const
-{
- return doSubstitution(0, params_.templ.guiName);
+ case LFUN_MOUSE_RELEASE:
+ case LFUN_INSET_EDIT:
+ InsetExternalMailer(*this).showDialog(cmd.view());
+ return DISPATCHED;
+
+ default:
+ return UNDISPATCHED;
+ }
}
-void InsetExternal::edit(BufferView * bv,
- int /*x*/, int /*y*/, mouse_button::state)
+void InsetExternal::setFromParams(Params const & p)
{
- view_ = bv;
- view_->owner()->getDialogs().showExternal(this);
+ params_.filename = p.filename;
+ params_.parameters = p.parameters;
+ params_.templ = p.templ;
}
-void InsetExternal::edit(BufferView * bv, bool)
+string const InsetExternal::editMessage() const
{
- edit(bv, 0, 0, mouse_button::none);
+ return doSubstitution(0, params_.templ.guiName);
}
}
-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();
+
+ if (in.empty())
+ return;
+
+ istringstream data(STRCONV(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 STRCONV(data.str());
}