#include "MetricsInfo.h"
#include "OutputParams.h"
+#include "frontends/alert.h"
+
#include "graphics/PreviewLoader.h"
+#include "support/ExceptionMessage.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
#include <sstream>
using namespace std;
-
-using lyx::support::DocFileName;
+using namespace lyx::support;
namespace {
namespace lyx {
+namespace Alert = frontend::Alert;
+
extern bool use_gui;
namespace external {
TempName::TempName()
{
- support::FileName const tempname(support::tempName(support::FileName(), "lyxext"));
+ FileName const tempname = FileName::tempName("lyxext");
// FIXME: This is unsafe
tempname.removeFile();
// must have an extension for the converter code to work correctly.
- tempname_ = support::FileName(tempname.absFilename() + ".tmp");
+ tempname_ = FileName(tempname.absFilename() + ".tmp");
}
const_iterator it = ids.begin();
const_iterator end = ids.end();
- it = std::find(it, end, value);
+ it = find(it, end, value);
if (it == end)
data = T();
}
<< "\ttemplate " << templatename() << '\n';
if (!filename.empty()) {
- // when we save, we still use the original filename
- EmbeddedFiles::EmbeddedFileList::const_iterator it =
- buffer.embeddedFiles().find(filename.toFilesystemEncoding());
- if (it != buffer.embeddedFiles().end())
- os << "\tfilename " << DocFileName(it->absFilename()).outputFilename(buffer.filePath()) << '\n';
- else
- os << "\tfilename " << filename.outputFilename(buffer.filePath()) << '\n';
- }
-
+ os << "\tfilename " << filename.outputFilename(buffer.filePath()) << '\n';
+ os << "\tembed " << (filename.embedded() ? "true" : "false") << '\n';
+ }
if (display != defaultDisplayType)
os << "\tdisplay "
<< external::displayTranslator().find(display)
}
if (!resizedata.no_resize()) {
- using support::float_equal;
double const scl = convert<double>(resizedata.scale);
if (!float_equal(scl, 0.0, 0.05)) {
if (!float_equal(scl, 100.0, 0.05))
enum ExternalTags {
EX_TEMPLATE = 1,
EX_FILENAME,
+ EX_EMBED,
EX_DISPLAY,
EX_LYXSCALE,
EX_DRAFT,
{ "draft", EX_DRAFT},
{ "extra", EX_EXTRA },
{ "filename", EX_FILENAME},
+ { "embed", EX_EMBED},
{ "height", EX_HEIGHT },
{ "keepAspectRatio", EX_KEEPASPECTRATIO },
{ "lyxscale", EX_LYXSCALE},
lex.eatLine();
string const name = lex.getString();
filename.set(name, buffer.filePath());
- // maybe this file is embedded
- EmbeddedFiles::EmbeddedFileList::const_iterator it = buffer.embeddedFiles().find(filename.toFilesystemEncoding());
- if (it != buffer.embeddedFiles().end())
- // using available file, embedded or external, depending on file availability and
- // embedding status.
- filename = DocFileName(it->availableFile(&buffer));
+ break;
+ }
+
+ case EX_EMBED: {
+ lex.next();
+ filename.setEmbed(lex.getBool());
break;
}
Buffer const & buffer = cur.buffer();
InsetExternalParams p;
InsetExternalMailer::string2params(to_utf8(cmd.argument()), buffer, p);
+ if (!p.filename.empty()) {
+ try {
+ p.filename.enable(buffer.embedded(), &buffer);
+ } catch (ExceptionMessage const & message) {
+ Alert::error(message.title_, message.details_);
+ // do not set parameter if an error happens
+ break;
+ }
+ }
setParams(p, buffer);
break;
}
}
-void InsetExternal::registerEmbeddedFiles(Buffer const &,
- EmbeddedFiles & files) const
+void InsetExternal::registerEmbeddedFiles(Buffer const & buffer,
+ EmbeddedFileList & files) const
{
- files.registerFile(params_.filename.absFilename(), false, this);
+ files.registerFile(params_.filename, this, buffer);
+}
+
+
+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.embedded(), &buf);
+ // this will not be set if an exception is thorwn in enable()
+ params_.filename = temp;
}
{
graphics::Params gparams;
- gparams.filename = eparams.filename;
+ gparams.filename = eparams.filename.availableFile();
+ gparams.icon = eparams.filename.embedded() ? "pin.png" : "";
gparams.scale = eparams.lyxscale;
if (eparams.clipdata.clip)
gparams.bb = eparams.clipdata.bbox;
external::getTemplatePtr(params);
if (!ptr)
// FIXME UNICODE
- return support::bformat((_("External template %1$s is not installed")),
+ return bformat((_("External template %1$s is not installed")),
from_utf8(params.templatename()));
// FIXME UNICODE
docstring gui = _(ptr->guiName);
void InsetExternal::read(Buffer const & buffer, Lexer & lex)
{
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.embedded(), & buffer);
setParams(params, buffer);
+ }
}