mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
Remove the FileName parameter of Buffer::loadLyXFile and friends. Now, getAutosaveFileNameFor and getEmergencyFileNamefor can be removed too. Last, the call to lyxvc.file_found_hook can now be centralized and can be given the correct parameter (d->filename instead of the name of the emergency/autosave file).
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36145 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
e3c3c18f27
commit
afa873dc5f
@ -876,7 +876,7 @@ Buffer::ReadStatus Buffer::readFile(FileName const & fn)
|
||||
}
|
||||
|
||||
// InsetInfo needs to know if file is under VCS
|
||||
lyxvc().file_found_hook(fn);
|
||||
lyxvc().file_found_hook(d->filename);
|
||||
|
||||
if (readDocument(lex)) {
|
||||
Alert::error(_("Document format failure"),
|
||||
@ -3229,13 +3229,7 @@ int AutoSaveBuffer::generateChild()
|
||||
|
||||
FileName Buffer::getEmergencyFileName() const
|
||||
{
|
||||
return getEmergencyFileNameFor(d->filename);
|
||||
}
|
||||
|
||||
|
||||
FileName Buffer::getEmergencyFileNameFor(FileName const & fn) const
|
||||
{
|
||||
return FileName(fn.absFileName() + ".emergency");
|
||||
return FileName(d->filename.absFileName() + ".emergency");
|
||||
}
|
||||
|
||||
|
||||
@ -3251,15 +3245,9 @@ FileName Buffer::getAutosaveFileName() const
|
||||
if (!isUnnamed() || fpath.empty() || !FileName(fpath).exists())
|
||||
fpath = filePath();
|
||||
|
||||
string const fname = d->filename.onlyFileName();
|
||||
return getAutosaveFileNameFor(makeAbsPath(fname, fpath));
|
||||
}
|
||||
string const fname = "#" + d->filename.onlyFileName() + "#";
|
||||
|
||||
|
||||
FileName Buffer::getAutosaveFileNameFor(FileName const & fn) const
|
||||
{
|
||||
string const fname = "#" + onlyFileName(fn.absFileName()) + "#";
|
||||
return FileName(onlyPath(fn.absFileName()) + fname);
|
||||
return makeAbsPath(fname, fpath);
|
||||
}
|
||||
|
||||
|
||||
@ -3618,25 +3606,25 @@ vector<string> Buffer::backends() const
|
||||
}
|
||||
|
||||
|
||||
Buffer::ReadStatus Buffer::extractFromVC(FileName const & fn)
|
||||
Buffer::ReadStatus Buffer::extractFromVC()
|
||||
{
|
||||
bool const found = LyXVC::file_not_found_hook(fn);
|
||||
bool const found = LyXVC::file_not_found_hook(d->filename);
|
||||
if (!found)
|
||||
return ReadFileNotFound;
|
||||
if (!fn.isReadableFile())
|
||||
if (!d->filename.isReadableFile())
|
||||
return ReadVCError;
|
||||
return ReadSuccess;
|
||||
}
|
||||
|
||||
|
||||
Buffer::ReadStatus Buffer::loadEmergency(FileName const & fn)
|
||||
Buffer::ReadStatus Buffer::loadEmergency()
|
||||
{
|
||||
FileName const emergencyFile = getEmergencyFileNameFor(fn);
|
||||
FileName const emergencyFile = getEmergencyFileName();
|
||||
if (!emergencyFile.exists()
|
||||
|| emergencyFile.lastModified() <= fn.lastModified())
|
||||
|| emergencyFile.lastModified() <= d->filename.lastModified())
|
||||
return ReadFileNotFound;
|
||||
|
||||
docstring const file = makeDisplayPath(fn.absFileName(), 20);
|
||||
docstring const file = makeDisplayPath(d->filename.absFileName(), 20);
|
||||
docstring const text = bformat(_("An emergency save of the document "
|
||||
"%1$s exists.\n\nRecover emergency save?"), file);
|
||||
|
||||
@ -3651,12 +3639,11 @@ Buffer::ReadStatus Buffer::loadEmergency(FileName const & fn)
|
||||
bool const success = (ret_llf == ReadSuccess);
|
||||
if (success) {
|
||||
markDirty();
|
||||
lyxvc().file_found_hook(fn);
|
||||
str = _("Document was successfully recovered.");
|
||||
} else
|
||||
str = _("Document was NOT successfully recovered.");
|
||||
str += "\n\n" + bformat(_("Remove emergency file now?\n(%1$s)"),
|
||||
makeDisplayPath(emergencyFile.absFileName()));
|
||||
makeDisplayPath(emergencyFile.absFileName()));
|
||||
|
||||
int const del_emerg =
|
||||
Alert::prompt(_("Delete emergency file?"), str, 1, 1,
|
||||
@ -3686,15 +3673,15 @@ Buffer::ReadStatus Buffer::loadEmergency(FileName const & fn)
|
||||
}
|
||||
|
||||
|
||||
Buffer::ReadStatus Buffer::loadAutosave(FileName const & fn)
|
||||
Buffer::ReadStatus Buffer::loadAutosave()
|
||||
{
|
||||
// Now check if autosave file is newer.
|
||||
FileName const autosaveFile = getAutosaveFileNameFor(fn);
|
||||
FileName const autosaveFile = getAutosaveFileName();
|
||||
if (!autosaveFile.exists()
|
||||
|| autosaveFile.lastModified() <= fn.lastModified())
|
||||
|| autosaveFile.lastModified() <= d->filename.lastModified())
|
||||
return ReadFileNotFound;
|
||||
|
||||
docstring const file = makeDisplayPath(fn.absFileName(), 20);
|
||||
docstring const file = makeDisplayPath(d->filename.absFileName(), 20);
|
||||
docstring const text = bformat(_("The backup of the document %1$s "
|
||||
"is newer.\n\nLoad the backup instead?"), file);
|
||||
int const ret = Alert::prompt(_("Load backup?"), text, 0, 2,
|
||||
@ -3707,7 +3694,6 @@ Buffer::ReadStatus Buffer::loadAutosave(FileName const & fn)
|
||||
// the file is not saved if we load the autosave file.
|
||||
if (ret_llf == ReadSuccess) {
|
||||
markDirty();
|
||||
lyxvc().file_found_hook(fn);
|
||||
return ReadSuccess;
|
||||
}
|
||||
return ReadAutosaveFailure;
|
||||
@ -3723,23 +3709,23 @@ Buffer::ReadStatus Buffer::loadAutosave(FileName const & fn)
|
||||
}
|
||||
|
||||
|
||||
Buffer::ReadStatus Buffer::loadLyXFile(FileName const & fn)
|
||||
Buffer::ReadStatus Buffer::loadLyXFile()
|
||||
{
|
||||
if (!fn.isReadableFile()) {
|
||||
ReadStatus const ret_rvc = extractFromVC(fn);
|
||||
if (!d->filename.isReadableFile()) {
|
||||
ReadStatus const ret_rvc = extractFromVC();
|
||||
if (ret_rvc != ReadSuccess)
|
||||
return ret_rvc;
|
||||
}
|
||||
|
||||
ReadStatus const ret_re = loadEmergency(fn);
|
||||
ReadStatus const ret_re = loadEmergency();
|
||||
if (ret_re == ReadSuccess || ret_re == ReadCancel)
|
||||
return ret_re;
|
||||
|
||||
ReadStatus const ret_ra = loadAutosave(fn);
|
||||
ReadStatus const ret_ra = loadAutosave();
|
||||
if (ret_ra == ReadSuccess || ret_ra == ReadCancel)
|
||||
return ret_ra;
|
||||
|
||||
return loadThisLyXFile(fn);
|
||||
return loadThisLyXFile(d->filename);
|
||||
}
|
||||
|
||||
|
||||
@ -4120,7 +4106,7 @@ Buffer::ReadStatus Buffer::reload()
|
||||
d->filename.refresh();
|
||||
docstring const disp_fn = makeDisplayPath(d->filename.absFileName());
|
||||
|
||||
ReadStatus const status = loadLyXFile(d->filename);
|
||||
ReadStatus const status = loadLyXFile();
|
||||
if (status == ReadSuccess) {
|
||||
updateBuffer();
|
||||
changed(true);
|
||||
|
19
src/Buffer.h
19
src/Buffer.h
@ -185,13 +185,13 @@ public:
|
||||
|
||||
/// \name Functions involved in reading files/strings.
|
||||
//@{
|
||||
/// Loads a LyX file \c fn into the buffer. This function
|
||||
/// Loads the LyX file into the buffer. This function
|
||||
/// tries to extract the file from version control if it
|
||||
/// cannot be found. If it can be found, it will try to
|
||||
/// read an emergency save file or an autosave file.
|
||||
/// \sa loadThisLyXFile
|
||||
ReadStatus loadLyXFile(support::FileName const & fn);
|
||||
/// Loads a LyX file \c fn into the buffer. If you want
|
||||
ReadStatus loadLyXFile();
|
||||
/// Loads the LyX file \c fn into the buffer. If you want
|
||||
/// to check for files in a version control container,
|
||||
/// emergency or autosave files, one should use \c loadLyXFile.
|
||||
/// /sa loadLyXFile
|
||||
@ -218,7 +218,7 @@ private:
|
||||
/// before reading if the file cannot be found. This is only
|
||||
/// implemented for RCS.
|
||||
/// \sa LyXVC::file_not_found_hook
|
||||
ReadStatus extractFromVC(support::FileName const & fn);
|
||||
ReadStatus extractFromVC();
|
||||
/// Reads the first tag of a LyX File and
|
||||
/// returns the file format number.
|
||||
ReadStatus parseLyXFormat(Lexer & lex, support::FileName const & fn,
|
||||
@ -250,18 +250,11 @@ public:
|
||||
|
||||
private:
|
||||
/// Try to load an autosave file associated to \c fn.
|
||||
ReadStatus loadAutosave(support::FileName const & fn);
|
||||
/// Get the filename of the autosave file associated with \c fn
|
||||
support::FileName getAutosaveFileNameFor(support::FileName const & fn)
|
||||
const;
|
||||
|
||||
ReadStatus loadAutosave();
|
||||
/// Try to load an emergency file associated to \c fn.
|
||||
ReadStatus loadEmergency(support::FileName const & fn);
|
||||
ReadStatus loadEmergency();
|
||||
/// Get the filename of the emergency file associated with the Buffer
|
||||
support::FileName getEmergencyFileName() const;
|
||||
/// Get the filename of the emergency file associated with \c fn
|
||||
support::FileName getEmergencyFileNameFor(support::FileName const & fn)
|
||||
const;
|
||||
//@}
|
||||
|
||||
public:
|
||||
|
@ -2511,8 +2511,8 @@ void BufferView::insertLyXFile(FileName const & fname)
|
||||
message(bformat(_("Inserting document %1$s..."), disp_fn));
|
||||
|
||||
docstring res;
|
||||
Buffer buf("", false);
|
||||
if (buf.loadLyXFile(filename) == Buffer::ReadSuccess) {
|
||||
Buffer buf(filename.absFileName(), false);
|
||||
if (buf.loadLyXFile() == Buffer::ReadSuccess) {
|
||||
ErrorList & el = buffer_.errorList("Parse");
|
||||
// Copy the inserted document error list into the current buffer one.
|
||||
el = buf.errorList("Parse");
|
||||
|
@ -496,7 +496,7 @@ bool LyX::loadFiles()
|
||||
continue;
|
||||
|
||||
Buffer * buf = pimpl_->buffer_list_.newBuffer(fname.absFileName(), false);
|
||||
if (buf->loadLyXFile(fname) == Buffer::ReadSuccess) {
|
||||
if (buf->loadLyXFile() == Buffer::ReadSuccess) {
|
||||
ErrorList const & el = buf->errorList("Parse");
|
||||
if (!el.empty())
|
||||
for_each(el.begin(), el.end(),
|
||||
|
@ -94,7 +94,7 @@ Buffer * checkAndLoadLyXFile(FileName const & filename, bool const acceptDirty)
|
||||
// Buffer creation is not possible.
|
||||
return 0;
|
||||
}
|
||||
if (b->loadLyXFile(filename) != Buffer::ReadSuccess) {
|
||||
if (b->loadLyXFile() != Buffer::ReadSuccess) {
|
||||
// do not save an emergency file when releasing the buffer
|
||||
b->markClean();
|
||||
theBufferList().release(b);
|
||||
@ -268,7 +268,7 @@ Buffer * loadIfNeeded(FileName const & fname)
|
||||
// Buffer creation is not possible.
|
||||
return 0;
|
||||
|
||||
if (buffer->loadLyXFile(fname) != Buffer::ReadSuccess) {
|
||||
if (buffer->loadLyXFile() != Buffer::ReadSuccess) {
|
||||
//close the buffer we just opened
|
||||
theBufferList().release(buffer);
|
||||
return 0;
|
||||
|
@ -440,7 +440,7 @@ Buffer * InsetInclude::loadIfNeeded() const
|
||||
// Buffer creation is not possible.
|
||||
return 0;
|
||||
|
||||
if (child->loadLyXFile(included_file) != Buffer::ReadSuccess) {
|
||||
if (child->loadLyXFile() != Buffer::ReadSuccess) {
|
||||
failedtoload_ = true;
|
||||
//close the buffer we just opened
|
||||
theBufferList().release(child);
|
||||
|
Loading…
Reference in New Issue
Block a user