Add InsetExternal::Params::read, write functions.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7841 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-09-30 13:51:00 +00:00
parent e5d63b47d2
commit adbb65c87a
3 changed files with 118 additions and 100 deletions

View 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

View 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();
}

View 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_(); }