]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
Restore the version number position on the splash screen
[lyx.git] / src / buffer.C
index 2630fc4b8e058be83df23725aece13c8ed21f422..345325a8690ed139ff531761f9963cdb45bd4eb9 100644 (file)
@@ -141,7 +141,7 @@ using std::string;
 
 namespace {
 
-int const LYX_FORMAT = 256;
+int const LYX_FORMAT = 263;
 
 } // namespace anon
 
@@ -178,8 +178,6 @@ public:
        /// name of the file the buffer is associated with.
        FileName filename;
 
-       Messages * messages;
-
        /** Set to true only when the file is fully loaded.
         *  Used to prevent the premature generation of previews
         *  and by the citation inset.
@@ -199,7 +197,7 @@ public:
 
 Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_)
        : lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_),
-         filename(file), messages(0), file_fully_loaded(false), inset(params),
+         filename(file), file_fully_loaded(false), inset(params),
          toc_backend(&parent)
 {
        inset.setAutoBreakRows(true);
@@ -215,13 +213,13 @@ Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_)
 Buffer::Buffer(string const & file, bool readonly)
        : pimpl_(new Impl(*this, FileName(file), readonly))
 {
-       lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
+       LYXERR(Debug::INFO) << "Buffer::Buffer()" << endl;
 }
 
 
 Buffer::~Buffer()
 {
-       lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
+       LYXERR(Debug::INFO) << "Buffer::~Buffer()" << endl;
        // here the buffer should take care that it is
        // saved properly, before it goes into the void.
 
@@ -369,10 +367,10 @@ pair<Buffer::LogType, string> const Buffer::getLogName() const
        if (fs::exists(bname.toFilesystemEncoding()) &&
            (!fs::exists(fname.toFilesystemEncoding()) ||
             fs::last_write_time(fname.toFilesystemEncoding()) < fs::last_write_time(bname.toFilesystemEncoding()))) {
-               lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
+               LYXERR(Debug::FILES) << "Log name calculated as: " << bname << endl;
                return make_pair(Buffer::buildlog, bname.absFilename());
        }
-       lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
+       LYXERR(Debug::FILES) << "Log name calculated as: " << fname << endl;
        return make_pair(Buffer::latexlog, fname.absFilename());
 }
 
@@ -428,6 +426,10 @@ int Buffer::readHeader(LyXLex & lex)
        params().headheight.erase();
        params().headsep.erase();
        params().footskip.erase();
+       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"];
 
@@ -447,7 +449,7 @@ int Buffer::readHeader(LyXLex & lex)
                        continue;
                }
 
-               lyxerr[Debug::PARSER] << "Handling document header token: `"
+               LYXERR(Debug::PARSER) << "Handling document header token: `"
                                      << token << '\'' << endl;
 
                string unknown = params().readToken(lex, token);
@@ -590,11 +592,6 @@ bool Buffer::readString(std::string const & s)
                break;
        }
 
-       // After we have read a file, we must ensure that the buffer
-       // language is set and used in the gui.
-       // If you know of a better place to put this, please tell me. (Lgb)
-       updateDocLang(params().language);
-
        return true;
 }
 
@@ -614,11 +611,6 @@ bool Buffer::readFile(FileName const & filename)
        if (readFile(lex, filename) != success)
                return false;
 
-       // After we have read a file, we must ensure that the buffer
-       // language is set and used in the gui.
-       // If you know of a better place to put this, please tell me. (Lgb)
-       updateDocLang(params().language);
-
        return true;
 }
 
@@ -649,7 +641,7 @@ Buffer::ReadStatus Buffer::readFile(LyXLex & lex, FileName const & filename,
        lex.next();
        string const token(lex.getString());
 
-       if (!lex.isOK()) {
+       if (!lex) {
                Alert::error(_("Document could not be read"),
                             bformat(_("%1$s could not be read."), from_utf8(filename.absFilename())));
                return failure;
@@ -685,7 +677,7 @@ Buffer::ReadStatus Buffer::readFile(LyXLex & lex, FileName const & filename,
                FileName const tmpfile(tempName());
                if (tmpfile.empty()) {
                        Alert::error(_("Conversion failed"),
-                                    bformat(_("%1$s is from an earlier"
+                                    bformat(_("%1$s is from a different"
                                              " version of LyX, but a temporary"
                                              " file for converting it could"
                                                            " not be created."),
@@ -695,7 +687,7 @@ Buffer::ReadStatus Buffer::readFile(LyXLex & lex, FileName const & filename,
                FileName const lyx2lyx = libFileSearch("lyx2lyx", "lyx2lyx");
                if (lyx2lyx.empty()) {
                        Alert::error(_("Conversion script not found"),
-                                    bformat(_("%1$s is from an earlier"
+                                    bformat(_("%1$s is from a different"
                                               " version of LyX, but the"
                                               " conversion script lyx2lyx"
                                                            " could not be found."),
@@ -710,14 +702,14 @@ Buffer::ReadStatus Buffer::readFile(LyXLex & lex, FileName const & filename,
                        << ' ' << quoteName(filename.toFilesystemEncoding());
                string const command_str = command.str();
 
-               lyxerr[Debug::INFO] << "Running '"
+               LYXERR(Debug::INFO) << "Running '"
                                    << command_str << '\''
                                    << endl;
 
                cmd_ret const ret = runCommand(command_str);
                if (ret.first != 0) {
                        Alert::error(_("Conversion script failed"),
-                                    bformat(_("%1$s is from an earlier version"
+                                    bformat(_("%1$s is from a different version"
                                              " of LyX, but the lyx2lyx script"
                                                            " failed to convert it."),
                                              from_utf8(filename.absFilename())));
@@ -772,7 +764,7 @@ bool Buffer::save() const
                                     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;
+                       LYXERR(Debug::DEBUG) << "Fs error: " << fe.what() << endl;
                }
        }
 
@@ -868,8 +860,8 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
                           OutputParams const & runparams,
                           bool output_preamble, bool output_body)
 {
-       string const encoding = params().encoding().iconvName();
-       lyxerr[Debug::LATEX] << "makeLaTeXFile encoding: "
+       string const encoding = runparams.encoding->iconvName();
+       LYXERR(Debug::LATEX) << "makeLaTeXFile encoding: "
                << encoding << "..." << endl;
 
        odocfstream ofs(encoding);
@@ -910,10 +902,10 @@ void Buffer::writeLaTeXSource(odocstream & os,
        OutputParams runparams = runparams_in;
 
        // validate the buffer.
-       lyxerr[Debug::LATEX] << "  Validating buffer..." << endl;
+       LYXERR(Debug::LATEX) << "  Validating buffer..." << endl;
        LaTeXFeatures features(*this, params(), runparams);
        validate(features);
-       lyxerr[Debug::LATEX] << "  Buffer validation done." << endl;
+       LYXERR(Debug::LATEX) << "  Buffer validation done." << endl;
 
        texrow().reset();
 
@@ -929,7 +921,7 @@ void Buffer::writeLaTeXSource(odocstream & os,
                texrow().newline();
                texrow().newline();
        }
-       lyxerr[Debug::INFO] << "lyx document header finished" << endl;
+       LYXERR(Debug::INFO) << "lyx document header finished" << endl;
        // There are a few differences between nice LaTeX and usual files:
        // usual is \batchmode and has a
        // special input@path to allow the including of figures
@@ -970,7 +962,7 @@ void Buffer::writeLaTeXSource(odocstream & os,
                os << "\\begin{document}\n";
                texrow().newline();
        } // output_preamble
-       lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
+       LYXERR(Debug::INFO) << "preamble finished, now the body." << endl;
 
        if (!lyxrc.language_auto_begin) {
                // FIXME UNICODE
@@ -1013,17 +1005,18 @@ void Buffer::writeLaTeXSource(odocstream & os,
                os << "\\end{document}\n";
                texrow().newline();
 
-               lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
+               LYXERR(Debug::LATEX) << "makeLaTeXFile...done" << endl;
        } else {
-               lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
+               LYXERR(Debug::LATEX) << "LaTeXFile for inclusion made."
                                     << endl;
        }
+       runparams_in.encoding = runparams.encoding;
 
        // Just to be sure. (Asger)
        texrow().newline();
 
-       lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
-       lyxerr[Debug::INFO] << "Row count was " << texrow().rows() - 1
+       LYXERR(Debug::INFO) << "Finished making LaTeX file." << endl;
+       LYXERR(Debug::INFO) << "Row count was " << texrow().rows() - 1
                            << '.' << endl;
 }
 
@@ -1050,7 +1043,7 @@ void Buffer::makeDocBookFile(FileName const & fname,
                              OutputParams const & runparams,
                              bool const body_only)
 {
-       lyxerr[Debug::LATEX] << "makeDocBookFile..." << endl;
+       LYXERR(Debug::LATEX) << "makeDocBookFile..." << endl;
 
        //ofstream ofs;
         odocfstream ofs;
@@ -1145,15 +1138,15 @@ int Buffer::runChktex()
        busy(true);
 
        // get LaTeX-Filename
-       string const name = getLatexName(false);
-       string const path = temppath();
+       FileName const path(temppath());
+       string const name = addName(path.absFilename(), getLatexName());
        string const org_path = filePath();
 
        support::Path p(path); // path to LaTeX file
        message(_("Running chktex..."));
 
        // Generate the LaTeX file if neccessary
-       OutputParams runparams;
+       OutputParams runparams(&params().encoding());
        runparams.flavor = OutputParams::LATEX;
        runparams.nice = false;
        makeLaTeXFile(FileName(name), org_path, runparams);
@@ -1166,8 +1159,11 @@ int Buffer::runChktex()
                Alert::error(_("chktex failure"),
                             _("Could not run chktex successfully."));
        } else if (res > 0) {
+               ErrorList & errorList = errorLists_["ChkTeX"];
+               // Clear out old errors
+               errorList.clear();
                // Fill-in the error list with the TeX errors
-               bufferErrors(*this, terr, errorLists_["ChkTeX"]);
+               bufferErrors(*this, terr, errorList);
        }
 
        busy(false);
@@ -1187,7 +1183,7 @@ void Buffer::validate(LaTeXFeatures & features) const
 
        // AMS Style is at document level
        if (params().use_amsmath == BufferParams::package_on
-           || tclass.provides(LyXTextClass::amsmath))
+           || tclass.provides("amsmath"))
                features.require("amsmath");
        if (params().use_esint == BufferParams::package_on)
                features.require("esint");
@@ -1260,19 +1256,20 @@ void Buffer::fillWithBibKeys(vector<pair<string, docstring> > & keys)
        for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
                if (it->lyxCode() == InsetBase::BIBTEX_CODE) {
                        InsetBibtex const & inset =
-                               dynamic_cast<InsetBibtex const &>(*it);
+                               static_cast<InsetBibtex const &>(*it);
                        inset.fillWithBibKeys(*this, keys);
                } else if (it->lyxCode() == InsetBase::INCLUDE_CODE) {
                        InsetInclude const & inset =
-                               dynamic_cast<InsetInclude const &>(*it);
+                               static_cast<InsetInclude const &>(*it);
                        inset.fillWithBibKeys(*this, keys);
                } else if (it->lyxCode() == InsetBase::BIBITEM_CODE) {
                        InsetBibitem const & inset =
-                               dynamic_cast<InsetBibitem const &>(*it);
+                               static_cast<InsetBibitem const &>(*it);
                        // FIXME UNICODE
                        string const key = to_utf8(inset.getParam("key"));
                        docstring const label = inset.getParam("label");
-                       docstring const ref; // = pit->asString(this, false);
+                       DocIterator doc_it(it); doc_it.forwardPos();
+                       docstring const ref = doc_it.paragraph().asString(*this, false);
                        docstring const info = label + "TheBibliographyRef" + ref;
                        keys.push_back(pair<string, docstring>(key, info));
                }
@@ -1295,14 +1292,14 @@ void Buffer::updateBibfilesCache()
        for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
                if (it->lyxCode() == InsetBase::BIBTEX_CODE) {
                        InsetBibtex const & inset =
-                               dynamic_cast<InsetBibtex const &>(*it);
+                               static_cast<InsetBibtex const &>(*it);
                        vector<FileName> const bibfiles = inset.getFiles(*this);
                        bibfilesCache_.insert(bibfilesCache_.end(),
                                bibfiles.begin(),
                                bibfiles.end());
                } else if (it->lyxCode() == InsetBase::INCLUDE_CODE) {
                        InsetInclude & inset =
-                               dynamic_cast<InsetInclude &>(*it);
+                               static_cast<InsetInclude &>(*it);
                        inset.updateBibfilesCache(*this);
                        vector<FileName> const & bibfiles =
                                        inset.getBibfilesCache(*this);
@@ -1376,9 +1373,6 @@ void Buffer::changeLanguage(Language const * from, Language const * to)
        BOOST_ASSERT(from);
        BOOST_ASSERT(to);
 
-       // Take care of l10n/i18n
-       updateDocLang(to);
-
        for_each(par_iterator_begin(),
                 par_iterator_end(),
                 bind(&Paragraph::changeLanguage, _1, params(), from, to));
@@ -1388,14 +1382,6 @@ void Buffer::changeLanguage(Language const * from, Language const * to)
 }
 
 
-void Buffer::updateDocLang(Language const * nlang)
-{
-       BOOST_ASSERT(nlang);
-
-       pimpl_->messages = &getMessages(nlang->code());
-}
-
-
 bool Buffer::isMultiLingual() const
 {
        ParConstIterator end = par_iterator_end();
@@ -1465,8 +1451,9 @@ Language const * Buffer::getLanguage() const
 
 docstring const Buffer::B_(string const & l10n) const
 {
-       if (pimpl_->messages) 
-               return pimpl_->messages->get(l10n);
+       Language const * lang = pimpl_->params.language;
+       if (lang)
+               return getMessages(lang->code()).get(l10n);
 
        return _(l10n);
 }
@@ -1659,7 +1646,7 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to,
 
        for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
                if (it->lyxCode() == code) {
-                       InsetCommand & inset = dynamic_cast<InsetCommand &>(*it);
+                       InsetCommand & inset = static_cast<InsetCommand &>(*it);
                        inset.replaceContents(to_utf8(from), to_utf8(to));
                }
        }
@@ -1669,7 +1656,7 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to,
 void Buffer::getSourceCode(odocstream & os, pit_type par_begin,
        pit_type par_end, bool full_source)
 {
-       OutputParams runparams;
+       OutputParams runparams(&params().encoding());
        runparams.nice = true;
        runparams.flavor = OutputParams::LATEX;
        runparams.linelen = lyxrc.plaintext_linelen;