X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FExporter.cpp;h=a5a153aacdd7e0c069d5c3c279a2a1e5f0b8987c;hb=66ca99798bff016b0a60cb10bd2124c5c228c8b6;hp=766cb6d7bd35c99d795119001428c9ce091e3f3d;hpb=8de36d389b8e668dcfa68e54a9b2e2ee2ca105dd;p=lyx.git diff --git a/src/Exporter.cpp b/src/Exporter.cpp index 766cb6d7bd..a5a153aacd 100644 --- a/src/Exporter.cpp +++ b/src/Exporter.cpp @@ -36,34 +36,19 @@ namespace lyx { namespace Alert = frontend::Alert; -/// Ask the user what to do if the destination file already exists -/// and is different from the source file. -static int checkOverwrite(FileName const & src_file, FileName const & dst_file) +/// Ask the user what to do if a file already exists +static int checkOverwrite(FileName const & filename) { - if (!dst_file.exists()) - return 0; - - if (src_file.checksum() == dst_file.checksum()) - return -1; + if (!filename.exists()) + return 1; docstring text = bformat(_("The file %1$s already exists.\n\n" "Do you want to overwrite that file?"), - makeDisplayPath(dst_file.absFilename())); - int choice = Alert::prompt(_("Overwrite file?"), - text, 0, 2, + makeDisplayPath(filename.absFileName())); + return Alert::prompt(_("Overwrite file?"), + text, 0, 3, _("&Keep file"), _("&Overwrite"), - _("&Cancel export")); - - if (choice == 0) - return -1; - - if (choice == 1) { - text = _("Should I continue asking for overwriting files?"); - return Alert::prompt(_("Overwrite all files?"), - text, 0, 0, - _("Continue &asking"), _("&Overwrite all")); - } - return choice; + _("Overwrite &all"), _("&Cancel export")); } @@ -85,17 +70,20 @@ CopyStatus copyFile(string const & format, // overwrite themselves. This check could be changed to // boost::filesystem::equivalent(sourceFile, destFile) if export to // other directories than the document directory is desired. - if (!prefixIs(onlyPath(sourceFile.absFilename()), package().temp_dir().absFilename())) + // Also don't overwrite files that already exist and are identical + // to the source files. + if (!prefixIs(onlyPath(sourceFile.absFileName()), package().temp_dir().absFileName()) + || sourceFile.checksum() == destFile.checksum()) return ret; if (!force) { - switch(checkOverwrite(sourceFile, destFile)) { - case -1: - return SUCCESS; + switch(checkOverwrite(destFile)) { case 0: + return SUCCESS; + case 1: ret = SUCCESS; break; - case 1: + case 2: ret = FORCE; break; default: @@ -107,8 +95,8 @@ CopyStatus copyFile(string const & format, if (!mover.copy(sourceFile, destFile, latexFile)) Alert::error(_("Couldn't copy file"), bformat(_("Copying %1$s to %2$s failed."), - makeDisplayPath(sourceFile.absFilename()), - makeDisplayPath(destFile.absFilename()))); + makeDisplayPath(sourceFile.absFileName()), + makeDisplayPath(destFile.absFileName()))); return ret; } @@ -143,7 +131,7 @@ void ExportData::addExternalFile(string const & format, void ExportData::addExternalFile(string const & format, FileName const & sourceName) { - addExternalFile(format, sourceName, onlyFilename(sourceName.absFilename())); + addExternalFile(format, sourceName, onlyFileName(sourceName.absFileName())); }