remove Buffer & argument in functions realted to embedded files

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23292 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2008-02-27 21:51:29 +00:00
parent f8ba8db758
commit 9b39c142b6
13 changed files with 57 additions and 64 deletions

View File

@ -1388,7 +1388,7 @@ void Buffer::updateBibfilesCache() const
if (it->lyxCode() == BIBTEX_CODE) { if (it->lyxCode() == BIBTEX_CODE) {
InsetBibtex const & inset = InsetBibtex const & inset =
static_cast<InsetBibtex const &>(*it); static_cast<InsetBibtex const &>(*it);
EmbeddedFileList const bibfiles = inset.getFiles(*this); EmbeddedFileList const bibfiles = inset.embeddedFiles();
d->bibfilesCache_.insert(d->bibfilesCache_.end(), d->bibfilesCache_.insert(d->bibfilesCache_.end(),
bibfiles.begin(), bibfiles.begin(),
bibfiles.end()); bibfiles.end());

View File

@ -246,12 +246,12 @@ bool EmbeddedFile::updateFromExternalFile() const
} }
void EmbeddedFile::updateInsets(Buffer const * buf) const void EmbeddedFile::updateInsets() const
{ {
vector<Inset const *>::const_iterator it = inset_list_.begin(); vector<Inset const *>::const_iterator it = inset_list_.begin();
vector<Inset const *>::const_iterator it_end = inset_list_.end(); vector<Inset const *>::const_iterator it_end = inset_list_.end();
for (; it != it_end; ++it) for (; it != it_end; ++it)
const_cast<Inset *>(*it)->updateEmbeddedFile(*buf, *this); const_cast<Inset *>(*it)->updateEmbeddedFile(*this);
} }
@ -386,9 +386,9 @@ void EmbeddedFileList::enable(bool flag, Buffer & buffer)
for (; it != it_end; ++it) { for (; it != it_end; ++it) {
it->enable(flag, &buffer); it->enable(flag, &buffer);
if (it->embedded()) if (it->embedded())
count_embedded ++; ++count_embedded;
else else
count_external ++; ++count_external;
} }
// if operation is successful (no exception is thrown) // if operation is successful (no exception is thrown)
buffer.markDirty(); buffer.markDirty();
@ -396,7 +396,7 @@ void EmbeddedFileList::enable(bool flag, Buffer & buffer)
// if the operation is successful, update insets // if the operation is successful, update insets
for (it = begin(); it != it_end; ++it) for (it = begin(); it != it_end; ++it)
it->updateInsets(&buffer); it->updateInsets();
// show result // show result
if (flag) { if (flag) {
@ -429,7 +429,7 @@ void EmbeddedFileList::registerFile(EmbeddedFile const & file,
from_utf8(it->outputFilename()))); from_utf8(it->outputFilename())));
it->setEmbed(true); it->setEmbed(true);
// update the inset with this embedding status. // update the inset with this embedding status.
const_cast<Inset*>(inset)->updateEmbeddedFile(buffer, *it); const_cast<Inset*>(inset)->updateEmbeddedFile(*it);
} }
it->addInset(inset); it->addInset(inset);
return; return;
@ -445,7 +445,7 @@ void EmbeddedFileList::update(Buffer const & buffer)
clear(); clear();
for (InsetIterator it = inset_iterator_begin(buffer.inset()); it; ++it) for (InsetIterator it = inset_iterator_begin(buffer.inset()); it; ++it)
it->registerEmbeddedFiles(buffer, *this); it->registerEmbeddedFiles(*this);
} }
@ -492,4 +492,4 @@ bool EmbeddedFileList::writeFile(DocFileName const & filename, Buffer const & bu
return true; return true;
} }
} } // namespace lyx

View File

@ -160,7 +160,7 @@ public:
/// embedded file instead of external file. To make sure inset pointers /// embedded file instead of external file. To make sure inset pointers
/// are up to date, please make sure there is no modification to the /// are up to date, please make sure there is no modification to the
/// document between EmbeddedFiles::update() and this function. /// document between EmbeddedFiles::update() and this function.
void updateInsets(Buffer const * buf) const; void updateInsets() const;
/// Check readability of availableFile /// Check readability of availableFile
bool isReadableFile() const; bool isReadableFile() const;

View File

@ -418,7 +418,7 @@ void Inset::setDimCache(MetricsInfo const & mi, Dimension const & dim) const
Buffer const * Inset::updateFrontend() const Buffer const * Inset::updateFrontend() const
{ {
return theApp()? theApp()->updateInset(this) : 0; return theApp() ? theApp()->updateInset(this) : 0;
} }
} // namespace lyx } // namespace lyx

View File

@ -423,9 +423,9 @@ public:
/// pit is the ParConstIterator of the paragraph containing the inset /// pit is the ParConstIterator of the paragraph containing the inset
virtual void addToToc(ParConstIterator const &) const {} virtual void addToToc(ParConstIterator const &) const {}
/// report files that can be embedded with the lyx file /// report files that can be embedded with the lyx file
virtual void registerEmbeddedFiles(Buffer const &, EmbeddedFileList &) const {} virtual void registerEmbeddedFiles(EmbeddedFileList &) const {}
/// use embedded or external file after the embedding status of a file is changed /// use embedded or external file after the embedding status of a file is changed
virtual void updateEmbeddedFile(Buffer const &, EmbeddedFile const &) {} virtual void updateEmbeddedFile(EmbeddedFile const &) {}
/// Fill keys with BibTeX information /// Fill keys with BibTeX information
virtual void fillWithBibKeys(BiblioInfo &, InsetIterator const &) const {} virtual void fillWithBibKeys(BiblioInfo &, InsetIterator const &) const {}
/// Update the counters of this inset and of its contents /// Update the counters of this inset and of its contents

View File

@ -107,7 +107,7 @@ void InsetBibtex::doDispatch(Cursor & cur, FuncRequest & cmd)
bibfiles = split(bibfiles, tmp, ','); bibfiles = split(bibfiles, tmp, ',');
embedStatus = split(embedStatus, emb, ','); embedStatus = split(embedStatus, emb, ',');
while (!tmp.empty()) { while (!tmp.empty()) {
EmbeddedFile file(changeExtension(tmp, "bib"), cur.buffer().filePath()); EmbeddedFile file(changeExtension(tmp, "bib"), buffer().filePath());
if (!newBibfiles.empty()) if (!newBibfiles.empty())
newBibfiles += ","; newBibfiles += ",";
newBibfiles += tmp; newBibfiles += tmp;
@ -128,14 +128,14 @@ void InsetBibtex::doDispatch(Cursor & cur, FuncRequest & cmd)
setParams(p); setParams(p);
try { try {
// test parameter and copy files // test parameter and copy files
getFiles(cur.buffer()); embeddedFiles();
} catch (ExceptionMessage const & message) { } catch (ExceptionMessage const & message) {
Alert::error(message.title_, message.details_); Alert::error(message.title_, message.details_);
// do not set parameter if an error happens // do not set parameter if an error happens
setParams(orig); setParams(orig);
break; break;
} }
cur.buffer().updateBibfilesCache(); buffer().updateBibfilesCache();
break; break;
} }
@ -189,7 +189,7 @@ int InsetBibtex::latex(odocstream & os, OutputParams const & runparams) const
// use such filenames.) // use such filenames.)
// Otherwise, store the (maybe absolute) path to the original, // Otherwise, store the (maybe absolute) path to the original,
// unmangled database name. // unmangled database name.
EmbeddedFileList const bibs = getFiles(buffer()); EmbeddedFileList const bibs = embeddedFiles();
EmbeddedFileList::const_iterator it = bibs.begin(); EmbeddedFileList::const_iterator it = bibs.begin();
EmbeddedFileList::const_iterator it_end = bibs.end(); EmbeddedFileList::const_iterator it_end = bibs.end();
odocstringstream dbs; odocstringstream dbs;
@ -343,9 +343,9 @@ int InsetBibtex::latex(odocstream & os, OutputParams const & runparams) const
} }
EmbeddedFileList const InsetBibtex::getFiles(Buffer const & buffer) const EmbeddedFileList InsetBibtex::embeddedFiles() const
{ {
FileName path(buffer.filePath()); FileName path(buffer().filePath());
PathChanger p(path); PathChanger p(path);
EmbeddedFileList vec; EmbeddedFileList vec;
@ -359,10 +359,10 @@ EmbeddedFileList const InsetBibtex::getFiles(Buffer const & buffer) const
embedStatus = split(embedStatus, emb, ','); embedStatus = split(embedStatus, emb, ',');
while (!tmp.empty()) { while (!tmp.empty()) {
if (!emb.empty()) { if (!emb.empty()) {
EmbeddedFile file(changeExtension(tmp, "bib"), buffer.filePath()); EmbeddedFile file(changeExtension(tmp, "bib"), buffer().filePath());
// If the file structure is correct, this should not fail. // If the file structure is correct, this should not fail.
file.setEmbed(true); file.setEmbed(true);
file.enable(buffer.embedded(), &buffer); file.enable(buffer().embedded(), &buffer());
vec.push_back(file); vec.push_back(file);
} else { } else {
// this includes the cases when the embed parameter is empty // this includes the cases when the embed parameter is empty
@ -370,9 +370,9 @@ EmbeddedFileList const InsetBibtex::getFiles(Buffer const & buffer) const
// If we didn't find a matching file name just fail silently // If we didn't find a matching file name just fail silently
if (!file.empty()) { if (!file.empty()) {
EmbeddedFile efile = EmbeddedFile(file.absFilename(), buffer.filePath()); EmbeddedFile efile = EmbeddedFile(file.absFilename(), buffer().filePath());
efile.setEmbed(false); efile.setEmbed(false);
efile.enable(buffer.embedded(), &buffer); efile.enable(buffer().embedded(), &buffer());
vec.push_back(efile); vec.push_back(efile);
} }
} }
@ -627,7 +627,7 @@ namespace {
void InsetBibtex::fillWithBibKeys(BiblioInfo & keylist, void InsetBibtex::fillWithBibKeys(BiblioInfo & keylist,
InsetIterator const & /*di*/) const InsetIterator const & /*di*/) const
{ {
EmbeddedFileList const files = getFiles(buffer()); EmbeddedFileList const files = embeddedFiles();
for (vector<EmbeddedFile>::const_iterator it = files.begin(); for (vector<EmbeddedFile>::const_iterator it = files.begin();
it != files.end(); ++ it) { it != files.end(); ++ it) {
// This bibtex parser is a first step to parse bibtex files // This bibtex parser is a first step to parse bibtex files
@ -822,25 +822,25 @@ void InsetBibtex::validate(LaTeXFeatures & features) const
} }
void InsetBibtex::registerEmbeddedFiles(Buffer const & buffer, EmbeddedFileList & files) const void InsetBibtex::registerEmbeddedFiles(EmbeddedFileList & files) const
{ {
EmbeddedFileList const dbs = getFiles(buffer); EmbeddedFileList const dbs = embeddedFiles();
for (vector<EmbeddedFile>::const_iterator it = dbs.begin(); for (vector<EmbeddedFile>::const_iterator it = dbs.begin();
it != dbs.end(); ++ it) it != dbs.end(); ++it)
files.registerFile(*it, this, buffer); files.registerFile(*it, this, buffer());
} }
void InsetBibtex::updateEmbeddedFile(Buffer const & buf, EmbeddedFile const & file) void InsetBibtex::updateEmbeddedFile(EmbeddedFile const & file)
{ {
// look for the item and update status // look for the item and update status
docstring bibfiles; docstring bibfiles;
docstring embed; docstring embed;
bool first = true; bool first = true;
EmbeddedFileList dbs = getFiles(buf); EmbeddedFileList dbs = embeddedFiles();
for (EmbeddedFileList::iterator it = dbs.begin(); for (EmbeddedFileList::iterator it = dbs.begin();
it != dbs.end(); ++ it) { it != dbs.end(); ++it) {
// update from file // update from file
if (it->absFilename() == file.absFilename()) if (it->absFilename() == file.absFilename())
it->setEmbed(file.embedded()); it->setEmbed(file.embedded());
@ -848,9 +848,10 @@ void InsetBibtex::updateEmbeddedFile(Buffer const & buf, EmbeddedFile const & fi
if (!first) { if (!first) {
bibfiles += ','; bibfiles += ',';
embed += ','; embed += ',';
} else } else {
first = false; first = false;
bibfiles += from_utf8(it->outputFilename(buf.filePath())); }
bibfiles += from_utf8(it->outputFilename(buffer().filePath()));
if (it->embedded()) if (it->embedded())
embed += from_utf8(it->inzipName()); embed += from_utf8(it->inzipName());
} }

View File

@ -38,9 +38,9 @@ public:
/// ///
int latex(odocstream &, OutputParams const &) const; int latex(odocstream &, OutputParams const &) const;
/// ///
virtual void fillWithBibKeys(BiblioInfo &, InsetIterator const &) const; void fillWithBibKeys(BiblioInfo &, InsetIterator const &) const;
/// ///
EmbeddedFileList const getFiles(Buffer const &) const; EmbeddedFileList embeddedFiles() const;
/// ///
bool addDatabase(std::string const &); bool addDatabase(std::string const &);
/// ///
@ -55,17 +55,15 @@ public:
static bool isCompatibleCommand(std::string const & s) static bool isCompatibleCommand(std::string const & s)
{ return s == "bibtex"; } { return s == "bibtex"; }
/// ///
void registerEmbeddedFiles(Buffer const &, EmbeddedFileList &) const; void registerEmbeddedFiles(EmbeddedFileList &) const;
/// ///
void updateEmbeddedFile(Buffer const & buf, EmbeddedFile const & file); void updateEmbeddedFile(EmbeddedFile const & file);
protected: protected:
/// ///
virtual void doDispatch(Cursor & cur, FuncRequest & cmd); void doDispatch(Cursor & cur, FuncRequest & cmd);
private: private:
/// ///
virtual Inset * clone() const; Inset * clone() const;
}; };

View File

@ -495,19 +495,17 @@ bool InsetExternal::getStatus(Cursor & cur, FuncRequest const & cmd,
} }
void InsetExternal::registerEmbeddedFiles(Buffer const & buffer, void InsetExternal::registerEmbeddedFiles(EmbeddedFileList & files) const
EmbeddedFileList & files) const
{ {
files.registerFile(params_.filename, this, buffer); files.registerFile(params_.filename, this, buffer());
} }
void InsetExternal::updateEmbeddedFile(Buffer const & buf, void InsetExternal::updateEmbeddedFile(EmbeddedFile const & file)
EmbeddedFile const & file)
{ {
// when embedding is enabled, change of embedding status leads to actions // when embedding is enabled, change of embedding status leads to actions
EmbeddedFile temp = file; EmbeddedFile temp = file;
temp.enable(buf.embedded(), &buf); temp.enable(buffer().embedded(), &buffer());
// this will not be set if an exception is thorwn in enable() // this will not be set if an exception is thorwn in enable()
params_.filename = temp; params_.filename = temp;
} }

View File

@ -146,9 +146,9 @@ public:
/// ///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const; bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
/// external file can be embedded /// external file can be embedded
void registerEmbeddedFiles(Buffer const &, EmbeddedFileList &) const; void registerEmbeddedFiles(EmbeddedFileList &) const;
/// ///
void updateEmbeddedFile(Buffer const &, EmbeddedFile const &); void updateEmbeddedFile(EmbeddedFile const &);
protected: protected:
InsetExternal(InsetExternal const &); InsetExternal(InsetExternal const &);

View File

@ -214,19 +214,17 @@ bool InsetGraphics::getStatus(Cursor & cur, FuncRequest const & cmd,
} }
void InsetGraphics::registerEmbeddedFiles(Buffer const & buffer, void InsetGraphics::registerEmbeddedFiles(EmbeddedFileList & files) const
EmbeddedFileList & files) const
{ {
files.registerFile(params().filename, this, buffer); files.registerFile(params().filename, this, buffer());
} }
void InsetGraphics::updateEmbeddedFile(Buffer const & buf, void InsetGraphics::updateEmbeddedFile(EmbeddedFile const & file)
EmbeddedFile const & file)
{ {
// when embedding is enabled, change of embedding status leads to actions // when embedding is enabled, change of embedding status leads to actions
EmbeddedFile temp = file; EmbeddedFile temp = file;
temp.enable(buf.embedded(), &buf); temp.enable(buffer().embedded(), &buffer());
// this will not be set if an exception is thorwn in enable() // this will not be set if an exception is thorwn in enable()
params_.filename = temp; params_.filename = temp;

View File

@ -76,9 +76,9 @@ public:
/// ///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const; bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
/// all graphics can be embedded /// all graphics can be embedded
void registerEmbeddedFiles(Buffer const &, EmbeddedFileList &) const; void registerEmbeddedFiles(EmbeddedFileList &) const;
/// ///
void updateEmbeddedFile(Buffer const &, EmbeddedFile const &); void updateEmbeddedFile(EmbeddedFile const &);
/// Force inset into LTR environment if surroundings are RTL? /// Force inset into LTR environment if surroundings are RTL?
virtual bool forceLTR() const { return true; } virtual bool forceLTR() const { return true; }
protected: protected:

View File

@ -908,15 +908,13 @@ void InsetInclude::updateLabels(ParIterator const &)
} }
void InsetInclude::registerEmbeddedFiles(Buffer const & buffer, void InsetInclude::registerEmbeddedFiles(EmbeddedFileList & files) const
EmbeddedFileList & files) const
{ {
files.registerFile(includedFilename(buffer, params()), this, buffer); files.registerFile(includedFilename(buffer(), params()), this, buffer());
} }
void InsetInclude::updateEmbeddedFile(Buffer const & buf, void InsetInclude::updateEmbeddedFile(EmbeddedFile const & file)
EmbeddedFile const & file)
{ {
InsetCommandParams p = params(); InsetCommandParams p = params();
p["filename"] = from_utf8(file.outputFilename()); p["filename"] = from_utf8(file.outputFilename());

View File

@ -87,9 +87,9 @@ public:
/// ///
void updateLabels(ParIterator const &); void updateLabels(ParIterator const &);
/// child document can be embedded /// child document can be embedded
void registerEmbeddedFiles(Buffer const &, EmbeddedFileList &) const; void registerEmbeddedFiles(EmbeddedFileList &) const;
/// ///
void updateEmbeddedFile(Buffer const & buf, EmbeddedFile const & file); void updateEmbeddedFile(EmbeddedFile const & file);
/// ///
static ParamInfo const & findInfo(std::string const &); static ParamInfo const & findInfo(std::string const &);
/// ///