#include "LaTeX.h"
#include "Layout.h"
#include "LyX.h"
+#include "LyXVC.h"
#include "TextClass.h"
#include "Paragraph.h"
#include "ParagraphList.h"
#include "support/filetools.h"
#include "support/gettext.h"
#include "support/lstrings.h"
+#include "support/mutex.h"
#include "support/textutils.h"
using namespace std;
docstring const text = bformat(_(
"The document %1$s is already loaded and has unsaved changes.\n"
"Do you want to abandon your changes and reload the version on disk?"), file);
- if (!Alert::prompt(_("Reload saved document?"),
- text, 0, 1, _("&Reload"), _("&Keep Changes"))) {
- // reload the document
- if (checkBuffer->reload() != Buffer::ReadSuccess)
+ int res = Alert::prompt(_("Reload saved document?"),
+ text, 2, 2, _("Yes, &Reload"), _("No, &Keep Changes"), _("&Cancel"));
+ switch (res) {
+ case 0: {
+ // reload the document
+ if (checkBuffer->reload() != Buffer::ReadSuccess)
+ return 0;
+ return checkBuffer;
+ }
+ case 1:
+ // keep changes
+ return checkBuffer;
+ case 2:
+ // cancel
return 0;
}
- return checkBuffer;
}
- if (filename.exists()) {
- if (!filename.isReadableFile()) {
- docstring text = bformat(_("The file %1$s exists but is not "
- "readable by the current user."),
- from_utf8(filename.absFileName()));
- Alert::error(_("File not readable!"), text);
- return 0;
+ bool const exists = filename.exists();
+ bool const tryVC = exists ? false : LyXVC::fileInVC(filename);
+ if (exists || tryVC) {
+ if (exists) {
+ if (!filename.isReadableFile()) {
+ docstring text = bformat(_("The file %1$s exists but is not "
+ "readable by the current user."),
+ from_utf8(filename.absFileName()));
+ Alert::error(_("File not readable!"), text);
+ return 0;
+ }
+ if (filename.extension() == "lyx" && filename.isFileEmpty()) {
+ // Makes it possible to open an empty (0 bytes) .lyx file
+ return newFile(filename.absFileName(), "", true);
+ }
}
Buffer * b = theBufferList().newBuffer(filename.absFileName());
if (!b) {
string const & templatename)
{
static map<string, int> file_number;
+ static Mutex mutex;
+ Mutex::Locker locker(&mutex);
FileName filename;
do {
- filename.set(path,
+ filename.set(path,
prefix + convert<string>(++file_number[prefix]) + ".lyx");
}
while (theBufferList().exists(filename) || filename.isReadableFile());
-
+
return newFile(filename.absFileName(), templatename, false);
}
{
Buffer * buffer = theBufferList().getBuffer(fname);
if (!buffer) {
- if (!fname.exists())
+ if (!fname.exists() && !LyXVC::fileInVC(fname))
return 0;
buffer = theBufferList().newBuffer(fname.absFileName());