Embedding: add embedding support for InsetExternal. (params["embed"] is added)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22442 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Bo Peng 2008-01-08 16:42:28 +00:00
parent c81fd7337d
commit 09a6f725d0
4 changed files with 53 additions and 10 deletions

View File

@ -110,6 +110,8 @@ GuiExternal::GuiExternal(GuiView & lv)
this, SLOT(change_adaptor())); this, SLOT(change_adaptor()));
connect(browsePB, SIGNAL(clicked()), connect(browsePB, SIGNAL(clicked()),
this, SLOT(browseClicked())); this, SLOT(browseClicked()));
connect(embedCB, SIGNAL(toggled(bool)),
this, SLOT(change_adaptor()));
connect(editPB, SIGNAL(clicked()), connect(editPB, SIGNAL(clicked()),
this, SLOT(editClicked())); this, SLOT(editClicked()));
connect(externalCO, SIGNAL(activated(QString)), connect(externalCO, SIGNAL(activated(QString)),
@ -557,6 +559,7 @@ void GuiExternal::updateContents()
string const name = string const name =
params_.filename.outputFilename(bufferFilepath()); params_.filename.outputFilename(bufferFilepath());
fileED->setText(toqstr(name)); fileED->setText(toqstr(name));
embedCB->setCheckState(params_.filename.embedded() ? Qt::Checked : Qt::Unchecked);
externalCO->setCurrentIndex(getTemplateNumber(params_.templatename())); externalCO->setCurrentIndex(getTemplateNumber(params_.templatename()));
updateTemplate(); updateTemplate();
@ -639,6 +642,7 @@ void GuiExternal::updateTemplate()
void GuiExternal::applyView() void GuiExternal::applyView()
{ {
params_.filename.set(fromqstr(fileED->text()), bufferFilepath()); params_.filename.set(fromqstr(fileED->text()), bufferFilepath());
params_.filename.setEmbed(embedCB->checkState() == Qt::Checked);
params_.settemplate(getTemplate(externalCO->currentIndex()).lyxName); params_.settemplate(getTemplate(externalCO->currentIndex()).lyxName);

View File

@ -50,7 +50,7 @@ Template const * getTemplatePtr(InsetExternalParams const & params)
void editExternal(InsetExternalParams const & params, Buffer const & buffer) void editExternal(InsetExternalParams const & params, Buffer const & buffer)
{ {
formats.edit(buffer, params.filename, formats.edit(buffer, params.filename.availableFile(),
formats.getFormatFromFile(params.filename)); formats.getFormatFromFile(params.filename));
} }
@ -254,7 +254,7 @@ void updateExternal(InsetExternalParams const & params,
if (from_checksum != temp_checksum) { if (from_checksum != temp_checksum) {
Mover const & mover = getMover(from_format); Mover const & mover = getMover(from_format);
if (!mover.copy(params.filename, temp_file)) { if (!mover.copy(params.filename.availableFile(), temp_file)) {
LYXERR(Debug::EXTERNAL, "external::updateExternal. " LYXERR(Debug::EXTERNAL, "external::updateExternal. "
<< "Unable to copy " << params.filename << " to " << temp_file); << "Unable to copy " << params.filename << " to " << temp_file);
return; // FAILURE return; // FAILURE
@ -310,7 +310,7 @@ void updateExternal(InsetExternalParams const & params,
ErrorList el; ErrorList el;
bool const success = bool const success =
theConverters().convert(&buffer, temp_file, abs_to_file, theConverters().convert(&buffer, temp_file, abs_to_file,
params.filename, from_format, to_format, el, params.filename.availableFile(), from_format, to_format, el,
Converters::try_default | Converters::try_cache); Converters::try_default | Converters::try_cache);
if (!success) { if (!success) {

View File

@ -31,8 +31,11 @@
#include "MetricsInfo.h" #include "MetricsInfo.h"
#include "OutputParams.h" #include "OutputParams.h"
#include "frontends/alert.h"
#include "graphics/PreviewLoader.h" #include "graphics/PreviewLoader.h"
#include "support/ExceptionMessage.h"
#include "support/filetools.h" #include "support/filetools.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/lyxlib.h" #include "support/lyxlib.h"
@ -59,6 +62,8 @@ string defaultTemplateName;
namespace lyx { namespace lyx {
namespace Alert = frontend::Alert;
extern bool use_gui; extern bool use_gui;
namespace external { namespace external {
@ -182,9 +187,10 @@ void InsetExternalParams::write(Buffer const & buffer, ostream & os) const
os << "External\n" os << "External\n"
<< "\ttemplate " << templatename() << '\n'; << "\ttemplate " << templatename() << '\n';
if (!filename.empty()) if (!filename.empty()) {
os << "\tfilename " << filename.outputFilename(buffer.filePath()) << '\n'; os << "\tfilename " << filename.outputFilename(buffer.filePath()) << '\n';
os << "\tembed " << (filename.embedded() ? "true" : "false") << '\n';
}
if (display != defaultDisplayType) if (display != defaultDisplayType)
os << "\tdisplay " os << "\tdisplay "
<< external::displayTranslator().find(display) << external::displayTranslator().find(display)
@ -241,6 +247,7 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
enum ExternalTags { enum ExternalTags {
EX_TEMPLATE = 1, EX_TEMPLATE = 1,
EX_FILENAME, EX_FILENAME,
EX_EMBED,
EX_DISPLAY, EX_DISPLAY,
EX_LYXSCALE, EX_LYXSCALE,
EX_DRAFT, EX_DRAFT,
@ -264,6 +271,7 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
{ "draft", EX_DRAFT}, { "draft", EX_DRAFT},
{ "extra", EX_EXTRA }, { "extra", EX_EXTRA },
{ "filename", EX_FILENAME}, { "filename", EX_FILENAME},
{ "embed", EX_EMBED},
{ "height", EX_HEIGHT }, { "height", EX_HEIGHT },
{ "keepAspectRatio", EX_KEEPASPECTRATIO }, { "keepAspectRatio", EX_KEEPASPECTRATIO },
{ "lyxscale", EX_LYXSCALE}, { "lyxscale", EX_LYXSCALE},
@ -293,6 +301,12 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
break; break;
} }
case EX_EMBED: {
lex.next();
filename.setEmbed(lex.getBool());
break;
}
case EX_DISPLAY: { case EX_DISPLAY: {
lex.next(); lex.next();
string const name = lex.getString(); string const name = lex.getString();
@ -437,6 +451,15 @@ void InsetExternal::doDispatch(Cursor & cur, FuncRequest & cmd)
Buffer const & buffer = cur.buffer(); Buffer const & buffer = cur.buffer();
InsetExternalParams p; InsetExternalParams p;
InsetExternalMailer::string2params(to_utf8(cmd.argument()), buffer, p); InsetExternalMailer::string2params(to_utf8(cmd.argument()), buffer, p);
if (!p.filename.empty()) {
try {
p.filename.enable(buffer.embeddedFiles().enabled(), &buffer);
} catch (ExceptionMessage const & message) {
Alert::error(message.title_, message.details_);
// do not set parameter if an error happens
break;
}
}
setParams(p, buffer); setParams(p, buffer);
break; break;
} }
@ -476,8 +499,18 @@ bool InsetExternal::getStatus(Cursor & cur, FuncRequest const & cmd,
void InsetExternal::registerEmbeddedFiles(Buffer const &, void InsetExternal::registerEmbeddedFiles(Buffer const &,
EmbeddedFiles & files) const EmbeddedFiles & files) const
{ {
// temporarily disable embedding for this inset files.registerFile(params_.filename, this);
/* files.registerFile(params_.filename, this); */ }
void InsetExternal::updateEmbeddedFile(Buffer const & buf,
EmbeddedFile const & file)
{
// when embedding is enabled, change of embedding status leads to actions
EmbeddedFile temp = file;
temp.enable(buf.embeddedFiles().enabled(), &buf);
// this will not be set if an exception is thorwn in enable()
params_.filename = temp;
} }
@ -532,7 +565,8 @@ graphics::Params get_grfx_params(InsetExternalParams const & eparams)
{ {
graphics::Params gparams; graphics::Params gparams;
gparams.filename = eparams.filename; gparams.filename = eparams.filename.availableFile();
gparams.icon = eparams.filename.embedded() ? "pin.png" : "";
gparams.scale = eparams.lyxscale; gparams.scale = eparams.lyxscale;
if (eparams.clipdata.clip) if (eparams.clipdata.clip)
gparams.bb = eparams.clipdata.bbox; gparams.bb = eparams.clipdata.bbox;
@ -671,8 +705,11 @@ void InsetExternal::write(Buffer const & buffer, ostream & os) const
void InsetExternal::read(Buffer const & buffer, Lexer & lex) void InsetExternal::read(Buffer const & buffer, Lexer & lex)
{ {
InsetExternalParams params; InsetExternalParams params;
if (params.read(buffer, lex)) if (params.read(buffer, lex)) {
// exception handling is not needed as long as embedded files are in place.
params.filename.enable(buffer.embeddedFiles().enabled(), & buffer);
setParams(params, buffer); setParams(params, buffer);
}
} }

View File

@ -80,7 +80,7 @@ public:
std::string const & templatename() const { return templatename_; } std::string const & templatename() const { return templatename_; }
/// The external file. /// The external file.
support::DocFileName filename; EmbeddedFile filename;
/// How the inset is to be displayed by LyX. /// How the inset is to be displayed by LyX.
external::DisplayType display; external::DisplayType display;
/// The scale of the displayed graphic (if shown). /// The scale of the displayed graphic (if shown).
@ -150,6 +150,8 @@ public:
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const; bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
/// external file can be embedded /// external file can be embedded
void registerEmbeddedFiles(Buffer const &, EmbeddedFiles &) const; void registerEmbeddedFiles(Buffer const &, EmbeddedFiles &) const;
///
void updateEmbeddedFile(Buffer const &, EmbeddedFile const &);
protected: protected:
InsetExternal(InsetExternal const &); InsetExternal(InsetExternal const &);