]> git.lyx.org Git - lyx.git/commitdiff
use "new" Lexer interface...
authorAndré Pönitz <poenitz@gmx.net>
Thu, 3 Apr 2008 22:39:06 +0000 (22:39 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 3 Apr 2008 22:39:06 +0000 (22:39 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24109 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/InsetWrap.cpp
src/insets/InsetWrap.h

index a9f92cedc27714061916675735cc9cc28363c77c..26b8cd236bbb9db2ec3c031cb6340537f62b8cbc 100644 (file)
@@ -25,7 +25,6 @@
 #include "FuncStatus.h"
 #include "LaTeXFeatures.h"
 #include "Lexer.h"
-#include "OutputParams.h"
 #include "TextClass.h"
 #include "TocBackend.h"
 
 
 using namespace std;
 
-namespace lyx {
 
+namespace lyx {
 
 InsetWrap::InsetWrap(Buffer const & buf, string const & type)
-       : InsetCollapsable(buf), name_(from_utf8(type))
+       : InsetCollapsable(buf)
 {
        setLabel(_("wrap: ") + floatName(type, buf.params()));
        params_.type = type;
@@ -59,6 +58,12 @@ InsetWrap::~InsetWrap()
 }
 
 
+docstring InsetWrap::name() const
+{
+       return from_utf8(params_.type);
+}
+
+
 void InsetWrap::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
@@ -117,58 +122,20 @@ void InsetWrap::updateLabels(ParIterator const & it)
 void InsetWrapParams::write(ostream & os) const
 {
        os << "Wrap " << type << '\n';
-       os << "lines " << lines << "\n";
-       os << "placement " << placement << "\n";
-       os << "overhang " << overhang.asString() << "\n";
+       os << "lines " << lines << '\n';
+       os << "placement " << placement << '\n';
+       os << "overhang " << overhang.asString() << '\n';
        os << "width \"" << width.asString() << "\"\n";
 }
 
 
 void InsetWrapParams::read(Lexer & lex)
 {
-       string token;
-
-       lex >> token;
-       if (token == "lines")
-               lex >> lines;
-       else {
-               lyxerr << "InsetWrap::Read:: Missing 'lines'-tag!"
-                       << endl;
-               // take countermeasures
-               lex.pushToken(token);
-       }
-       if (!lex)
-               return;
-       lex >> token;
-       if (token == "placement")
-               lex >> placement;
-       else {
-               lyxerr << "InsetWrap::Read:: Missing 'placement'-tag!"
-                       << endl;
-               lex.pushToken(token);
-       }
-       if (!lex)
-               return;
-       lex >> token;
-       if (token == "overhang") {
-               lex.next();
-               overhang = Length(lex.getString());
-       } else {
-               lyxerr << "InsetWrap::Read:: Missing 'overhang'-tag!"
-                       << endl;
-               lex.pushToken(token);
-       }
-       if (!lex)
-               return;
-       lex >> token;
-       if (token == "width") {
-               lex.next();
-               width = Length(lex.getString());
-       } else {
-               lyxerr << "InsetWrap::Read:: Missing 'width'-tag!"
-                       << endl;
-               lex.pushToken(token);
-       }
+       lex.setContext("InsetWrapParams::read");
+       lex >> "lines" >> lines;
+       lex >> "placement" >> placement;
+       lex >> "overhang" >> overhang;
+       lex >> "width" >> width;
 }
 
 
@@ -263,31 +230,13 @@ bool InsetWrap::showInsetDialog(BufferView * bv) const
 void InsetWrap::string2params(string const & in, InsetWrapParams & params)
 {
        params = InsetWrapParams();
-       if (in.empty())
-               return;
-
        istringstream data(in);
        Lexer lex;
        lex.setStream(data);
-
-       string name;
-       lex >> name;
-       if (!lex || name != "wrap") {
-               LYXERR0("Expected arg 1 to be \"wrap\" in " << in);
-               return;
-       }
-
-       // This is part of the inset proper that is usually swallowed
-       // by Text::readInset
-       string id;
-       lex >> id;
-       if (!lex || id != "Wrap") {
-               LYXERR0("Expected arg 2 to be \"Wrap\" in " << in);
-               return;
-       }
-
-       // We have to read the type here!
-       lex >> params.type;
+       lex.setContext("InsetWrap::string2params");
+       lex >> "wrap";
+       lex >> "Wrap";  // Part of the inset proper, swallowed by Text::readInset
+       lex >> params.type; // We have to read the type here!
        params.read(lex);
 }
 
index 6078e53ec6a5191ba63d3815ae0e53b59c59bb80..f22c2fd086fb1edd975a86099d93d1852ed96fdc 100644 (file)
@@ -81,14 +81,12 @@ private:
        ///
        void doDispatch(Cursor & cur, FuncRequest & cmd);
        ///
-       docstring name() const { return name_; }
+       docstring name() const;
        ///
        Inset * clone() const { return new InsetWrap(*this); }
 
        ///
        InsetWrapParams params_;
-       ///
-       docstring name_;
 };
 
 } // namespace lyx