]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetcommand.C
Rename LatexRunParams::fragile as moving_arg.
[lyx.git] / src / insets / insetcommand.C
index 1c47948e7e17d327765068c63583dfb58e098a07..f1235c1abc7ee2c2e65aaa710ef0934226499ac5 100644 (file)
@@ -1,25 +1,29 @@
-/* This file is part of
- * ======================================================
+/**
+ * \file insetcommand.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author Angus Leeming
+ * \author Lars Gullik Bjønnes
  *
- *         Copyright 1995 Matthias Ettrich
- *          Copyright 1995-2001 The LyX Team.
- *
- * ====================================================== */
+ * Full author contact details are available in file CREDITS
+ */
 
 #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)
@@ -36,7 +40,7 @@ void InsetCommand::setParams(InsetCommandParams const & p)
 
 
 int InsetCommand::latex(Buffer const *, ostream & os,
-                       bool /*fragile*/, bool/*fs*/) const
+                       LatexRunParams const &) const
 {
        os << getCommand();
        return 0;
@@ -59,3 +63,88 @@ int InsetCommand::docbook(Buffer const *, ostream &, bool) const
 {
        return 0;
 }
+
+
+dispatch_result InsetCommand::localDispatch(FuncRequest const & cmd)
+{
+       lyxerr << "InsetCommand::localDispatch: " << cmd.action << "\n";
+       switch (cmd.action) {
+       case LFUN_INSET_MODIFY: {
+               InsetCommandParams p;
+               InsetCommandMailer::string2params(cmd.argument, p);
+               if (p.getCmdName().empty())
+                       return UNDISPATCHED;
+
+               setParams(p);
+               cmd.view()->updateInset(this);
+               return DISPATCHED;
+       }
+
+       case LFUN_INSET_DIALOG_UPDATE:
+               InsetCommandMailer(cmd.argument, *this).updateDialog(cmd.view());
+               return DISPATCHED;
+
+       case LFUN_MOUSE_RELEASE:
+               return localDispatch(FuncRequest(cmd.view(), LFUN_INSET_EDIT));
+
+       default:
+               return UNDISPATCHED;
+       }
+
+}
+
+
+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());
+
+       if (in.empty())
+               return;
+       
+       istringstream data(STRCONV(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 STRCONV(data.str());
+}