]> git.lyx.org Git - lyx.git/commitdiff
Add InsetExternal::Params::read, write functions.
authorAngus Leeming <leeming@lyx.org>
Tue, 30 Sep 2003 13:51:00 +0000 (13:51 +0000)
committerAngus Leeming <leeming@lyx.org>
Tue, 30 Sep 2003 13:51:00 +0000 (13:51 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7841 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/ChangeLog
src/insets/insetexternal.C
src/insets/insetexternal.h

index 7e6a81606ab55e2bdf84ad940f8bc885fbdb567d..bbd36a96879213ac132603109c48a5002aa90a11 100644 (file)
@@ -1,3 +1,7 @@
+2003-09-30  Angus Leeming  <leeming@lyx.org>
+
+       * insetexternal.[Ch] (Params::read, write): new member functions.
+
 2003-09-25  Angus Leeming  <leeming@lyx.org>
 
        * insetexternal.[Ch] (TempName): new (private) nested struct with
index b29d976b7f5ed5ce8f98e536a964c5226768d14b..f14dc5cb2d87787109a7fe245a33bd5f4d68168d 100644 (file)
@@ -130,6 +130,109 @@ void InsetExternal::Params::settemplate(string const & name)
 }
 
 
+void InsetExternal::Params::write(Buffer const & buffer, ostream & os) const
+{
+       os << "External\n"
+          << "\ttemplate " << templatename() << '\n';
+
+       if (!filename.empty())
+               os << "\tfilename "
+                  << filename.outputFilename(buffer.filePath())
+                  << '\n';
+
+       if (display != defaultDisplayType)
+               os << "\tdisplay " << lyx::graphics::displayTranslator.find(display)
+                  << '\n';
+
+       if (lyxscale != defaultLyxScale)
+               os << "\tlyxscale " << tostr(lyxscale) << '\n';
+}
+
+
+bool InsetExternal::Params::read(Buffer const & buffer, LyXLex & lex)
+{
+       enum ExternalTags {
+               EX_TEMPLATE = 1,
+               EX_FILENAME,
+               EX_DISPLAY,
+               EX_LYXSCALE,
+               EX_END
+       };
+
+       keyword_item external_tags[] = {
+               { "\\end_inset",     EX_END },
+               { "display",         EX_DISPLAY},
+               { "filename",        EX_FILENAME},
+               { "lyxscale",        EX_LYXSCALE},
+               { "template",        EX_TEMPLATE }
+       };
+
+       pushpophelper pph(lex, external_tags, EX_END);
+
+       bool found_end  = false;
+       bool read_error = false;
+
+       while (lex.isOK()) {
+               switch (lex.lex()) {
+               case EX_TEMPLATE:
+                       lex.next();
+                       templatename_ = lex.getString();
+                       break;
+
+               case EX_FILENAME: {
+                       lex.next();
+                       string const name = lex.getString();
+                       filename.set(name, buffer.filePath());
+                       break;
+               }
+
+               case EX_DISPLAY: {
+                       lex.next();
+                       string const name = lex.getString();
+                       display = lyx::graphics::displayTranslator.find(name);
+                       break;
+               }
+
+               case EX_LYXSCALE:
+                       lex.next();
+                       lyxscale = lex.getInteger();
+                       break;
+
+               case EX_END:
+                       found_end = true;
+                       break;
+
+               default:
+                       lex.printError("ExternalInset::read: "
+                                      "Wrong tag: $$Token");
+                       read_error = true;
+                       break;
+               }
+
+               if (found_end || read_error)
+                       break;
+       }
+
+       if (!found_end) {
+               lex.printError("ExternalInset::read: "
+                              "Missing \\end_inset.");
+       }
+
+       // This is a trick to make sure that the data are self-consistent.
+       settemplate(templatename_);
+
+       lyxerr[Debug::EXTERNAL]
+               << "InsetExternal::Params::read: "
+               << "template: '"   << templatename()
+               << "' filename: '" << filename.absFilename()
+               << "' display: '"  << display
+               << "' scale: '"    << lyxscale
+               << '\'' << endl;
+
+       return !read_error;
+}
 InsetExternal::InsetExternal()
        : renderer_(new ButtonRenderer)
 {}
@@ -298,105 +401,15 @@ void InsetExternal::setParams(Params const & p, Buffer const & buffer)
 
 void InsetExternal::write(Buffer const & buffer, ostream & os) const
 {
-       os << "External\n"
-          << "\ttemplate " << params_.templatename() << '\n';
-
-       if (!params_.filename.empty())
-               os << "\tfilename "
-                  << params_.filename.outputFilename(buffer.filePath())
-                  << '\n';
-
-       if (params_.display != defaultDisplayType)
-               os << "\tdisplay " << lyx::graphics::displayTranslator.find(params_.display)
-                  << '\n';
-
-       if (params_.lyxscale != defaultLyxScale)
-               os << "\tlyxscale " << tostr(params_.lyxscale) << '\n';
+       params_.write(buffer, os);
 }
 
 
 void InsetExternal::read(Buffer const & buffer, LyXLex & lex)
 {
-       enum ExternalTags {
-               EX_TEMPLATE = 1,
-               EX_FILENAME,
-               EX_DISPLAY,
-               EX_LYXSCALE,
-               EX_END
-       };
-
-       keyword_item external_tags[] = {
-               { "\\end_inset", EX_END },
-               { "display", EX_DISPLAY},
-               { "filename", EX_FILENAME},
-               { "lyxscale", EX_LYXSCALE},
-               { "template", EX_TEMPLATE }
-       };
-
-       pushpophelper pph(lex, external_tags, EX_END);
-
-       bool found_end  = false;
-       bool read_error = false;
-
-       InsetExternal::Params params;
-       while (lex.isOK()) {
-               switch (lex.lex()) {
-               case EX_TEMPLATE: {
-                       lex.next();
-                       params.settemplate(lex.getString());
-                       break;
-               }
-
-               case EX_FILENAME: {
-                       lex.next();
-                       string const name = lex.getString();
-                       params.filename.set(name, buffer.filePath());
-                       break;
-               }
-
-               case EX_DISPLAY: {
-                       lex.next();
-                       string const name = lex.getString();
-                       params.display = lyx::graphics::displayTranslator.find(name);
-                       break;
-               }
-
-               case EX_LYXSCALE: {
-                       lex.next();
-                       params.lyxscale = lex.getInteger();
-                       break;
-               }
-
-               case EX_END:
-                       found_end = true;
-                       break;
-
-               default:
-                       lex.printError("ExternalInset::read: "
-                                      "Wrong tag: $$Token");
-                       read_error = true;
-                       break;
-               }
-
-               if (found_end || read_error)
-                       break;
-       }
-
-       if (!found_end) {
-               lex.printError("ExternalInset::read: "
-                              "Missing \\end_inset.");
-       }
-
-       // Replace the inset's store
-       setParams(params, buffer);
-
-       lyxerr[Debug::EXTERNAL]
-               << "InsetExternal::Read: "
-               << "template: '" << params_.templatename()
-               << "' filename: '" << params_.filename.absFilename()
-               << "' display: '" << params_.display
-               << "' scale: '" << params_.lyxscale
-               << '\'' << endl;
+       Params params;
+       if (params.read(buffer, lex))
+               setParams(params, buffer);
 }
 
 
@@ -687,9 +700,7 @@ void InsetExternalMailer::string2params(string const & in,
        }
 
        if (lex.isOK()) {
-               InsetExternal inset;
-               inset.read(buffer, lex);
-               params = inset.params();
+               params.read(buffer, lex);
        }
 }
 
@@ -698,11 +709,9 @@ string const
 InsetExternalMailer::params2string(InsetExternal::Params const & params,
                                   Buffer const & buffer)
 {
-       InsetExternal inset;
-       inset.setParams(params, buffer);
        ostringstream data;
        data << name_ << ' ';
-       inset.write(buffer, data);
+       params.write(buffer, data);
        data << "\\end_inset\n";
        return data.str();
 }
index 51b9871aabe0ec4fe13353b642db95c45481f81a..528a8bbdef9908ec24c342c9b9897139bb1a4794 100644 (file)
@@ -13,7 +13,9 @@
 #define INSET_EXTERNAL_H
 
 #include "inset.h"
+
 #include "graphics/GraphicsTypes.h"
+
 #include "support/filename.h"
 
 #include <boost/scoped_ptr.hpp>
@@ -47,6 +49,9 @@ public:
        struct Params {
                Params();
 
+               void write(Buffer const &, std::ostream &) const;
+               bool read(Buffer const &, LyXLex &);
+
                /// The name of the tempfile used for manipulations.
                string const & tempname() const { return tempname_(); }