#include "Buffer.h"
#include "Cursor.h"
-#include "debug.h"
+#include "support/debug.h"
#include "DispatchResult.h"
#include "Exporter.h"
#include "FuncStatus.h"
#include "FuncRequest.h"
-#include "gettext.h"
+#include "support/gettext.h"
#include "LaTeXFeatures.h"
-#include "LyX.h"
#include "Lexer.h"
#include "LyXRC.h"
#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 std::string;
-using std::istringstream;
-using std::ostream;
-using std::ostringstream;
-using std::vector;
-
-using lyx::support::DocFileName;
+using namespace std;
+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
- support::unlink(tempname);
+ tempname.removeFile();
// must have an extension for the converter code to work correctly.
- tempname_ = support::FileName(tempname.absFilename() + ".tmp");
+ tempname_ = FileName(tempname.absFilename() + ".tmp");
}
TempName::~TempName()
{
- support::unlink(tempname_);
+ tempname_.removeFile();
}
-TempName &
-TempName::operator=(TempName const & other)
+TempName & TempName::operator=(TempName const & other)
{
if (this != &other)
tempname_ = TempName()();
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;
}
break;
default:
- lex.printError("ExternalInset::read: "
- "Wrong tag: $$Token");
+ lex.printError("ExternalInset::read: Wrong tag: $$Token");
read_error = true;
break;
}
void InsetExternal::statusChanged() const
{
- LyX::cref().updateInset(this);
+ updateFrontend();
}
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, this, buffer);
+}
+
+
+void InsetExternal::updateEmbeddedFile(Buffer const & buf,
+ EmbeddedFile const & file)
{
- files.registerFile(params_.filename.absFilename(), false, this);
+ // 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;
BOOST_ASSERT(false);
}
if (gparams.display == graphics::DefaultDisplay)
- gparams.display = lyxrc.display_graphics;
+ gparams.display = graphics::DisplayType(lyxrc.display_graphics);
// Override the above if we're not using a gui
if (!use_gui)
gparams.display = graphics::NoDisplay;
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);
button_ptr->update(getScreenLabel(params_, buffer), true);
break;
+ }
- } case RENDERGRAPHIC: {
+ case RENDERGRAPHIC: {
RenderGraphic * graphic_ptr = renderer_->asGraphic();
if (!graphic_ptr) {
renderer_.reset(new RenderGraphic(this));
graphic_ptr->update(get_grfx_params(params_));
break;
+ }
- } case RENDERPREVIEW: {
+ case RENDERPREVIEW: {
RenderMonitoredPreview * preview_ptr =
renderer_->asMonitoredPreview();
if (!preview_ptr) {
void InsetExternal::fileChanged() const
{
- Buffer const * const buffer_ptr = LyX::cref().updateInset(this);
- if (!buffer_ptr)
+ Buffer const * const buffer = updateFrontend();
+ if (!buffer)
return;
RenderMonitoredPreview * const ptr = renderer_->asMonitoredPreview();
BOOST_ASSERT(ptr);
- Buffer const & buffer = *buffer_ptr;
- ptr->removePreview(buffer);
- add_preview_and_start_loading(*ptr, *this, buffer);
+ ptr->removePreview(*buffer);
+ add_preview_and_start_loading(*ptr, *this, *buffer);
}
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);
+ }
}
bool preview_wanted(InsetExternalParams const & params)
{
return params.display == external::PreviewDisplay &&
- params.filename.isFileReadable();
+ params.filename.isReadableFile();
}