BufferList::getBuffer(): migrate to FileName.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25958 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2008-07-29 08:16:09 +00:00
parent d1d7252c46
commit d56faa70c4
7 changed files with 17 additions and 26 deletions

View File

@ -276,11 +276,7 @@ docstring BufferList::emergencyWrite(Buffer * buf)
bool BufferList::exists(FileName const & fname) const
{
return find_if(bstore.begin(), bstore.end(),
bind(equal_to<FileName>(),
bind(&Buffer::fileName, _1),
fname))
!= bstore.end();
return getBuffer(fname) != 0;
}
@ -293,14 +289,10 @@ bool BufferList::isLoaded(Buffer const * b) const
}
Buffer * BufferList::getBuffer(string const & s)
Buffer * BufferList::getBuffer(support::FileName const & fname) const
{
BufferStorage::iterator it =
find_if(bstore.begin(), bstore.end(),
bind(equal_to<string>(),
bind(&Buffer::absFileName, _1),
s));
BufferStorage::const_iterator it = find_if(bstore.begin(), bstore.end(),
bind(equal_to<FileName>(), bind(&Buffer::fileName, _1), fname));
return it != bstore.end() ? (*it) : 0;
}

View File

@ -91,7 +91,7 @@ public:
/// return index of named buffer in buffer list
int bufferNum(std::string const & name) const;
/// returns a pointer to the buffer with the given name.
Buffer * getBuffer(std::string const &);
Buffer * getBuffer(support::FileName const &) const;
/// returns a pointer to the buffer with the given number.
Buffer * getBuffer(unsigned int);
/// returns a pointer to the buffer whose temppath matches the string

View File

@ -488,7 +488,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
/*
case LFUN_BUFFER_WRITE:
case LFUN_BUFFER_WRITE_AS: {
Buffer * b = theBufferList().getBuffer(cmd.getArg(0));
Buffer * b = theBufferList().getBuffer(FileName(cmd.getArg(0)));
enable = b && (b->isUnnamed() || !b->isClean());
break;
}
@ -1110,7 +1110,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
FileName const s = fileSearch(string(), changeExtension(file_name, ".lyx"), "lyx");
// Either change buffer or load the file
if (theBufferList().exists(s))
buf = theBufferList().getBuffer(s.absFilename());
buf = theBufferList().getBuffer(s);
else {
buf = lyx_view_->loadDocument(s);
loaded = true;
@ -1267,7 +1267,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
Buffer * child = 0;
bool parsed = false;
if (theBufferList().exists(filename)) {
child = theBufferList().getBuffer(filename.absFilename());
child = theBufferList().getBuffer(filename);
} else {
setMessage(bformat(_("Opening child document %1$s..."),
makeDisplayPath(filename.absFilename())));

View File

@ -60,7 +60,7 @@ namespace Alert = frontend::Alert;
Buffer * checkAndLoadLyXFile(FileName const & filename)
{
// File already open?
Buffer * checkBuffer = theBufferList().getBuffer(filename.absFilename());
Buffer * checkBuffer = theBufferList().getBuffer(filename);
if (checkBuffer) {
if (checkBuffer->isClean())
return checkBuffer;

View File

@ -347,8 +347,7 @@ void GuiRef::updateRefs()
{
refs_.clear();
string const name = theBufferList().getFileNames()[bufferCO->currentIndex()];
Buffer const * buf = theBufferList().getBuffer(
support::makeAbsPath(name).absFilename());
Buffer const * buf = theBufferList().getBuffer(support::makeAbsPath(name));
buf->getLabelList(refs_);
sortCB->setEnabled(!refs_.empty());
refsLW->setEnabled(!refs_.empty());

View File

@ -1443,7 +1443,7 @@ void GuiView::importDocument(string const & argument)
FileName const lyxfile(support::changeExtension(fullname.absFilename(), ".lyx"));
// Check if the document already is open
Buffer * buf = theBufferList().getBuffer(lyxfile.absFilename());
Buffer * buf = theBufferList().getBuffer(lyxfile);
if (buf) {
setBuffer(buf);
if (!closeBuffer()) {
@ -1784,7 +1784,7 @@ bool GuiView::dispatch(FuncRequest const & cmd)
break;
case LFUN_BUFFER_SWITCH:
setBuffer(theBufferList().getBuffer(to_utf8(cmd.argument())));
setBuffer(theBufferList().getBuffer(FileName(to_utf8(cmd.argument()))));
break;
case LFUN_BUFFER_NEXT:

View File

@ -371,7 +371,7 @@ Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params)
if (!isLyXFilename(included_file.absFilename()))
return 0;
Buffer * child = theBufferList().getBuffer(included_file.absFilename());
Buffer * child = theBufferList().getBuffer(included_file);
if (!child) {
// the readonly flag can/will be wrong, not anymore I think.
if (!included_file.exists())
@ -459,7 +459,7 @@ int InsetInclude::latex(odocstream & os, OutputParams const & runparams) const
if (!loadIfNeeded(buffer(), params()))
return false;
Buffer * tmp = theBufferList().getBuffer(included_file.absFilename());
Buffer * tmp = theBufferList().getBuffer(included_file);
if (tmp->params().baseClass() != masterBuffer->params().baseClass()) {
// FIXME UNICODE
@ -617,7 +617,7 @@ int InsetInclude::docbook(odocstream & os, OutputParams const & runparams) const
DocFileName writefile(changeExtension(included_file, ".sgml"));
if (loadIfNeeded(buffer(), params())) {
Buffer * tmp = theBufferList().getBuffer(included_file);
Buffer * tmp = theBufferList().getBuffer(FileName(included_file));
string const mangled = writefile.mangledFilename();
writefile = makeAbsPath(mangled,
@ -681,7 +681,7 @@ void InsetInclude::validate(LaTeXFeatures & features) const
// to be loaded:
if (loadIfNeeded(buffer(), params())) {
// a file got loaded
Buffer * const tmp = theBufferList().getBuffer(included_file);
Buffer * const tmp = theBufferList().getBuffer(FileName(included_file));
// make sure the buffer isn't us
// FIXME RECURSIVE INCLUDES
// This is not sufficient, as recursive includes could be
@ -703,7 +703,7 @@ void InsetInclude::fillWithBibKeys(BiblioInfo & keys,
{
if (loadIfNeeded(buffer(), params())) {
string const included_file = includedFilename(buffer(), params()).absFilename();
Buffer * tmp = theBufferList().getBuffer(included_file);
Buffer * tmp = theBufferList().getBuffer(FileName(included_file));
BiblioInfo const & newkeys = tmp->localBibInfo();
keys.mergeBiblioInfo(newkeys);
}