From: Abdelrazak Younes Date: Tue, 29 Jul 2008 07:53:08 +0000 (+0000) Subject: First step toward fixing http://bugzilla.lyx.org/show_bug.cgi?id=3243 X-Git-Tag: 1.6.10~3833 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=5ac9db6dfc52371ae8a3d46eea231306c2a85754;p=features.git First step toward fixing http://bugzilla.lyx.org/show_bug.cgi?id=3243 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25955 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferList.cpp b/src/BufferList.cpp index 4512cae4ab..7026cd8ea5 100644 --- a/src/BufferList.cpp +++ b/src/BufferList.cpp @@ -25,6 +25,7 @@ #include "support/ExceptionMessage.h" #include "support/debug.h" #include "support/filetools.h" +#include "support/FileName.h" #include "support/gettext.h" #include "support/lstrings.h" #include "support/Package.h" @@ -273,8 +274,10 @@ docstring BufferList::emergencyWrite(Buffer * buf) } -bool BufferList::exists(string const & s) const +bool BufferList::exists(FileName const & fname) const { + //FIXME: use Buffer::fileName()! + string const s = fname.absFilename(); return find_if(bstore.begin(), bstore.end(), bind(equal_to(), bind(&Buffer::absFileName, _1), diff --git a/src/BufferList.h b/src/BufferList.h index 1943c16ba3..1f830f7d5a 100644 --- a/src/BufferList.h +++ b/src/BufferList.h @@ -22,6 +22,10 @@ namespace lyx { class Buffer; class OutputParams; +namespace support { +class FileName; +} + /** * The class holds all all open buffers, and handles construction * and deletions of new ones. @@ -79,7 +83,7 @@ public: Buffer * last(); /// returns true if the buffer exists already - bool exists(std::string const &) const; + bool exists(support::FileName const &) const; /// returns true if the buffer is loaded bool isLoaded(Buffer const * b) const; diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index f69f5f8882..9269b6b48c 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -246,14 +246,14 @@ void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer) LASSERT(!bm.filename.empty(), /**/); string const file = bm.filename.absFilename(); // if the file is not opened, open it. - if (!theBufferList().exists(file)) { + if (!theBufferList().exists(bm.filename)) { if (openFile) dispatch(FuncRequest(LFUN_FILE_OPEN, file)); else return; } // open may fail, so we need to test it again - if (!theBufferList().exists(file)) + if (!theBufferList().exists(bm.filename)) return; // if the current buffer is not that one, switch to it. @@ -1109,7 +1109,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) // and get full path FileName const s = fileSearch(string(), changeExtension(file_name, ".lyx"), "lyx"); // Either change buffer or load the file - if (theBufferList().exists(s.absFilename())) + if (theBufferList().exists(s)) buf = theBufferList().getBuffer(s.absFilename()); else { buf = lyx_view_->loadDocument(s); @@ -1266,7 +1266,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) view()->saveBookmark(false); Buffer * child = 0; bool parsed = false; - if (theBufferList().exists(filename.absFilename())) { + if (theBufferList().exists(filename)) { child = theBufferList().getBuffer(filename.absFilename()); } else { setMessage(bformat(_("Opening child document %1$s..."), diff --git a/src/buffer_funcs.cpp b/src/buffer_funcs.cpp index 0bf934c63c..21d9e1a9a0 100644 --- a/src/buffer_funcs.cpp +++ b/src/buffer_funcs.cpp @@ -153,16 +153,15 @@ Buffer * newUnnamedFile(string const & templatename, FileName const & path) { static int newfile_number; - string document_path = path.absFilename(); - string filename = addName(document_path, + FileName filename(path, "newfile" + convert(++newfile_number) + ".lyx"); while (theBufferList().exists(filename) - || FileName(filename).isReadableFile()) { + || filename.isReadableFile()) { ++newfile_number; - filename = addName(document_path, + filename.set(path, "newfile" + convert(newfile_number) + ".lyx"); } - return newFile(filename, templatename, false); + return newFile(filename.absFilename(), templatename, false); }