]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
Updates from Bennett and myself.
[lyx.git] / src / buffer.C
index 41185b825dfc5c961f915b70df0ae34b02ff01f2..992d61a846c9c464313472fc06a10b4b8b403b53 100644 (file)
@@ -47,6 +47,7 @@
 #include "pariterator.h"
 #include "sgml.h"
 #include "texrow.h"
+#include "TocBackend.h"
 #include "undo.h"
 #include "version.h"
 
@@ -100,6 +101,7 @@ using support::changeExtension;
 using support::cmd_ret;
 using support::createBufferTmpDir;
 using support::destroyDir;
+using support::FileName;
 using support::getFormatFromContents;
 using support::isDirWriteable;
 using support::libFileSearch;
@@ -142,7 +144,7 @@ using std::string;
 
 namespace {
 
-int const LYX_FORMAT = 252;
+int const LYX_FORMAT = 255;
 
 } // namespace anon
 
@@ -192,13 +194,16 @@ public:
 
        ///
        MacroTable macros;
+
+       ///
+       TocBackend toc_backend;
 };
 
 
 Buffer::Impl::Impl(Buffer & parent, string const & file, bool readonly_)
        : lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_),
-         filename(file), file_fully_loaded(false),
-               inset(params)
+         filename(file), file_fully_loaded(false), inset(params),
+         toc_backend(&parent)
 {
        inset.setAutoBreakRows(true);
        lyxvc.buffer(&parent);
@@ -326,6 +331,18 @@ TexRow const & Buffer::texrow() const
 }
 
 
+TocBackend & Buffer::tocBackend()
+{
+       return pimpl_->toc_backend;
+}
+
+
+TocBackend const & Buffer::tocBackend() const
+{
+       return pimpl_->toc_backend;
+}
+
+
 string const Buffer::getLatexName(bool const no_path) const
 {
        string const name = changeExtension(makeLatexName(fileName()), ".tex");
@@ -444,7 +461,7 @@ int Buffer::readHeader(LyXLex & lex)
                                docstring const s = bformat(_("Unknown token: "
                                                                        "%1$s %2$s\n"),
                                                         from_utf8(token),
-                                                        from_utf8(lex.getString()));
+                                                        lex.getDocString());
                                errorList.push_back(ErrorItem(_("Document header error"),
                                        s, -1, 0, 0));
                        }
@@ -538,11 +555,9 @@ void Buffer::insertStringAsLines(ParagraphList & pars,
                                }
                                space_inserted = true;
                        }
-/* FIXME: not needed anymore?
                } else if (!isPrintable(*cit)) {
                        // Ignore unprintables
                        continue;
-*/
                } else {
                        // just insert the character
                        par.insertChar(pos, *cit, font, params().trackChanges);
@@ -557,7 +572,8 @@ void Buffer::insertStringAsLines(ParagraphList & pars,
 bool Buffer::readFile(string const & filename)
 {
        // Check if the file is compressed.
-       string const format = getFormatFromContents(filename);
+       FileName const name(makeAbsPath(filename));
+       string const format = getFormatFromContents(name);
        if (format == "gzip" || format == "zip" || format == "compress") {
                params().compressed = true;
        }
@@ -565,7 +581,7 @@ bool Buffer::readFile(string const & filename)
        // remove dummy empty par
        paragraphs().clear();
        LyXLex lex(0, 0);
-       lex.setFile(filename);
+       lex.setFile(name);
        if (!readFile(lex, filename))
                return false;
 
@@ -641,7 +657,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
                                              from_utf8(filename)));
                        return false;
                }
-               string const lyx2lyx = libFileSearch("lyx2lyx", "lyx2lyx");
+               FileName const lyx2lyx = libFileSearch("lyx2lyx", "lyx2lyx");
                if (lyx2lyx.empty()) {
                        Alert::error(_("Conversion script not found"),
                                     bformat(_("%1$s is from an earlier"
@@ -652,7 +668,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
                        return false;
                }
                ostringstream command;
-               command << os::python() << ' ' << quoteName(lyx2lyx)
+               command << os::python() << ' ' << quoteName(lyx2lyx.toFilesystemEncoding())
                        << " -t " << convert<string>(LYX_FORMAT)
                        << " -o " << quoteName(tmpfile) << ' '
                        << quoteName(filename);
@@ -731,7 +747,7 @@ bool Buffer::save() const
        } else {
                // Saving failed, so backup is not backup
                if (lyxrc.make_backup)
-                       rename(s, fileName());
+                       rename(FileName(s), FileName(fileName()));
                return false;
        }
        return true;
@@ -817,9 +833,20 @@ bool Buffer::makeLaTeXFile(string const & fname,
                           OutputParams const & runparams,
                           bool output_preamble, bool output_body)
 {
-       string const encoding = (params().inputenc == "auto") ?
-               params().language->encoding()->iconvName() :
-               encodings.getEncoding(params().inputenc)->iconvName();
+       string encoding;
+       if (params().inputenc == "auto")
+               encoding = params().language->encoding()->iconvName();
+       else {
+               Encoding const * enc = encodings.getFromLaTeXName(params().inputenc);
+               if (enc)
+                       encoding = enc->iconvName();
+               else {
+                       lyxerr << "Unknown inputenc value `"
+                              << params().inputenc
+                              << "'. Using `auto' instead." << endl;
+                       encoding = params().language->encoding()->iconvName();
+               }
+       }
        lyxerr[Debug::LATEX] << "makeLaTeXFile encoding: "
                << encoding << "..." << endl;
 
@@ -1137,9 +1164,11 @@ void Buffer::validate(LaTeXFeatures & features) const
                features.require("dvipost");
 
        // AMS Style is at document level
-       if (params().use_amsmath == BufferParams::AMS_ON
+       if (params().use_amsmath == BufferParams::package_on
            || tclass.provides(LyXTextClass::amsmath))
                features.require("amsmath");
+       if (params().use_esint == BufferParams::package_on)
+               features.require("esint");
 
        for_each(paragraphs().begin(), paragraphs().end(),
                 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
@@ -1418,6 +1447,18 @@ docstring const Buffer::B_(string const & l10n) const
 }
 
 
+docstring const Buffer::translateLabel(docstring const & label) const
+{
+       if (support::isAscii(label))
+               // Probably standard layout, try to translate
+               return B_(to_ascii(label));
+       else
+               // This must be a user defined layout. We cannot translate
+               // this, since gettext accepts only ascii keys.
+               return label;
+}
+
+
 bool Buffer::isClean() const
 {
        return pimpl_->lyx_clean;
@@ -1600,7 +1641,6 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to,
        } else
                getLabelList(labels);
 
-       // FIXME UNICODE
        if (lyx::count(labels.begin(), labels.end(), from) > 1)
                return;