more unicode filenames

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16133 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2006-12-02 16:07:15 +00:00
parent 591d47a64b
commit ed99f752f9
22 changed files with 225 additions and 200 deletions

View File

@ -83,8 +83,10 @@ namespace lyx {
using support::addPath;
using support::bformat;
using support::FileFilterList;
using support::FileName;
using support::fileSearch;
using support::isDirWriteable;
using support::isFileReadable;
using support::makeDisplayPath;
using support::makeAbsPath;
using support::package;
@ -153,7 +155,7 @@ void BufferView::setBuffer(Buffer * b)
buffer_->saveCursor(cursor_.selectionBegin(),
cursor_.selectionEnd());
// current buffer is going to be switched-off, save cursor pos
LyX::ref().session().lastFilePos().save(buffer_->fileName(),
LyX::ref().session().lastFilePos().save(FileName(buffer_->fileName()),
boost::tie(cursor_.pit(), cursor_.pos()) );
}
@ -205,20 +207,11 @@ void BufferView::setBuffer(Buffer * b)
}
bool BufferView::loadLyXFile(string const & filename, bool tolastfiles)
bool BufferView::loadLyXFile(FileName const & filename, bool tolastfiles)
{
// Get absolute path of file and add ".lyx"
// to the filename if necessary
string s = fileSearch(string(), filename, "lyx").absFilename();
bool const found = !s.empty();
if (!found)
s = filename;
// File already open?
if (theBufferList().exists(s)) {
docstring const file = makeDisplayPath(s, 20);
if (theBufferList().exists(filename.absFilename())) {
docstring const file = makeDisplayPath(filename.absFilename(), 20);
docstring text = bformat(_("The document %1$s is already "
"loaded.\n\nDo you want to revert "
"to the saved version?"), file);
@ -226,11 +219,11 @@ bool BufferView::loadLyXFile(string const & filename, bool tolastfiles)
text, 0, 1, _("&Revert"), _("&Switch to document"));
if (ret != 0) {
setBuffer(theBufferList().getBuffer(s));
setBuffer(theBufferList().getBuffer(filename.absFilename()));
return true;
}
// FIXME: should be LFUN_REVERT
if (!theBufferList().close(theBufferList().getBuffer(s), false))
if (!theBufferList().close(theBufferList().getBuffer(filename.absFilename()), false))
return false;
// Fall through to new load. (Asger)
buffer_ = 0;
@ -238,21 +231,21 @@ bool BufferView::loadLyXFile(string const & filename, bool tolastfiles)
Buffer * b = 0;
if (found) {
b = theBufferList().newBuffer(s);
if (!lyx::loadLyXFile(b, s)) {
if (isFileReadable(filename)) {
b = theBufferList().newBuffer(filename.absFilename());
if (!lyx::loadLyXFile(b, filename)) {
theBufferList().release(b);
return false;
}
} else {
docstring text = bformat(_("The document %1$s does not yet "
"exist.\n\nDo you want to create "
"a new document?"), from_utf8(s));
"a new document?"), from_utf8(filename.absFilename()));
int const ret = Alert::prompt(_("Create new document?"),
text, 0, 1, _("&Create"), _("Cancel"));
if (ret == 0) {
b = newFile(s, string(), true);
b = newFile(filename.absFilename(), string(), true);
if (!b)
return false;
} else
@ -267,7 +260,7 @@ bool BufferView::loadLyXFile(string const & filename, bool tolastfiles)
if (lyxrc.use_lastfilepos) {
pit_type pit;
pos_type pos;
boost::tie(pit, pos) = LyX::ref().session().lastFilePos().load(s);
boost::tie(pit, pos) = LyX::ref().session().lastFilePos().load(filename);
// I am not sure how to separate the following part to a function
// so I will leave this to Lars.
//
@ -288,7 +281,7 @@ bool BufferView::loadLyXFile(string const & filename, bool tolastfiles)
}
if (tolastfiles)
LyX::ref().session().lastFiles().add(b->fileName());
LyX::ref().session().lastFiles().add(FileName(b->fileName()));
return true;
}
@ -296,9 +289,8 @@ bool BufferView::loadLyXFile(string const & filename, bool tolastfiles)
void BufferView::reload()
{
string const fn = buffer_->fileName();
if (theBufferList().close(buffer_, false))
loadLyXFile(fn);
loadLyXFile(FileName(buffer_->fileName()));
}
@ -532,7 +524,7 @@ Change const BufferView::getCurrentChange() const
void BufferView::saveBookmark(bool persistent)
{
LyX::ref().session().bookmarks().save(
buffer_->fileName(),
FileName(buffer_->fileName()),
cursor_.paragraph().id(),
cursor_.pos(),
persistent
@ -1395,7 +1387,7 @@ void BufferView::menuInsertLyXFile(string const & filenm)
docstring res;
Buffer buf("", false);
if (lyx::loadLyXFile(&buf, makeAbsPath(filename))) {
if (lyx::loadLyXFile(&buf, FileName(filename))) {
ErrorList & el = buffer_->errorList("Parse");
// Copy the inserted document error list into the current buffer one.
el = buf.errorList("Parse");

View File

@ -30,6 +30,8 @@
namespace lyx {
namespace support { class FileName; }
class Buffer;
class Change;
class DocIterator;
@ -91,7 +93,7 @@ public:
/// redisplay the referenced buffer.
void reload();
/// load a buffer into the view.
bool loadLyXFile(std::string const & name, bool tolastfiles = true);
bool loadLyXFile(support::FileName const & name, bool tolastfiles = true);
/// perform pending painting updates.
/** \c fitcursor means first

View File

@ -564,7 +564,7 @@ int LaTeX::scanLogFile(TeXErrors & terr)
int retval = NO_ERRORS;
string tmp = onlyFilename(changeExtension(file, ".log"));
lyxerr[Debug::LATEX] << "Log file: " << tmp << endl;
ifstream ifs(tmp.c_str());
ifstream ifs(FileName(makeAbsPath(tmp)).toFilesystemEncoding().c_str());
string token;
while (getline(ifs, token)) {
@ -796,7 +796,7 @@ void LaTeX::deplog(DepTable & head)
// This line is not present if no toc should be created.
static regex miktexTocReg("\\\\tf@toc=\\\\write.*");
ifstream ifs(logfile.c_str());
ifstream ifs(FileName(makeAbsPath(logfile)).toFilesystemEncoding().c_str());
while (ifs) {
// Ok, the scanning of files here is not sufficient.
// Sometimes files are named by "File: xxx" only

View File

@ -448,10 +448,11 @@ void expandLastfiles(Menu & tomenu)
int ii = 1;
for (; lfit != lf.end() && ii < 10; ++lfit, ++ii) {
string const file = lfit->absFilename();
docstring const label = convert<docstring>(ii) + ". "
+ makeDisplayPath((*lfit), 30)
+ makeDisplayPath(file, 30)
+ char_type('|') + convert<docstring>(ii);
tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_FILE_OPEN, (*lfit))));
tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_FILE_OPEN, file)));
}
}
@ -486,7 +487,7 @@ void expandBookmarks(Menu & tomenu)
for (size_t i = 1; i <= bm.size(); ++i) {
if (bm.isValid(i)) {
docstring const label = convert<docstring>(i) + ". "
+ makeDisplayPath(bm.bookmark(i).filename, 20)
+ makeDisplayPath(bm.bookmark(i).filename.absFilename(), 20)
+ char_type('|') + convert<docstring>(i);
tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_BOOKMARK_GOTO,
convert<docstring>(i))));

View File

@ -55,7 +55,6 @@ using namespace std;
using support::bformat;
using support::FileName;
using support::libFileSearch;
using support::makeAbsPath;
using support::makeDisplayPath;
using support::onlyFilename;
using support::onlyPath;
@ -69,13 +68,13 @@ namespace fs = boost::filesystem;
namespace {
bool readFile(Buffer * const b, string const & s)
bool readFile(Buffer * const b, FileName const & s)
{
BOOST_ASSERT(b);
// File information about normal file
if (!fs::exists(s)) {
docstring const file = makeDisplayPath(s, 50);
if (!fs::exists(s.toFilesystemEncoding())) {
docstring const file = makeDisplayPath(s.absFilename(), 50);
docstring text = bformat(_("The specified document\n%1$s"
"\ncould not be read."), file);
Alert::error(_("Could not read document"), text);
@ -83,12 +82,13 @@ bool readFile(Buffer * const b, string const & s)
}
// Check if emergency save file exists and is newer.
string const e = onlyPath(s) + onlyFilename(s) + ".emergency";
FileName const e(s.absFilename() + ".emergency");
if (fs::exists(e) && fs::exists(s)
&& fs::last_write_time(e) > fs::last_write_time(s))
if (fs::exists(e.toFilesystemEncoding()) &&
fs::exists(s.toFilesystemEncoding()) &&
fs::last_write_time(e.toFilesystemEncoding()) > fs::last_write_time(s.toFilesystemEncoding()))
{
docstring const file = makeDisplayPath(s, 20);
docstring const file = makeDisplayPath(s.absFilename(), 20);
docstring const text =
bformat(_("An emergency save of the document "
"%1$s exists.\n\n"
@ -100,7 +100,7 @@ bool readFile(Buffer * const b, string const & s)
case 0:
// the file is not saved if we load the emergency file.
b->markDirty();
return b->readFile(e);
return b->readFile(e.absFilename());
case 1:
break;
default:
@ -109,12 +109,13 @@ bool readFile(Buffer * const b, string const & s)
}
// Now check if autosave file is newer.
string const a = onlyPath(s) + '#' + onlyFilename(s) + '#';
FileName const a(onlyPath(s.absFilename()) + '#' + onlyFilename(s.absFilename()) + '#');
if (fs::exists(a) && fs::exists(s)
&& fs::last_write_time(a) > fs::last_write_time(s))
if (fs::exists(a.toFilesystemEncoding()) &&
fs::exists(s.toFilesystemEncoding()) &&
fs::last_write_time(a.toFilesystemEncoding()) > fs::last_write_time(s.toFilesystemEncoding()))
{
docstring const file = makeDisplayPath(s, 20);
docstring const file = makeDisplayPath(s.absFilename(), 20);
docstring const text =
bformat(_("The backup of the document "
"%1$s is newer.\n\nLoad the "
@ -126,16 +127,16 @@ bool readFile(Buffer * const b, string const & s)
case 0:
// the file is not saved if we load the autosave file.
b->markDirty();
return b->readFile(a);
return b->readFile(a.absFilename());
case 1:
// Here we delete the autosave
unlink(FileName(makeAbsPath(a)));
unlink(a);
break;
default:
return false;
}
}
return b->readFile(s);
return b->readFile(s.absFilename());
}
@ -143,19 +144,19 @@ bool readFile(Buffer * const b, string const & s)
bool loadLyXFile(Buffer * b, string const & s)
bool loadLyXFile(Buffer * b, FileName const & s)
{
BOOST_ASSERT(b);
if (fs::is_readable(s)) {
if (fs::is_readable(s.toFilesystemEncoding())) {
if (readFile(b, s)) {
b->lyxvc().file_found_hook(s);
if (!fs::is_writable(s))
if (!fs::is_writable(s.toFilesystemEncoding()))
b->setReadonly(true);
return true;
}
} else {
docstring const file = makeDisplayPath(s, 20);
docstring const file = makeDisplayPath(s.absFilename(), 20);
// Here we probably should run
if (LyXVC::file_not_found_hook(s)) {
docstring const text =

View File

@ -20,6 +20,7 @@
namespace lyx {
namespace support { class FileName; }
class Buffer;
class DocIterator;
@ -31,7 +32,7 @@ class ParIterator;
* Loads a LyX file \c filename into \c Buffer
* and \return success status.
*/
bool loadLyXFile(Buffer *, std::string const & filename);
bool loadLyXFile(Buffer *, support::FileName const & filename);
/* Make a new file (buffer) with name \c filename based on a template
* named \c templatename

View File

@ -160,7 +160,7 @@ bool BufferList::quitWriteAll()
// if master/slave are both open, do not save slave since it
// will be automatically loaded when the master is loaded
if ((*it)->getMasterBuffer() == (*it))
LyX::ref().session().lastOpened().add((*it)->fileName());
LyX::ref().session().lastOpened().add(FileName((*it)->fileName()));
}
return true;

View File

@ -52,12 +52,12 @@ namespace lyx {
# include <unistd.h>
#endif
using lyx::frontend::WorkArea;
using frontend::WorkArea;
using lyx::docstring;
using lyx::support::bformat;
using lyx::support::makeDisplayPath;
using lyx::support::onlyFilename;
using support::bformat;
using support::FileName;
using support::makeDisplayPath;
using support::onlyFilename;
using std::endl;
using std::string;
@ -137,7 +137,7 @@ void LyXView::setBuffer(Buffer * b)
}
bool LyXView::loadLyXFile(string const & filename, bool tolastfiles)
bool LyXView::loadLyXFile(FileName const & filename, bool tolastfiles)
{
busy(true);

View File

@ -27,6 +27,8 @@
namespace lyx {
namespace support { class FileName; }
class Buffer;
class InsetBase;
class Menubar;
@ -128,7 +130,7 @@ public:
//@}
/// load a buffer into the current workarea
bool loadLyXFile(std::string const & name, bool tolastfiles = true);
bool loadLyXFile(support::FileName const & name, bool tolastfiles = true);
/// set a buffer to the current workarea
void setBuffer(Buffer * b);

View File

@ -40,13 +40,13 @@ using std::string;
using std::vector;
bool Importer::Import(LyXView * lv, string const & filename,
bool Importer::Import(LyXView * lv, FileName const & filename,
string const & format, ErrorList & errorList)
{
docstring const displaypath = makeDisplayPath(filename);
docstring const displaypath = makeDisplayPath(filename.absFilename());
lv->message(bformat(_("Importing %1$s..."), displaypath));
string const lyxfile = changeExtension(filename, ".lyx");
FileName const lyxfile(changeExtension(filename.absFilename(), ".lyx"));
string loader_format;
vector<string> loaders = Loaders();
@ -55,10 +55,10 @@ bool Importer::Import(LyXView * lv, string const & filename,
it != loaders.end(); ++it) {
if (converters.isReachable(format, *it)) {
string const tofile =
changeExtension(filename,
changeExtension(filename.absFilename(),
formats.extension(*it));
if (!converters.convert(0, FileName(filename), FileName(tofile),
FileName(filename), format, *it, errorList))
if (!converters.convert(0, filename, FileName(tofile),
filename, format, *it, errorList))
return false;
loader_format = *it;
break;
@ -78,14 +78,14 @@ bool Importer::Import(LyXView * lv, string const & filename,
if (loader_format == "lyx") {
lv->loadLyXFile(lyxfile);
} else {
Buffer * const b = newFile(lyxfile, string(), true);
Buffer * const b = newFile(lyxfile.absFilename(), string(), true);
if (b)
lv->setBuffer(b);
else
return false;
bool as_paragraphs = loader_format == "textparagraph";
string filename2 = (loader_format == format) ? filename
: changeExtension(filename,
string filename2 = (loader_format == format) ? filename.absFilename()
: changeExtension(filename.absFilename(),
formats.extension(loader_format));
insertAsciiFile(lv->view(), filename2, as_paragraphs);
lv->dispatch(FuncRequest(LFUN_MARK_OFF));

View File

@ -20,6 +20,8 @@
namespace lyx {
namespace support { class FileName; }
class LyXView;
class ErrorList;
class Format;
@ -27,7 +29,7 @@ class Format;
class Importer {
public:
///
static bool Import(LyXView * lv, std::string const & filename,
static bool Import(LyXView * lv, support::FileName const & filename,
std::string const & format, ErrorList & errorList);
///

View File

@ -354,10 +354,11 @@ bool loadIfNeeded(Buffer const & buffer, InsetCommandParams const & params)
Buffer * buf = theBufferList().getBuffer(included_file);
if (!buf) {
// the readonly flag can/will be wrong, not anymore I think.
if (!fs::exists(included_file))
FileName const fullname(included_file);
if (!fs::exists(fullname.toFilesystemEncoding()))
return false;
buf = theBufferList().newBuffer(included_file);
if (!loadLyXFile(buf, included_file))
if (!loadLyXFile(buf, fullname))
return false;
}
if (buf)

View File

@ -103,7 +103,7 @@ bool quitting; // flag, that we are quitting the program
bool menuWrite(Buffer * buffer)
{
if (buffer->save()) {
LyX::ref().session().lastFiles().add(buffer->fileName());
LyX::ref().session().lastFiles().add(FileName(buffer->fileName()));
return true;
}

View File

@ -338,7 +338,7 @@ int LyX::exec(int & argc, char * argv[])
support::init_package(argv[0], cl_system_support, cl_user_support,
support::top_build_dir_is_one_level_up);
vector<string> files;
vector<FileName> files;
if (!use_gui) {
// FIXME: create a ConsoleApplication
@ -472,7 +472,7 @@ void LyX::quit()
int LyX::loadFiles(int & argc, char * argv[],
vector<string> & files)
vector<FileName> & files)
{
// check for any spurious extra arguments
// other than documents
@ -498,28 +498,27 @@ int LyX::loadFiles(int & argc, char * argv[],
// frontend.
if (argv[argi][0] == '-')
continue;
files.push_back(os::internal_path(argv[argi]));
// get absolute path of file and add ".lyx" to
// the filename if necessary
files.push_back(fileSearch(string(), os::internal_path(argv[argi]), "lyx"));
}
if (first_start)
files.push_back(i18nLibFileSearch("examples", "splash.lyx").absFilename());
files.push_back(i18nLibFileSearch("examples", "splash.lyx"));
Buffer * last_loaded = 0;
vector<string>::const_iterator it = files.begin();
vector<string>::const_iterator end = files.end();
vector<FileName>::const_iterator it = files.begin();
vector<FileName>::const_iterator end = files.end();
for (; it != end; ++it) {
// get absolute path of file and add ".lyx" to
// the filename if necessary
string s = fileSearch(string(), *it, "lyx").absFilename();
if (s.empty()) {
Buffer * const b = newFile(*it, string(), true);
if (it->empty()) {
Buffer * const b = newFile(it->absFilename(), string(), true);
if (b)
last_loaded = b;
} else {
Buffer * buf = pimpl_->buffer_list_.newBuffer(s, false);
if (loadLyXFile(buf, s)) {
Buffer * buf = pimpl_->buffer_list_.newBuffer(it->absFilename(), false);
if (loadLyXFile(buf, *it)) {
last_loaded = buf;
ErrorList const & el = buf->errorList("Parse");
if (!el.empty())
@ -550,7 +549,7 @@ void LyX::execBatchCommands()
}
void LyX::restoreGuiSession(vector<string> const & files)
void LyX::restoreGuiSession(vector<FileName> const & files)
{
LyXView * view = newLyXView();
@ -560,7 +559,7 @@ void LyX::restoreGuiSession(vector<string> const & files)
// if a file is specified, I assume that user wants to edit *that* file
if (files.empty() && lyxrc.load_session) {
vector<string> const & lastopened = pimpl_->session_->lastOpened().getfiles();
vector<FileName> const & lastopened = pimpl_->session_->lastOpened().getfiles();
// do not add to the lastfile list since these files are restored from
// last seesion, and should be already there (regular files), or should
// not be added at all (help files).

View File

@ -14,6 +14,8 @@
#ifndef LYX_MAIN_H
#define LYX_MAIN_H
#include "support/filename.h"
#include <boost/scoped_ptr.hpp>
#include <boost/utility.hpp>
@ -121,10 +123,10 @@ private:
\return exit code failure if any.
*/
int loadFiles(int & argc, char * argv[],
std::vector<std::string> & files);
std::vector<support::FileName> & files);
/// Create a View and restore GUI Session.
void restoreGuiSession(std::vector<std::string> const & files);
void restoreGuiSession(std::vector<support::FileName> const & files);
/// Initialize RC font for the GUI.
void initGuiFont();

View File

@ -1045,7 +1045,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
// might be visible in more than one LyXView.
if (lyx_view_ && lyx_view_->view()->buffer()) {
// save cursor Position for opened files to .lyx/session
LyX::ref().session().lastFilePos().save(lyx_view_->buffer()->fileName(),
LyX::ref().session().lastFilePos().save(FileName(lyx_view_->buffer()->fileName()),
boost::tie(view()->cursor().pit(), view()->cursor().pos()) );
}
@ -1076,14 +1076,14 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
setErrorMessage(_("Missing argument"));
break;
}
string const fname = i18nLibFileSearch("doc", arg, "lyx").absFilename();
FileName const fname = i18nLibFileSearch("doc", arg, "lyx");
if (fname.empty()) {
lyxerr << "LyX: unable to find documentation file `"
<< arg << "'. Bad installation?" << endl;
break;
}
lyx_view_->message(bformat(_("Opening help file %1$s..."),
makeDisplayPath(fname)));
makeDisplayPath(fname.absFilename())));
lyx_view_->loadLyXFile(fname, false);
break;
}
@ -1196,10 +1196,10 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
} else {
// Must replace extension of the file to be .lyx
// and get full path
string const s = changeExtension(file_name, ".lyx");
FileName const s = fileSearch(string(), changeExtension(file_name, ".lyx"), "lyx");
// Either change buffer or load the file
if (theBufferList().exists(s)) {
lyx_view_->setBuffer(theBufferList().getBuffer(s));
if (theBufferList().exists(s.absFilename())) {
lyx_view_->setBuffer(theBufferList().getBuffer(s.absFilename()));
} else {
lyx_view_->loadLyXFile(s);
}
@ -1359,7 +1359,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
if (theBufferList().exists(filename))
lyx_view_->setBuffer(theBufferList().getBuffer(filename));
else
lyx_view_->loadLyXFile(filename);
lyx_view_->loadLyXFile(FileName(filename));
// Set the parent name of the child document.
// This makes insertion of citations and references in the child work,
// when the target is in the parent or another child document.
@ -1678,15 +1678,16 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
unsigned int idx = convert<unsigned int>(to_utf8(cmd.argument()));
BookmarksSection::Bookmark const bm = LyX::ref().session().bookmarks().bookmark(idx);
BOOST_ASSERT(!bm.filename.empty());
string const file = bm.filename.absFilename();
// if the file is not opened, open it.
if (!theBufferList().exists(bm.filename))
dispatch(FuncRequest(LFUN_FILE_OPEN, bm.filename));
if (!theBufferList().exists(file))
dispatch(FuncRequest(LFUN_FILE_OPEN, file));
// open may fail, so we need to test it again
if (theBufferList().exists(bm.filename)) {
if (theBufferList().exists(file)) {
// if the current buffer is not that one, switch to it.
if (lyx_view_->buffer()->fileName() != bm.filename)
dispatch(FuncRequest(LFUN_BUFFER_SWITCH, bm.filename));
// BOOST_ASSERT(lyx_view_->buffer()->fileName() != bm.filename);
if (lyx_view_->buffer()->fileName() != file)
dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
// BOOST_ASSERT(lyx_view_->buffer()->fileName() != file);
view()->moveToPosition(bm.par_id, bm.par_pos);
}
break;
@ -1795,6 +1796,7 @@ void LyXFunc::sendDispatchMessage(docstring const & msg, FuncRequest const & cmd
void LyXFunc::menuNew(string const & name, bool fromTemplate)
{
// FIXME: initpath is not used. What to do?
string initpath = lyxrc.document_path;
string filename(name);
@ -1884,10 +1886,8 @@ void LyXFunc::open(string const & fname)
// get absolute path of file and add ".lyx" to the filename if
// necessary
FileName const fullname = fileSearch(string(), filename, "lyx");
BOOST_ASSERT(!fullname.empty());
filename = fullname.absFilename();
docstring const disp_fn = makeDisplayPath(filename);
if (!fullname.empty())
filename = fullname.absFilename();
// if the file doesn't exist, let the user create one
if (!fs::exists(fullname.toFilesystemEncoding())) {
@ -1898,10 +1898,11 @@ void LyXFunc::open(string const & fname)
return;
}
docstring const disp_fn = makeDisplayPath(filename);
lyx_view_->message(bformat(_("Opening document %1$s..."), disp_fn));
docstring str2;
if (lyx_view_->loadLyXFile(filename)) {
if (lyx_view_->loadLyXFile(fullname)) {
str2 = bformat(_("Document %1$s opened."), disp_fn);
} else {
str2 = bformat(_("Could not open document %1$s"), disp_fn);
@ -1963,13 +1964,13 @@ void LyXFunc::doImport(string const & argument)
return;
// get absolute path of file
filename = makeAbsPath(filename);
FileName const fullname(makeAbsPath(filename));
string const lyxfile = changeExtension(filename, ".lyx");
FileName const lyxfile(changeExtension(fullname.absFilename(), ".lyx"));
// Check if the document already is open
if (use_gui && theBufferList().exists(lyxfile)) {
if (!theBufferList().close(theBufferList().getBuffer(lyxfile), true)) {
if (use_gui && theBufferList().exists(lyxfile.absFilename())) {
if (!theBufferList().close(theBufferList().getBuffer(lyxfile.absFilename()), true)) {
lyx_view_->message(_("Canceled."));
return;
}
@ -1977,8 +1978,8 @@ void LyXFunc::doImport(string const & argument)
// if the file exists already, and we didn't do
// -i lyx thefile.lyx, warn
if (fs::exists(lyxfile) && filename != lyxfile) {
docstring const file = makeDisplayPath(lyxfile, 30);
if (fs::exists(lyxfile.toFilesystemEncoding()) && fullname != lyxfile) {
docstring const file = makeDisplayPath(lyxfile.absFilename(), 30);
docstring text = bformat(_("The document %1$s already exists.\n\n"
"Do you want to over-write that document?"), file);
@ -1992,7 +1993,7 @@ void LyXFunc::doImport(string const & argument)
}
ErrorList errorList;
Importer::Import(lyx_view_, filename, format, errorList);
Importer::Import(lyx_view_, fullname, format, errorList);
// FIXME (Abdel 12/08/06): Is there a need to display the error list here?
}
@ -2000,7 +2001,7 @@ void LyXFunc::doImport(string const & argument)
void LyXFunc::closeBuffer()
{
// save current cursor position
LyX::ref().session().lastFilePos().save(lyx_view_->buffer()->fileName(),
LyX::ref().session().lastFilePos().save(FileName(lyx_view_->buffer()->fileName()),
boost::tie(view()->cursor().pit(), view()->cursor().pos()) );
if (theBufferList().close(lyx_view_->buffer(), true) && !quitting) {
if (theBufferList().empty()) {

View File

@ -54,9 +54,9 @@ LyXVC::~LyXVC()
{}
bool LyXVC::file_found_hook(string const & fn)
bool LyXVC::file_found_hook(FileName const & fn)
{
string found_file;
FileName found_file;
// Check if file is under RCS
if (!(found_file = RCS::find_file(fn)).empty()) {
vcs.reset(new RCS(found_file));
@ -74,7 +74,7 @@ bool LyXVC::file_found_hook(string const & fn)
}
bool LyXVC::file_not_found_hook(string const & fn)
bool LyXVC::file_not_found_hook(FileName const & fn)
{
// Check if file is under RCS
if (!RCS::find_file(fn).empty())
@ -93,10 +93,10 @@ void LyXVC::buffer(Buffer * buf)
void LyXVC::registrer()
{
string const filename = owner_->fileName();
FileName const filename(owner_->fileName());
// there must be a file to save
if (!isFileReadable(FileName(makeAbsPath(filename)))) {
if (!isFileReadable(filename)) {
Alert::error(_("Document not saved"),
_("You must save the document "
"before it can be registered."));
@ -105,19 +105,19 @@ void LyXVC::registrer()
// it is very likely here that the vcs is not created yet...
if (!vcs) {
string const cvs_entries = "CVS/Entries";
FileName const cvs_entries(makeAbsPath("CVS/Entries"));
if (isFileReadable(FileName(makeAbsPath(cvs_entries)))) {
if (isFileReadable(cvs_entries)) {
lyxerr[Debug::LYXVC]
<< "LyXVC: registering "
<< to_utf8(makeDisplayPath(filename))
<< to_utf8(makeDisplayPath(filename.absFilename()))
<< " with CVS" << endl;
vcs.reset(new CVS(cvs_entries, filename));
} else {
lyxerr[Debug::LYXVC]
<< "LyXVC: registering "
<< to_utf8(makeDisplayPath(filename))
<< to_utf8(makeDisplayPath(filename.absFilename()))
<< " with RCS" << endl;
vcs.reset(new RCS(filename));
}
@ -229,7 +229,7 @@ string const LyXVC::getLogFile() const
if (!vcs)
return string();
string tmpf = tempName(string(), "lyxvclog");
FileName const tmpf(tempName(string(), "lyxvclog"));
if (tmpf.empty()) {
lyxerr[Debug::LYXVC] << "Could not generate logfile "
<< tmpf << endl;
@ -237,7 +237,7 @@ string const LyXVC::getLogFile() const
}
lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;
vcs->getLog(tmpf);
return tmpf;
return tmpf.absFilename();
}

View File

@ -19,6 +19,7 @@
namespace lyx {
namespace support { class FileName; }
class VCS;
class Buffer;
@ -50,7 +51,7 @@ public:
the appropiate actions is taken. Returns true if the file is under
control by a VCS.
*/
bool file_found_hook(std::string const & fn);
bool file_found_hook(support::FileName const & fn);
/** This function should be run when a file is requested for loading,
but it does not exist. This function will then check for a VC master
@ -59,7 +60,7 @@ public:
viewing/editing. Returns true if the file is under control by a VCS
and the user wants to view/edit it.
*/
static bool file_not_found_hook(std::string const & fn);
static bool file_not_found_hook(support::FileName const & fn);
///
void buffer(Buffer *);

View File

@ -23,7 +23,9 @@
#include <algorithm>
#include <iterator>
using lyx::support::absolutePath;
using lyx::support::addName;
using lyx::support::FileName;
using lyx::support::package;
namespace fs = boost::filesystem;
@ -71,12 +73,15 @@ void LastFilesSection::read(istream & is)
if (c == '[')
break;
getline(is, tmp);
if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ')
if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ' || !absolutePath(tmp))
continue;
// read lastfiles
if (fs::exists(tmp) && !fs::is_directory(tmp) && lastfiles.size() < num_lastfiles)
lastfiles.push_back(tmp);
FileName const file(tmp);
if (fs::exists(file.toFilesystemEncoding()) &&
!fs::is_directory(file.toFilesystemEncoding()) &&
lastfiles.size() < num_lastfiles)
lastfiles.push_back(file);
else
lyxerr[Debug::INIT] << "LyX: Warning: Ignore last file: " << tmp << endl;
} while (is.good());
@ -87,11 +92,11 @@ void LastFilesSection::write(ostream & os) const
{
os << '\n' << sec_lastfiles << '\n';
copy(lastfiles.begin(), lastfiles.end(),
ostream_iterator<string>(os, "\n"));
ostream_iterator<FileName>(os, "\n"));
}
void LastFilesSection::add(string const & file)
void LastFilesSection::add(FileName const & file)
{
// If file already exist, delete it and reinsert at front.
LastFiles::iterator it = find(lastfiles.begin(), lastfiles.end(), file);
@ -124,11 +129,13 @@ void LastOpenedSection::read(istream & is)
if (c == '[')
break;
getline(is, tmp);
if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ')
if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ' || !absolutePath(tmp))
continue;
if (fs::exists(tmp) && !fs::is_directory(tmp))
lastopened.push_back(tmp);
FileName const file(tmp);
if (fs::exists(file.toFilesystemEncoding()) &&
!fs::is_directory(file.toFilesystemEncoding()))
lastopened.push_back(file);
else
lyxerr[Debug::INIT] << "LyX: Warning: Ignore last opened file: " << tmp << endl;
} while (is.good());
@ -139,11 +146,11 @@ void LastOpenedSection::write(ostream & os) const
{
os << '\n' << sec_lastopened << '\n';
copy(lastopened.begin(), lastopened.end(),
ostream_iterator<string>(os, "\n"));
ostream_iterator<FileName>(os, "\n"));
}
void LastOpenedSection::add(string const & file)
void LastOpenedSection::add(FileName const & file)
{
lastopened.push_back(file);
}
@ -178,8 +185,13 @@ void LastFilePosSection::read(istream & is)
itmp >> pos;
itmp.ignore(2); // ignore ", "
itmp >> fname;
if (fs::exists(fname) && !fs::is_directory(fname) && lastfilepos.size() < num_lastfilepos)
lastfilepos[fname] = boost::tie(pit, pos);
if (!absolutePath(fname))
continue;
FileName const file(fname);
if (fs::exists(file.toFilesystemEncoding()) &&
!fs::is_directory(file.toFilesystemEncoding()) &&
lastfilepos.size() < num_lastfilepos)
lastfilepos[file] = boost::tie(pit, pos);
else
lyxerr[Debug::INIT] << "LyX: Warning: Ignore pos of last file: " << fname << endl;
} catch (...) {
@ -201,13 +213,13 @@ void LastFilePosSection::write(ostream & os) const
}
void LastFilePosSection::save(string const & fname, FilePos pos)
void LastFilePosSection::save(FileName const & fname, FilePos pos)
{
lastfilepos[fname] = pos;
}
LastFilePosSection::FilePos LastFilePosSection::load(string const & fname) const
LastFilePosSection::FilePos LastFilePosSection::load(FileName const & fname) const
{
FilePosMap::const_iterator entry = lastfilepos.find(fname);
// Has position information, return it.
@ -242,10 +254,15 @@ void BookmarksSection::read(istream & is)
itmp >> pos;
itmp.ignore(2); // ignore ", "
itmp >> fname;
if (!absolutePath(fname))
continue;
FileName const file(fname);
// only load valid bookmarks
if (fs::exists(fname) && !fs::is_directory(fname) && bookmarks.size() < max_bookmarks)
bookmarks.push_back(Bookmark(fname, id, pos));
else
if (fs::exists(file.toFilesystemEncoding()) &&
!fs::is_directory(file.toFilesystemEncoding()) &&
bookmarks.size() < max_bookmarks)
bookmarks.push_back(Bookmark(file, id, pos));
else
lyxerr[Debug::INIT] << "LyX: Warning: Ignore bookmark of file: " << fname << endl;
} catch (...) {
lyxerr[Debug::INIT] << "LyX: Warning: unknown Bookmark info: " << tmp << endl;
@ -265,7 +282,7 @@ void BookmarksSection::write(ostream & os) const
}
void BookmarksSection::save(std::string const & fname, int par_id, pos_type par_pos, bool persistent)
void BookmarksSection::save(FileName const & fname, int par_id, pos_type par_pos, bool persistent)
{
if (persistent) {
bookmarks.push_front(Bookmark(fname, par_id, par_pos));
@ -407,7 +424,7 @@ Session::Session(unsigned int num) :
{
// locate the session file
// note that the session file name 'session' is hard-coded
session_file = addName(package().user_support(), "session");
session_file = FileName(addName(package().user_support(), "session"));
//
readFile();
}
@ -417,7 +434,7 @@ void Session::readFile()
{
// we will not complain if we can't find session_file nor will
// we issue a warning. (Lgb)
ifstream is(session_file.c_str());
ifstream is(session_file.toFilesystemEncoding().c_str());
string tmp;
while (getline(is, tmp)) {
@ -446,7 +463,7 @@ void Session::readFile()
void Session::writeFile() const
{
ofstream os(session_file.c_str());
ofstream os(session_file.toFilesystemEncoding().c_str());
if (os) {
os << "## Automatically generated lyx session file \n"
<< "## Editing this file manually may cause lyx to crash.\n";

View File

@ -13,7 +13,8 @@
#ifndef SESSION_H
#define SESSION_H
#include <support/types.h>
#include "support/filename.h"
#include "support/types.h"
#include <boost/utility.hpp>
#include <boost/tuple/tuple.hpp>
@ -55,7 +56,7 @@ class LastFilesSection : SessionSection
{
public:
///
typedef std::deque<std::string> LastFiles;
typedef std::deque<support::FileName> LastFiles;
public:
///
@ -77,7 +78,7 @@ public:
file in the list is popped from the end.
@param file the file to insert in the lastfile list.
*/
void add(std::string const & file);
void add(support::FileName const & file);
private:
/// Default number of lastfiles.
@ -103,7 +104,7 @@ class LastOpenedSection : SessionSection
{
public:
///
typedef std::vector<std::string> LastOpened;
typedef std::vector<support::FileName> LastOpened;
public:
///
@ -118,7 +119,7 @@ public:
/** add file to lastopened file list
@param file filename to add
*/
void add(std::string const & file);
void add(support::FileName const & file);
/** clear lastopened file list
*/
@ -137,7 +138,7 @@ public:
typedef boost::tuple<pit_type, pos_type> FilePos;
///
typedef std::map<std::string, FilePos> FilePosMap;
typedef std::map<support::FileName, FilePos> FilePosMap;
public:
///
@ -153,12 +154,12 @@ public:
@param fname file entry for which to save position information
@param pos position of the cursor when the file is closed.
*/
void save(std::string const & fname, FilePos pos);
void save(support::FileName const & fname, FilePos pos);
/** load saved cursor position from the fname entry in the filepos map
@param fname file entry for which to load position information
*/
FilePos load(std::string const & fname) const;
FilePos load(support::FileName const & fname) const;
private:
/// default number of lastfilepos to save */
@ -177,7 +178,7 @@ public:
class Bookmark {
public:
/// Filename
std::string filename;
support::FileName filename;
/// Cursor paragraph Id
int par_id;
/// Cursor position
@ -185,7 +186,7 @@ public:
///
Bookmark() : par_id(0), par_pos(0) {}
///
Bookmark(std::string const & f, int id, pos_type pos)
Bookmark(support::FileName const & f, int id, pos_type pos)
: filename(f), par_id(id), par_pos(pos) {}
};
@ -199,7 +200,7 @@ public:
/// Save the current position as bookmark
/// if save==false, save to temp_bookmark
void save(std::string const & fname, int par_id, pos_type par_pos, bool persistent);
void save(support::FileName const & fname, int par_id, pos_type par_pos, bool persistent);
/// return bookmark, return temp_bookmark if i==0
Bookmark const & bookmark(unsigned int i) const;
@ -379,7 +380,7 @@ public:
private:
/// file to save session, determined in the constructor.
std::string session_file;
support::FileName session_file;
/** Read the session file.
Reads the #.lyx/session# at the beginning of the LyX session.

View File

@ -31,6 +31,7 @@ namespace lyx {
using support::addName;
using support::addPath;
using support::contains;
using support::FileName;
using support::onlyFilename;
using support::onlyPath;
using support::quoteName;
@ -65,44 +66,42 @@ int VCS::doVCCommand(string const & cmd, string const & path)
}
RCS::RCS(string const & m)
RCS::RCS(FileName const & m)
{
master_ = m;
scanMaster();
}
string const RCS::find_file(string const & file)
FileName const RCS::find_file(FileName const & file)
{
string tmp = file;
// Check if *,v exists.
tmp += ",v";
FileName tmp(file.absFilename() + ",v");
lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
<< tmp << endl;
if (fs::is_readable(tmp)) {
if (fs::is_readable(tmp.toFilesystemEncoding())) {
lyxerr[Debug::LYXVC] << "Yes " << file
<< " is under rcs." << endl;
return tmp;
} else {
// Check if RCS/*,v exists.
tmp = addName(addPath(onlyPath(file), "RCS"), file);
tmp += ",v";
tmp = FileName(addName(addPath(onlyPath(file.absFilename()), "RCS"), file.absFilename()) + ",v");
lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
<< tmp << endl;
if (fs::is_readable(tmp)) {
if (fs::is_readable(tmp.toFilesystemEncoding())) {
lyxerr[Debug::LYXVC] << "Yes " << file
<< " it is under rcs."<< endl;
return tmp;
}
}
return string();
return FileName();
}
void RCS::retrieve(string const & file)
void RCS::retrieve(FileName const & file)
{
lyxerr[Debug::LYXVC] << "LyXVC::RCS: retrieve.\n\t" << file << endl;
VCS::doVCCommand("co -q -r " + quoteName(file),
VCS::doVCCommand("co -q -r " + quoteName(file.toFilesystemEncoding()),
string());
}
@ -111,7 +110,7 @@ void RCS::scanMaster()
{
lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl;
ifstream ifs(master_.c_str());
ifstream ifs(master_.toFilesystemEncoding().c_str());
string token;
bool read_enough = false;
@ -216,15 +215,15 @@ void RCS::undoLast()
}
void RCS::getLog(string const & tmpf)
void RCS::getLog(FileName const & tmpf)
{
doVCCommand("rlog " + quoteName(onlyFilename(owner_->fileName()))
+ " > " + tmpf,
+ " > " + tmpf.toFilesystemEncoding(),
owner_->filePath());
}
CVS::CVS(string const & m, string const & f)
CVS::CVS(FileName const & m, FileName const & f)
{
master_ = m;
file_ = f;
@ -232,26 +231,27 @@ CVS::CVS(string const & m, string const & f)
}
string const CVS::find_file(string const & file)
FileName const CVS::find_file(FileName const & file)
{
// First we look for the CVS/Entries in the same dir
// where we have file.
string const dir = onlyPath(file) + "/CVS/Entries";
string const tmpf = "/" + onlyFilename(file) + "/";
FileName const dir(onlyPath(file.absFilename()) + "/CVS/Entries");
string const tmpf = '/' + onlyFilename(file.absFilename()) + '/';
lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
<< "' for `" << tmpf << '\'' << endl;
if (fs::is_readable(dir)) {
if (fs::is_readable(dir.toFilesystemEncoding())) {
// Ok we are at least in a CVS dir. Parse the CVS/Entries
// and see if we can find this file. We do a fast and
// dirty parse here.
ifstream ifs(dir.c_str());
ifstream ifs(dir.toFilesystemEncoding().c_str());
string line;
while (getline(ifs, line)) {
lyxerr[Debug::LYXVC] << "\tEntries: " << line << endl;
if (contains(line, tmpf)) return dir;
if (contains(line, tmpf))
return dir;
}
}
return string();
return FileName();
}
@ -260,8 +260,8 @@ void CVS::scanMaster()
lyxerr[Debug::LYXVC] << "LyXVC::CVS: scanMaster. \n Checking: "
<< master_ << endl;
// Ok now we do the real scan...
ifstream ifs(master_.c_str());
string tmpf = "/" + onlyFilename(file_) + "/";
ifstream ifs(master_.toFilesystemEncoding().c_str());
string tmpf = '/' + onlyFilename(file_.absFilename()) + '/';
lyxerr[Debug::LYXVC] << "\tlooking for `" << tmpf << '\'' << endl;
string line;
static regex const reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
@ -281,7 +281,7 @@ void CVS::scanMaster()
//sm[4]; // options
//sm[5]; // tag or tagdate
// FIXME: must double check file is stattable/existing
time_t mod = fs::last_write_time(file_);
time_t mod = fs::last_write_time(file_.toFilesystemEncoding());
string mod_date = rtrim(asctime(gmtime(&mod)), "\n");
lyxerr[Debug::LYXVC]
<< "Date in Entries: `" << file_date
@ -346,10 +346,10 @@ void CVS::undoLast()
}
void CVS::getLog(string const & tmpf)
void CVS::getLog(FileName const & tmpf)
{
doVCCommand("cvs log " + quoteName(onlyFilename(owner_->fileName()))
+ " > " + tmpf,
+ " > " + tmpf.toFilesystemEncoding(),
owner_->filePath());
}

View File

@ -12,6 +12,8 @@
#ifndef VC_BACKEND_H
#define VC_BACKEND_H
#include "support/filename.h"
#include <string>
@ -44,7 +46,7 @@ public:
* getLog - read the revision log into the given file
* @param fname file name to read into
*/
virtual void getLog(std::string const &) = 0;
virtual void getLog(support::FileName const &) = 0;
/// return the current version description
virtual std::string const versionString() const = 0;
/// return the current version
@ -75,7 +77,7 @@ protected:
* The master VC file. For RCS this is *,v or RCS/ *,v. master should
* have full path.
*/
std::string master_;
support::FileName master_;
/// The status of the VC controlled file.
VCStatus vcstatus;
@ -98,12 +100,12 @@ class RCS : public VCS {
public:
explicit
RCS(std::string const & m);
RCS(support::FileName const & m);
/// return the revision file for the given file, if found
static std::string const find_file(std::string const & file);
static support::FileName const find_file(support::FileName const & file);
static void retrieve(std::string const & file);
static void retrieve(support::FileName const & file);
virtual void registrer(std::string const & msg);
@ -115,7 +117,7 @@ public:
virtual void undoLast();
virtual void getLog(std::string const &);
virtual void getLog(support::FileName const &);
virtual std::string const versionString() const {
return "RCS: " + version_;
@ -131,10 +133,10 @@ class CVS : public VCS {
public:
///
explicit
CVS(std::string const & m, std::string const & f);
CVS(support::FileName const & m, support::FileName const & f);
/// return the revision file for the given file, if found
static std::string const find_file(std::string const & file);
static support::FileName const find_file(support::FileName const & file);
virtual void registrer(std::string const & msg);
@ -146,7 +148,7 @@ public:
virtual void undoLast();
virtual void getLog(std::string const &);
virtual void getLog(support::FileName const &);
virtual std::string const versionString() const {
return "CVS: " + version_;
@ -156,7 +158,7 @@ protected:
virtual void scanMaster();
private:
std::string file_;
support::FileName file_;
};
} // namespace lyx