]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetNewline.cpp
Stupid bug fix.
[lyx.git] / src / insets / InsetNewline.cpp
index 72faac733bc590ceeb8c845819b762ab5e987baf..62be1d3ca87e2f909b1cab6929de57236768d743 100644 (file)
 
 #include "InsetNewline.h"
 
+#include "Dimension.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
-#include "Dimension.h"
 #include "Lexer.h"
 #include "MetricsInfo.h"
 #include "OutputParams.h"
 
+#include "frontends/Application.h"
 #include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
 #include "support/debug.h"
-#include "support/docstring.h"
 #include "support/docstream.h"
+#include "support/docstring.h"
 
 using namespace std;
 
@@ -34,6 +35,7 @@ namespace lyx {
 InsetNewline::InsetNewline()
 {}
 
+
 void InsetNewlineParams::write(ostream & os) const
 {
        string command;
@@ -50,23 +52,16 @@ void InsetNewlineParams::write(ostream & os) const
 
 void InsetNewlineParams::read(Lexer & lex)
 {
-       lex.next();
-       string const command = lex.getString();
-
-       if (command == "newline")
+       string token;
+       lex.setContext("InsetNewlineParams::read");
+       lex >> token;   
+       if (token == "newline")
                kind = InsetNewlineParams::NEWLINE;
-       else if (command == "linebreak")
+       else if (token == "linebreak")
                kind = InsetNewlineParams::LINEBREAK;
        else
-               lex.printError("InsetNewline: Unknown kind: `$$Token'");
-
-       string token;
-       lex >> token;
-       if (!lex)
-               return;
-       if (token != "\\end_inset")
-               lex.printError("Missing \\end_inset at this point. "
-                              "Read: `$$Token'");
+               lex.printError("Unknown kind: `$$Token'");
+       lex >> "\\end_inset";
 }
 
 
@@ -98,7 +93,7 @@ void InsetNewline::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_INSET_MODIFY: {
                InsetNewlineParams params;
-               InsetNewlineMailer::string2params(to_utf8(cmd.argument()), params);
+               string2params(to_utf8(cmd.argument()), params);
                params_.kind = params.kind;
                break;
        }
@@ -118,10 +113,10 @@ bool InsetNewline::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_INSET_MODIFY:
                if (cmd.getArg(0) == "newline") {
                        InsetNewlineParams params;
-                       InsetNewlineMailer::string2params(to_utf8(cmd.argument()), params);
+                       string2params(to_utf8(cmd.argument()), params);
                        status.setOnOff(params_.kind == params.kind);
-               } else
-                       status.enabled(true);
+               }
+               status.setEnabled(true);
                return true;
        default:
                return Inset::getStatus(cur, cmd, status);
@@ -259,43 +254,24 @@ docstring InsetNewline::contextMenu(BufferView const &, int, int) const
 }
 
 
-string const InsetNewlineMailer::name_ = "newline";
-
-
-InsetNewlineMailer::InsetNewlineMailer(InsetNewline & inset)
-       : inset_(inset)
-{}
-
-
-string const InsetNewlineMailer::inset2string(Buffer const &) const
-{
-       return params2string(inset_.params());
-}
-
-
-void InsetNewlineMailer::string2params(string const & in, InsetNewlineParams & params)
+void InsetNewline::string2params(string const & in, InsetNewlineParams & params)
 {
        params = InsetNewlineParams();
        if (in.empty())
                return;
-
        istringstream data(in);
-       Lexer lex(0,0);
+       Lexer lex;
        lex.setStream(data);
-
-       string name;
-       lex >> name;
-       if (!lex || name != name_)
-               return print_mailer_error("InsetNewlineMailer", in, 1, name_);
-
+       lex.setContext("InsetNewline::string2params");
+       lex >> "newline";
        params.read(lex);
 }
 
 
-string const InsetNewlineMailer::params2string(InsetNewlineParams const & params)
+string InsetNewline::params2string(InsetNewlineParams const & params)
 {
        ostringstream data;
-       data << name_ << ' ';
+       data << "newline" << ' ';
        params.write(data);
        return data.str();
 }