mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Complete the removal of the embedding stuff. Maybe. It's hard to be sure we got everything, but this does compile, and it seems to work at least reasonably well. Any problems should of course be reported to the list.
For the record, this developer is sorry that the problems with this code were not noticed much earlier. It's not fun to do so much work and then have it all reverted. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24373 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
b749e175c6
commit
8a69ffd3bf
@ -25,7 +25,6 @@
|
||||
#include "Converter.h"
|
||||
#include "Counters.h"
|
||||
#include "DocIterator.h"
|
||||
#include "EmbeddedFiles.h"
|
||||
#include "Encoding.h"
|
||||
#include "ErrorList.h"
|
||||
#include "Exporter.h"
|
||||
@ -191,9 +190,6 @@ public:
|
||||
/// Container for all sort of Buffer dependant errors.
|
||||
map<string, ErrorList> errorLists;
|
||||
|
||||
/// all embedded files of this buffer
|
||||
EmbeddedFileList embedded_files;
|
||||
|
||||
/// timestamp and checksum used to test if the file has been externally
|
||||
/// modified. (Used to properly enable 'File->Revert to saved', bug 4114).
|
||||
time_t timestamp_;
|
||||
@ -239,8 +235,7 @@ Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_)
|
||||
: parent_buffer(0), lyx_clean(true), bak_clean(true), unnamed(false),
|
||||
read_only(readonly_), filename(file), file_fully_loaded(false),
|
||||
toc_backend(&parent), macro_lock(false),
|
||||
embedded_files(), timestamp_(0), checksum_(0), wa_(0),
|
||||
undo_(parent)
|
||||
timestamp_(0), checksum_(0), wa_(0), undo_(parent)
|
||||
{
|
||||
temppath = createBufferTmpDir();
|
||||
lyxvc.setBuffer(&parent);
|
||||
@ -367,24 +362,6 @@ TocBackend & Buffer::tocBackend() const
|
||||
}
|
||||
|
||||
|
||||
EmbeddedFileList & Buffer::embeddedFiles()
|
||||
{
|
||||
return d->embedded_files;
|
||||
}
|
||||
|
||||
|
||||
EmbeddedFileList const & Buffer::embeddedFiles() const
|
||||
{
|
||||
return d->embedded_files;
|
||||
}
|
||||
|
||||
|
||||
bool Buffer::embedded() const
|
||||
{
|
||||
return params().embedded;
|
||||
}
|
||||
|
||||
|
||||
Undo & Buffer::undo()
|
||||
{
|
||||
return d->undo_;
|
||||
@ -503,8 +480,7 @@ int Buffer::readHeader(Lexer & lex)
|
||||
LYXERR(Debug::PARSER, "Handling document header token: `"
|
||||
<< token << '\'');
|
||||
|
||||
string unknown = params().readToken(lex, token, d->filename.onlyPath(),
|
||||
d->temppath);
|
||||
string unknown = params().readToken(lex, token, d->filename.onlyPath());
|
||||
if (!unknown.empty()) {
|
||||
if (unknown[0] != '\\' && token == "\\textclass") {
|
||||
Alert::warning(_("Unknown document class"),
|
||||
@ -575,22 +551,6 @@ bool Buffer::readDocument(Lexer & lex)
|
||||
// read main text
|
||||
bool const res = text().read(*this, lex, errorList, &(d->inset));
|
||||
|
||||
// Enable embeded files, which will set temp path and move
|
||||
// inconsistent inzip files if needed.
|
||||
try {
|
||||
embeddedFiles().validate(*this);
|
||||
embeddedFiles().enable(params().embedded, *this, false);
|
||||
} catch (ExceptionMessage const & message) {
|
||||
Alert::error(message.title_, message.details_);
|
||||
Alert::warning(_("Failed to read embedded files"),
|
||||
_("Due to most likely a bug, LyX failed to locate all embedded "
|
||||
"file. If you unzip the LyX file, you should be able to see and "
|
||||
"open content.lyx which is your main text. You may also be able "
|
||||
"to recover some embedded files. Please report this bug to the "
|
||||
"lyx-devel mailing list."));
|
||||
return false;
|
||||
}
|
||||
|
||||
updateMacros();
|
||||
updateMacroInstances();
|
||||
return res;
|
||||
@ -688,20 +648,7 @@ bool Buffer::readFile(FileName const & filename)
|
||||
// decompress to a temp directory
|
||||
LYXERR(Debug::FILES, filename << " is in zip format. Unzip to " << temppath());
|
||||
::unzipToDir(filename.toFilesystemEncoding(), temppath());
|
||||
//
|
||||
FileName lyxfile(addName(temppath(), "content.lyx"));
|
||||
// if both manifest.txt and file.lyx exist, this is am embedded file
|
||||
if (lyxfile.exists()) {
|
||||
// if in bundled format, save checksum of the compressed file, not content.lyx
|
||||
saveCheckSum(filename);
|
||||
params().embedded = true;
|
||||
fname = lyxfile;
|
||||
}
|
||||
}
|
||||
// The embedded lyx file can also be compressed, for backward compatibility
|
||||
format = fname.guessFormatFromContents();
|
||||
if (format == "gzip" || format == "zip" || format == "compress")
|
||||
params().compressed = true;
|
||||
|
||||
// remove dummy empty par
|
||||
paragraphs().clear();
|
||||
@ -888,22 +835,15 @@ bool Buffer::writeFile(FileName const & fname) const
|
||||
|
||||
bool retval = false;
|
||||
|
||||
FileName content;
|
||||
if (params().embedded)
|
||||
// first write the .lyx file to the temporary directory
|
||||
content = FileName(addName(temppath(), "content.lyx"));
|
||||
else
|
||||
content = fname;
|
||||
|
||||
docstring const str = bformat(_("Saving document %1$s..."),
|
||||
makeDisplayPath(content.absFilename()));
|
||||
makeDisplayPath(fname.absFilename()));
|
||||
message(str);
|
||||
|
||||
if (params().compressed) {
|
||||
gz::ogzstream ofs(content.toFilesystemEncoding().c_str(), ios::out|ios::trunc);
|
||||
gz::ogzstream ofs(fname.toFilesystemEncoding().c_str(), ios::out|ios::trunc);
|
||||
retval = ofs && write(ofs);
|
||||
} else {
|
||||
ofstream ofs(content.toFilesystemEncoding().c_str(), ios::out|ios::trunc);
|
||||
ofstream ofs(fname.toFilesystemEncoding().c_str(), ios::out|ios::trunc);
|
||||
retval = ofs && write(ofs);
|
||||
}
|
||||
|
||||
@ -914,15 +854,6 @@ bool Buffer::writeFile(FileName const & fname) const
|
||||
|
||||
removeAutosaveFile(d->filename.absFilename());
|
||||
|
||||
if (params().embedded) {
|
||||
message(str + _(" writing embedded files."));
|
||||
// if embedding is enabled, write file.lyx and all the embedded files
|
||||
// to the zip file fname.
|
||||
if (!d->embedded_files.writeFile(fname, *this)) {
|
||||
message(str + _(" could not write embedded files!"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
saveCheckSum(d->filename);
|
||||
message(str + _(" done."));
|
||||
|
||||
@ -2597,4 +2528,5 @@ void Buffer::bufferErrors(TeXErrors const & terr, ErrorList & errorList) const
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace lyx
|
||||
|
11
src/Buffer.h
11
src/Buffer.h
@ -14,6 +14,7 @@
|
||||
|
||||
#include "insets/InsetCode.h"
|
||||
|
||||
#include "support/FileNameList.h"
|
||||
#include "support/strfwd.h"
|
||||
#include "support/types.h"
|
||||
#include "support/SignalSlot.h"
|
||||
@ -25,7 +26,6 @@
|
||||
namespace lyx {
|
||||
|
||||
class BufferParams;
|
||||
class EmbeddedFileList;
|
||||
class DocIterator;
|
||||
class ErrorItem;
|
||||
class ErrorList;
|
||||
@ -404,15 +404,10 @@ public:
|
||||
/// method is const because modifying this backend does not touch
|
||||
/// the document contents.
|
||||
TocBackend & tocBackend() const;
|
||||
|
||||
//@{
|
||||
EmbeddedFileList & embeddedFiles();
|
||||
EmbeddedFileList const & embeddedFiles() const;
|
||||
bool embedded() const;
|
||||
//@}
|
||||
|
||||
///
|
||||
Undo & undo();
|
||||
|
||||
|
||||
/// This function is called when the buffer is changed.
|
||||
void changed() const;
|
||||
/// This function is called when the buffer structure is changed.
|
||||
|
@ -277,7 +277,6 @@ public:
|
||||
|
||||
AuthorList authorlist;
|
||||
BranchList branchlist;
|
||||
vector<string> extraEmbeddedFiles;
|
||||
Bullet temp_bullets[4];
|
||||
Bullet user_defined_bullets[4];
|
||||
Spacing spacing;
|
||||
@ -351,7 +350,6 @@ BufferParams::BufferParams()
|
||||
listings_params = string();
|
||||
pagestyle = "default";
|
||||
compressed = false;
|
||||
embedded = lyxrc.use_bundled_format;
|
||||
for (int iter = 0; iter < 4; ++iter) {
|
||||
user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
|
||||
temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
|
||||
@ -378,18 +376,6 @@ AuthorList const & BufferParams::authors() const
|
||||
}
|
||||
|
||||
|
||||
vector<string> & BufferParams::extraEmbeddedFiles()
|
||||
{
|
||||
return pimpl_->extraEmbeddedFiles;
|
||||
}
|
||||
|
||||
|
||||
vector<string> const & BufferParams::extraEmbeddedFiles() const
|
||||
{
|
||||
return pimpl_->extraEmbeddedFiles;
|
||||
}
|
||||
|
||||
|
||||
BranchList & BufferParams::branchlist()
|
||||
{
|
||||
return pimpl_->branchlist;
|
||||
@ -467,7 +453,7 @@ void BufferParams::setDefSkip(VSpace const & vs)
|
||||
|
||||
|
||||
string BufferParams::readToken(Lexer & lex, string const & token,
|
||||
FileName const & filepath, FileName const & temppath)
|
||||
FileName const & filepath)
|
||||
{
|
||||
if (token == "\\textclass") {
|
||||
lex.next();
|
||||
@ -476,8 +462,6 @@ string BufferParams::readToken(Lexer & lex, string const & token,
|
||||
// NOTE: in this case, the textclass (.cls file) is assumed to be available.
|
||||
string tcp;
|
||||
LayoutFileList & bcl = LayoutFileList::get();
|
||||
if (!temppath.empty())
|
||||
tcp = bcl.addLayoutFile(classname, temppath.absFilename(), LayoutFileList::Embedded);
|
||||
if (tcp.empty() && !filepath.empty())
|
||||
tcp = bcl.addLayoutFile(classname, filepath.absFilename(), LayoutFileList::Local);
|
||||
if (!tcp.empty())
|
||||
@ -673,16 +657,6 @@ string BufferParams::readToken(Lexer & lex, string const & token,
|
||||
toktmp << endl;
|
||||
return toktmp;
|
||||
}
|
||||
} else if (token == "\\extra_embedded_files") {
|
||||
extraEmbeddedFiles().clear();
|
||||
string par;
|
||||
lex >> par;
|
||||
string tmp;
|
||||
par = split(par, tmp, ',');
|
||||
while (!tmp.empty()) {
|
||||
extraEmbeddedFiles().push_back(tmp);
|
||||
par = split(par, tmp, ',');
|
||||
}
|
||||
} else {
|
||||
lyxerr << "BufferParams::readToken(): Unknown token: " <<
|
||||
token << endl;
|
||||
|
@ -67,8 +67,7 @@ public:
|
||||
/// read a header token, if unrecognised, return it or an unknown class name
|
||||
std::string readToken(Lexer & lex,
|
||||
std::string const & token, ///< token to read.
|
||||
support::FileName const & filepath,
|
||||
support::FileName const & temppath); ///< where to look for local layout file.
|
||||
support::FileName const & filepath);
|
||||
|
||||
///
|
||||
void writeFile(std::ostream &) const;
|
||||
@ -266,11 +265,6 @@ public:
|
||||
bool outputChanges;
|
||||
///
|
||||
bool compressed;
|
||||
///
|
||||
bool embedded;
|
||||
///
|
||||
std::vector<std::string> & extraEmbeddedFiles();
|
||||
std::vector<std::string> const & extraEmbeddedFiles() const;
|
||||
|
||||
/// the author list for the document
|
||||
AuthorList & authors();
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include "Cursor.h"
|
||||
#include "CutAndPaste.h"
|
||||
#include "DispatchResult.h"
|
||||
#include "EmbeddedFiles.h"
|
||||
#include "ErrorList.h"
|
||||
#include "factory.h"
|
||||
#include "FloatList.h"
|
||||
@ -943,11 +942,6 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
|
||||
break;
|
||||
}
|
||||
|
||||
case LFUN_BUFFER_TOGGLE_EMBEDDING: {
|
||||
flag.setOnOff(buffer_.params().embedded);
|
||||
break;
|
||||
}
|
||||
|
||||
case LFUN_SCREEN_UP:
|
||||
case LFUN_SCREEN_DOWN:
|
||||
case LFUN_SCROLL:
|
||||
@ -1311,16 +1305,6 @@ bool BufferView::dispatch(FuncRequest const & cmd)
|
||||
buffer_.params().compressed = !buffer_.params().compressed;
|
||||
break;
|
||||
|
||||
case LFUN_BUFFER_TOGGLE_EMBEDDING: {
|
||||
// turn embedding on/off
|
||||
try {
|
||||
buffer_.embeddedFiles().enable(!buffer_.params().embedded, buffer_, true);
|
||||
} catch (ExceptionMessage const & message) {
|
||||
Alert::error(message.title_, message.details_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case LFUN_NEXT_INSET_TOGGLE: {
|
||||
// this is the real function we want to invoke
|
||||
FuncRequest tmpcmd = FuncRequest(LFUN_INSET_TOGGLE, cmd.origin);
|
||||
|
@ -496,8 +496,8 @@ bool Converters::move(string const & fmt,
|
||||
string const to_base = removeExtension(to.absFilename());
|
||||
string const to_extension = getExtension(to.absFilename());
|
||||
|
||||
FileNameList const files = FileName(path).dirList(getExtension(from.absFilename()));
|
||||
for (FileNameList::const_iterator it = files.begin();
|
||||
support::FileNameList const files = FileName(path).dirList(getExtension(from.absFilename()));
|
||||
for (support::FileNameList::const_iterator it = files.begin();
|
||||
it != files.end(); ++it) {
|
||||
string const from2 = it->absFilename();
|
||||
string const file2 = onlyFilename(from2);
|
||||
|
@ -861,7 +861,7 @@ void pasteClipboardGraphics(Cursor & cur, ErrorList & /* errorList */,
|
||||
// create inset for graphic
|
||||
InsetGraphics * inset = new InsetGraphics(cur.buffer());
|
||||
InsetGraphicsParams params;
|
||||
params.filename = EmbeddedFile(filename.absFilename(), cur.buffer().filePath());
|
||||
params.filename = support::DocFileName(filename.absFilename());
|
||||
inset->setParams(params);
|
||||
cur.recordUndo();
|
||||
cur.insert(inset);
|
||||
|
@ -1,645 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file EmbeddedFileList.cpp
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Bo Peng
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "EmbeddedFiles.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "BufferParams.h"
|
||||
#include "ErrorList.h"
|
||||
#include "Format.h"
|
||||
#include "InsetIterator.h"
|
||||
#include "Lexer.h"
|
||||
#include "LyX.h"
|
||||
#include "Paragraph.h"
|
||||
#include "Session.h"
|
||||
|
||||
#include "frontends/alert.h"
|
||||
|
||||
#include "support/debug.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/gettext.h"
|
||||
#include "support/convert.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/ExceptionMessage.h"
|
||||
#include "support/FileZipListDir.h"
|
||||
|
||||
#include "support/assert.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <utility>
|
||||
|
||||
using namespace std;
|
||||
using namespace lyx::support;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
namespace Alert = frontend::Alert;
|
||||
|
||||
EmbeddedFile::EmbeddedFile(string const & file, std::string const & buffer_path)
|
||||
: DocFileName("", false), embedded_(false), inset_list_()
|
||||
{
|
||||
set(file, buffer_path);
|
||||
}
|
||||
|
||||
|
||||
void EmbeddedFile::set(std::string const & filename, std::string const & buffer_path)
|
||||
{
|
||||
DocFileName::set(filename, buffer_path);
|
||||
if (filename.empty())
|
||||
return;
|
||||
|
||||
if (!buffer_path.empty())
|
||||
inzip_name_ = calcInzipName(buffer_path);
|
||||
}
|
||||
|
||||
|
||||
void EmbeddedFile::setInzipName(std::string const & name)
|
||||
{
|
||||
if (name.empty() || name == inzip_name_)
|
||||
return;
|
||||
|
||||
// an enabled EmbeededFile should have this problem handled
|
||||
LASSERT(!isEnabled(), /**/);
|
||||
// file will be synced when it is enabled
|
||||
inzip_name_ = name;
|
||||
}
|
||||
|
||||
|
||||
string EmbeddedFile::embeddedFile() const
|
||||
{
|
||||
LASSERT(isEnabled(), /**/);
|
||||
return temp_path_ + inzip_name_;
|
||||
}
|
||||
|
||||
|
||||
FileName EmbeddedFile::availableFile() const
|
||||
{
|
||||
if (isEnabled() && embedded())
|
||||
return FileName(embeddedFile());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
string EmbeddedFile::latexFilename(std::string const & buffer_path) const
|
||||
{
|
||||
return (isEnabled() && embedded()) ? inzip_name_ : relFilename(buffer_path);
|
||||
}
|
||||
|
||||
|
||||
void EmbeddedFile::addInset(Inset const * inset)
|
||||
{
|
||||
if (inset)
|
||||
inset_list_.push_back(inset);
|
||||
}
|
||||
|
||||
|
||||
void EmbeddedFile::setEmbed(bool embed)
|
||||
{
|
||||
embedded_ = embed;
|
||||
}
|
||||
|
||||
|
||||
void EmbeddedFile::enable(bool enabled, Buffer const & buf, bool updateFile)
|
||||
{
|
||||
// This function will be called when
|
||||
// 1. through EmbeddedFiles::enable() when a file is read. Files
|
||||
// should be in place so no updateFromExternalFile or extract()
|
||||
// should be called. (updateFile should be false in this case).
|
||||
// 2. through menu item enable/disable. updateFile should be true.
|
||||
// 3. A single embedded file is added or modified. updateFile
|
||||
// can be true or false.
|
||||
LYXERR(Debug::FILES, (enabled ? "Enable" : "Disable")
|
||||
<< " " << absFilename()
|
||||
<< (updateFile ? " (update file)." : " (no update)."));
|
||||
|
||||
if (enabled) {
|
||||
temp_path_ = buf.temppath();
|
||||
if (!suffixIs(temp_path_, '/'))
|
||||
temp_path_ += '/';
|
||||
if (embedded() && updateFile)
|
||||
updateFromExternalFile();
|
||||
} else {
|
||||
// when a new embeddeed file is created, it is not enabled, and
|
||||
// there is no need to extract.
|
||||
if (isEnabled() && embedded() && updateFile)
|
||||
extract();
|
||||
temp_path_ = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool EmbeddedFile::extract() const
|
||||
{
|
||||
LASSERT(isEnabled(), /**/);
|
||||
|
||||
string ext_file = absFilename();
|
||||
string emb_file = embeddedFile();
|
||||
|
||||
FileName emb(emb_file);
|
||||
FileName ext(ext_file);
|
||||
|
||||
if (!emb.exists()) {
|
||||
if (ext.exists())
|
||||
return true;
|
||||
throw ExceptionMessage(ErrorException, _("Failed to extract file"),
|
||||
bformat(_("Cannot extract file '%1$s'.\n"
|
||||
"Source file %2$s does not exist"),
|
||||
from_utf8(outputFilename()), from_utf8(emb_file)));
|
||||
}
|
||||
|
||||
// if external file already exists ...
|
||||
if (ext.exists()) {
|
||||
// no need to copy if the files are the same
|
||||
if (checksum() == FileName(emb_file).checksum())
|
||||
return true;
|
||||
// otherwise, ask if overwrite
|
||||
int ret = Alert::prompt(
|
||||
_("Overwrite external file?"),
|
||||
bformat(_("External file %1$s already exists, do you want to overwrite it?"),
|
||||
from_utf8(ext_file)), 1, 1, _("&Overwrite"), _("&Cancel"));
|
||||
if (ret != 0)
|
||||
// if the user does not want to overwrite, we still consider it
|
||||
// a successful operation.
|
||||
return true;
|
||||
}
|
||||
// copy file
|
||||
|
||||
// need to make directory?
|
||||
FileName path = ext.onlyPath();
|
||||
if (!path.createPath()) {
|
||||
throw ExceptionMessage(ErrorException, _("Copy file failure"),
|
||||
bformat(_("Cannot create file path '%1$s'.\n"
|
||||
"Please check whether the path is writeable."),
|
||||
from_utf8(path.absFilename())));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (emb.copyTo(ext)) {
|
||||
LYXERR(Debug::FILES, "Extract file " << emb_file << " to " << ext_file << endl);
|
||||
return true;
|
||||
}
|
||||
|
||||
throw ExceptionMessage(ErrorException, _("Copy file failure"),
|
||||
bformat(_("Cannot copy file %1$s to %2$s.\n"
|
||||
"Please check whether the directory exists and is writeable."),
|
||||
from_utf8(emb_file), from_utf8(ext_file)));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool EmbeddedFile::updateFromExternalFile() const
|
||||
{
|
||||
LASSERT(isEnabled(), /**/);
|
||||
|
||||
string ext_file = absFilename();
|
||||
string emb_file = embeddedFile();
|
||||
|
||||
FileName emb(emb_file);
|
||||
FileName ext(ext_file);
|
||||
|
||||
if (!ext.exists()) {
|
||||
// no need to update
|
||||
if (emb.exists())
|
||||
return true;
|
||||
// no external and internal file
|
||||
throw ExceptionMessage(ErrorException,
|
||||
_("Failed to embed file"),
|
||||
bformat(_("Failed to embed file %1$s.\n"
|
||||
"Please check whether this file exists and is readable."),
|
||||
from_utf8(ext_file)));
|
||||
}
|
||||
|
||||
// if embedded file already exists ...
|
||||
if (emb.exists()) {
|
||||
// no need to copy if the files are the same
|
||||
if (checksum() == FileName(emb_file).checksum())
|
||||
return true;
|
||||
// other wise, ask if overwrite
|
||||
int const ret = Alert::prompt(
|
||||
_("Update embedded file?"),
|
||||
bformat(_("Embedded file %1$s already exists, do you want to overwrite it"),
|
||||
from_utf8(ext_file)), 1, 1, _("&Overwrite"), _("&Cancel"));
|
||||
if (ret != 0)
|
||||
// if the user does not want to overwrite, we still consider it
|
||||
// a successful operation.
|
||||
return true;
|
||||
}
|
||||
// copy file
|
||||
// need to make directory?
|
||||
FileName path = emb.onlyPath();
|
||||
if (!path.isDirectory())
|
||||
path.createPath();
|
||||
if (ext.copyTo(emb))
|
||||
return true;
|
||||
throw ExceptionMessage(ErrorException,
|
||||
_("Copy file failure"),
|
||||
bformat(_("Cannot copy file %1$s to %2$s.\n"
|
||||
"Please check whether the directory exists and is writeable."),
|
||||
from_utf8(ext_file), from_utf8(emb_file)));
|
||||
//LYXERR(Debug::DEBUG, "Fs error: " << fe.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
EmbeddedFile EmbeddedFile::copyTo(Buffer const & buf)
|
||||
{
|
||||
EmbeddedFile file = EmbeddedFile(absFilename(), buf.filePath());
|
||||
file.setEmbed(embedded());
|
||||
file.enable(buf.embedded(), buf, false);
|
||||
|
||||
// use external file.
|
||||
if (!embedded())
|
||||
return file;
|
||||
|
||||
LYXERR(Debug::FILES, "Copy " << availableFile()
|
||||
<< " to " << file.availableFile());
|
||||
|
||||
FileName from_file = availableFile();
|
||||
FileName to_file = file.availableFile();
|
||||
|
||||
if (!from_file.exists()) {
|
||||
// no from file
|
||||
throw ExceptionMessage(ErrorException,
|
||||
_("Failed to copy embedded file"),
|
||||
bformat(_("Failed to embed file %1$s.\n"
|
||||
"Please check whether the source file is available"),
|
||||
from_utf8(absFilename())));
|
||||
file.setEmbed(false);
|
||||
return file;
|
||||
}
|
||||
|
||||
// if destination file already exists ...
|
||||
if (to_file.exists()) {
|
||||
// no need to copy if the files are the same
|
||||
if (checksum() == to_file.checksum())
|
||||
return file;
|
||||
// other wise, ask if overwrite
|
||||
int const ret = Alert::prompt(
|
||||
_("Update embedded file?"),
|
||||
bformat(_("Embedded file %1$s already exists, do you want to overwrite it"),
|
||||
from_utf8(to_file.absFilename())), 1, 1, _("&Overwrite"), _("&Cancel"));
|
||||
if (ret != 0)
|
||||
// if the user does not want to overwrite, we still consider it
|
||||
// a successful operation.
|
||||
return file;
|
||||
}
|
||||
// copy file
|
||||
// need to make directory?
|
||||
FileName path = to_file.onlyPath();
|
||||
if (!path.isDirectory())
|
||||
path.createPath();
|
||||
if (from_file.copyTo(to_file))
|
||||
return file;
|
||||
throw ExceptionMessage(ErrorException,
|
||||
_("Copy file failure"),
|
||||
bformat(_("Cannot copy file %1$s to %2$s.\n"
|
||||
"Please check whether the directory exists and is writeable."),
|
||||
from_utf8(from_file.absFilename()), from_utf8(to_file.absFilename())));
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
void EmbeddedFile::updateInsets() const
|
||||
{
|
||||
vector<Inset const *>::const_iterator it = inset_list_.begin();
|
||||
vector<Inset const *>::const_iterator it_end = inset_list_.end();
|
||||
for (; it != it_end; ++it)
|
||||
const_cast<Inset *>(*it)->updateEmbeddedFile(*this);
|
||||
}
|
||||
|
||||
|
||||
bool EmbeddedFile::isReadableFile() const
|
||||
{
|
||||
return availableFile().isReadableFile();
|
||||
}
|
||||
|
||||
|
||||
unsigned long EmbeddedFile::checksum() const
|
||||
{
|
||||
return availableFile().checksum();
|
||||
}
|
||||
|
||||
/**
|
||||
Under the lyx temp directory, content.lyx and its embedded files are usually
|
||||
saved as
|
||||
|
||||
$temp/$embDirName/file.lyx
|
||||
$temp/$embDirName/figure1.png for ./figure1.png)
|
||||
$temp/$embDirName/sub/figure2.png for ./sub/figure2.png)
|
||||
|
||||
This works fine for embedded files that are in the current or deeper directory
|
||||
of the document directory, but not for files such as ../figures/figure.png.
|
||||
A unique name $upDirName is chosen to represent .. in such filenames so that
|
||||
'up' directories can be stored 'down' the directory tree:
|
||||
|
||||
$temp/$embDirName/$upDirName/figures/figure.png for ../figures/figure.png
|
||||
$temp/$embDirName/$upDirName/$upDirName/figure.png for ../../figure.png
|
||||
|
||||
This name has to be fixed because it is used in lyx bundled .zip file.
|
||||
|
||||
Using a similar trick, we use $absDirName for absolute path so that
|
||||
an absolute filename can be saved as
|
||||
|
||||
$temp/$embDirName/$absDirName/a/absolute/path for /a/absolute/path
|
||||
|
||||
FIXME:
|
||||
embDirName is set to . so that embedded layout and class files can be
|
||||
used directly. However, putting all embedded files directly under
|
||||
the temp directory may lead to file conflicts. For example, if a user
|
||||
embeds a file blah.log in blah.lyx, it will be replaced when
|
||||
'latex blah.tex' is called.
|
||||
*/
|
||||
const std::string embDirName = ".";
|
||||
const std::string upDirName = "LyX.Embed.Dir.Up";
|
||||
const std::string absDirName = "LyX.Embed.Dir.Abs";
|
||||
const std::string driveName = "LyX.Embed.Drive";
|
||||
const std::string spaceName = "LyX.Embed.Space";
|
||||
|
||||
std::string EmbeddedFile::calcInzipName(std::string const & buffer_path)
|
||||
{
|
||||
string inzipName = to_utf8(makeRelPath(from_utf8(absFilename()),
|
||||
from_utf8(buffer_path)));
|
||||
|
||||
if (FileName(inzipName).isAbsolute())
|
||||
inzipName = absDirName + '/' + inzipName;
|
||||
|
||||
// replace .. by upDirName
|
||||
if (prefixIs(inzipName, "."))
|
||||
inzipName = subst(inzipName, "..", upDirName);
|
||||
// replace special characters by their value
|
||||
inzipName = subst(inzipName, ":", driveName);
|
||||
inzipName = subst(inzipName, " ", spaceName);
|
||||
|
||||
// to avoid name conflict between $docu_path/file and $temp_path/file
|
||||
// embedded files are in a subdirectory of $temp_path.
|
||||
inzipName = embDirName + '/' + inzipName;
|
||||
return inzipName;
|
||||
}
|
||||
|
||||
|
||||
void EmbeddedFile::syncInzipFile(std::string const & buffer_path)
|
||||
{
|
||||
LASSERT(isEnabled(), /**/);
|
||||
string old_emb_file = temp_path_ + '/' + inzip_name_;
|
||||
FileName old_emb(old_emb_file);
|
||||
|
||||
if (!old_emb.exists())
|
||||
throw ExceptionMessage(ErrorException, _("Failed to open file"),
|
||||
bformat(_("Embedded file %1$s does not exist. Did you tamper lyx temporary directory?"),
|
||||
old_emb.displayName()));
|
||||
|
||||
string new_inzip_name = calcInzipName(buffer_path);
|
||||
if (new_inzip_name == inzip_name_)
|
||||
return;
|
||||
|
||||
LYXERR(Debug::FILES, " OLD ZIP " << old_emb_file <<
|
||||
" NEW ZIP " << calcInzipName(buffer_path));
|
||||
|
||||
string new_emb_file = temp_path_ + '/' + new_inzip_name;
|
||||
FileName new_emb(new_emb_file);
|
||||
|
||||
// need to make directory?
|
||||
FileName path = new_emb.onlyPath();
|
||||
if (!path.createPath()) {
|
||||
throw ExceptionMessage(ErrorException, _("Sync file failure"),
|
||||
bformat(_("Cannot create file path '%1$s'.\n"
|
||||
"Please check whether the path is writeable."),
|
||||
from_utf8(path.absFilename())));
|
||||
return;
|
||||
}
|
||||
|
||||
if (old_emb.copyTo(new_emb)) {
|
||||
LYXERR(Debug::FILES, "Sync inzip file from " << inzip_name_
|
||||
<< " to " << new_inzip_name);
|
||||
inzip_name_ = new_inzip_name;
|
||||
return;
|
||||
}
|
||||
throw ExceptionMessage(ErrorException, _("Sync file failure"),
|
||||
bformat(_("Cannot copy file %1$s to %2$s.\n"
|
||||
"Please check whether the directory exists and is writeable."),
|
||||
from_utf8(old_emb_file), from_utf8(new_emb_file)));
|
||||
}
|
||||
|
||||
|
||||
bool operator==(EmbeddedFile const & lhs, EmbeddedFile const & rhs)
|
||||
{
|
||||
return lhs.absFilename() == rhs.absFilename()
|
||||
&& lhs.saveAbsPath() == rhs.saveAbsPath()
|
||||
&& lhs.embedded() == rhs.embedded();
|
||||
}
|
||||
|
||||
|
||||
bool operator!=(EmbeddedFile const & lhs, EmbeddedFile const & rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
|
||||
void EmbeddedFileList::enable(bool enabled, Buffer & buffer, bool updateFile)
|
||||
{
|
||||
// update embedded file list
|
||||
update(buffer);
|
||||
|
||||
int count_embedded = 0;
|
||||
int count_external = 0;
|
||||
iterator it = begin();
|
||||
iterator it_end = end();
|
||||
// an exception may be thrown
|
||||
for (; it != it_end; ++it) {
|
||||
it->enable(enabled, buffer, updateFile);
|
||||
if (it->embedded())
|
||||
++count_embedded;
|
||||
else
|
||||
++count_external;
|
||||
}
|
||||
// if operation is successful (no exception is thrown)
|
||||
buffer.params().embedded = enabled;
|
||||
|
||||
// if the operation is successful, update insets
|
||||
for (it = begin(); it != it_end; ++it)
|
||||
it->updateInsets();
|
||||
|
||||
if (!updateFile || (count_external == 0 && count_embedded == 0))
|
||||
return;
|
||||
|
||||
// show result
|
||||
if (enabled) {
|
||||
docstring const msg = bformat(_("%1$d external files are ignored.\n"
|
||||
"%2$d embeddable files are embedded.\n"), count_external, count_embedded);
|
||||
Alert::information(_("Packing all files"), msg);
|
||||
} else {
|
||||
docstring const msg = bformat(_("%1$d external files are ignored.\n"
|
||||
"%2$d embedded files are extracted.\n"), count_external, count_embedded);
|
||||
Alert::information(_("Unpacking all files"), msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void EmbeddedFileList::registerFile(EmbeddedFile const & file,
|
||||
Inset const * inset, Buffer const & buffer)
|
||||
{
|
||||
LASSERT(!buffer.embedded() || file.isEnabled(), /**/);
|
||||
|
||||
string newfile = file.absFilename();
|
||||
iterator efp = findFile(newfile);
|
||||
if (efp != end()) {
|
||||
if (efp->embedded() != file.embedded()) {
|
||||
Alert::error(_("Wrong embedding status."),
|
||||
bformat(_("File %1$s is included in more than one insets, "
|
||||
"but with different embedding status. Assuming embedding status."),
|
||||
from_utf8(efp->outputFilename())));
|
||||
efp->setEmbed(true);
|
||||
// update the inset with this embedding status.
|
||||
const_cast<Inset*>(inset)->updateEmbeddedFile(*efp);
|
||||
}
|
||||
efp->addInset(inset);
|
||||
return;
|
||||
}
|
||||
file.clearInsets();
|
||||
push_back(file);
|
||||
back().addInset(inset);
|
||||
}
|
||||
|
||||
|
||||
EmbeddedFileList::const_iterator
|
||||
EmbeddedFileList::findFile(std::string const & filename) const
|
||||
{
|
||||
// try to find this file from the list
|
||||
std::vector<EmbeddedFile>::const_iterator it = begin();
|
||||
std::vector<EmbeddedFile>::const_iterator it_end = end();
|
||||
for (; it != it_end; ++it)
|
||||
if (it->absFilename() == filename)
|
||||
return it;
|
||||
return end();
|
||||
}
|
||||
|
||||
|
||||
EmbeddedFileList::iterator
|
||||
EmbeddedFileList::findFile(std::string const & filename)
|
||||
{
|
||||
// try to find this file from the list
|
||||
std::vector<EmbeddedFile>::iterator it = begin();
|
||||
std::vector<EmbeddedFile>::iterator it_end = end();
|
||||
for (; it != it_end; ++it)
|
||||
if (it->absFilename() == filename)
|
||||
return it;
|
||||
return end();
|
||||
}
|
||||
|
||||
|
||||
void EmbeddedFileList::validate(Buffer const & buffer)
|
||||
{
|
||||
clear();
|
||||
|
||||
for (InsetIterator it = inset_iterator_begin(buffer.inset()); it; ++it)
|
||||
it->registerEmbeddedFiles(*this);
|
||||
|
||||
iterator it = begin();
|
||||
iterator it_end = end();
|
||||
for (; it != it_end; ++it) {
|
||||
if (buffer.embedded() && it->embedded())
|
||||
// An exception will be raised if inzip file does not exist
|
||||
it->syncInzipFile(buffer.filePath());
|
||||
else
|
||||
// inzipName may be OS dependent
|
||||
it->setInzipName(it->calcInzipName(buffer.filePath()));
|
||||
}
|
||||
for (it = begin(); it != it_end; ++it)
|
||||
it->updateInsets();
|
||||
|
||||
if (!buffer.embedded())
|
||||
return;
|
||||
|
||||
// check if extra embedded files exist
|
||||
vector<string> extra = buffer.params().extraEmbeddedFiles();
|
||||
vector<string>::iterator e_it = extra.begin();
|
||||
vector<string>::iterator e_end = extra.end();
|
||||
for (; e_it != e_end; ++e_it) {
|
||||
EmbeddedFile file = EmbeddedFile(*e_it, buffer.filePath());
|
||||
// do not update from external file
|
||||
file.enable(true, buffer, false);
|
||||
// but we do need to check file existence.
|
||||
if (!FileName(file.embeddedFile()).exists())
|
||||
throw ExceptionMessage(ErrorException, _("Failed to open file"),
|
||||
bformat(_("Embedded file %1$s does not exist. Did you tamper lyx temporary directory?"),
|
||||
file.displayName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void EmbeddedFileList::update(Buffer const & buffer)
|
||||
{
|
||||
clear();
|
||||
|
||||
for (InsetIterator it = inset_iterator_begin(buffer.inset()); it; ++it)
|
||||
it->registerEmbeddedFiles(*this);
|
||||
|
||||
// add extra embedded files
|
||||
vector<string> extra = buffer.params().extraEmbeddedFiles();
|
||||
vector<string>::iterator it = extra.begin();
|
||||
vector<string>::iterator it_end = extra.end();
|
||||
for (; it != it_end; ++it) {
|
||||
EmbeddedFile file = EmbeddedFile(*it, buffer.filePath());
|
||||
file.setEmbed(true);
|
||||
file.enable(buffer.embedded(), buffer, false);
|
||||
insert(end(), file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool EmbeddedFileList::writeFile(DocFileName const & filename, Buffer const & buffer)
|
||||
{
|
||||
// file in the temporary path has the content
|
||||
string const content = FileName(addName(buffer.temppath(),
|
||||
"content.lyx")).toFilesystemEncoding();
|
||||
|
||||
vector<pair<string, string> > filenames;
|
||||
// add content.lyx to filenames
|
||||
filenames.push_back(make_pair(content, "content.lyx"));
|
||||
// prepare list of embedded file
|
||||
update(buffer);
|
||||
//
|
||||
iterator it = begin();
|
||||
iterator it_end = end();
|
||||
for (; it != it_end; ++it) {
|
||||
if (it->embedded()) {
|
||||
string file = it->embeddedFile();
|
||||
if (!FileName(file).exists())
|
||||
throw ExceptionMessage(ErrorException, _("Failed to write file"),
|
||||
bformat(_("Embedded file %1$s does not exist. Did you tamper lyx temporary directory?"),
|
||||
it->displayName()));
|
||||
filenames.push_back(make_pair(file, it->inzipName()));
|
||||
LYXERR(Debug::FILES, "Writing file " << it->outputFilename()
|
||||
<< " as " << it->inzipName() << endl);
|
||||
}
|
||||
}
|
||||
// write a zip file with all these files. Write to a temp file first, to
|
||||
// avoid messing up the original file in case something goes terribly wrong.
|
||||
DocFileName zipfile(addName(buffer.temppath(),
|
||||
onlyFilename(changeExtension(
|
||||
filename.toFilesystemEncoding(), ".zip"))));
|
||||
|
||||
::zipFiles(zipfile.toFilesystemEncoding(), filenames);
|
||||
// copy file back
|
||||
if (!zipfile.copyTo(filename)) {
|
||||
Alert::error(_("Save failure"),
|
||||
bformat(_("Cannot create file %1$s.\n"
|
||||
"Please check whether the directory exists and is writeable."),
|
||||
from_utf8(filename.absFilename())));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace lyx
|
@ -1,257 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file EmbeddedFiles.h
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Bo Peng
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef EMBEDDEDFILES_H
|
||||
#define EMBEDDEDFILES_H
|
||||
|
||||
#include "support/FileName.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
|
||||
This file, and the embed checkbox in dialogs of InsetGraphics etc, implements
|
||||
an 'Embedded Files' feature of lyx.
|
||||
|
||||
|
||||
Expected features:
|
||||
=========================
|
||||
|
||||
1. Bundled .lyx file can embed graphics, listings, bib file etc. The bundle
|
||||
format is used when Document->Save in bundled format is selected.
|
||||
|
||||
2. Embedded file.lyx file is a zip file, with content.lyx and embedded files.
|
||||
|
||||
3. The embedding status of embedded files are set from individual insets.
|
||||
|
||||
4. Extra files such as .cls and .layout can be embedded from Document->
|
||||
Settings->Embedded Files->Extra Embedded Files.
|
||||
|
||||
5. When Document->Save in bundled format is selected, all embedded files
|
||||
become bundled. Changes to the external version of this file does not
|
||||
affect the output of the .lyx file.
|
||||
|
||||
6. When Document->Save in bundled format is unchecked, all embedded files
|
||||
are copied to their original locations.
|
||||
|
||||
Overall, this feature allows two ways of editing a .lyx file
|
||||
|
||||
a. The continuous use of the pure-text .lyx file format with external
|
||||
files. This is the default file format, and allows external editing
|
||||
of .lyx file and better use of version control systems.
|
||||
|
||||
b. The embedded way. Figures etc are inserted to .lyx file and will
|
||||
be embedded. These embedded files can be viewed or edited through
|
||||
the embedding dialog. This file can be shared with others more
|
||||
easily.
|
||||
|
||||
Format a and b can be converted easily, by packing/unpacking a .lyx file.
|
||||
|
||||
Implementation:
|
||||
======================
|
||||
|
||||
1. An EmbeddedFiles class is implemented to keep the embedded files (
|
||||
class EmbeddedFile). (c.f. src/EmbeddedFiles.[h|cpp])
|
||||
|
||||
2. When a file is saved, it is scanned for embedded files. (c.f.
|
||||
EmbeddedFiles::update(), Inset::registerEmbeddedFiles()).
|
||||
|
||||
3. When a lyx file file.lyx is saved, it is save to tmppath()/content.lyx
|
||||
first. Embedded files are compressed along with content.lyx.
|
||||
If embedding is disabled, file.lyx is saved in the usual pure-text format.
|
||||
(c.f. Buffer::writeFile(), EmbeddedFiles::writeFile())
|
||||
|
||||
4. When a lyx file.lyx file is opened, if it is a zip file, it is
|
||||
decompressed to tmppath() and tmppath()/content.lyx is read as usual.
|
||||
(c.f. bool Buffer::readFile())
|
||||
|
||||
5. A menu item Document -> Save in bundled format is provided to pack/unpack
|
||||
a .lyx file.
|
||||
|
||||
6. If embedding of a .lyx file with embedded files is disabled, all its
|
||||
embedded files are copied to their respective external filenames. This
|
||||
is why external filename will exist even if a file is at "EMBEDDED" status.
|
||||
|
||||
*/
|
||||
|
||||
namespace lyx {
|
||||
|
||||
class Buffer;
|
||||
class Inset;
|
||||
class Lexer;
|
||||
class ErrorList;
|
||||
|
||||
class EmbeddedFile : public support::DocFileName
|
||||
{
|
||||
public:
|
||||
///
|
||||
EmbeddedFile(std::string const & file = std::string(),
|
||||
std::string const & buffer_path = std::string());
|
||||
|
||||
/// set filename and inzipName.
|
||||
/**
|
||||
* NOTE: inzip_name_ is not unique across operation systems and is not
|
||||
* guaranteed to be the same across different versions of LyX.
|
||||
* inzip_name_ will be saved to the LyX file, and is used to indicate
|
||||
* whether or not a file is embedded, and where the embedded file is in
|
||||
* the bundled file. When a file is read, the stored inzip names are used
|
||||
* at first. EmbeddedFiles::validate() will then scan these embedded files
|
||||
* and update their inzip name, moving bundled files around if needed.
|
||||
* This scheme has the advantage that it is safe to change how inzip files
|
||||
* are saved in a bundled file.
|
||||
*
|
||||
* NOTE that this treatment does not welcome an UUID solution because
|
||||
* all embedded files will have to be renamed when an embedded file is
|
||||
* opened. It is of course possible to use saved inzipname, but that is
|
||||
* not easy. For example, when a new EmbeddedFile is created with the same
|
||||
* file as an old one, it needs to be synced to the old inzipname...
|
||||
**/
|
||||
void set(std::string const & filename, std::string const & buffer_path);
|
||||
/** Set the inzip name of an EmbeddedFile, which should be the name
|
||||
* of an actual embedded file on disk.
|
||||
*/
|
||||
void setInzipName(std::string const & name);
|
||||
|
||||
/// filename in the zip file, which is related to buffer temp directory.
|
||||
std::string inzipName() const { return inzip_name_; }
|
||||
|
||||
/// embedded file, equals to temppath()/inzipName()
|
||||
std::string embeddedFile() const;
|
||||
/// embeddedFile() or absFilename() depending on embedding status
|
||||
/// and whether or not embedding is enabled.
|
||||
FileName availableFile() const;
|
||||
/// relative file name or inzipName()
|
||||
std::string latexFilename(std::string const & buffer_path) const;
|
||||
|
||||
/// add an inset that refers to this file
|
||||
void addInset(Inset const * inset);
|
||||
/// clear all isnets that associated with this file.
|
||||
void clearInsets() const { inset_list_.clear(); }
|
||||
|
||||
/// embedding status of this file
|
||||
bool embedded() const { return embedded_; }
|
||||
/// set embedding status.
|
||||
void setEmbed(bool embed);
|
||||
|
||||
/// whether or not embedding is enabled for the current file
|
||||
/**
|
||||
* An embedded file needs to know the temp path of a buffer to know
|
||||
* where its embedded copy is. This has to be stored within EmbeddedFile
|
||||
* because this class is often used when Buffer is unavailable. However,
|
||||
* when an embedded file is copied to another buffer, temp_path_ has
|
||||
* to be updated and file copying may be needed.
|
||||
*/
|
||||
bool isEnabled() const { return !temp_path_.empty(); }
|
||||
/// enable embedding of this file
|
||||
void enable(bool enabled, Buffer const & buf, bool updateFile);
|
||||
|
||||
/// extract file, does not change embedding status
|
||||
bool extract() const;
|
||||
/// update embedded file from external file, does not change embedding status
|
||||
bool updateFromExternalFile() const;
|
||||
/// copy an embedded file to another buffer
|
||||
EmbeddedFile copyTo(Buffer const & buf);
|
||||
///
|
||||
/// After the embedding status is changed, update all insets related
|
||||
/// to this file item. For example, a graphic inset may need to monitor
|
||||
/// embedded file instead of external file.
|
||||
void updateInsets() const;
|
||||
|
||||
/// Check readability of availableFile
|
||||
bool isReadableFile() const;
|
||||
/// Calculate checksum of availableFile
|
||||
unsigned long checksum() const;
|
||||
|
||||
// calculate inzip_name_ from filename
|
||||
std::string calcInzipName(std::string const & buffer_path);
|
||||
// move an embedded disk file with an existing inzip_name_ to
|
||||
// a calculated inzip_name_, if they differ.
|
||||
void syncInzipFile(std::string const & buffer_path);
|
||||
private:
|
||||
/// filename in zip file
|
||||
std::string inzip_name_;
|
||||
/// the status of this docfile
|
||||
bool embedded_;
|
||||
/// Insets that contains this file item. Because a
|
||||
/// file item can be referred by several Insets, a vector is used.
|
||||
mutable std::vector<Inset const *> inset_list_;
|
||||
/// Embedded file needs to know whether enbedding is enabled,
|
||||
/// and where is the lyx temporary directory. Such information can
|
||||
/// be retrived from a buffer, but a buffer is not always available when
|
||||
/// an EmbeddedFile is used.
|
||||
std::string temp_path_;
|
||||
};
|
||||
|
||||
|
||||
bool operator==(EmbeddedFile const & lhs, EmbeddedFile const & rhs);
|
||||
bool operator!=(EmbeddedFile const & lhs, EmbeddedFile const & rhs);
|
||||
|
||||
|
||||
class EmbeddedFileList {
|
||||
public:
|
||||
///
|
||||
typedef std::vector<EmbeddedFile>::iterator iterator;
|
||||
///
|
||||
typedef std::vector<EmbeddedFile>::const_iterator const_iterator;
|
||||
///
|
||||
iterator begin() { return eflist_.begin(); }
|
||||
iterator end() { return eflist_.end(); }
|
||||
const_iterator begin() const { return eflist_.begin(); }
|
||||
const_iterator end() const { return eflist_.end(); }
|
||||
///
|
||||
void push_back(EmbeddedFile const & ef) { eflist_.push_back(ef); }
|
||||
///
|
||||
EmbeddedFile const & back() const { return eflist_.back(); }
|
||||
EmbeddedFile & back() { return eflist_.back(); }
|
||||
///
|
||||
void clear() { eflist_.clear(); }
|
||||
///
|
||||
bool empty() const { return eflist_.empty(); }
|
||||
///
|
||||
void insert(iterator position, const_iterator itbeg, const_iterator itend)
|
||||
{ eflist_.insert(position, itbeg, itend); }
|
||||
void insert(iterator position, EmbeddedFile const & ef)
|
||||
{ eflist_.insert(position, ef); }
|
||||
///
|
||||
iterator erase(iterator position) { return eflist_.erase(position); }
|
||||
|
||||
|
||||
/// set buffer params embedded flag. Files will be updated or extracted
|
||||
/// if such an operation fails, enable will fail.
|
||||
void enable(bool enabled, Buffer & buffer, bool updateFile);
|
||||
|
||||
/// add a file item.
|
||||
/** \param file Embedded file to add
|
||||
* \param inset Inset pointer
|
||||
*/
|
||||
void registerFile(EmbeddedFile const & file, Inset const * inset,
|
||||
Buffer const & buffer);
|
||||
/// returns an iterator pointing to the Embedded file representing
|
||||
/// the file with the absolute filename <filename>.
|
||||
const_iterator findFile(std::string const & filename) const;
|
||||
iterator findFile(std::string const & filename);
|
||||
|
||||
/// validate embedded fies after a file is read.
|
||||
void validate(Buffer const & buffer);
|
||||
/// scan the buffer and get a list of EmbeddedFile
|
||||
void update(Buffer const & buffer);
|
||||
/// write a zip file
|
||||
bool writeFile(support::DocFileName const & filename, Buffer const & buffer);
|
||||
private:
|
||||
///
|
||||
std::vector<EmbeddedFile> eflist_;
|
||||
};
|
||||
|
||||
} // namespace lyx
|
||||
|
||||
#endif
|
@ -375,45 +375,44 @@ enum FuncCode
|
||||
LFUN_MASTER_BUFFER_UPDATE, // Tommaso, 20070920
|
||||
LFUN_INFO_INSERT, // bpeng, 20071007
|
||||
LFUN_CALL, // broider, 20071002
|
||||
LFUN_BUFFER_TOGGLE_EMBEDDING, // bpeng, 20071021
|
||||
LFUN_CHAR_LEFT, // dov, 20071022
|
||||
// 290
|
||||
LFUN_CHAR_LEFT_SELECT, // dov, 20071022
|
||||
// 290
|
||||
LFUN_CHAR_RIGHT, // dov, 20071022
|
||||
LFUN_CHAR_RIGHT_SELECT, // dov, 20071022
|
||||
LFUN_FINISHED_BACKWARD, // dov, 20071022
|
||||
LFUN_FINISHED_FORWARD, // dov, 20071022
|
||||
// 295
|
||||
LFUN_WORD_LEFT, // dov, 20071028
|
||||
// 295
|
||||
LFUN_WORD_LEFT_SELECT, // dov, 20071028
|
||||
LFUN_WORD_RIGHT, // dov, 20071028
|
||||
LFUN_WORD_RIGHT_SELECT, // dov, 20071028
|
||||
LFUN_MATH_MACRO_FOLD,
|
||||
// 300
|
||||
LFUN_MATH_MACRO_UNFOLD,
|
||||
// 300
|
||||
LFUN_MATH_MACRO_ADD_PARAM,
|
||||
LFUN_MATH_MACRO_REMOVE_PARAM,
|
||||
LFUN_MATH_MACRO_APPEND_GREEDY_PARAM,
|
||||
LFUN_MATH_MACRO_REMOVE_GREEDY_PARAM,
|
||||
// 305
|
||||
LFUN_MATH_MACRO_MAKE_OPTIONAL,
|
||||
// 305
|
||||
LFUN_MATH_MACRO_MAKE_NONOPTIONAL,
|
||||
LFUN_MATH_MACRO_ADD_OPTIONAL_PARAM,
|
||||
LFUN_MATH_MACRO_REMOVE_OPTIONAL_PARAM,
|
||||
LFUN_MATH_MACRO_ADD_GREEDY_OPTIONAL_PARAM,
|
||||
// 310
|
||||
LFUN_IN_MATHMACROTEMPLATE,
|
||||
// 310
|
||||
LFUN_SCROLL,
|
||||
LFUN_UI_TOGGLE,
|
||||
LFUN_SPLIT_VIEW,
|
||||
LFUN_CLOSE_TAB_GROUP,
|
||||
// 315
|
||||
LFUN_COMPLETION_POPUP,
|
||||
// 315
|
||||
LFUN_COMPLETION_INLINE,
|
||||
LFUN_COMPLETION_COMPLETE,
|
||||
LFUN_NEXT_INSET_MODIFY, // JSpitzm 20080323
|
||||
LFUN_LASTACTION // end of the table
|
||||
// 320
|
||||
// 319
|
||||
};
|
||||
|
||||
|
||||
|
@ -195,8 +195,6 @@ void LayoutFileList::reset(LayoutFileIndex const & classname) {
|
||||
|
||||
|
||||
string const LayoutFileList::localPrefix = "LOCAL:";
|
||||
string const LayoutFileList::embeddedPrefix = "EMBED:";
|
||||
|
||||
|
||||
LayoutFileIndex
|
||||
LayoutFileList::addLayoutFile(string const & textclass, string const & path,
|
||||
@ -212,8 +210,6 @@ LayoutFileIndex
|
||||
|
||||
if (type == Local)
|
||||
localIndex = localPrefix + fullName;
|
||||
else if (type == Embedded)
|
||||
localIndex = embeddedPrefix + textclass;
|
||||
|
||||
// if the local file has already been loaded, return it
|
||||
if (haveClass(localIndex))
|
||||
|
@ -90,8 +90,7 @@ public:
|
||||
|
||||
enum Layout_Type {
|
||||
System,
|
||||
Local,
|
||||
Embedded
|
||||
Local
|
||||
};
|
||||
|
||||
/// add a textclass from user local directory.
|
||||
@ -104,7 +103,6 @@ public:
|
||||
std::vector<LayoutFileIndex> classList() const;
|
||||
///
|
||||
static std::string const localPrefix;
|
||||
static std::string const embeddedPrefix;
|
||||
private:
|
||||
///
|
||||
typedef std::map<std::string, LayoutFile *> ClassMap;
|
||||
|
@ -1478,14 +1478,6 @@ void LyXAction::init()
|
||||
* \endvar
|
||||
*/
|
||||
{ LFUN_BUFFER_TOGGLE_COMPRESSION, "buffer-toggle-compression", Noop, Buffer },
|
||||
/*!
|
||||
* \var lyx::FuncCode lyx::LFUN_BUFFER_TOGGLE_EMBEDDING
|
||||
* \li Action: Toggles the embeddding feature on/off.
|
||||
* \li Syntax: buffer-toggle-embedding
|
||||
* \li Origin: bpeng, 21 Oct 2007
|
||||
* \endvar
|
||||
*/
|
||||
{ LFUN_BUFFER_TOGGLE_EMBEDDING, "buffer-toggle-embedding", Noop, Buffer },
|
||||
/*!
|
||||
* \var lyx::FuncCode lyx::LFUN_BUFFER_CLOSE
|
||||
* \li Action: Closes the current buffer.
|
||||
|
@ -163,7 +163,6 @@ LexerKeyword lyxrcTags[] = {
|
||||
{ "\\tex_expects_windows_paths", LyXRC::RC_TEX_EXPECTS_WINDOWS_PATHS },
|
||||
{ "\\ui_file", LyXRC::RC_UIFILE },
|
||||
{ "\\use_alt_language", LyXRC::RC_USE_ALT_LANG },
|
||||
{ "\\use_bundled_format", LyXRC::RC_USE_BUNDLED_FORMAT },
|
||||
{ "\\use_converter_cache", LyXRC::RC_USE_CONVERTER_CACHE },
|
||||
{ "\\use_escape_chars", LyXRC::RC_USE_ESC_CHARS },
|
||||
{ "\\use_input_encoding", LyXRC::RC_USE_INP_ENC },
|
||||
@ -297,7 +296,6 @@ void LyXRC::setDefaults()
|
||||
user_name = to_utf8(support::user_name());
|
||||
user_email = to_utf8(support::user_email());
|
||||
open_buffers_in_tabs = true;
|
||||
use_bundled_format = false;
|
||||
|
||||
// Fullscreen settings
|
||||
full_screen_limit = false;
|
||||
@ -1048,9 +1046,6 @@ int LyXRC::read(Lexer & lexrc)
|
||||
case RC_OPEN_BUFFERS_IN_TABS:
|
||||
lexrc >> open_buffers_in_tabs;
|
||||
break;
|
||||
case RC_USE_BUNDLED_FORMAT:
|
||||
lexrc >> use_bundled_format;
|
||||
break;
|
||||
|
||||
case RC_LAST:
|
||||
break; // this is just a dummy
|
||||
@ -1639,19 +1634,10 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
|
||||
}
|
||||
if (tag != RC_LAST)
|
||||
break;
|
||||
case RC_USE_BUNDLED_FORMAT:
|
||||
if (ignore_system_lyxrc ||
|
||||
use_bundled_format != system_lyxrc.use_bundled_format) {
|
||||
os << "\\use_bundled_format "
|
||||
<< convert<string>(use_bundled_format)
|
||||
<< '\n';
|
||||
}
|
||||
if (tag != RC_LAST)
|
||||
break;
|
||||
|
||||
os << "\n#\n"
|
||||
<< "# COLOR SECTION ###################################\n"
|
||||
<< "#\n\n";
|
||||
os << "\n#\n"
|
||||
<< "# COLOR SECTION ###################################\n"
|
||||
<< "#\n\n";
|
||||
|
||||
case RC_SET_COLOR:
|
||||
for (int i = 0; i < Color_ignore; ++i) {
|
||||
|
@ -152,7 +152,6 @@ public:
|
||||
RC_USER_NAME,
|
||||
RC_USETEMPDIR,
|
||||
RC_USE_ALT_LANG,
|
||||
RC_USE_BUNDLED_FORMAT,
|
||||
RC_USE_CONVERTER_CACHE,
|
||||
RC_USE_ESC_CHARS,
|
||||
RC_USE_INP_ENC,
|
||||
@ -443,8 +442,6 @@ public:
|
||||
bool completion_popup_after_complete;
|
||||
///
|
||||
bool open_buffers_in_tabs;
|
||||
///
|
||||
bool use_bundled_format;
|
||||
};
|
||||
|
||||
|
||||
|
@ -99,7 +99,6 @@ SOURCEFILESCORE = \
|
||||
CutAndPaste.cpp \
|
||||
DepTable.cpp \
|
||||
DocIterator.cpp \
|
||||
EmbeddedFiles.cpp \
|
||||
Encoding.cpp \
|
||||
ErrorList.cpp \
|
||||
Exporter.cpp \
|
||||
@ -196,7 +195,6 @@ HEADERFILESCORE = \
|
||||
DepTable.h \
|
||||
DispatchResult.h \
|
||||
DocIterator.h \
|
||||
EmbeddedFiles.h \
|
||||
Encoding.h \
|
||||
ErrorList.h \
|
||||
Exporter.h \
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "BufferParams.h"
|
||||
#include "EmbeddedFiles.h"
|
||||
#include "ui_BibtexAddUi.h"
|
||||
#include "qt_helpers.h"
|
||||
#include "Validator.h"
|
||||
@ -32,6 +31,7 @@
|
||||
#include "support/debug.h"
|
||||
#include "support/ExceptionMessage.h"
|
||||
#include "support/FileFilterList.h"
|
||||
#include "support/FileName.h"
|
||||
#include "support/filetools.h" // changeExtension
|
||||
#include "support/gettext.h"
|
||||
#include "support/lstrings.h"
|
||||
|
@ -1282,16 +1282,6 @@ void GuiDocument::classChanged()
|
||||
setLayoutComboByIDString(bp_.baseClassID());
|
||||
return;
|
||||
}
|
||||
} else if (prefixIs(classname, LayoutFileList::embeddedPrefix)) {
|
||||
int const ret = Alert::prompt(_("Embedded layout"),
|
||||
_("The layout file you have selected is an embedded layout that\n"
|
||||
"is embedded to a buffer. You cannot make use of it unless\n"
|
||||
"it is already embedded to this buffer.\n"),
|
||||
1, 1, _("&Set Layout"), _("&Cancel"));
|
||||
if (ret == 1) {
|
||||
setLayoutComboByIDString(bp_.baseClassID());
|
||||
return;
|
||||
}
|
||||
}
|
||||
// FIXME Note that by doing things this way, we load the TextClass
|
||||
// as soon as it is selected. So, if you use the scroll wheel when
|
||||
|
@ -315,12 +315,6 @@ void GuiGraphics::on_getPB_clicked()
|
||||
}
|
||||
|
||||
|
||||
void GuiGraphics::on_filename_textChanged(const QString & filename)
|
||||
{
|
||||
EmbeddedFile file = EmbeddedFile(fromqstr(filename), fromqstr(bufferFilepath()));
|
||||
}
|
||||
|
||||
|
||||
void GuiGraphics::setAutoText()
|
||||
{
|
||||
if (scaleCB->isChecked())
|
||||
@ -596,7 +590,7 @@ void GuiGraphics::updateContents()
|
||||
else
|
||||
origin->setCurrentIndex(0);
|
||||
|
||||
//// latex section
|
||||
// latex section
|
||||
latexoptions->setText(toqstr(igp.special));
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,6 @@ private Q_SLOTS:
|
||||
void change_bb();
|
||||
void on_browsePB_clicked();
|
||||
void on_getPB_clicked();
|
||||
void on_filename_textChanged(const QString &);
|
||||
void on_scaleCB_toggled(bool);
|
||||
void on_WidthCB_toggled(bool);
|
||||
void on_HeightCB_toggled(bool);
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "support/os.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/FileFilterList.h"
|
||||
#include "support/FileName.h"
|
||||
#include "support/filetools.h"
|
||||
|
||||
#include "insets/InsetListingsParams.h"
|
||||
|
@ -1838,8 +1838,6 @@ PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent)
|
||||
this, SIGNAL(changed()));
|
||||
connect(tooltipCB, SIGNAL(toggled(bool)),
|
||||
this, SIGNAL(changed()));
|
||||
connect(useBundledCB, SIGNAL(toggled(bool)),
|
||||
this, SIGNAL(changed()));
|
||||
lastfilesSB->setMaximum(maxlastfiles);
|
||||
}
|
||||
|
||||
@ -1855,7 +1853,6 @@ void PrefUserInterface::apply(LyXRC & rc) const
|
||||
rc.num_lastfiles = lastfilesSB->value();
|
||||
rc.use_tooltip = tooltipCB->isChecked();
|
||||
rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
|
||||
rc.use_bundled_format = useBundledCB->isChecked();
|
||||
}
|
||||
|
||||
|
||||
@ -1874,7 +1871,6 @@ void PrefUserInterface::update(LyXRC const & rc)
|
||||
lastfilesSB->setValue(rc.num_lastfiles);
|
||||
tooltipCB->setChecked(rc.use_tooltip);
|
||||
openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
|
||||
useBundledCB->setChecked(rc.use_bundled_format);
|
||||
}
|
||||
|
||||
|
||||
|
@ -224,8 +224,6 @@ docstring GuiToc::guiName(string const & type) const
|
||||
return _("Table of Contents");
|
||||
if (type == "child")
|
||||
return _("Child Documents");
|
||||
if (type == "embedded")
|
||||
return _("Embedded Files");
|
||||
if (type == "graphics")
|
||||
return _("List of Graphics");
|
||||
if (type == "equation")
|
||||
|
@ -949,12 +949,6 @@ void GuiView::updateToc()
|
||||
}
|
||||
|
||||
|
||||
void GuiView::updateEmbeddedFiles()
|
||||
{
|
||||
updateDialog("embedding", "");
|
||||
}
|
||||
|
||||
|
||||
void GuiView::autoSave()
|
||||
{
|
||||
LYXERR(Debug::INFO, "Running autoSave()");
|
||||
@ -2018,7 +2012,7 @@ namespace {
|
||||
|
||||
char const * const dialognames[] = {
|
||||
"aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
|
||||
"citation", "document", "embedding", "errorlist", "ert", "external", "file",
|
||||
"citation", "document", "errorlist", "ert", "external", "file",
|
||||
"findreplace", "float", "graphics", "include", "index", "nomenclature", "label", "log",
|
||||
"mathdelimiter", "mathmatrix", "note", "paragraph", "prefs", "print",
|
||||
"ref", "sendto", "space", "spellchecker", "symbols", "tabular", "tabularcreate",
|
||||
|
@ -109,8 +109,6 @@ public:
|
||||
|
||||
/// called on timeout
|
||||
void autoSave();
|
||||
///
|
||||
void updateEmbeddedFiles();
|
||||
|
||||
/// \return the current buffer view.
|
||||
BufferView * view();
|
||||
|
@ -914,9 +914,7 @@ void MenuDefinition::expandToc(Buffer const * buf)
|
||||
else if (cit->first == "child") {
|
||||
label = qt_("Child Documents");
|
||||
in_other_list = false;
|
||||
} else if (cit->first == "embedded")
|
||||
label = qt_("Embedded Files");
|
||||
else if (cit->first == "graphics")
|
||||
} else if (cit->first == "graphics")
|
||||
label = qt_("List of Graphics");
|
||||
else if (cit->first == "equation")
|
||||
label = qt_("List of Equations");
|
||||
|
@ -171,13 +171,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="4" >
|
||||
<widget class="QCheckBox" name="useBundledCB" >
|
||||
<property name="text" >
|
||||
<string>Use &bundled format for new documents</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -25,8 +25,7 @@ namespace graphics {
|
||||
Params::Params()
|
||||
: display(ColorDisplay),
|
||||
scale(100),
|
||||
angle(0),
|
||||
icon("")
|
||||
angle(0)
|
||||
{}
|
||||
|
||||
|
||||
@ -36,8 +35,7 @@ bool operator==(Params const & a, Params const & b)
|
||||
a.display == b.display &&
|
||||
a.bb == b.bb &&
|
||||
a.scale == b.scale &&
|
||||
a.angle == b.angle &&
|
||||
a.icon == b.icon);
|
||||
a.angle == b.angle);
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,12 +72,6 @@ public:
|
||||
*/
|
||||
/// Rotation angle.
|
||||
double angle;
|
||||
|
||||
/** The icon to be displayed to the top-left corner of an image.
|
||||
* It is mutable because an icon reflects a temporary state of
|
||||
* the image, and is variable.
|
||||
*/
|
||||
mutable std::string icon;
|
||||
};
|
||||
|
||||
bool operator==(Params const &, Params const &);
|
||||
|
@ -50,8 +50,8 @@ Template const * getTemplatePtr(InsetExternalParams const & params)
|
||||
|
||||
void editExternal(InsetExternalParams const & params, Buffer const & buffer)
|
||||
{
|
||||
formats.edit(buffer, params.filename.availableFile(),
|
||||
formats.getFormatFromFile(params.filename));
|
||||
formats.edit(buffer, params.filename,
|
||||
formats.getFormatFromFile(params.filename));
|
||||
}
|
||||
|
||||
|
||||
@ -254,7 +254,7 @@ void updateExternal(InsetExternalParams const & params,
|
||||
|
||||
if (from_checksum != temp_checksum) {
|
||||
Mover const & mover = getMover(from_format);
|
||||
if (!mover.copy(params.filename.availableFile(), temp_file)) {
|
||||
if (!mover.copy(params.filename, temp_file)) {
|
||||
LYXERR(Debug::EXTERNAL, "external::updateExternal. "
|
||||
<< "Unable to copy " << params.filename << " to " << temp_file);
|
||||
return; // FAILURE
|
||||
@ -310,7 +310,7 @@ void updateExternal(InsetExternalParams const & params,
|
||||
ErrorList el;
|
||||
bool const success =
|
||||
theConverters().convert(&buffer, temp_file, abs_to_file,
|
||||
params.filename.availableFile(), from_format, to_format, el,
|
||||
params.filename, from_format, to_format, el,
|
||||
Converters::try_default | Converters::try_cache);
|
||||
|
||||
if (!success) {
|
||||
|
@ -53,8 +53,7 @@ class ParConstIterator;
|
||||
class ParIterator;
|
||||
class Text;
|
||||
class TocList;
|
||||
class EmbeddedFile;
|
||||
class EmbeddedFileList;
|
||||
class FileNameList;
|
||||
|
||||
|
||||
namespace graphics { class PreviewLoader; }
|
||||
@ -435,11 +434,6 @@ public:
|
||||
/// Add an entry to the TocList
|
||||
/// pit is the ParConstIterator of the paragraph containing the inset
|
||||
virtual void addToToc(ParConstIterator const &) const {}
|
||||
/// report files that can be embedded with the lyx file
|
||||
virtual void registerEmbeddedFiles(EmbeddedFileList &) const {}
|
||||
/// update the properties of an embedded file of an inset
|
||||
/// the name of the embedded file should not change.
|
||||
virtual void updateEmbeddedFile(EmbeddedFile const &) {}
|
||||
/// Fill keys with BibTeX information
|
||||
virtual void fillWithBibKeys(BiblioInfo &, InsetIterator const &) const {}
|
||||
/// Update the counters of this inset and of its contents
|
||||
|
@ -292,7 +292,7 @@ support::FileNameList InsetBibtex::getBibFiles() const
|
||||
FileName path(buffer().filePath());
|
||||
support::PathChanger p(path);
|
||||
|
||||
FileNameList vec;
|
||||
support::FileNameList vec;
|
||||
|
||||
vector<docstring> bibfilelist = getVectorFromString(getParam("bibfiles"));
|
||||
vector<docstring>::const_iterator it = bibfilelist.begin();
|
||||
|
@ -13,7 +13,6 @@
|
||||
#define INSET_BIBTEX_H
|
||||
|
||||
#include "BiblioInfo.h"
|
||||
#include "EmbeddedFiles.h"
|
||||
#include "InsetCommand.h"
|
||||
|
||||
#include "support/FileNameList.h"
|
||||
@ -22,7 +21,6 @@
|
||||
|
||||
namespace lyx {
|
||||
|
||||
|
||||
/** Used to insert BibTeX's information
|
||||
*/
|
||||
class InsetBibtex : public InsetCommand {
|
||||
|
@ -190,6 +190,7 @@ void InsetExternalParams::write(Buffer const & buf, ostream & os) const
|
||||
|
||||
if (!filename.empty())
|
||||
os << "\tfilename " << filename.outputFilename(buf.filePath()) << '\n';
|
||||
|
||||
if (display != defaultDisplayType)
|
||||
os << "\tdisplay "
|
||||
<< external::displayTranslator().find(display)
|
||||
@ -246,7 +247,6 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
|
||||
enum {
|
||||
EX_TEMPLATE = 1,
|
||||
EX_FILENAME,
|
||||
EX_EMBED,
|
||||
EX_DISPLAY,
|
||||
EX_LYXSCALE,
|
||||
EX_DRAFT,
|
||||
@ -268,7 +268,6 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
|
||||
{ "clip", EX_CLIP },
|
||||
{ "display", EX_DISPLAY},
|
||||
{ "draft", EX_DRAFT},
|
||||
{ "embed", EX_EMBED},
|
||||
{ "extra", EX_EXTRA },
|
||||
{ "filename", EX_FILENAME},
|
||||
{ "height", EX_HEIGHT },
|
||||
@ -300,14 +299,6 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
|
||||
break;
|
||||
}
|
||||
|
||||
case EX_EMBED: {
|
||||
lex.next();
|
||||
string const name = lex.getString();
|
||||
filename.setInzipName(name);
|
||||
filename.setEmbed(!name.empty());
|
||||
break;
|
||||
}
|
||||
|
||||
case EX_DISPLAY: {
|
||||
lex.next();
|
||||
string const name = lex.getString();
|
||||
@ -426,23 +417,6 @@ InsetExternal::~InsetExternal()
|
||||
}
|
||||
|
||||
|
||||
void InsetExternal::setBuffer(Buffer & buffer)
|
||||
{
|
||||
if (buffer_) {
|
||||
try {
|
||||
// a file may not be copied successfully when, e.g. buffer_
|
||||
// has already been closed.
|
||||
params_.filename = params_.filename.copyTo(buffer);
|
||||
} catch (ExceptionMessage const & message) {
|
||||
Alert::error(message.title_, message.details_);
|
||||
// failed to embed
|
||||
params_.filename.setEmbed(false);
|
||||
}
|
||||
}
|
||||
Inset::setBuffer(buffer);
|
||||
}
|
||||
|
||||
|
||||
void InsetExternal::statusChanged() const
|
||||
{
|
||||
updateFrontend();
|
||||
@ -503,18 +477,6 @@ bool InsetExternal::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
}
|
||||
|
||||
|
||||
void InsetExternal::registerEmbeddedFiles(EmbeddedFileList & files) const
|
||||
{
|
||||
files.registerFile(params_.filename, this, buffer());
|
||||
}
|
||||
|
||||
|
||||
void InsetExternal::updateEmbeddedFile(EmbeddedFile const & file)
|
||||
{
|
||||
params_.filename = file;
|
||||
}
|
||||
|
||||
|
||||
void InsetExternal::edit(Cursor & cur, bool, EntryDirection)
|
||||
{
|
||||
cur.bv().showDialog("external",
|
||||
@ -568,8 +530,7 @@ graphics::Params get_grfx_params(InsetExternalParams const & eparams)
|
||||
{
|
||||
graphics::Params gparams;
|
||||
|
||||
gparams.filename = eparams.filename.availableFile();
|
||||
gparams.icon = eparams.filename.embedded() ? "pin.png" : "";
|
||||
gparams.filename = eparams.filename;
|
||||
gparams.scale = eparams.lyxscale;
|
||||
if (eparams.clipdata.clip)
|
||||
gparams.bb = eparams.clipdata.bbox;
|
||||
@ -738,11 +699,8 @@ void InsetExternal::write(ostream & os) const
|
||||
void InsetExternal::read(Lexer & lex)
|
||||
{
|
||||
InsetExternalParams params;
|
||||
if (params.read(buffer(), lex)) {
|
||||
// exception handling is not needed as long as embedded files are in place.
|
||||
params.filename.enable(buffer().embedded(), buffer(), false);
|
||||
if (params.read(buffer(), lex))
|
||||
setParams(params);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
#include "Inset.h"
|
||||
#include "ExternalTransforms.h"
|
||||
#include "EmbeddedFiles.h"
|
||||
|
||||
#include "support/FileName.h"
|
||||
#include "support/Translator.h"
|
||||
@ -78,7 +77,7 @@ public:
|
||||
std::string const & templatename() const { return templatename_; }
|
||||
|
||||
/// The external file.
|
||||
EmbeddedFile filename;
|
||||
support::DocFileName filename;
|
||||
/// How the inset is to be displayed by LyX.
|
||||
external::DisplayType display;
|
||||
/// The scale of the displayed graphic (if shown).
|
||||
@ -119,8 +118,6 @@ public:
|
||||
InsetExternalParams const & params() const;
|
||||
///
|
||||
void setParams(InsetExternalParams const &);
|
||||
///
|
||||
void setBuffer(Buffer & buffer);
|
||||
/// \returns the number of rows (\n's) of generated code.
|
||||
int latex(odocstream &, OutputParams const &) const;
|
||||
|
||||
@ -151,10 +148,6 @@ private:
|
||||
void edit(Cursor & cur, bool front, EntryDirection entry_from);
|
||||
///
|
||||
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
|
||||
/// external file can be embedded
|
||||
void registerEmbeddedFiles(EmbeddedFileList &) const;
|
||||
///
|
||||
void updateEmbeddedFile(EmbeddedFile const &);
|
||||
///
|
||||
void doDispatch(Cursor & cur, FuncRequest & cmd);
|
||||
///
|
||||
|
@ -54,7 +54,6 @@ TODO
|
||||
#include "Converter.h"
|
||||
#include "Cursor.h"
|
||||
#include "DispatchResult.h"
|
||||
#include "EmbeddedFiles.h"
|
||||
#include "ErrorList.h"
|
||||
#include "Exporter.h"
|
||||
#include "Format.h"
|
||||
@ -182,23 +181,6 @@ InsetGraphics::~InsetGraphics()
|
||||
}
|
||||
|
||||
|
||||
void InsetGraphics::setBuffer(Buffer & buffer)
|
||||
{
|
||||
if (buffer_) {
|
||||
try {
|
||||
// a file may not be copied successfully when, e.g. buffer_
|
||||
// has already been closed.
|
||||
params_.filename = params_.filename.copyTo(buffer);
|
||||
} catch (ExceptionMessage const & message) {
|
||||
Alert::error(message.title_, message.details_);
|
||||
// failed to embed
|
||||
params_.filename.setEmbed(false);
|
||||
}
|
||||
}
|
||||
Inset::setBuffer(buffer);
|
||||
}
|
||||
|
||||
|
||||
void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
{
|
||||
switch (cmd.action) {
|
||||
@ -254,23 +236,10 @@ bool InsetGraphics::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
}
|
||||
|
||||
|
||||
void InsetGraphics::registerEmbeddedFiles(EmbeddedFileList & files) const
|
||||
{
|
||||
files.registerFile(params().filename, this, buffer());
|
||||
}
|
||||
|
||||
|
||||
void InsetGraphics::updateEmbeddedFile(EmbeddedFile const & file)
|
||||
{
|
||||
// only properties of an embedded file can be changed here.
|
||||
params_.filename = file;
|
||||
}
|
||||
|
||||
|
||||
void InsetGraphics::edit(Cursor & cur, bool, EntryDirection)
|
||||
{
|
||||
cur.bv().showDialog("graphics", params2string(params(),
|
||||
cur.bv().buffer()), this);
|
||||
cur.bv().buffer()), this);
|
||||
}
|
||||
|
||||
|
||||
@ -304,7 +273,6 @@ void InsetGraphics::read(Lexer & lex)
|
||||
lex.setContext("InsetGraphics::read");
|
||||
//lex >> "Graphics";
|
||||
readInsetGraphics(lex, buffer().filePath(), params_);
|
||||
params_.filename.enable(buffer().embedded(), buffer(), false);
|
||||
graphic_->update(params().as_grfxParams());
|
||||
}
|
||||
|
||||
@ -569,7 +537,7 @@ string InsetGraphics::prepareFile(OutputParams const & runparams) const
|
||||
if (params().filename.empty())
|
||||
return string();
|
||||
|
||||
string const orig_file = params().filename.availableFile().absFilename();
|
||||
string const orig_file = params().filename.absFilename();
|
||||
// this is for dryrun and display purposes, do not use latexFilename
|
||||
string const rel_file = params().filename.relFilename(buffer().filePath());
|
||||
|
||||
@ -579,7 +547,7 @@ string InsetGraphics::prepareFile(OutputParams const & runparams) const
|
||||
|
||||
// temp_file will contain the file for LaTeX to act on if, for example,
|
||||
// we move it to a temp dir or uncompress it.
|
||||
FileName temp_file = params().filename.availableFile();
|
||||
FileName temp_file = params().filename;
|
||||
|
||||
// The master buffer. This is useful when there are multiple levels
|
||||
// of include files
|
||||
@ -599,7 +567,7 @@ string InsetGraphics::prepareFile(OutputParams const & runparams) const
|
||||
|
||||
GraphicsCopyStatus status;
|
||||
boost::tie(status, temp_file) =
|
||||
copyToDirIfNeeded(params().filename.availableFile(), temp_path);
|
||||
copyToDirIfNeeded(params().filename, temp_path);
|
||||
|
||||
if (status == FAILURE)
|
||||
return orig_file;
|
||||
@ -935,11 +903,7 @@ void InsetGraphics::addToToc(ParConstIterator const & cpit) const
|
||||
{
|
||||
TocBackend & backend = buffer().tocBackend();
|
||||
|
||||
docstring str = params_.filename.displayName();
|
||||
if (params_.filename.embedded()) {
|
||||
backend.toc("embedded").push_back(TocItem(cpit, 0, str));
|
||||
str += _(" (embedded)");
|
||||
}
|
||||
docstring const str = params_.filename.displayName();
|
||||
backend.toc("graphics").push_back(TocItem(cpit, 0, str));
|
||||
}
|
||||
|
||||
|
@ -56,8 +56,6 @@ private:
|
||||
///
|
||||
InsetGraphics(InsetGraphics const &);
|
||||
|
||||
///
|
||||
void setBuffer(Buffer & buffer);
|
||||
///
|
||||
bool isLabeled() const { return true; }
|
||||
void metrics(MetricsInfo &, Dimension &) const;
|
||||
@ -92,10 +90,6 @@ private:
|
||||
void editGraphics(InsetGraphicsParams const &, Buffer const &) const;
|
||||
///
|
||||
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
|
||||
/// all graphics can be embedded
|
||||
void registerEmbeddedFiles(EmbeddedFileList &) const;
|
||||
///
|
||||
void updateEmbeddedFile(EmbeddedFile const &);
|
||||
///
|
||||
void addToToc(ParConstIterator const &) const;
|
||||
///
|
||||
|
@ -182,11 +182,6 @@ bool InsetGraphicsParams::Read(Lexer & lex, string const & token, string const &
|
||||
if (token == "filename") {
|
||||
lex.eatLine();
|
||||
filename.set(lex.getString(), bufpath);
|
||||
} else if (token == "embed") {
|
||||
lex.next();
|
||||
string const name = lex.getString();
|
||||
filename.setInzipName(name);
|
||||
filename.setEmbed(!name.empty());
|
||||
} else if (token == "lyxscale") {
|
||||
lex.next();
|
||||
lyxscale = lex.getInteger();
|
||||
@ -251,8 +246,7 @@ bool InsetGraphicsParams::Read(Lexer & lex, string const & token, string const &
|
||||
graphics::Params InsetGraphicsParams::as_grfxParams() const
|
||||
{
|
||||
graphics::Params pars;
|
||||
pars.filename = filename.availableFile();
|
||||
pars.icon = filename.embedded() ? "pin.png" : "";
|
||||
pars.filename = filename;
|
||||
pars.scale = lyxscale;
|
||||
pars.angle = convert<double>(rotateAngle);
|
||||
|
||||
|
@ -16,7 +16,10 @@
|
||||
|
||||
#include "graphics/GraphicsTypes.h"
|
||||
#include "Length.h"
|
||||
#include "EmbeddedFiles.h"
|
||||
|
||||
#include "support/FileName.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace lyx {
|
||||
|
||||
@ -31,7 +34,7 @@ class InsetGraphicsParams
|
||||
{
|
||||
public:
|
||||
/// Image filename.
|
||||
EmbeddedFile filename;
|
||||
support::DocFileName filename;
|
||||
/// Scaling the Screen inside Lyx
|
||||
unsigned int lyxscale;
|
||||
/// How to display the image inside LyX
|
||||
|
@ -140,9 +140,10 @@ FileName const includedFilename(Buffer const & buffer,
|
||||
InsetCommandParams const & params)
|
||||
{
|
||||
return makeAbsPath(to_utf8(params["filename"]),
|
||||
onlyPath(parentFilename(buffer)));
|
||||
onlyPath(parentFilename(buffer)));
|
||||
}
|
||||
|
||||
|
||||
InsetLabel * createLabel(docstring const & label_str)
|
||||
{
|
||||
if (label_str.empty())
|
||||
@ -385,8 +386,7 @@ int InsetInclude::latex(odocstream & os, OutputParams const & runparams) const
|
||||
if (incfile.empty())
|
||||
return 0;
|
||||
|
||||
FileName const included_file =
|
||||
includedFilename(buffer(), params());
|
||||
FileName const included_file = includedFilename(buffer(), params());
|
||||
|
||||
// Check we're not trying to include ourselves.
|
||||
// FIXME RECURSIVE INCLUDE
|
||||
|
@ -38,16 +38,13 @@ namespace lyx {
|
||||
RenderGraphic::RenderGraphic(Inset const * inset)
|
||||
{
|
||||
loader_.connect(boost::bind(&Inset::updateFrontend, inset));
|
||||
icon_.connect(boost::bind(&Inset::updateFrontend, inset));
|
||||
}
|
||||
|
||||
|
||||
RenderGraphic::RenderGraphic(RenderGraphic const & other, Inset const * inset)
|
||||
: RenderBase(other), loader_(other.loader_), icon_(other.icon_),
|
||||
params_(other.params_)
|
||||
: RenderBase(other), loader_(other.loader_), params_(other.params_)
|
||||
{
|
||||
loader_.connect(boost::bind(&Inset::updateFrontend, inset));
|
||||
icon_.connect(boost::bind(&Inset::updateFrontend, inset));
|
||||
}
|
||||
|
||||
|
||||
@ -63,15 +60,6 @@ void RenderGraphic::update(graphics::Params const & params)
|
||||
|
||||
if (!params_.filename.empty())
|
||||
loader_.reset(params_.filename, params_);
|
||||
// If icon is set to empty, icon_ will not be reset to empty
|
||||
// but will not be displayed. This is to avoid repeated loading
|
||||
// of the same icon when figure status changes.
|
||||
if (!params_.icon.empty()) {
|
||||
support::FileName const icon = support::libFileSearch("images/",
|
||||
params_.icon, "png");
|
||||
if (!icon.empty()) // using an empty bounding box
|
||||
icon_.reset(icon, graphics::Params());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -186,10 +174,6 @@ void RenderGraphic::draw(PainterInfo & pi, int x, int y) const
|
||||
loader_.startLoading();
|
||||
if (!loader_.monitoring())
|
||||
loader_.startMonitoring();
|
||||
if (icon_.status() == graphics::WaitingToLoad)
|
||||
icon_.startLoading();
|
||||
if (!icon_.monitoring())
|
||||
icon_.startMonitoring();
|
||||
}
|
||||
|
||||
// This will draw the graphics. If the graphics has not been
|
||||
@ -229,9 +213,6 @@ void RenderGraphic::draw(PainterInfo & pi, int x, int y) const
|
||||
y - 4, msg, msgFont);
|
||||
}
|
||||
}
|
||||
if (!params_.icon.empty() && readyToDisplay(icon_))
|
||||
pi.pain.image(x + Inset::TEXT_TO_INSET_OFFSET, y - dim_.asc,
|
||||
10, 10, *icon_.image());
|
||||
}
|
||||
|
||||
|
||||
|
@ -45,7 +45,6 @@ private:
|
||||
|
||||
/// The stored data.
|
||||
graphics::Loader loader_;
|
||||
graphics::Loader icon_;
|
||||
graphics::Params params_;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user