]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
* output_plaintext.C: cosmetics in comment: line length cannot be < 0
[lyx.git] / src / buffer.C
index 1fe5db90ffdd672512fec7fdc4d8c290111a6e43..b6f6f67c1ed82ed01762c6a780a2fb68ae2f1305 100644 (file)
@@ -199,8 +199,8 @@ public:
 
 Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_)
        : lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_),
-         filename(file), file_fully_loaded(false), inset(params),
-         toc_backend(&parent), messages(0)
+         filename(file), messages(0), file_fully_loaded(false), inset(params),
+         toc_backend(&parent)
 {
        inset.setAutoBreakRows(true);
        lyxvc.buffer(&parent);
@@ -752,41 +752,40 @@ bool Buffer::save() const
        // We don't need autosaves in the immediate future. (Asger)
        resetAutosaveTimers();
 
+       string const encodedFilename = pimpl_->filename.toFilesystemEncoding();
+
+       FileName backupName;
+       bool madeBackup = false;
+
        // make a backup if the file already exists
-       string s;
-       if (lyxrc.make_backup && fs::exists(pimpl_->filename.toFilesystemEncoding())) {
-               s = fileName() + '~';
+       if (lyxrc.make_backup && fs::exists(encodedFilename)) {
+               backupName = FileName(fileName() + '~');
                if (!lyxrc.backupdir_path.empty())
-                       s = addName(lyxrc.backupdir_path,
-                                   subst(os::internal_path(s),'/','!'));
+                       backupName = FileName(addName(lyxrc.backupdir_path,
+                                             subst(os::internal_path(backupName.absFilename()), '/', '!')));
 
-               // It might very well be that this variant is just
-               // good enough. (Lgb)
-               // But to use this we need fs::copy_file to actually do a copy,
-               // even when the target file exists. (Lgb)
                try {
-                   fs::copy_file(pimpl_->filename.toFilesystemEncoding(), s, false);
-               }
-               catch (fs::filesystem_error const & fe) {
+                       fs::copy_file(encodedFilename, backupName.toFilesystemEncoding(), false);
+                       madeBackup = true;
+               catch (fs::filesystem_error const & fe) {
                        Alert::error(_("Backup failure"),
-                                    bformat(_("LyX was not able to make a backup copy in %1$s.\n"
-                                                           "Please check if the directory exists and is writeable."),
-                                         from_utf8(fs::path(s).branch_path().native_directory_string())));
-                       lyxerr[Debug::DEBUG] << "Fs error: "
-                                            << fe.what() << endl;
+                                    bformat(_("Cannot create backup file %1$s.\n"
+                                              "Please check whether the directory exists and is writeable."),
+                                            from_utf8(backupName.absFilename())));
+                       lyxerr[Debug::DEBUG] << "Fs error: " << fe.what() << endl;
                }
        }
 
        if (writeFile(pimpl_->filename)) {
                markClean();
                removeAutosaveFile(fileName());
+               return true;
        } else {
                // Saving failed, so backup is not backup
-               if (lyxrc.make_backup)
-                       rename(FileName(s), pimpl_->filename);
+               if (madeBackup)
+                       rename(backupName, pimpl_->filename);
                return false;
        }
-       return true;
 }
 
 
@@ -1473,18 +1472,6 @@ docstring const Buffer::B_(string const & l10n) const
 }
 
 
-docstring const Buffer::translateLabel(docstring const & label) const
-{
-       if (support::isAscii(label))
-               // Probably standard layout, try to translate
-               return B_(to_ascii(label));
-       else
-               // This must be a user defined layout. We cannot translate
-               // this, since gettext accepts only ascii keys.
-               return label;
-}
-
-
 bool Buffer::isClean() const
 {
        return pimpl_->lyx_clean;
@@ -1685,7 +1672,7 @@ void Buffer::getSourceCode(odocstream & os, pit_type par_begin,
        OutputParams runparams;
        runparams.nice = true;
        runparams.flavor = OutputParams::LATEX;
-       runparams.linelen = lyxrc.ascii_linelen;
+       runparams.linelen = lyxrc.plaintext_linelen;
        // No side effect of file copying and image conversion
        runparams.dryrun = true;