]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
Patch by Richard Heck:
[lyx.git] / src / Buffer.cpp
index f4088ae8ac904d1d195fceb8ef896a489d3b6268..3fac1fc26e5c1fa535917414667f6217e2e21219 100644 (file)
@@ -3,7 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -142,7 +142,7 @@ using std::string;
 
 namespace {
 
-int const LYX_FORMAT = 271;
+int const LYX_FORMAT = 276;
 
 } // namespace anon
 
@@ -193,6 +193,9 @@ public:
 
        ///
        TocBackend toc_backend;
+
+       /// Container for all sort of Buffer dependant errors.
+       map<string, ErrorList> errorLists;
 };
 
 
@@ -427,12 +430,13 @@ int Buffer::readHeader(Lexer & lex)
        params().headheight.erase();
        params().headsep.erase();
        params().footskip.erase();
+       params().listings_params.clear();
        for (int i = 0; i < 4; ++i) {
                params().user_defined_bullet(i) = ITEMIZE_DEFAULTS[i];
                params().temp_bullet(i) = ITEMIZE_DEFAULTS[i];
        }
 
-       ErrorList & errorList = errorLists_["Parse"];
+       ErrorList & errorList = pimpl_->errorLists["Parse"];
 
        while (lex.isOK()) {
                lex.next();
@@ -483,7 +487,7 @@ int Buffer::readHeader(Lexer & lex)
 // Returns false if "\end_document" is not read (Asger)
 bool Buffer::readDocument(Lexer & lex)
 {
-       ErrorList & errorList = errorLists_["Parse"];
+       ErrorList & errorList = pimpl_->errorLists["Parse"];
        errorList.clear();
 
        lex.next();
@@ -509,20 +513,20 @@ bool Buffer::readDocument(Lexer & lex)
        if (params().outputChanges) {
                bool dvipost    = LaTeXFeatures::isAvailable("dvipost");
                bool xcolorsoul = LaTeXFeatures::isAvailable("soul") &&
-                                 LaTeXFeatures::isAvailable("xcolor");
-               
+                                 LaTeXFeatures::isAvailable("xcolor");
+
                if (!dvipost && !xcolorsoul) {
                        Alert::warning(_("Changes not shown in LaTeX output"),
-                                      _("Changes will not be highlighted in LaTeX output, "
-                                        "because neither dvipost nor xcolor/soul are installed.\n"
-                                        "Please install these packages or redefine "
-                                        "\\lyxadded and \\lyxdeleted in the LaTeX preamble."));
+                                      _("Changes will not be highlighted in LaTeX output, "
+                                        "because neither dvipost nor xcolor/soul are installed.\n"
+                                        "Please install these packages or redefine "
+                                        "\\lyxadded and \\lyxdeleted in the LaTeX preamble."));
                } else if (!xcolorsoul) {
                        Alert::warning(_("Changes not shown in LaTeX output"),
-                                      _("Changes will not be highlighted in LaTeX output "
-                                        "when using pdflatex, because xcolor and soul are not installed.\n"
-                                        "Please install both packages or redefine "
-                                        "\\lyxadded and \\lyxdeleted in the LaTeX preamble."));
+                                      _("Changes will not be highlighted in LaTeX output "
+                                        "when using pdflatex, because xcolor and soul are not installed.\n"
+                                        "Please install both packages or redefine "
+                                        "\\lyxadded and \\lyxdeleted in the LaTeX preamble."));
                }
        }
 
@@ -717,10 +721,10 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename,
                }
                ostringstream command;
                command << os::python()
-                       << ' ' << quoteName(lyx2lyx.toFilesystemEncoding())
-                       << " -t " << convert<string>(LYX_FORMAT)
-                       << " -o " << quoteName(tmpfile.toFilesystemEncoding())
-                       << ' ' << quoteName(filename.toFilesystemEncoding());
+                       << ' ' << quoteName(lyx2lyx.toFilesystemEncoding())
+                       << " -t " << convert<string>(LYX_FORMAT)
+                       << " -o " << quoteName(tmpfile.toFilesystemEncoding())
+                       << ' ' << quoteName(filename.toFilesystemEncoding());
                string const command_str = command.str();
 
                LYXERR(Debug::INFO) << "Running '"
@@ -775,16 +779,16 @@ bool Buffer::save() const
                backupName = FileName(fileName() + '~');
                if (!lyxrc.backupdir_path.empty())
                        backupName = FileName(addName(lyxrc.backupdir_path,
-                                             subst(os::internal_path(backupName.absFilename()), '/', '!')));
+                                             subst(os::internal_path(backupName.absFilename()), '/', '!')));
 
                try {
                        fs::copy_file(encodedFilename, backupName.toFilesystemEncoding(), false);
                        madeBackup = true;
                } catch (fs::filesystem_error const & fe) {
                        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())));
+                                    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;
                }
        }
@@ -842,6 +846,19 @@ bool Buffer::write(ostream & ofs) const
            << "\\lyxformat " << LYX_FORMAT << "\n"
            << "\\begin_document\n";
 
+
+       /// For each author, set 'used' to true if there is a change
+       /// by this author in the document; otherwise set it to 'false'.
+       AuthorList::Authors::const_iterator a_it = params().authors().begin();
+       AuthorList::Authors::const_iterator a_end = params().authors().end();
+       for (; a_it != a_end; ++a_it)
+               a_it->second.used(false);
+
+       ParIterator const end = par_iterator_end();
+       ParIterator it = par_iterator_begin();
+       for ( ; it != end; ++it)
+               it->checkAuthors(params().authors());
+
        // now write out the buffer parameters.
        ofs << "\\begin_header\n";
        params().writeFile(ofs);
@@ -999,8 +1016,8 @@ void Buffer::writeLaTeXSource(odocstream & os,
            !params().language->babel().empty()) {
                // FIXME UNICODE
                os << from_utf8(subst(lyxrc.language_command_begin,
-                                          "$$lang",
-                                          params().language->babel()))
+                                          "$$lang",
+                                          params().language->babel()))
                   << '\n';
                texrow().newline();
        }
@@ -1046,8 +1063,8 @@ void Buffer::writeLaTeXSource(odocstream & os,
        if (!lyxrc.language_auto_end &&
            !params().language->babel().empty()) {
                os << from_utf8(subst(lyxrc.language_command_end,
-                                          "$$lang",
-                                          params().language->babel()))
+                                          "$$lang",
+                                          params().language->babel()))
                   << '\n';
                texrow().newline();
        }
@@ -1097,7 +1114,7 @@ void Buffer::makeDocBookFile(FileName const & fname,
        LYXERR(Debug::LATEX) << "makeDocBookFile..." << endl;
 
        //ofstream ofs;
-        odocfstream ofs;
+       odocfstream ofs;
        if (!openFileWrite(ofs, fname))
                return;
 
@@ -1125,12 +1142,12 @@ void Buffer::writeDocBookSource(odocstream & os, string const & fname,
                if (runparams.flavor == OutputParams::XML)
                        os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
 
-                // FIXME UNICODE
+               // FIXME UNICODE
                os << "<!DOCTYPE " << from_ascii(top_element) << ' ';
 
-                // FIXME UNICODE
+               // FIXME UNICODE
                if (! tclass.class_header().empty())
-                        os << from_ascii(tclass.class_header());
+                       os << from_ascii(tclass.class_header());
                else if (runparams.flavor == OutputParams::XML)
                        os << "PUBLIC \"-//OASIS//DTD DocBook XML//EN\" "
                            << "\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\"";
@@ -1151,7 +1168,7 @@ void Buffer::writeDocBookSource(odocstream & os, string const & fname,
                preamble += features.getLyXSGMLEntities();
 
                if (!preamble.empty()) {
-                        os << "\n [ " << preamble << " ]";
+                       os << "\n [ " << preamble << " ]";
                }
                os << ">\n\n";
        }
@@ -1210,7 +1227,7 @@ int Buffer::runChktex()
                Alert::error(_("chktex failure"),
                             _("Could not run chktex successfully."));
        } else if (res > 0) {
-               ErrorList & errorList = errorLists_["ChkTeX"];
+               ErrorList & errorList = pimpl_->errorLists["ChkTeX"];
                // Clear out old errors
                errorList.clear();
                // Fill-in the error list with the TeX errors
@@ -1232,9 +1249,9 @@ void Buffer::validate(LaTeXFeatures & features) const
        if (params().outputChanges) {
                bool dvipost    = LaTeXFeatures::isAvailable("dvipost");
                bool xcolorsoul = LaTeXFeatures::isAvailable("soul") &&
-                                 LaTeXFeatures::isAvailable("xcolor");
-               
-               if (features.runparams().flavor == OutputParams::LATEX) {
+                                 LaTeXFeatures::isAvailable("xcolor");
+
+               if (features.runparams().flavor == OutputParams::LATEX) {
                        if (dvipost) {
                                features.require("ct-dvipost");
                                features.require("dvipost");
@@ -1242,7 +1259,7 @@ void Buffer::validate(LaTeXFeatures & features) const
                                features.require("ct-xcolor-soul");
                                features.require("soul");
                                features.require("xcolor");
-                       } else {        
+                       } else {
                                features.require("ct-none");
                        }
                } else if (features.runparams().flavor == OutputParams::PDFLATEX ) {
@@ -1254,7 +1271,7 @@ void Buffer::validate(LaTeXFeatures & features) const
                        } else {
                                features.require("ct-none");
                        }
-               }
+               }
        }
 
        // AMS Style is at document level
@@ -1612,7 +1629,11 @@ bool Buffer::isReadonly() const
 
 void Buffer::setParentName(string const & name)
 {
-       params().parentname = name;
+       if (name == pimpl_->filename.absFilename())
+               // Avoids recursive include.
+               params().parentname.clear();
+       else
+               params().parentname = name;
 }
 
 
@@ -1739,7 +1760,7 @@ void Buffer::getSourceCode(odocstream & os, pit_type par_begin,
        runparams.dryrun = true;
 
        if (full_source) {
-               os << "% Preview source code\n\n";
+               os << "% " << _("Preview source code") << "\n\n";
                if (isLatex())
                        writeLaTeXSource(os, filePath(), runparams, true, true);
                else {
@@ -1749,10 +1770,15 @@ void Buffer::getSourceCode(odocstream & os, pit_type par_begin,
                runparams.par_begin = par_begin;
                runparams.par_end = par_end;
                if (par_begin + 1 == par_end)
-                       os << "% Preview source code for paragraph " << par_begin << "\n\n";
+                       os << "% "
+                          << bformat(_("Preview source code for paragraph %1$s"), par_begin)
+                          << "\n\n";
                else
-                       os << "% Preview source code from paragraph " << par_begin
-                          << " to " << par_end - 1 << "\n\n";
+                       os << "% "
+                          << bformat(_("Preview source code from paragraph %1$s to %2$s"),
+                                       convert<docstring>(par_begin),
+                                       convert<docstring>(par_end - 1))
+                          << "\n\n";
                // output paragraphs
                if (isLatex()) {
                        texrow().reset();
@@ -1768,8 +1794,8 @@ void Buffer::getSourceCode(odocstream & os, pit_type par_begin,
 ErrorList const & Buffer::errorList(string const & type) const
 {
        static ErrorList const emptyErrorList;
-       std::map<string, ErrorList>::const_iterator I = errorLists_.find(type);
-       if (I == errorLists_.end())
+       std::map<string, ErrorList>::const_iterator I = pimpl_->errorLists.find(type);
+       if (I == pimpl_->errorLists.end())
                return emptyErrorList;
 
        return I->second;
@@ -1778,7 +1804,7 @@ ErrorList const & Buffer::errorList(string const & type) const
 
 ErrorList & Buffer::errorList(string const & type)
 {
-       return errorLists_[type];
+       return pimpl_->errorLists[type];
 }