]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetcommandparams.C
fix #832
[lyx.git] / src / insets / insetcommandparams.C
index 93a3070d49c27a759653c2464fec2b97881d789b..82a4056cbee398a65c25c7ba5a328873b6429133 100644 (file)
@@ -1,21 +1,25 @@
-/* This file is part of
- * ======================================================
+/**
+ * \file insetcommandparams.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
  *
- *          Copyright 2002-2002 The LyX Team.
- *
- * ====================================================== */
+ * Full author contact details are available in file CREDITS
+ */
 
+#include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
 
 #include "insetcommandparams.h"
 #include "lyxlex.h"
 #include "debug.h"
 
+#include "support/LOstream.h"
+
+using std::ostream;
+using std::endl;
+
 
 InsetCommandParams::InsetCommandParams()
 {}
@@ -24,53 +28,10 @@ InsetCommandParams::InsetCommandParams()
 InsetCommandParams::InsetCommandParams(string const & n,
                                        string const & c,
                                        string const & o)
-       : cmdname(n), contents(c), options(o)
+       : cmdname(n), contents(c), options(o), preview_(false)
 {}
 
 
-string const InsetCommandParams::getAsString() const
-{
-       return cmdname + "|++|" + contents + "|++|" + options;
-}
-
-
-void InsetCommandParams::setFromString(string const & b)
-{
-       string::size_type idx = b.find("|++|");
-       if (idx == string::npos) {
-               cmdname = b;
-               contents = "";
-               options = "";
-               return;
-       }
-
-       cmdname = b.substr(0, idx);
-       string tmp = b.substr(idx+4);
-
-       idx = tmp.find("|++|");
-       if (idx == string::npos) {
-               contents = tmp;
-               options = "";
-       } else {
-               contents  = tmp.substr(0, idx);
-               options = tmp.substr(idx+4);
-       }
-}
-
-
-bool InsetCommandParams::operator==(InsetCommandParams const & o) const
-{
-       return cmdname == o.cmdname && contents == o.contents
-               && options == o.options;
-}
-
-
-bool InsetCommandParams::operator!=(InsetCommandParams const & o) const
-{
-       return !(*this == o);
-}
-
-
 void InsetCommandParams::scanCommand(string const & cmd)
 {
        string tcmdname, toptions, tcontents;
@@ -145,10 +106,14 @@ void InsetCommandParams::read(LyXLex & lex)
        }
 
        while (lex.isOK()) {
-               lex.nextToken();
+               lex.next();
                token = lex.getString();
                if (token == "\\end_inset")
                        break;
+               if (token == "preview") {
+                       lex.next();
+                       preview_ = lex.getBool();
+               }
        }
        if (token != "\\end_inset") {
                lex.printError("Missing \\end_inset at this point. "
@@ -166,9 +131,25 @@ void InsetCommandParams::write(ostream & os) const
 string const InsetCommandParams::getCommand() const
 {
        string s;
-       if (!getCmdName().empty()) s += "\\"+getCmdName();
-       if (!getOptions().empty()) s += "["+getOptions()+']';
-       s += "{"+getContents()+'}';
+       if (!getCmdName().empty()) s += '\\' + getCmdName();
+       if (!getOptions().empty()) s += '[' + getOptions() + ']';
+       s += '{' + getContents() + '}';
        return s;
 }
 
+
+bool operator==(InsetCommandParams const & o1,
+               InsetCommandParams const & o2)
+{
+       return o1.getCmdName() == o2.getCmdName()
+               && o1.getContents() == o2.getContents()
+               && o1.getOptions() == o2.getOptions()
+               && o1.preview() == o2.preview();
+}
+
+
+bool operator!=(InsetCommandParams const & o1,
+               InsetCommandParams const & o2)
+{
+       return !(o1 == o2);
+}