]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
Add margin to paragraph dialog.
[lyx.git] / src / buffer.C
index 80691626f9659b5f81a22702666f71c4a3af7119..345325a8690ed139ff531761f9963cdb45bd4eb9 100644 (file)
@@ -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());
 }
 
@@ -451,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);
@@ -594,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;
 }
 
@@ -618,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;
 }
 
@@ -653,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;
@@ -714,7 +702,7 @@ 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;
 
@@ -776,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;
                }
        }
 
@@ -872,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);
@@ -914,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();
 
@@ -933,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
@@ -974,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
@@ -1017,9 +1005,9 @@ 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;
@@ -1027,8 +1015,8 @@ void Buffer::writeLaTeXSource(odocstream & os,
        // 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;
 }
 
@@ -1055,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;
@@ -1150,8 +1138,8 @@ int Buffer::runChktex()
        busy(true);
 
        // get LaTeX-Filename
-       string const path = temppath();
-        string const name = addName(path, getLatexName());
+       FileName const path(temppath());
+       string const name = addName(path.absFilename(), getLatexName());
        string const org_path = filePath();
 
        support::Path p(path); // path to LaTeX file
@@ -1195,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");
@@ -1385,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));
@@ -1397,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();
@@ -1474,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);
 }