#include "insetfloat.h"
+#include "insettext.h"
+
+#include "buffer.h"
+#include "BufferView.h"
+#include "debug.h"
+#include "Floating.h"
+#include "FloatList.h"
+#include "funcrequest.h"
#include "gettext.h"
+#include "iterators.h"
+#include "LaTeXFeatures.h"
#include "lyxfont.h"
-#include "BufferView.h"
+#include "lyxlex.h"
#include "lyxtext.h"
-#include "insets/insettext.h"
+
#include "support/LOstream.h"
#include "support/lstrings.h"
-#include "FloatList.h"
-#include "LaTeXFeatures.h"
-#include "debug.h"
-#include "Floating.h"
-#include "buffer.h"
+
#include "frontends/LyXView.h"
#include "frontends/Dialogs.h"
-#include "lyxlex.h"
-#include "iterators.h"
using std::ostream;
using std::endl;
InsetFloat::~InsetFloat()
{
- hideDialog();
+ InsetFloatMailer mailer(*this);
+ mailer.hideDialog();
}
-void InsetFloat::writeParams(ostream & os) const
+dispatch_result InsetFloat::localDispatch(FuncRequest const & cmd)
{
- os << "Float " // getInsetName()
- << params_.type << '\n';
+ Inset::RESULT result = UNDISPATCHED;
+
+ switch (cmd.action) {
+ case LFUN_INSET_MODIFY: {
+ InsetFloatParams params;
+ InsetFloatMailer::string2params(cmd.argument, params);
+
+ params_.placement = params.placement;
+ params_.wide = params.wide;
- if (!params_.placement.empty()) {
- os << "placement " << params_.placement << "\n";
+ cmd.view()->updateInset(this);
+ result = DISPATCHED;
}
- if (params_.wide) {
- os << "wide true\n";
- } else {
- os << "wide false\n";
+ break;
+
+ case LFUN_INSET_DIALOG_UPDATE: {
+ InsetFloatMailer mailer(*this);
+ mailer.updateDialog(cmd.view());
+ }
+ break;
+
+ default:
+ result = InsetCollapsable::localDispatch(cmd);
}
+
+ return result;
}
-void InsetFloat::write(Buffer const * buf, ostream & os) const
+void InsetFloatParams::write(ostream & os) const
{
- writeParams(os);
- InsetCollapsable::write(buf, os);
+ os << "Float " // getInsetName()
+ << type << '\n';
+
+ if (!placement.empty()) {
+ os << "placement " << placement << "\n";
+ }
+ if (wide) {
+ os << "wide true\n";
+ } else {
+ os << "wide false\n";
+ }
}
-void InsetFloat::readParams(Buffer const * buf, LyXLex & lex)
+void InsetFloatParams::read(LyXLex & lex)
{
if (lex.isOK()) {
lex.next();
string token = lex.getString();
if (token == "placement") {
lex.next();
- params_.placement = lex.getString();
+ placement = lex.getString();
} else {
// take countermeasures
lex.pushToken(token);
if (token == "wide") {
lex.next();
string const tmptoken = lex.getString();
- if (tmptoken == "true")
- wide(true, buf->params);
- else
- wide(false, buf->params);
+ wide = (tmptoken == "true");
} else {
lyxerr << "InsetFloat::Read:: Missing wide!"
<< endl;
}
+void InsetFloat::write(Buffer const * buf, ostream & os) const
+{
+ params_.write(os);
+ InsetCollapsable::write(buf, os);
+}
+
+
void InsetFloat::read(Buffer const * buf, LyXLex & lex)
{
- readParams(buf, lex);
+ params_.read(lex);
+ wide(params_.wide, buf->params);
InsetCollapsable::read(buf, lex);
}
bool InsetFloat::showInsetDialog(BufferView * bv) const
{
if (!inset.showInsetDialog(bv)) {
- bv->owner()->getDialogs().showFloat(const_cast<InsetFloat *>(this));
+ InsetFloat * tmp = const_cast<InsetFloat *>(this);
+ InsetFloatMailer mailer(*tmp);
+ mailer.showDialog(bv);
}
return true;
}
}
}
}
+
+
+string const InsetFloatMailer::name_("float");
+
+InsetFloatMailer::InsetFloatMailer(InsetFloat & inset)
+ : inset_(inset)
+{}
+
+
+string const InsetFloatMailer::inset2string() const
+{
+ return params2string(inset_.params());
+}
+
+
+void InsetFloatMailer::string2params(string const & in,
+ InsetFloatParams & params)
+{
+ params = InsetFloatParams();
+
+ 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 != "Float" || !lex.eatLine())
+ return;
+ }
+
+ if (lex.isOK()) {
+ params.read(lex);
+ }
+}
+
+
+string const
+InsetFloatMailer::params2string(InsetFloatParams const & params)
+{
+ ostringstream data;
+ data << name_ << ' ';
+ params.write(data);
+
+ return data.str();
+}