From: Richard Heck Date: Mon, 25 Oct 2010 12:24:15 +0000 (+0000) Subject: Return early again if there's nothing to do. Also, mark the buffer dirty X-Git-Tag: 2.0.0~2261 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=5cd48620f104b15540d83f674b82cf755271a62e;p=features.git Return early again if there's nothing to do. Also, mark the buffer dirty only if we manage to read the autosave file successfully. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35824 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 2b886bebca..3f2bbe5706 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -3661,31 +3661,36 @@ Buffer::ReadStatus Buffer::readAutosave(FileName const & fn) // Now check if autosave file is newer. FileName const autosaveFile(onlyPath(fn.absFileName()) + '#' + onlyFileName(fn.absFileName()) + '#'); - if (autosaveFile.exists() - && autosaveFile.lastModified() > fn.lastModified()) { - docstring const file = makeDisplayPath(fn.absFileName(), 20); - docstring const text = - bformat(_("The backup of the document " - "%1$s is newer.\n\nLoad the " - "backup instead?"), file); - switch (Alert::prompt(_("Load backup?"), text, 0, 2, - _("&Load backup"), _("Load &original"), - _("&Cancel") )) - { - case 0: - // the file is not saved if we load the autosave file. + if (!autosaveFile.exists() + || autosaveFile.lastModified() <= fn.lastModified()) + return ReadFileNotFound; + + docstring const file = makeDisplayPath(fn.absFileName(), 20); + docstring const text = + bformat(_("The backup of the document %1$s is newer.\n\n" + "Load the backup instead?"), file); + switch (Alert::prompt(_("Load backup?"), text, 0, 2, + _("&Load backup"), _("Load &original"), + _("&Cancel") )) + { + case 0: { + bool success = readFile(autosaveFile); + // the file is not saved if we load the autosave file. + if (success) { markDirty(); - return readFile(autosaveFile) ? ReadSuccess - : ReadAutosaveFailure; - case 1: - // Here we delete the autosave - autosaveFile.removeFile(); - return ReadOriginal; - default: - return ReadCancel; + return ReadSuccess; } + return ReadAutosaveFailure; } - return ReadFileNotFound; + case 1: + // Here we delete the autosave + autosaveFile.removeFile(); + return ReadOriginal; + default: + return ReadCancel; + } + // suppress warning + return ReadCancel; }