#include "insets/RenderPreview.h"
#include "Buffer.h"
-#include "LCursor.h"
-#include "debug.h"
+#include "Cursor.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 "LyXLex.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 "support/convert.h"
-#include "support/translator.h"
+#include "support/Translator.h"
#include <boost/bind.hpp>
#include <sstream>
-using std::endl;
-using std::string;
-using std::auto_ptr;
-using std::istringstream;
-using std::ostream;
-using std::ostringstream;
-using std::vector;
-
+using namespace std;
+using namespace lyx::support;
namespace {
unsigned int const defaultLyxScale = 100;
-string defaultTemplateName = "RasterImage";
+string defaultTemplateName;
} // namespace anon
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()();
InsetExternalParams::InsetExternalParams()
: display(defaultDisplayType),
lyxscale(defaultLyxScale),
- draft(false),
- templatename_(defaultTemplateName)
-{}
+ draft(false)
+{
+ if (defaultTemplateName.empty()) {
+ external::TemplateManager const & etm =
+ external::TemplateManager::get();
+ templatename_ = etm.getTemplates().begin()->first;
+ } else
+ templatename_ = defaultTemplateName;
+}
namespace {
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();
}
os << "External\n"
<< "\ttemplate " << templatename() << '\n';
- if (!filename.empty())
- os << "\tfilename "
- << filename.outputFilename(buffer.filePath())
- << '\n';
-
+ if (!filename.empty()) {
+ 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))
}
-bool InsetExternalParams::read(Buffer const & buffer, LyXLex & lex)
+bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
{
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},
{ "width", EX_WIDTH }
};
- pushpophelper pph(lex, external_tags, EX_END);
+ PushPopHelper pph(lex, external_tags, EX_END);
bool found_end = false;
bool read_error = false;
filename.set(name, buffer.filePath());
break;
}
+
+ case EX_EMBED: {
+ lex.next();
+ filename.setEmbed(lex.getBool());
+ break;
+ }
case EX_DISPLAY: {
lex.next();
case EX_HEIGHT:
lex.next();
- resizedata.height = LyXLength(lex.getString());
+ resizedata.height = Length(lex.getString());
break;
case EX_KEEPASPECTRATIO:
case EX_WIDTH:
lex.next();
- resizedata.width = LyXLength(lex.getString());
+ resizedata.width = Length(lex.getString());
break;
case EX_END:
break;
default:
- lex.printError("ExternalInset::read: "
- "Wrong tag: $$Token");
+ lex.printError("ExternalInset::read: Wrong tag: $$Token");
read_error = true;
break;
}
InsetExternal::InsetExternal(InsetExternal const & other)
- : InsetOld(other),
+ : Inset(other),
boost::signals::trackable(),
params_(other.params_),
renderer_(other.renderer_->clone(this))
{}
-auto_ptr<InsetBase> InsetExternal::doClone() const
+Inset * InsetExternal::clone() const
{
- return auto_ptr<InsetBase>(new InsetExternal(*this));
+ return new InsetExternal(*this);
}
void InsetExternal::statusChanged() const
{
- LyX::cref().updateInset(this);
+ updateFrontend();
}
-void InsetExternal::doDispatch(LCursor & cur, FuncRequest & cmd)
+void InsetExternal::doDispatch(Cursor & cur, FuncRequest & cmd)
{
switch (cmd.action) {
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;
}
break;
case LFUN_MOUSE_RELEASE:
- InsetExternalMailer(*this).showDialog(&cur.bv());
+ if (!cur.selection())
+ InsetExternalMailer(*this).showDialog(&cur.bv());
break;
default:
- InsetBase::doDispatch(cur, cmd);
+ Inset::doDispatch(cur, cmd);
}
}
-bool InsetExternal::getStatus(LCursor & cur, FuncRequest const & cmd,
+bool InsetExternal::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & flag) const
{
switch (cmd.action) {
return true;
default:
- return InsetBase::getStatus(cur, cmd, flag);
+ return Inset::getStatus(cur, cmd, flag);
}
}
-void InsetExternal::edit(LCursor & cur, bool)
+void InsetExternal::registerEmbeddedFiles(Buffer const & buffer,
+ EmbeddedFileList & files) const
+{
+ 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;
+}
+
+
+void InsetExternal::edit(Cursor & cur, bool)
{
InsetExternalMailer(*this).showDialog(&cur.bv());
}
-bool InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const
+void InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const
{
renderer_->metrics(mi, dim);
- bool const changed = dim_ != dim;
- dim_ = dim;
- return changed;
}
void InsetExternal::draw(PainterInfo & pi, int x, int y) const
{
- setPosCache(pi, x, y);
renderer_->draw(pi, x, y);
}
{
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);
return from_utf8(external::doSubstitution(params, buffer,
- ptr->guiName, false));
+ to_utf8(gui), false));
}
void add_preview_and_start_loading(RenderMonitoredPreview &,
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, LyXLex & lex)
+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);
+ }
}
int InsetExternal::latex(Buffer const & buf, odocstream & os,
- OutputParams const & runparams) const
+ OutputParams const & runparams) const
{
if (params_.draft) {
// FIXME UNICODE
if (cit != et.formats.end()) {
return external::writeExternal(params_, "PDFLaTeX",
- buf, os,
- *(runparams.exportdata),
- external_in_tmpdir,
- dryrun);
- }
+ buf, os,
+ *(runparams.exportdata),
+ external_in_tmpdir,
+ dryrun);
+ }
}
return external::writeExternal(params_, "LaTeX", buf, os,
- *(runparams.exportdata),
- external_in_tmpdir,
- dryrun);
+ *(runparams.exportdata),
+ external_in_tmpdir,
+ dryrun);
}
int InsetExternal::plaintext(Buffer const & buf, odocstream & os,
- OutputParams const & runparams) const
+ OutputParams const & runparams) const
{
os << '\n'; // output external material on a new line
external::writeExternal(params_, "Ascii", buf, os,
- *(runparams.exportdata), false,
- runparams.dryrun || runparams.inComment);
+ *(runparams.exportdata), false,
+ runparams.dryrun || runparams.inComment);
return PLAINTEXT_NEWLINE;
}
int InsetExternal::docbook(Buffer const & buf, odocstream & os,
- OutputParams const & runparams) const
+ OutputParams const & runparams) const
{
return external::writeExternal(params_, "DocBook", buf, os,
*(runparams.exportdata), false,
- runparams.dryrun || runparams.inComment);
+ runparams.dryrun || runparams.inComment);
}
bool preview_wanted(InsetExternalParams const & params)
{
return params.display == external::PreviewDisplay &&
- support::isFileReadable(params.filename);
+ params.filename.isReadableFile();
}
return;
istringstream data(in);
- LyXLex lex(0,0);
+ Lexer lex(0,0);
lex.setStream(data);
string name;
return print_mailer_error("InsetExternalMailer", in, 1, name_);
// This is part of the inset proper that is usually swallowed
- // by LyXText::readInset
+ // by Text::readInset
string id;
lex >> id;
if (!lex || id != "External")