]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
Some cleanup for the Floating class.
[lyx.git] / src / Buffer.cpp
index 4876f9fc5a802fc78ae9c780d4e7236035e76b40..a7d19dc303dc0ce700e627bb3a6a6fce3b1e4bcd 100644 (file)
@@ -930,7 +930,7 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename,
                        << ' ' << quoteName(lyx2lyx.toFilesystemEncoding())
                        << " -t " << convert<string>(LYX_FORMAT)
                        << " -o " << quoteName(tmpfile.toFilesystemEncoding())
-                       << ' ' << quoteName(filename.toFilesystemEncoding());
+                       << ' ' << quoteName(filename.toSafeFilesystemEncoding());
                string const command_str = command.str();
 
                LYXERR(Debug::INFO, "Running '" << command_str << '\'');
@@ -977,8 +977,6 @@ bool Buffer::save() const
        // We don't need autosaves in the immediate future. (Asger)
        resetAutosaveTimers();
 
-       string const encodedFilename = d->filename.toFilesystemEncoding();
-
        FileName backupName;
        bool madeBackup = false;
 
@@ -1036,11 +1034,13 @@ bool Buffer::writeFile(FileName const & fname) const
                makeDisplayPath(fname.absFilename()));
        message(str);
 
+       string const encoded_fname = fname.toSafeFilesystemEncoding(os::CREATE);
+
        if (params().compressed) {
-               gz::ogzstream ofs(fname.toFilesystemEncoding().c_str(), ios::out|ios::trunc);
+               gz::ogzstream ofs(encoded_fname.c_str(), ios::out|ios::trunc);
                retval = ofs && write(ofs);
        } else {
-               ofstream ofs(fname.toFilesystemEncoding().c_str(), ios::out|ios::trunc);
+               ofstream ofs(encoded_fname.c_str(), ios::out|ios::trunc);
                retval = ofs && write(ofs);
        }
 
@@ -1310,39 +1310,35 @@ void Buffer::writeLaTeXSource(odocstream & os,
                        // We don't know the encoding of inputpath
                        docstring const inputpath = from_utf8(latex_path(original_path));
                        docstring uncodable_glyphs;
-                       for (size_t n = 0; n < inputpath.size(); ++n) {
-                               docstring const glyph = docstring(1, inputpath[n]);
-                               try {
-                                       if (runparams.encoding
-                                           && runparams.encoding->latexChar(inputpath[n]) != glyph) {
+                       Encoding const * const enc = runparams.encoding;
+                       if (enc) {
+                               for (size_t n = 0; n < inputpath.size(); ++n) {
+                                       docstring const glyph =
+                                               docstring(1, inputpath[n]);
+                                       if (enc->latexChar(inputpath[n], true) != glyph) {
                                                LYXERR0("Uncodable character '"
                                                        << glyph
                                                        << "' in input path!");
                                                uncodable_glyphs += glyph;
                                        }
-                               } catch (EncodingException & /* e */) {
-                                       LYXERR0("Uncodable character '"
-                                               << glyph
-                                               << "' in input path!");
-                                       uncodable_glyphs += glyph;
                                }
                        }
 
                        // warn user if we found uncodable glyphs.
                        if (!uncodable_glyphs.empty()) {
-                               frontend::Alert::warning(_("Uncodable character in path"),
+                               frontend::Alert::warning(_("Uncodable character in file path"),
                                                support::bformat(_("The path of your document\n"
                                                  "(%1$s)\n"
                                                  "contains glyphs that are unknown in the\n"
                                                  "current document encoding (namely %2$s).\n"
                                                  "This will likely result in incomplete output.\n\n"
                                                  "Chose an appropriate document encoding (such as utf8)\n"
-                                                 "or change the path name."), inputpath, uncodable_glyphs));
+                                                 "or change the file path name."), inputpath, uncodable_glyphs));
                        } else {
                                os << "\\makeatletter\n"
-                                 << "\\def\\input@path{{"
-                                 << inputpath << "/}}\n"
-                                 << "\\makeatother\n";
+                                  << "\\def\\input@path{{"
+                                  << inputpath << "/}}\n"
+                                  << "\\makeatother\n";
                                d->texrow.newline();
                                d->texrow.newline();
                                d->texrow.newline();
@@ -1554,7 +1550,7 @@ void Buffer::writeLyXHTMLSource(odocstream & os,
 {
        LaTeXFeatures features(*this, params(), runparams);
        validate(features);
-       updateLabels(UpdateMaster, OutputUpdate);
+       updateBuffer(UpdateMaster, OutputUpdate);
        checkBibInfoCache();
        d->bibinfo_.makeCitationLabels(*this);
        updateMacros();
@@ -1611,6 +1607,7 @@ int Buffer::runChktex()
        OutputParams runparams(&params().encoding());
        runparams.flavor = OutputParams::LATEX;
        runparams.nice = false;
+       runparams.linelen = lyxrc.plaintext_linelen;
        makeLaTeXFile(FileName(name), org_path, runparams);
 
        TeXErrors terr;
@@ -1897,7 +1894,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
 
        case LFUN_BUFFER_EXPORT: {
                bool success = doExport(argument, false, false);
-               dr.setError(success);
+               dr.setError(!success);
                if (!success)
                        dr.setMessage(bformat(_("Error exporting to format: %1$s."), 
                                              func.argument()));
@@ -2216,6 +2213,9 @@ std::set<Language const *> Buffer::getLanguages() const
 void Buffer::getLanguages(std::set<Language const *> & languages) const
 {
        ParConstIterator end = par_iterator_end();
+       // add the buffer language, even if it's not actively used
+       languages.insert(language());
+       // iterate over the paragraphs
        for (ParConstIterator it = par_iterator_begin(); it != end; ++it)
                it->getLanguages(languages);
        // also children
@@ -3565,7 +3565,7 @@ void Buffer::setBuffersForInsets() const
 }
 
 
-void Buffer::updateLabels(UpdateScope scope, UpdateType utype) const
+void Buffer::updateBuffer(UpdateScope scope, UpdateType utype) const
 {
        // Use the master text class also for child documents
        Buffer const * const master = masterBuffer();
@@ -3583,7 +3583,7 @@ void Buffer::updateLabels(UpdateScope scope, UpdateType utype) const
                // If this is a child document start with the master
                if (master != this) {
                        bufToUpdate.insert(this);
-                       master->updateLabels(UpdateMaster, utype);
+                       master->updateBuffer(UpdateMaster, utype);
                        // Do this here in case the master has no gui associated with it. Then, 
                        // the TocModel is not updated and TocModel::toc_ is invalid (bug 5699).
                        if (!master->d->gui_)
@@ -3611,7 +3611,7 @@ void Buffer::updateLabels(UpdateScope scope, UpdateType utype) const
 
        // do the real work
        ParIterator parit = cbuf.par_iterator_begin();
-       updateLabels(parit, utype);
+       updateBuffer(parit, utype);
 
        if (master != this)
                // TocBackend update will be done later.
@@ -3822,7 +3822,7 @@ void Buffer::Impl::setLabel(ParIterator & it, UpdateType utype) const
 }
 
 
-void Buffer::updateLabels(ParIterator & parit, UpdateType utype) const
+void Buffer::updateBuffer(ParIterator & parit, UpdateType utype) const
 {
        LASSERT(parit.pit() == 0, /**/);
 
@@ -3855,7 +3855,7 @@ void Buffer::updateLabels(ParIterator & parit, UpdateType utype) const
                InsetList::const_iterator end = parit->insetList().end();
                for (; iit != end; ++iit) {
                        parit.pos() = iit->pos;
-                       iit->inset->updateLabels(parit, utype);
+                       iit->inset->updateBuffer(parit, utype);
                }
        }
 }
@@ -3906,7 +3906,7 @@ bool Buffer::reload()
 
        bool const success = loadLyXFile(d->filename);
        if (success) {
-               updateLabels();
+               updateBuffer();
                changed(true);
                markClean();
                message(bformat(_("Document %1$s reloaded."), disp_fn));