- // get absolute path of file and add ".lyx" to the filename if
- // necessary
- string s = FileSearch(string(), filename, "lyx");
- if (s.empty()) {
- s = filename;
- }
-
- // file already open?
- if (exists(s)) {
- string const file = MakeDisplayPath(s, 20);
- string text = bformat(_("The document %1$s is already loaded.\n\n"
- "Do you want to revert to the saved version?"), file);
- int const ret = Alert::prompt(_("Revert to saved document?"),
- text, 0, 1, _("&Revert"), _("&Switch to document"));
-
- if (ret == 0) {
- // FIXME: should be LFUN_REVERT
- if (!close(getBuffer(s), false)) {
- return 0;
- }
- // Fall through to new load. (Asger)
- } else {
- // Here, we pretend that we just loaded the
- // open document
- return getBuffer(s);
- }
- }
-
- Buffer * b = 0;
- bool ro = false;
- switch (IsFileWriteable(s)) {
- case 0:
- ro = true;
- // Fall through
- case 1:
- b = readFile(s, ro);
- if (b) {
- b->lyxvc.file_found_hook(s);
- }
- break; //fine- it's r/w
- case -1: {
- string const file = MakeDisplayPath(s, 20);
- // Here we probably should run
- if (LyXVC::file_not_found_hook(s)) {
- string text = bformat(_("Do you want to retrieve the document"
- " %1$s from version control?"), file);
- int const ret = Alert::prompt(_("Retrieve from version control?"),
- text, 0, 1, _("&Retrieve"), _("&Cancel"));
-
- if (ret == 0) {
- // How can we know _how_ to do the checkout?
- // With the current VC support it has to be,
- // a RCS file since CVS do not have special ,v files.
- RCS::retrieve(s);
- return loadLyXFile(filename, tolastfiles);
- }
- }
-
- string text = bformat(_("The document %1$s does not yet exist.\n\n"
- "Do you want to create a new document?"), file);
- int const ret = Alert::prompt(_("Create new document?"),
- text, 0, 1, _("&Create"), _("Cancel"));
-
- if (ret == 0)
- b = newFile(s, string(), true);
-
- break;
- }
- }
-
- if (b && tolastfiles)
- lastfiles->newFile(b->fileName());
-
- return b;