mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 21:40:19 +00:00
Embedding feature patch 5: handling of embedded files (operation without external files)
* src/insets/InsetGraphicsParams.h|cpp: * src/insets/InsetExternal.cpp: read/write buffer with embedded file * src/insets/InsetGraphics.cpp: ditto * src/EmbeddedFiles.h|cpp: add find() function git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20075 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
3f0c6bc583
commit
c1e4304322
@ -275,6 +275,17 @@ bool EmbeddedFiles::write(DocFileName const & filename)
|
||||
}
|
||||
|
||||
|
||||
EmbeddedFiles::EmbeddedFileList::const_iterator EmbeddedFiles::find(std::string filename) const
|
||||
{
|
||||
EmbeddedFileList::const_iterator it = file_list_.begin();
|
||||
EmbeddedFileList::const_iterator it_end = file_list_.end();
|
||||
for (; it != it_end; ++it)
|
||||
if (it->absFilename() == filename || it->embeddedFile(buffer_) == filename)
|
||||
return it;
|
||||
return file_list_.end();
|
||||
}
|
||||
|
||||
|
||||
bool EmbeddedFiles::extractAll() const
|
||||
{
|
||||
EmbeddedFileList::const_iterator it = file_list_.begin();
|
||||
|
@ -225,6 +225,8 @@ public:
|
||||
EmbeddedFileList::iterator end() { return file_list_.end(); }
|
||||
EmbeddedFileList::const_iterator begin() const { return file_list_.begin(); }
|
||||
EmbeddedFileList::const_iterator end() const { return file_list_.end(); }
|
||||
// try to locate filename, using either absFilename() or embeddedFile()
|
||||
EmbeddedFileList::const_iterator find(std::string filename) const;
|
||||
///
|
||||
bool extractAll() const;
|
||||
///
|
||||
|
@ -50,6 +50,7 @@ using std::ostream;
|
||||
using std::ostringstream;
|
||||
using std::vector;
|
||||
|
||||
using lyx::support::DocFileName;
|
||||
|
||||
namespace {
|
||||
|
||||
@ -186,10 +187,15 @@ void InsetExternalParams::write(Buffer const & buffer, ostream & os) const
|
||||
os << "External\n"
|
||||
<< "\ttemplate " << templatename() << '\n';
|
||||
|
||||
if (!filename.empty())
|
||||
os << "\tfilename "
|
||||
<< filename.outputFilename(buffer.filePath())
|
||||
<< '\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';
|
||||
}
|
||||
|
||||
if (display != defaultDisplayType)
|
||||
os << "\tdisplay "
|
||||
@ -297,6 +303,12 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -270,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);
|
||||
}
|
||||
|
||||
|
||||
@ -283,6 +283,13 @@ 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()
|
||||
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());
|
||||
}
|
||||
|
||||
@ -1016,7 +1023,7 @@ InsetGraphicsMailer::params2string(InsetGraphicsParams const & params,
|
||||
{
|
||||
ostringstream data;
|
||||
data << name_ << ' ';
|
||||
params.Write(data, buffer.filePath());
|
||||
params.Write(data, buffer);
|
||||
data << "\\end_inset\n";
|
||||
return data.str();
|
||||
}
|
||||
|
@ -17,6 +17,8 @@
|
||||
#include "LyX.h" // for use_gui
|
||||
#include "Lexer.h"
|
||||
#include "LyXRC.h"
|
||||
#include "Buffer.h"
|
||||
#include "EmbeddedFiles.h"
|
||||
|
||||
#include "graphics/GraphicsParams.h"
|
||||
|
||||
@ -32,6 +34,7 @@ namespace lyx {
|
||||
using support::float_equal;
|
||||
using support::readBB_from_PSFile;
|
||||
using support::token;
|
||||
using support::DocFileName;
|
||||
|
||||
using std::string;
|
||||
using std::ostream;
|
||||
@ -148,12 +151,18 @@ bool operator!=(InsetGraphicsParams const & left,
|
||||
}
|
||||
|
||||
|
||||
void InsetGraphicsParams::Write(ostream & os, string const & bufpath) const
|
||||
void InsetGraphicsParams::Write(ostream & os, Buffer const & buffer) const
|
||||
{
|
||||
// Do not write the default values
|
||||
|
||||
if (!filename.empty()) {
|
||||
os << "\tfilename " << filename.outputFilename(bufpath) << '\n';
|
||||
// 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';
|
||||
}
|
||||
if (lyxscale != 100)
|
||||
os << "\tlyxscale " << lyxscale << '\n';
|
||||
|
@ -23,6 +23,7 @@ namespace lyx {
|
||||
namespace graphics { class Params; }
|
||||
|
||||
class Lexer;
|
||||
class Buffer;
|
||||
|
||||
|
||||
/// This class holds all the parameters needed by insetGraphics.
|
||||
@ -73,7 +74,8 @@ public:
|
||||
///
|
||||
InsetGraphicsParams & operator=(InsetGraphicsParams const &);
|
||||
/// Save the parameters in the LyX format stream.
|
||||
void Write(std::ostream & os, std::string const & bufpath) const;
|
||||
/// Buffer is needed to figure out if a figure is embedded.
|
||||
void Write(std::ostream & os, Buffer const & buf) const;
|
||||
/// If the token belongs to our parameters, read it.
|
||||
bool Read(Lexer & lex, std::string const & token, std::string const & bufpath);
|
||||
/// convert
|
||||
|
Loading…
Reference in New Issue
Block a user