- // 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);
-#if USE_BOOST_FORMAT
- boost::format fmt(_("The document %1$s is already loaded.\n\nDo you want to revert to the saved version?"));
- fmt % file;
- string text = fmt.str();
-#else
- string text = _("The document ");
- text += file + _(" is already loaded.\n\nDo you want to revert to the saved version?");
-#endif
- int const ret = Alert::prompt(_("Revert to saved document?"),
- text, 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)) {
-#if USE_BOOST_FORMAT
- boost::format fmt(_("Do you want to retrieve the document %1$s from version control?"));
- fmt % file;
- string text = fmt.str();
-#else
- string text = _("Do you want to retrieve the document ");
- text += file + _(" from version control?");
-#endif
- int const ret = Alert::prompt(_("Retrieve from version control?"),
- text, 0, _("&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);
- }
- }
-
-#if USE_BOOST_FORMAT
- boost::format fmt(_("The document %1$s does not yet exist. Do you want to create a new document?"));
- fmt % file;
- string text = fmt.str();
-#else
- string text = _("The document ");
- text += file + _(" does not yet exist. Do you want to create a new document?");
-#endif
- int const ret = Alert::prompt(_("Create new document?"),
- text, 0, _("&Create"), _("Cancel"));
-
- if (ret == 0)
- b = newFile(s, string(), true);
-
- break;
- }
- }
-
- if (b && tolastfiles)
- lastfiles->newFile(b->fileName());
-
- return b;