#include <config.h>
-
#include "insetexternal.h"
#include "ExternalTemplate.h"
#include "BufferView.h"
#include "gettext.h"
#include "debug.h"
#include "lyxlex.h"
+#include "Lsstream.h"
#include "frontends/LyXView.h"
#include "frontends/Dialogs.h"
#include <cstdio>
#include <utility>
-
using std::ostream;
using std::endl;
dispatch_result InsetExternal::localDispatch(FuncRequest const & cmd)
{
- if (cmd.action != LFUN_INSET_MODIFY)
- return UNDISPATCHED;
+ 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;
+ }
- InsetExternal::Params p;
- InsetExternalMailer::string2params(cmd.argument, p);
- if (p.filename.empty())
- return UNDISPATCHED;
+ case LFUN_INSET_DIALOG_UPDATE:
+ InsetExternalMailer(*this).updateDialog(cmd.view());
+ return DISPATCHED;
- setFromParams(p);
- cmd.view()->updateInset(this, true);
- return DISPATCHED;
+ case LFUN_MOUSE_RELEASE:
+ case LFUN_INSET_EDIT:
+ InsetExternalMailer(*this).showDialog(cmd.view());
+ return DISPATCHED;
+
+ default:
+ return UNDISPATCHED;
+ }
}
}
-void InsetExternal::edit(BufferView *, int, int, mouse_button::state)
-{
- InsetExternalMailer mailer(*this);
- mailer.showDialog();
-}
-
-
-void InsetExternal::edit(BufferView * bv, bool)
-{
- edit(bv, 0, 0, mouse_button::none);
-}
-
-
void InsetExternal::write(Buffer const *, ostream & os) const
{
os << "External " << params_.templ.lyxName << ",\""
}
-bool operator==(InsetExternal::Params const & left,
- InsetExternal::Params const & right)
-{
- return ((left.filename == right.filename) &&
- (left.parameters == right.parameters) &&
- (left.templ.lyxName == right.templ.lyxName));
-}
-
-
-bool operator!=(InsetExternal::Params const & left,
- InsetExternal::Params const & right)
-{
- return !(left == right);
-}
-
-
string const InsetExternalMailer::name_("external");
InsetExternalMailer::InsetExternalMailer(InsetExternal & inset)
{
params = InsetExternal::Params();
- istringstream data(in);
+ if (in.empty())
+ return;
+
+ istringstream data(STRCONV(in));
LyXLex lex(0,0);
lex.setStream(data);
return;
}
- InsetExternal inset;
- inset.read(0, lex);
- params = inset.params();
+ if (lex.isOK()) {
+ InsetExternal inset;
+ inset.read(0, lex);
+ params = inset.params();
+ }
}
data << name_ << ' ';
inset.write(0, data);
data << "\\end_inset\n";
-
- return data.str();
+ return STRCONV(data.str());
}