]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
Remove the bogus fixme.
[lyx.git] / src / Buffer.cpp
index 7aa037a580107408d659cd31f0c7745c8bdc2ffb..04ac90c0f96d5f99543d14e0f56364653c95f268 100644 (file)
@@ -126,7 +126,7 @@ namespace {
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-int const LYX_FORMAT = 377; // uwestoehr: support for multirows
+int const LYX_FORMAT = 378; // ps: rev insetinfo
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
@@ -930,7 +930,7 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename,
                        << ' ' << quoteName(lyx2lyx.toFilesystemEncoding())
                        << " -t " << convert<string>(LYX_FORMAT)
                        << " -o " << quoteName(tmpfile.toFilesystemEncoding())
-                       << ' ' << quoteName(filename.toFilesystemEncoding());
+                       << ' ' << quoteName(filename.toSafeFilesystemEncoding());
                string const command_str = command.str();
 
                LYXERR(Debug::INFO, "Running '" << command_str << '\'');
@@ -977,8 +977,6 @@ bool Buffer::save() const
        // We don't need autosaves in the immediate future. (Asger)
        resetAutosaveTimers();
 
-       string const encodedFilename = d->filename.toFilesystemEncoding();
-
        FileName backupName;
        bool madeBackup = false;
 
@@ -1036,11 +1034,13 @@ bool Buffer::writeFile(FileName const & fname) const
                makeDisplayPath(fname.absFilename()));
        message(str);
 
+       string const encoded_fname = fname.toSafeFilesystemEncoding(os::CREATE);
+
        if (params().compressed) {
-               gz::ogzstream ofs(fname.toFilesystemEncoding().c_str(), ios::out|ios::trunc);
+               gz::ogzstream ofs(encoded_fname.c_str(), ios::out|ios::trunc);
                retval = ofs && write(ofs);
        } else {
-               ofstream ofs(fname.toFilesystemEncoding().c_str(), ios::out|ios::trunc);
+               ofstream ofs(encoded_fname.c_str(), ios::out|ios::trunc);
                retval = ofs && write(ofs);
        }
 
@@ -1309,13 +1309,40 @@ void Buffer::writeLaTeXSource(odocstream & os,
                        // FIXME UNICODE
                        // We don't know the encoding of inputpath
                        docstring const inputpath = from_utf8(latex_path(original_path));
-                       os << "\\makeatletter\n"
-                          << "\\def\\input@path{{"
-                          << inputpath << "/}}\n"
-                          << "\\makeatother\n";
-                       d->texrow.newline();
-                       d->texrow.newline();
-                       d->texrow.newline();
+                       docstring uncodable_glyphs;
+                       Encoding const * const enc = runparams.encoding;
+                       if (enc) {
+                               for (size_t n = 0; n < inputpath.size(); ++n) {
+                                       docstring const glyph =
+                                               docstring(1, inputpath[n]);
+                                       if (enc->latexChar(inputpath[n], true) != glyph) {
+                                               LYXERR0("Uncodable character '"
+                                                       << glyph
+                                                       << "' in input path!");
+                                               uncodable_glyphs += glyph;
+                                       }
+                               }
+                       }
+
+                       // warn user if we found uncodable glyphs.
+                       if (!uncodable_glyphs.empty()) {
+                               frontend::Alert::warning(_("Uncodable character in path"),
+                                               support::bformat(_("The path of your document\n"
+                                                 "(%1$s)\n"
+                                                 "contains glyphs that are unknown in the\n"
+                                                 "current document encoding (namely %2$s).\n"
+                                                 "This will likely result in incomplete output.\n\n"
+                                                 "Chose an appropriate document encoding (such as utf8)\n"
+                                                 "or change the path name."), inputpath, uncodable_glyphs));
+                       } else {
+                               os << "\\makeatletter\n"
+                                  << "\\def\\input@path{{"
+                                  << inputpath << "/}}\n"
+                                  << "\\makeatother\n";
+                               d->texrow.newline();
+                               d->texrow.newline();
+                               d->texrow.newline();
+                       }
                }
 
                // get parent macros (if this buffer has a parent) which will be
@@ -1866,7 +1893,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
 
        case LFUN_BUFFER_EXPORT: {
                bool success = doExport(argument, false, false);
-               dr.setError(success);
+               dr.setError(!success);
                if (!success)
                        dr.setMessage(bformat(_("Error exporting to format: %1$s."), 
                                              func.argument()));
@@ -3122,8 +3149,10 @@ void Buffer::removeAutosaveFile() const
 void Buffer::moveAutosaveFile(support::FileName const & oldauto) const
 {
        FileName const newauto = getAutosaveFilename();
-       if (!(oldauto == newauto || oldauto.moveTo(newauto)))
-               LYXERR0("Unable to remove autosave file `" << oldauto << "'!");
+       oldauto.refresh();
+       if (newauto != oldauto && oldauto.exists())
+               if (!oldauto.moveTo(newauto))
+                       LYXERR0("Unable to move autosave file `" << oldauto << "'!");
 }
 
 
@@ -3494,7 +3523,7 @@ bool Buffer::loadLyXFile(FileName const & s)
                // InsetInfo needs to know if file is under VCS
                lyxvc().file_found_hook(s);
                if (readFileHelper(s)) {
-                       setReadonly(!s.isWritable());
+                       d->read_only = !s.isWritable();
                        return true;
                }
        }