]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
*doxy
[lyx.git] / src / Buffer.cpp
index ce230e6360ff60046c4d505efebda80aadc921d0..9f8a9336d099394a5612c5472369f760b8e53070 100644 (file)
 #include "support/textutils.h"
 #include "support/types.h"
 
-#include <boost/bind.hpp>
-#include <boost/shared_ptr.hpp>
+#include "support/bind.h"
+#include "support/shared_ptr.h"
 
 #include <algorithm>
 #include <fstream>
@@ -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 = 378; // ps: rev insetinfo
+int const LYX_FORMAT = 388; // uwestoehr: support for more page sizes
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
@@ -302,13 +302,13 @@ static FileName createBufferTmpDir()
        // We are in our own directory.  Why bother to mangle name?
        // In fact I wrote this code to circumvent a problematic behaviour
        // (bug?) of EMX mkstemp().
-       FileName tmpfl(package().temp_dir().absFilename() + "/lyx_tmpbuf" +
+       FileName tmpfl(package().temp_dir().absFileName() + "/lyx_tmpbuf" +
                convert<string>(count++));
 
        if (!tmpfl.createDirectory(0777)) {
                throw ExceptionMessage(WarningException, _("Disk Error: "), bformat(
                        _("LyX could not create the temporary directory '%1$s' (Disk is full maybe?)"),
-                       from_utf8(tmpfl.absFilename())));
+                       from_utf8(tmpfl.absFileName())));
        }
        return tmpfl;
 }
@@ -399,7 +399,7 @@ Buffer::~Buffer()
        if (!d->cloned_buffer_ && !d->temppath.destroyDirectory()) {
                Alert::warning(_("Could not remove temporary directory"),
                        bformat(_("Could not remove the temporary directory %1$s"),
-                       from_utf8(d->temppath.absFilename())));
+                       from_utf8(d->temppath.absFileName())));
        }
 
        // Remove any previewed LaTeX snippets associated with this buffer.
@@ -411,7 +411,7 @@ Buffer::~Buffer()
 
 Buffer * Buffer::clone() const
 {
-       Buffer * buffer_clone = new Buffer(fileName().absFilename(), false, this);
+       Buffer * buffer_clone = new Buffer(fileName().absFileName(), false, this);
        buffer_clone->d->macro_lock = true;
        buffer_clone->d->children_positions.clear();
        // FIXME (Abdel 09/01/2010): this is too complicated. The whole children_positions and
@@ -507,7 +507,7 @@ LyXVC const & Buffer::lyxvc() const
 
 string const Buffer::temppath() const
 {
-       return d->temppath.absFilename();
+       return d->temppath.absFileName();
 }
 
 
@@ -546,20 +546,20 @@ string Buffer::latexName(bool const no_path) const
        FileName latex_name =
                makeLatexName(d->exportFileName());
        return no_path ? latex_name.onlyFileName()
-               : latex_name.absFilename();
+               : latex_name.absFileName();
 }
 
 
 FileName Buffer::Impl::exportFileName() const
 {
        docstring const branch_suffix =
-               params.branchlist().getFilenameSuffix();
+               params.branchlist().getFileNameSuffix();
        if (branch_suffix.empty())
                return filename;
 
        string const name = filename.onlyFileNameWithoutExt()
                + to_utf8(branch_suffix);
-       FileName res(filename.onlyPath().absFilename() + "/" + name);
+       FileName res(filename.onlyPath().absFileName() + "/" + name);
        res.changeExtension(filename.extension());
 
        return res;
@@ -579,12 +579,12 @@ string Buffer::logName(LogType * type) const
        string const path = temppath();
 
        FileName const fname(addName(temppath(),
-                                    onlyFilename(changeExtension(filename,
+                                    onlyFileName(changeExtension(filename,
                                                                  ".log"))));
 
        // FIXME: how do we know this is the name of the build log?
        FileName const bname(
-               addName(path, onlyFilename(
+               addName(path, onlyFileName(
                        changeExtension(filename,
                                        formats.extension(bufferFormat()) + ".out"))));
 
@@ -604,7 +604,7 @@ string Buffer::logName(LogType * type) const
                LYXERR(Debug::FILES, "Log name calculated as: " << bname);
                if (type)
                        *type = buildlog;
-               return bname.absFilename();
+               return bname.absFileName();
        // If we have a newer master file log or only a master log, show this
        } else if (fname != masterfname
                   && (!fname.exists() && (masterfname.exists()
@@ -612,12 +612,12 @@ string Buffer::logName(LogType * type) const
                LYXERR(Debug::FILES, "Log name calculated as: " << masterfname);
                if (type)
                        *type = mtype;
-               return masterfname.absFilename();
+               return masterfname.absFileName();
        }
        LYXERR(Debug::FILES, "Log name calculated as: " << fname);
        if (type)
                        *type = latexlog;
-       return fname.absFilename();
+       return fname.absFileName();
 }
 
 
@@ -668,6 +668,11 @@ int Buffer::readHeader(Lexer & lex)
        params().pdfoptions().clear();
        params().indiceslist().clear();
        params().backgroundcolor = lyx::rgbFromHexName("#ffffff");
+       params().isbackgroundcolor = false;
+       params().fontcolor = lyx::rgbFromHexName("#000000");
+       params().isfontcolor = false;
+       params().notefontcolor = lyx::rgbFromHexName("#cccccc");
+       params().boxbgcolor = lyx::rgbFromHexName("#ff0000");
 
        for (int i = 0; i < 4; ++i) {
                params().user_defined_bullet(i) = ITEMIZE_DEFAULTS[i];
@@ -766,7 +771,7 @@ bool Buffer::readDocument(Lexer & lex)
        if (!params().master.empty()) {
                FileName const master_file = makeAbsPath(params().master,
                           onlyPath(absFileName()));
-               if (isLyXFilename(master_file.absFilename())) {
+               if (isLyXFileName(master_file.absFileName())) {
                        Buffer * master = 
                                checkAndLoadLyXFile(master_file, true);
                        if (master) {
@@ -872,7 +877,7 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename,
        if (!lex.checkFor("\\lyxformat")) {
                Alert::error(_("Document format failure"),
                             bformat(_("%1$s is not a readable LyX document."),
-                                      from_utf8(filename.absFilename())));
+                                      from_utf8(filename.absFileName())));
                return failure;
        }
 
@@ -894,7 +899,7 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename,
                // Save the timestamp and checksum of disk file. If filename is an
                // emergency file, save the timestamp and checksum of the original lyx file
                // because isExternallyModified will check for this file. (BUG4193)
-               string diskfile = filename.absFilename();
+               string diskfile = filename.absFileName();
                if (suffixIs(diskfile, ".emergency"))
                        diskfile = diskfile.substr(0, diskfile.size() - 10);
                saveCheckSum(FileName(diskfile));
@@ -913,7 +918,7 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename,
                                              " version of LyX, but a temporary"
                                              " file for converting it could"
                                              " not be created."),
-                                             from_utf8(filename.absFilename())));
+                                             from_utf8(filename.absFileName())));
                        return failure;
                }
                FileName const lyx2lyx = libFileSearch("lyx2lyx", "lyx2lyx");
@@ -923,7 +928,7 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename,
                                               " version of LyX, but the"
                                               " conversion script lyx2lyx"
                                               " could not be found."),
-                                              from_utf8(filename.absFilename())));
+                                              from_utf8(filename.absFileName())));
                        return failure;
                }
                ostringstream command;
@@ -943,13 +948,13 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename,
                                     bformat(_("%1$s is from an older version"
                                              " of LyX, but the lyx2lyx script"
                                              " failed to convert it."),
-                                             from_utf8(filename.absFilename())));
+                                             from_utf8(filename.absFileName())));
                        else
                                Alert::error(_("Conversion script failed"),
                                     bformat(_("%1$s is from a newer version"
                                              " of LyX and cannot be converted by the"
                                                                " lyx2lyx script."),
-                                             from_utf8(filename.absFilename())));
+                                             from_utf8(filename.absFileName())));
                        return failure;
                } else {
                        bool const ret = readFile(tmpfile);
@@ -963,7 +968,7 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename,
                Alert::error(_("Document format failure"),
                             bformat(_("%1$s ended unexpectedly, which means"
                                                    " that it is probably corrupted."),
-                                      from_utf8(filename.absFilename())));
+                                      from_utf8(filename.absFileName())));
                return failure;
        }
 
@@ -975,6 +980,17 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename,
 // Should probably be moved to somewhere else: BufferView? GuiView?
 bool Buffer::save() const
 {
+       // ask if the disk file has been externally modified (use checksum method)
+       if (fileName().exists() && isExternallyModified(checksum_method)) {
+               docstring const file = makeDisplayPath(absFileName(), 20);
+               docstring text = bformat(_("Document %1$s has been externally modified. Are you sure "
+                                                            "you want to overwrite this file?"), file);
+               int const ret = Alert::prompt(_("Overwrite modified file?"),
+                       text, 1, 1, _("&Overwrite"), _("&Cancel"));
+               if (ret == 1)
+                       return false;
+       }
+
        // We don't need autosaves in the immediate future. (Asger)
        resetAutosaveTimers();
 
@@ -986,32 +1002,22 @@ bool Buffer::save() const
                backupName = FileName(absFileName() + '~');
                if (!lyxrc.backupdir_path.empty()) {
                        string const mangledName =
-                               subst(subst(backupName.absFilename(), '/', '!'), ':', '!');
+                               subst(subst(backupName.absFileName(), '/', '!'), ':', '!');
                        backupName = FileName(addName(lyxrc.backupdir_path,
                                                      mangledName));
                }
-               if (fileName().copyTo(backupName)) {
+               // do not copy because of #6587
+               if (fileName().moveTo(backupName)) {
                        madeBackup = true;
                } else {
                        Alert::error(_("Backup failure"),
                                     bformat(_("Cannot create backup file %1$s.\n"
                                               "Please check whether the directory exists and is writeable."),
-                                            from_utf8(backupName.absFilename())));
+                                            from_utf8(backupName.absFileName())));
                        //LYXERR(Debug::DEBUG, "Fs error: " << fe.what());
                }
        }
 
-       // ask if the disk file has been externally modified (use checksum method)
-       if (fileName().exists() && isExternallyModified(checksum_method)) {
-               docstring const file = makeDisplayPath(absFileName(), 20);
-               docstring text = bformat(_("Document %1$s has been externally modified. Are you sure "
-                                                            "you want to overwrite this file?"), file);
-               int const ret = Alert::prompt(_("Overwrite modified file?"),
-                       text, 1, 1, _("&Overwrite"), _("&Cancel"));
-               if (ret == 1)
-                       return false;
-       }
-
        if (writeFile(d->filename)) {
                markClean();
                return true;
@@ -1032,7 +1038,7 @@ bool Buffer::writeFile(FileName const & fname) const
        bool retval = false;
 
        docstring const str = bformat(_("Saving document %1$s..."),
-               makeDisplayPath(fname.absFilename()));
+               makeDisplayPath(fname.absFileName()));
        message(str);
 
        string const encoded_fname = fname.toSafeFilesystemEncoding(os::CREATE);
@@ -1050,7 +1056,8 @@ bool Buffer::writeFile(FileName const & fname) const
                return false;
        }
 
-       removeAutosaveFile();
+       // see bug 6587
+       // removeAutosaveFile();
 
        saveCheckSum(d->filename);
        message(str + _(" done."));
@@ -1065,7 +1072,7 @@ docstring Buffer::emergencyWrite()
        if (isClean())
                return docstring();
 
-       string const doc = isUnnamed() ? onlyFilename(absFileName()) : absFileName();
+       string const doc = isUnnamed() ? onlyFileName(absFileName()) : absFileName();
 
        docstring user_message = bformat(
                _("LyX: Attempting to save document %1$s\n"), from_utf8(doc));
@@ -1086,7 +1093,7 @@ docstring Buffer::emergencyWrite()
        }
 
        // 2) In HOME directory.
-       string s = addName(package().home_dir().absFilename(), absFileName());
+       string s = addName(package().home_dir().absFileName(), absFileName());
        s += ".emergency";
        lyxerr << ' ' << s << endl;
        if (writeFile(FileName(s))) {
@@ -1100,7 +1107,7 @@ docstring Buffer::emergencyWrite()
        // 3) In "/tmp" directory.
        // MakeAbsPath to prepend the current
        // drive letter on OS/2
-       s = addName(package().temp_dir().absFilename(), absFileName());
+       s = addName(package().temp_dir().absFileName(), absFileName());
        s += ".emergency";
        lyxerr << ' ' << s << endl;
        if (writeFile(FileName(s))) {
@@ -1411,6 +1418,12 @@ void Buffer::writeLaTeXSource(odocstream & os,
        // Just to be sure. (Asger)
        d->texrow.newline();
 
+       //for (int i = 0; i<d->texrow.rows(); i++) {
+       // int id,pos;
+       // if (d->texrow.getIdFromRow(i+1,id,pos) && id>0)
+       //      lyxerr << i+1 << ":" << id << ":" << getParFromID(id).paragraph().asString()<<"\n";
+       //}
+
        LYXERR(Debug::INFO, "Finished making LaTeX file.");
        LYXERR(Debug::INFO, "Row count was " << d->texrow.rows() - 1 << '.');
 }
@@ -1444,7 +1457,7 @@ void Buffer::makeDocBookFile(FileName const & fname,
        if (!openFileWrite(ofs, fname))
                return;
 
-       writeDocBookSource(ofs, fname.absFilename(), runparams, body_only);
+       writeDocBookSource(ofs, fname.absFileName(), runparams, body_only);
 
        ofs.close();
        if (ofs.fail())
@@ -1558,19 +1571,24 @@ void Buffer::writeLyXHTMLSource(odocstream & os,
        updateMacroInstances();
 
        if (!only_body) {
-               os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
-               os << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN\" \"http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd\">\n";
-               // FIXME Language should be set properly.
-               os << "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
-               os << "<head>\n";
-               // FIXME Presumably need to set this right
-               os << "<meta http-equiv=\"Content-type\" content=\"text/html;charset=UTF-8\" />\n";
-               os << "<title>" << features.htmlTitle() << "</title>\n";
+               os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+                  << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN\" \"http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd\">\n"
+                  // FIXME Language should be set properly.
+                  << "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
+                  << "<head>\n"
+                  << "<meta name=\"GENERATOR\" content=\"" << PACKAGE_STRING << "\" />\n"
+                  // FIXME Presumably need to set this right
+                  << "<meta http-equiv=\"Content-type\" content=\"text/html;charset=UTF-8\" />\n";
+
+               docstring const & doctitle = features.htmlTitle();
+               os << "<title>"
+                  << (doctitle.empty() ? from_ascii("LyX Document") : doctitle)
+                  << "</title>\n";
 
                os << "\n<!-- Text Class Preamble -->\n"
-                       << features.getTClassHTMLPreamble()
-                       << "\n<!-- Premable Snippets -->\n"
-                       << from_utf8(features.getPreambleSnippets());
+                  << features.getTClassHTMLPreamble()
+                  << "\n<!-- Premable Snippets -->\n"
+                  << from_utf8(features.getPreambleSnippets());
 
                os << "\n<!-- Layout-provided Styles -->\n";
                docstring const styleinfo = features.getTClassHTMLStyles();
@@ -1598,7 +1616,7 @@ int Buffer::runChktex()
 
        // get LaTeX-Filename
        FileName const path(temppath());
-       string const name = addName(path.absFilename(), latexName());
+       string const name = addName(path.absFileName(), latexName());
        string const org_path = filePath();
 
        PathChanger p(path); // path to LaTeX file
@@ -1612,7 +1630,7 @@ int Buffer::runChktex()
        makeLaTeXFile(FileName(name), org_path, runparams);
 
        TeXErrors terr;
-       Chktex chktex(lyxrc.chktex_command, onlyFilename(name), filePath());
+       Chktex chktex(lyxrc.chktex_command, onlyFileName(name), filePath());
        int const res = chktex.run(terr); // run chktex
 
        if (res == -1) {
@@ -1639,7 +1657,7 @@ void Buffer::validate(LaTeXFeatures & features) const
        updateMacros();
 
        for_each(paragraphs().begin(), paragraphs().end(),
-                boost::bind(&Paragraph::validate, _1, boost::ref(features)));
+                bind(&Paragraph::validate, _1, boost::ref(features)));
 
        if (lyxerr.debugging(Debug::LATEX)) {
                features.showStruct();
@@ -1804,7 +1822,7 @@ bool Buffer::getStatus(FuncRequest const & cmd, FuncStatus & flag)
 
        bool enable = true;
 
-       switch (cmd.action) {
+       switch (cmd.action()) {
 
                case LFUN_BUFFER_TOGGLE_READ_ONLY:
                        flag.setOnOff(isReadonly());
@@ -1876,7 +1894,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
 {
        if (isInternal()) {
                // FIXME? if there is an Buffer LFUN that can be dispatched even
-               // if internal, put a switch '(cmd.action)' here.
+               // if internal, put a switch '(cmd.action())' here.
                dr.dispatched(false);
                return;
        }
@@ -1885,7 +1903,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
        bool dispatched = true;
        undo().beginUndoGroup();
 
-       switch (func.action) {
+       switch (func.action()) {
        case LFUN_BUFFER_TOGGLE_READ_ONLY:
                if (lyxvc().inUse())
                        lyxvc().toggleReadOnly();
@@ -2003,7 +2021,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
                                bformat(_("Branch \"%1$s\" does not exist."), branchName);
                        dr.setMessage(msg);
                } else {
-                       branch->setSelected(func.action == LFUN_BRANCH_ACTIVATE);
+                       branch->setSelected(func.action() == LFUN_BRANCH_ACTIVATE);
                        dr.setError(false);
                        dr.update(Update::Force);
                }
@@ -2138,7 +2156,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
                                docstring text = bformat(
                                        _("The file %1$s already exists.\n\n"
                                          "Do you want to overwrite that file?"),
-                                       makeDisplayPath(filename.absFilename()));
+                                       makeDisplayPath(filename.absFileName()));
                                if (Alert::prompt(_("Overwrite file?"),
                                                  text, 0, 1, _("&Overwrite"), _("&Cancel")) != 0)
                                        break;
@@ -2374,13 +2392,13 @@ FileName Buffer::fileName() const
 
 string Buffer::absFileName() const
 {
-       return d->filename.absFilename();
+       return d->filename.absFileName();
 }
 
 
 string Buffer::filePath() const
 {
-       return d->filename.onlyPath().absFilename() + "/";
+       return d->filename.onlyPath().absFileName() + "/";
 }
 
 
@@ -2466,18 +2484,16 @@ void Buffer::getChildren(std::vector<Buffer *> & clist, bool grand_children) con
                clist.push_back(child);
                if (grand_children) {
                        // there might be grandchildren
-                       std::vector<Buffer *> glist = child->getChildren();
-                       for (vector<Buffer *>::const_iterator git = glist.begin();
-                                git != glist.end(); ++git)
-                               clist.push_back(*git);
+                       vector<Buffer *> glist = child->getChildren();
+                       clist.insert(clist.end(), glist.begin(), glist.end());
                }
        }
 }
 
 
-std::vector<Buffer *> Buffer::getChildren(bool grand_children) const
+vector<Buffer *> Buffer::getChildren(bool grand_children) const
 {
-       std::vector<Buffer *> v;
+       vector<Buffer *> v;
        getChildren(v, grand_children);
        return v;
 }
@@ -2973,11 +2989,11 @@ void Buffer::getSourceCode(odocstream & os, pit_type par_begin,
 ErrorList & Buffer::errorList(string const & type) const
 {
        static ErrorList emptyErrorList;
-       map<string, ErrorList>::iterator I = d->errorLists.find(type);
-       if (I == d->errorLists.end())
+       map<string, ErrorList>::iterator it = d->errorLists.find(type);
+       if (it == d->errorLists.end())
                return emptyErrorList;
 
-       return I->second;
+       return it->second;
 }
 
 
@@ -3052,15 +3068,15 @@ public:
        AutoSaveBuffer(Buffer const & buffer, FileName const & fname)
                : buffer_(buffer), fname_(fname) {}
        ///
-       virtual boost::shared_ptr<ForkedProcess> clone() const
+       virtual shared_ptr<ForkedProcess> clone() const
        {
-               return boost::shared_ptr<ForkedProcess>(new AutoSaveBuffer(*this));
+               return shared_ptr<ForkedProcess>(new AutoSaveBuffer(*this));
        }
        ///
        int start()
        {
                command_ = to_utf8(bformat(_("Auto-saving %1$s"),
-                                                from_utf8(fname_.absFilename())));
+                                                from_utf8(fname_.absFileName())));
                return run(DontWait);
        }
 private:
@@ -3126,7 +3142,7 @@ int AutoSaveBuffer::generateChild()
 } // namespace anon
 
 
-FileName Buffer::getAutosaveFilename() const
+FileName Buffer::getAutosaveFileName() const
 {
        // if the document is unnamed try to save in the backup dir, else
        // in the default document path, and as a last try in the filePath, 
@@ -3145,7 +3161,7 @@ FileName Buffer::getAutosaveFilename() const
 
 void Buffer::removeAutosaveFile() const
 {
-       FileName const f = getAutosaveFilename();
+       FileName const f = getAutosaveFileName();
        if (f.exists())
                f.removeFile();
 }
@@ -3153,7 +3169,7 @@ void Buffer::removeAutosaveFile() const
 
 void Buffer::moveAutosaveFile(support::FileName const & oldauto) const
 {
-       FileName const newauto = getAutosaveFilename();
+       FileName const newauto = getAutosaveFileName();
        oldauto.refresh();
        if (newauto != oldauto && oldauto.exists())
                if (!oldauto.moveTo(newauto))
@@ -3172,7 +3188,7 @@ void Buffer::autoSave() const
 
        // emit message signal.
        message(_("Autosaving current document..."));
-       AutoSaveBuffer autosave(*this, getAutosaveFilename());
+       AutoSaveBuffer autosave(*this, getAutosaveFileName());
        autosave.start();
 
        d->bak_clean = true;
@@ -3270,6 +3286,21 @@ bool Buffer::doExport(string const & format, bool put_in_tempdir,
        // HTML backend
        else if (backend_format == "xhtml") {
                runparams.flavor = OutputParams::HTML;
+               switch (params().html_math_output) {
+               case BufferParams::MathML: 
+                       runparams.math_flavor = OutputParams::MathAsMathML; 
+                       break;
+               case BufferParams::HTML: 
+                       runparams.math_flavor = OutputParams::MathAsHTML; 
+                       break;
+               case BufferParams::Images:
+                       runparams.math_flavor = OutputParams::MathAsImages; 
+                       break;
+               case BufferParams::LaTeX:
+                       runparams.math_flavor = OutputParams::MathAsLaTeX; 
+                       break;                                                                                  
+               }
+               
                makeLyXHTMLFile(FileName(filename), runparams);
        }       else if (backend_format == "lyx")
                writeFile(FileName(filename));
@@ -3302,17 +3333,26 @@ bool Buffer::doExport(string const & format, bool put_in_tempdir,
        bool const success = theConverters().convert(this, FileName(filename),
                tmp_result_file, FileName(absFileName()), backend_format, format,
                error_list);
-       // Emit the signal to show the error list.
+
+       // Emit the signal to show the error list or copy it back to the
+       // cloned Buffer so that it cab be emitted afterwards.
        if (format != backend_format) {
-               errors(error_type);
+               if (d->cloned_buffer_) {
+                       d->cloned_buffer_->d->errorLists[error_type] = 
+                               d->errorLists[error_type];
+               } else 
+                       errors(error_type);
                // also to the children, in case of master-buffer-view
                std::vector<Buffer *> clist = getChildren();
                for (vector<Buffer *>::const_iterator cit = clist.begin();
-                    cit != clist.end(); ++cit)
-                       (*cit)->errors(error_type, true);
+                       cit != clist.end(); ++cit) {
+                       if (d->cloned_buffer_) {
+                               (*cit)->d->cloned_buffer_->d->errorLists[error_type] = 
+                                       (*cit)->d->errorLists[error_type];
+                       } else
+                               (*cit)->errors(error_type, true);
+               }
        }
-       if (!success)
-               return false;
 
        if (d->cloned_buffer_) {
                // Enable reverse dvi or pdf to work by copying back the texrow
@@ -3320,20 +3360,27 @@ bool Buffer::doExport(string const & format, bool put_in_tempdir,
                // FIXME: There is a possibility of concurrent access to texrow
                // here from the main GUI thread that should be securized.
                d->cloned_buffer_->d->texrow = d->texrow;
+               string const error_type = bufferFormat();
+               d->cloned_buffer_->d->errorLists[error_type] = d->errorLists[error_type];
        }
 
+       if (!success)
+               return false;
+
        if (put_in_tempdir) {
-               result_file = tmp_result_file.absFilename();
+               result_file = tmp_result_file.absFileName();
                return true;
        }
 
-       result_file = changeExtension(d->exportFileName().absFilename(), ext);
+       result_file = changeExtension(d->exportFileName().absFileName(), ext);
        // We need to copy referenced files (e. g. included graphics
        // if format == "dvi") to the result dir.
        vector<ExportedFile> const files =
                runparams.exportdata->externalFiles(format);
        string const dest = onlyPath(result_file);
-       CopyStatus status = SUCCESS;
+       bool use_force = use_gui ? lyxrc.export_overwrite == ALL_FILES
+                                : force_overwrite == ALL_FILES;
+       CopyStatus status = use_force ? FORCE : SUCCESS;
        
        vector<ExportedFile>::const_iterator it = files.begin();
        vector<ExportedFile>::const_iterator const en = files.end();
@@ -3348,6 +3395,10 @@ bool Buffer::doExport(string const & format, bool put_in_tempdir,
                message(_("Document export cancelled."));
        } else if (tmp_result_file.exists()) {
                // Finally copy the main file
+               use_force = use_gui ? lyxrc.export_overwrite != NO_FILES
+                                   : force_overwrite != NO_FILES;
+               if (status == SUCCESS && use_force)
+                       status = FORCE;
                status = copyFile(format, tmp_result_file,
                        FileName(result_file), result_file,
                        status == FORCE);
@@ -3434,7 +3485,7 @@ bool Buffer::readFileHelper(FileName const & s)
 {
        // File information about normal file
        if (!s.exists()) {
-               docstring const file = makeDisplayPath(s.absFilename(), 50);
+               docstring const file = makeDisplayPath(s.absFileName(), 50);
                docstring text = bformat(_("The specified document\n%1$s"
                                                     "\ncould not be read."), file);
                Alert::error(_("Could not read document"), text);
@@ -3442,10 +3493,10 @@ bool Buffer::readFileHelper(FileName const & s)
        }
 
        // Check if emergency save file exists and is newer.
-       FileName const e(s.absFilename() + ".emergency");
+       FileName const e(s.absFileName() + ".emergency");
 
        if (e.exists() && s.exists() && e.lastModified() > s.lastModified()) {
-               docstring const file = makeDisplayPath(s.absFilename(), 20);
+               docstring const file = makeDisplayPath(s.absFileName(), 20);
                docstring const text =
                        bformat(_("An emergency save of the document "
                                  "%1$s exists.\n\n"
@@ -3465,7 +3516,7 @@ bool Buffer::readFileHelper(FileName const & s)
                        else
                                str = _("Document was NOT successfully recovered.");
                        str += "\n\n" + bformat(_("Remove emergency file now?\n(%1$s)"),
-                                               from_utf8(e.absFilename()));
+                                               makeDisplayPath(e.absFileName()));
 
                        if (!Alert::prompt(_("Delete emergency file?"), str, 1, 1,
                                        _("&Remove"), _("&Keep it"))) {
@@ -3488,10 +3539,10 @@ bool Buffer::readFileHelper(FileName const & s)
        }
 
        // Now check if autosave file is newer.
-       FileName const a(onlyPath(s.absFilename()) + '#' + onlyFilename(s.absFilename()) + '#');
+       FileName const a(onlyPath(s.absFileName()) + '#' + onlyFileName(s.absFileName()) + '#');
 
        if (a.exists() && s.exists() && a.lastModified() > s.lastModified()) {
-               docstring const file = makeDisplayPath(s.absFilename(), 20);
+               docstring const file = makeDisplayPath(s.absFileName(), 20);
                docstring const text =
                        bformat(_("The backup of the document "
                                  "%1$s is newer.\n\nLoad the "
@@ -3901,20 +3952,26 @@ int Buffer::spellCheck(DocIterator & from, DocIterator & to,
 bool Buffer::reload()
 {
        setBusy(true);
+       // c.f. bug 6587
+       removeAutosaveFile();
        // e.g., read-only status could have changed due to version control
        d->filename.refresh();
-       docstring const disp_fn = makeDisplayPath(d->filename.absFilename());
+       docstring const disp_fn = makeDisplayPath(d->filename.absFileName());
 
        bool const success = loadLyXFile(d->filename);
        if (success) {
                updateBuffer();
                changed(true);
+               updateTitles();
                markClean();
                message(bformat(_("Document %1$s reloaded."), disp_fn));
        } else {
                message(bformat(_("Could not reload document %1$s."), disp_fn));
        }       
        setBusy(false);
+       thePreviews().removeLoader(*this);
+       if (graphics::Previews::status() != LyXRC::PREVIEW_OFF)
+               thePreviews().generateBufferPreviews(*this);
        errors("Parse");
        return success;
 }
@@ -3940,7 +3997,7 @@ void Buffer::checkChildBuffers()
                docstring const & incfile = inset_inc->getParam("filename");
                string oldloc = cbuf->absFileName();
                string newloc = makeAbsPath(to_utf8(incfile),
-                               onlyPath(absFileName())).absFilename();
+                               onlyPath(absFileName())).absFileName();
                if (oldloc == newloc)
                        continue;
                // the location of the child file is incorrect.