class Buffer::Impl
{
public:
- Impl(Buffer & parent, string const & file, bool readonly);
+ Impl(Buffer & parent, FileName const & file, bool readonly);
limited_stack<Undo> undostack;
limited_stack<Undo> redostack;
bool read_only;
/// name of the file the buffer is associated with.
- string filename;
+ FileName filename;
boost::scoped_ptr<Messages> messages;
};
-Buffer::Impl::Impl(Buffer & parent, string const & file, bool readonly_)
+Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_)
: lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_),
filename(file), file_fully_loaded(false), inset(params),
toc_backend(&parent)
inset.setAutoBreakRows(true);
lyxvc.buffer(&parent);
temppath = createBufferTmpDir();
- params.filepath = onlyPath(file);
+ params.filepath = onlyPath(file.absFilename());
// FIXME: And now do something if temppath == string(), because we
// assume from now on that temppath points to a valid temp dir.
// See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg67406.html
Buffer::Buffer(string const & file, bool readonly)
- : pimpl_(new Impl(*this, file, readonly))
+ : pimpl_(new Impl(*this, FileName(file), readonly))
{
lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
}
string const path = temppath();
- string const fname = addName(path,
+ FileName const fname(addName(temppath(),
onlyFilename(changeExtension(filename,
- ".log")));
- string const bname =
+ ".log"))));
+ FileName const bname(
addName(path, onlyFilename(
changeExtension(filename,
- formats.extension("literate") + ".out")));
+ formats.extension("literate") + ".out"))));
// If no Latex log or Build log is newer, show Build log
- if (fs::exists(bname) &&
- (!fs::exists(fname) || fs::last_write_time(fname) < fs::last_write_time(bname))) {
+ if (fs::exists(bname.toFilesystemEncoding()) &&
+ (!fs::exists(fname.toFilesystemEncoding()) ||
+ fs::last_write_time(fname.toFilesystemEncoding()) < fs::last_write_time(bname.toFilesystemEncoding()))) {
lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
- return make_pair(Buffer::buildlog, bname);
+ return make_pair(Buffer::buildlog, bname.absFilename());
}
lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
- return make_pair(Buffer::latexlog, fname);
+ return make_pair(Buffer::latexlog, fname.absFilename());
}
void Buffer::setFileName(string const & newfile)
{
- pimpl_->filename = makeAbsPath(newfile);
- params().filepath = onlyPath(pimpl_->filename);
- setReadonly(fs::is_readonly(pimpl_->filename));
+ string const filename = makeAbsPath(newfile);
+ pimpl_->filename = FileName(filename);
+ params().filepath = onlyPath(filename);
+ setReadonly(fs::is_readonly(pimpl_->filename.toFilesystemEncoding()));
updateTitles();
}
// make a backup if the file already exists
string s;
- if (lyxrc.make_backup && fs::exists(fileName())) {
+ if (lyxrc.make_backup && fs::exists(pimpl_->filename.toFilesystemEncoding())) {
s = fileName() + '~';
if (!lyxrc.backupdir_path.empty())
s = addName(lyxrc.backupdir_path,
// But to use this we need fs::copy_file to actually do a copy,
// even when the target file exists. (Lgb)
try {
- fs::copy_file(fileName(), s, false);
+ fs::copy_file(pimpl_->filename.toFilesystemEncoding(), s, false);
}
catch (fs::filesystem_error const & fe) {
Alert::error(_("Backup failure"),
}
}
- if (writeFile(fileName())) {
+ if (writeFile(pimpl_->filename)) {
markClean();
removeAutosaveFile(fileName());
} else {
// Saving failed, so backup is not backup
if (lyxrc.make_backup)
- rename(FileName(s), FileName(fileName()));
+ rename(FileName(s), pimpl_->filename);
return false;
}
return true;
}
-bool Buffer::writeFile(string const & fname) const
+bool Buffer::writeFile(FileName const & fname) const
{
- if (pimpl_->read_only && fname == fileName())
+ if (pimpl_->read_only && fname == pimpl_->filename)
return false;
bool retval = false;
if (params().compressed) {
- io::filtering_ostream ofs(io::gzip_compressor() | io::file_sink(fname));
+ io::filtering_ostream ofs(io::gzip_compressor() | io::file_sink(fname.toFilesystemEncoding()));
if (!ofs)
return false;
retval = do_writeFile(ofs);
} else {
- ofstream ofs(fname.c_str(), ios::out|ios::trunc);
+ ofstream ofs(fname.toFilesystemEncoding().c_str(), ios::out|ios::trunc);
if (!ofs)
return false;
preamble += "<!ENTITY % output.print.bmp \"IGNORE\">\n";
}
- string const name = runparams.nice ? changeExtension(pimpl_->filename, ".sgml")
+ string const name = runparams.nice ? changeExtension(fileName(), ".sgml")
: fname;
preamble += features.getIncludedFiles(name);
preamble += features.getLyXSGMLEntities();
}
-string const & Buffer::fileName() const
+string const Buffer::fileName() const
{
- return pimpl_->filename;
+ return pimpl_->filename.absFilename();
}
namespace lyx {
+namespace support { class FileName; }
class BufferParams;
class ErrorItem;
bool save() const;
/// Write file. Returns \c false if unsuccesful.
- bool writeFile(std::string const &) const;
+ bool writeFile(support::FileName const &) const;
/// Just a wrapper for the method below, first creating the ofstream.
bool makeLaTeXFile(std::string const & filename,
void markDirty();
/// Returns the buffer's filename. It is always an absolute path.
- std::string const & fileName() const;
+ std::string const fileName() const;
/// Returns the the path where the buffer lives.
/// It is always an absolute path.
using support::addName;
using support::bformat;
+using support::FileName;
using support::makeAbsPath;
using support::makeDisplayPath;
using support::onlyFilename;
string s = buf->fileName();
s += ".emergency";
lyxerr << " " << s << endl;
- if (buf->writeFile(s)) {
+ if (buf->writeFile(FileName(s))) {
buf->markClean();
lyxerr << to_utf8(_(" Save seems successful. Phew.")) << endl;
return;
string s = addName(package().home_dir(), buf->fileName());
s += ".emergency";
lyxerr << ' ' << s << endl;
- if (buf->writeFile(s)) {
+ if (buf->writeFile(FileName(s))) {
buf->markClean();
lyxerr << to_utf8(_(" Save seems successful. Phew.")) << endl;
return;
s = addName(package().temp_dir(), buf->fileName());
s += ".emergency";
lyxerr << ' ' << s << endl;
- if (buf->writeFile(s)) {
+ if (buf->writeFile(FileName(s))) {
buf->markClean();
lyxerr << to_utf8(_(" Save seems successful. Phew.")) << endl;
return;
/// ask the user what to do if a file already exists
-int checkOverwrite(string const & filename)
+int checkOverwrite(FileName const & filename)
{
- if (fs::exists(filename)) {
+ if (fs::exists(filename.toFilesystemEncoding())) {
docstring text = bformat(_("The file %1$s already exists.\n\n"
"Do you want to over-write that file?"),
- makeDisplayPath(filename));
+ makeDisplayPath(filename.absFilename()));
return Alert::prompt(_("Over-write file?"),
text, 0, 2,
_("&Over-write"), _("Over-write &all"),
return ret;
if (!force) {
- switch(checkOverwrite(destFile.absFilename())) {
+ switch(checkOverwrite(destFile)) {
case 0:
ret = SUCCESS;
break;
writeFileAscii(*buffer, filename, runparams);
// no backend
else if (backend_format == "lyx")
- buffer->writeFile(filename);
+ buffer->writeFile(FileName(filename));
// Docbook backend
else if (buffer->isDocBook()) {
runparams.nice = !put_in_tempdir;
string const error_type = (format == "program")? "Build" : bufferFormat(*buffer);
string const ext = formats.extension(format);
- string const tmp_result_file = changeExtension(filename, ext);
+ FileName const tmp_result_file(changeExtension(filename, ext));
bool const success = converters.convert(buffer, FileName(filename),
- FileName(tmp_result_file), FileName(buffer->fileName()), backend_format, format,
+ tmp_result_file, FileName(buffer->fileName()), backend_format, format,
buffer->errorList(error_type));
// Emit the signal to show the error list.
buffer->errors(error_type);
return false;
if (put_in_tempdir)
- result_file = tmp_result_file;
+ result_file = tmp_result_file.absFilename();
else {
result_file = changeExtension(buffer->fileName(), ext);
// We need to copy referenced files (e. g. included graphics
}
if (status == CANCEL) {
buffer->message(_("Document export cancelled."));
- } else if (fs::exists(tmp_result_file)) {
+ } else if (fs::exists(tmp_result_file.toFilesystemEncoding())) {
// Finally copy the main file
- status = copyFile(format, FileName(tmp_result_file),
+ status = copyFile(format, tmp_result_file,
FileName(result_file), result_file,
status == FORCE);
buffer->message(bformat(_("Document exported as %1$s "
FileName const tmp_ret(tempName(string(), "lyxauto"));
if (!tmp_ret.empty()) {
- bv_.buffer()->writeFile(tmp_ret.absFilename());
+ bv_.buffer()->writeFile(tmp_ret);
// assume successful write of tmp_ret
if (!rename(tmp_ret, fname_)) {
failed = true;
if (failed) {
// failed to write/rename tmp_ret so try writing direct
- if (!bv_.buffer()->writeFile(fname_.absFilename())) {
+ if (!bv_.buffer()->writeFile(fname_)) {
// It is dangerous to do this in the child,
// but safe in the parent, so...
if (pid == -1)
format->extension());
filename = addName(buffer->temppath(), filename);
- if (!buffer->writeFile(filename))
+ if (!buffer->writeFile(FileName(filename)))
break;
} else {
<< endl;
}
- if (defaults.writeFile(defaults.fileName()))
+ if (defaults.writeFile(FileName(defaults.fileName())))
// FIXME Should use bformat
setMessage(_("Document defaults saved in ")
+ makeDisplayPath(fname));
// get absolute path of file and add ".lyx" to the filename if
// necessary
- string const fullpath = fileSearch(string(), filename, "lyx").absFilename();
- if (!fullpath.empty()) {
- filename = fullpath;
- }
+ FileName const fullname = fileSearch(string(), filename, "lyx");
+ BOOST_ASSERT(!fullname.empty());
+ filename = fullname.absFilename();
docstring const disp_fn = makeDisplayPath(filename);
// if the file doesn't exist, let the user create one
- if (!fs::exists(filename)) {
+ if (!fs::exists(fullname.toFilesystemEncoding())) {
// the user specifically chose this name. Believe him.
Buffer * const b = newFile(filename, string(), true);
if (b)