]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetcommand.C
The markDirty() and fitCursor() changes
[lyx.git] / src / insets / insetcommand.C
index 7350cbcad6780282a092bf20d1572965c4da25fc..dd2ae21cc49b19dd84af1a06c965dd2e71d2cea8 100644 (file)
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "insetcommand.h"
+#include "BufferView.h"
 #include "debug.h"
+#include "funcrequest.h"
+#include "lyxlex.h"
+
 #include "frontends/Painter.h"
 
+#include "support/lstrings.h"
+
+#include "Lsstream.h"
+
 using std::ostream;
-using std::endl;
 
 
 InsetCommand::InsetCommand(InsetCommandParams const & p, bool)
@@ -60,3 +63,93 @@ int InsetCommand::docbook(Buffer const *, ostream &, bool) const
 {
        return 0;
 }
+
+
+dispatch_result InsetCommand::localDispatch(FuncRequest const & cmd)
+{
+       dispatch_result result = UNDISPATCHED;
+
+       switch (cmd.action) {
+       case LFUN_INSET_MODIFY: {
+               InsetCommandParams p;
+               InsetCommandMailer::string2params(cmd.argument, p);
+               if (p.getCmdName().empty())
+                       break;
+
+               setParams(p);
+               cmd.view()->updateInset(this);
+               result = DISPATCHED;
+       }
+       break;
+
+       case LFUN_INSET_DIALOG_UPDATE: {
+               InsetCommandMailer mailer(cmd.argument, *this);
+               mailer.updateDialog(cmd.view());
+       }
+       break;
+
+       case LFUN_MOUSE_RELEASE:
+               edit(cmd.view(), cmd.x, cmd.y, cmd.button());
+               break;
+
+       default:
+               break;
+       }
+
+       return result;
+}
+
+
+InsetCommandMailer::InsetCommandMailer(string const & name,
+                                      InsetCommand & inset)
+       : name_(name), inset_(inset)
+{}
+
+
+string const InsetCommandMailer::inset2string() const
+{
+       return params2string(name(), inset_.params());
+}
+
+
+void InsetCommandMailer::string2params(string const & in,
+                                      InsetCommandParams & params)
+{
+       params.setCmdName(string());
+       params.setContents(string());
+       params.setOptions(string());
+
+       istringstream data(in);
+       LyXLex lex(0,0);
+       lex.setStream(data);
+
+       if (lex.isOK()) {
+               lex.next();
+               string const name = lex.getString();
+       }
+
+       // 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 != "LatexCommand")
+                       return;
+       }
+       if (lex.isOK()) {
+               params.read(lex);
+       }
+}
+
+
+string const
+InsetCommandMailer::params2string(string const & name,
+                                 InsetCommandParams const & params)
+{
+       ostringstream data;
+       data << name << ' ';
+       params.write(data);
+       data << "\\end_inset\n";
+
+       return data.str();
+}