X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetGraphics.cpp;h=70cfe9767d719a3d35a8a24788fe9cca231b2310;hb=3189e7b5dd438876016091463b8e66b134295fb5;hp=f48f784e7f99dccf5a2261797bcb39bec0602148;hpb=bcf64dd11c899e5937f447b19b62e1b3eac17a48;p=lyx.git diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp index f48f784e7f..70cfe9767d 100644 --- a/src/insets/InsetGraphics.cpp +++ b/src/insets/InsetGraphics.cpp @@ -71,12 +71,12 @@ TODO #include "Mover.h" #include "OutputParams.h" #include "sgml.h" +#include "EmbeddedFiles.h" #include "frontends/alert.h" #include "support/convert.h" #include "support/filetools.h" -#include "support/lyxalgo.h" // count #include "support/lyxlib.h" // sum #include "support/lstrings.h" #include "support/os.h" @@ -85,6 +85,7 @@ TODO #include #include +#include #include @@ -99,6 +100,7 @@ using support::FileName; using support::float_equal; using support::getExtension; using support::isFileReadable; +using support::isValidLaTeXFilename; using support::latex_path; using support::onlyFilename; using support::removeExtension; @@ -111,7 +113,6 @@ using support::unzippedFileName; using std::endl; using std::string; -using std::auto_ptr; using std::istringstream; using std::ostream; using std::ostringstream; @@ -164,9 +165,9 @@ InsetGraphics::InsetGraphics(InsetGraphics const & ig) } -auto_ptr InsetGraphics::doClone() const +Inset * InsetGraphics::clone() const { - return auto_ptr(new InsetGraphics(*this)); + return new InsetGraphics(*this); } @@ -180,7 +181,7 @@ void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd) { switch (cmd.action) { case LFUN_GRAPHICS_EDIT: { - Buffer const & buffer = *cur.bv().buffer(); + Buffer const & buffer = cur.bv().buffer(); InsetGraphicsParams p; InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer, p); editGraphics(p, buffer); @@ -230,6 +231,14 @@ bool InsetGraphics::getStatus(Cursor & cur, FuncRequest const & cmd, } +void InsetGraphics::registerEmbeddedFiles(Buffer const &, + EmbeddedFiles & files) const +{ + files.registerFile(params().filename.absFilename(), + false, this); +} + + void InsetGraphics::edit(Cursor & cur, bool) { InsetGraphicsMailer(*this).showDialog(&cur.bv()); @@ -261,7 +270,7 @@ Inset::EDITABLE InsetGraphics::editable() const void InsetGraphics::write(Buffer const & buf, ostream & os) const { os << "Graphics\n"; - params().Write(os, buf.filePath()); + params().Write(os, buf); } @@ -274,6 +283,16 @@ void InsetGraphics::read(Buffer const & buf, Lexer & lex) else LYXERR(Debug::GRAPHICS) << "Not a Graphics inset!" << endl; + // InsetGraphics is read, with filename in params_. We do not know if this file actually + // exists or is embedded so we need to get the 'availableFile' from buf.embeddedFiles() + if (buf.embeddedFiles().enabled()) { + EmbeddedFiles::EmbeddedFileList::const_iterator it = + buf.embeddedFiles().find(params_.filename.toFilesystemEncoding()); + if (it != buf.embeddedFiles().end()) + // using available file, embedded or external, depending on file availability and + // embedding status. + params_.filename = DocFileName(it->availableFile(&buf)); + } graphic_->update(params().as_grfxParams()); } @@ -607,6 +626,14 @@ string const InsetGraphics::prepareFile(Buffer const & buf, string output_file = support::os::external_path(runparams.nice ? params().filename.outputFilename(m_buffer->filePath()) : onlyFilename(temp_file.absFilename())); + + if (runparams.nice && !isValidLaTeXFilename(output_file)) { + frontend::Alert::warning(_("Invalid filename"), + _("The following filename is likely to cause trouble " + "when running the exported file through LaTeX: ") + + from_utf8(output_file)); + } + FileName source_file = runparams.nice ? FileName(params().filename) : temp_file; string const tex_format = (runparams.flavor == OutputParams::LATEX) ? "latex" : "pdflatex"; @@ -814,7 +841,7 @@ int InsetGraphics::latex(Buffer const & buf, odocstream & os, LYXERR(Debug::GRAPHICS) << "InsetGraphics::latex outputting:\n" << latex_str << endl; // Return how many newlines we issued. - return int(lyx::count(latex_str.begin(), latex_str.end(),'\n')); + return int(std::count(latex_str.begin(), latex_str.end(),'\n')); } @@ -839,8 +866,11 @@ int InsetGraphics::plaintext(Buffer const & buf, odocstream & os, namespace { -int writeImageObject(char * format, odocstream & os, OutputParams const & runparams, - docstring const graphic_label, docstring const attributes) +int writeImageObject(char const * format, + odocstream & os, + OutputParams const & runparams, + docstring const & graphic_label, + docstring const & attributes) { if (runparams.flavor != OutputParams::XML) { os << "