]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
Make layout test compile
[lyx.git] / src / Buffer.cpp
index 394e12d993624c98fbceea67c6fde251c2b90679..cbd46266e938c09351e11982e02dfd00165fb41e 100644 (file)
@@ -28,7 +28,7 @@
 #include "CutAndPaste.h"
 #include "DispatchResult.h"
 #include "DocIterator.h"
-#include "Encoding.h"
+#include "BufferEncodings.h"
 #include "ErrorList.h"
 #include "Exporter.h"
 #include "Format.h"
@@ -58,7 +58,6 @@
 #include "SpellChecker.h"
 #include "sgml.h"
 #include "TexRow.h"
-#include "TexStream.h"
 #include "Text.h"
 #include "TextClass.h"
 #include "TocBackend.h"
@@ -323,7 +322,7 @@ public:
        CloneList * clone_list_;
        /// are we in the process of exporting this buffer?
        mutable bool doing_export;
+
        /// compute statistics
        /// \p from initial position
        /// \p to points to the end position
@@ -354,6 +353,7 @@ private:
 /// Creates the per buffer temporary directory
 static FileName createBufferTmpDir()
 {
+       // FIXME THREAD
        static int count;
        // We are in our own directory.  Why bother to mangle name?
        // In fact I wrote this code to circumvent a problematic behaviour
@@ -529,7 +529,7 @@ void Buffer::cloneWithChildren(BufferMap & bufmap, CloneList * clones) const
 
        // The clone needs its own DocumentClass, since running updateBuffer() will
        // modify it, and we would otherwise be sharing it with the original Buffer.
-       buffer_clone->params().makeDocumentClass();
+       buffer_clone->params().makeDocumentClass(true);
        ErrorList el;
        cap::switchBetweenClasses(
                        params().documentClassPtr(), buffer_clone->params().documentClassPtr(),
@@ -577,7 +577,7 @@ Buffer * Buffer::cloneBufferOnly() const {
 
        // The clone needs its own DocumentClass, since running updateBuffer() will
        // modify it, and we would otherwise be sharing it with the original Buffer.
-       buffer_clone->params().makeDocumentClass();
+       buffer_clone->params().makeDocumentClass(true);
        ErrorList el;
        cap::switchBetweenClasses(
                        params().documentClassPtr(), buffer_clone->params().documentClassPtr(),
@@ -636,6 +636,21 @@ BufferParams const & Buffer::params() const
 }
 
 
+BufferParams const & Buffer::masterParams() const
+{
+       if (masterBuffer() == this)
+               return params();
+
+       BufferParams & mparams = const_cast<Buffer *>(masterBuffer())->params();
+       // Copy child authors to the params. We need those pointers.
+       AuthorList const & child_authors = params().authors();
+       AuthorList::Authors::const_iterator it = child_authors.begin();
+       for (; it != child_authors.end(); it++)
+               mparams.authors().record(*it);
+       return mparams;
+}
+
+
 ParagraphList & Buffer::paragraphs()
 {
        return text().paragraphs();
@@ -913,7 +928,7 @@ bool Buffer::readDocument(Lexer & lex)
 
        readHeader(lex);
 
-       if (params().outputChanges) {
+       if (params().output_changes) {
                bool dvipost    = LaTeXFeatures::isAvailable("dvipost");
                bool xcolorulem = LaTeXFeatures::isAvailable("ulem") &&
                                  LaTeXFeatures::isAvailable("xcolor");
@@ -933,7 +948,7 @@ bool Buffer::readDocument(Lexer & lex)
                }
        }
 
-       if (!params().master.empty()) {
+       if (!parent() && !params().master.empty()) {
                FileName const master_file = makeAbsPath(params().master,
                           onlyPath(absFileName()));
                if (isLyXFileName(master_file.absFileName())) {
@@ -994,7 +1009,8 @@ bool Buffer::importString(string const & format, docstring const & contents, Err
        TempFile const tempfile("Buffer_importStringXXXXXX." + fmt->extension());
        FileName const name(tempfile.name());
        ofdocstream os(name.toFilesystemEncoding().c_str());
-       bool const success = (os << contents);
+       // Do not convert os implicitly to bool, since that is forbidden in C++11.
+       bool const success = !(os << contents).fail();
        os.close();
 
        bool converted = false;
@@ -1484,7 +1500,6 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
        if (!openFileWrite(ofs, fname))
                return false;
 
-       //TexStream ts(ofs.rdbuf(), &texrow());
        ErrorList & errorList = d->errorLists["Export"];
        errorList.clear();
        bool failed_export = false;
@@ -1536,7 +1551,10 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
                lyxerr << "File '" << fname << "' was not closed properly." << endl;
        }
 
-       errors("Export");
+       if (runparams_in.silent)
+               errorList.clear();
+       else
+               errors("Export");
        return !failed_export;
 }
 
@@ -1558,7 +1576,7 @@ void Buffer::writeLaTeXSource(otexstream & os,
                d->ignore_parent = true;
 
        // Classify the unicode characters appearing in math insets
-       Encodings::initUnicodeMath(*this);
+       BufferEncodings::initUnicodeMath(*this);
 
        // validate the buffer.
        LYXERR(Debug::LATEX, "  Validating buffer...");
@@ -1916,7 +1934,7 @@ void Buffer::writeLyXHTMLSource(odocstream & os,
                                            << ";\n";
                                css << "}\n";
                }
-               
+
                docstring const dstyles = css.str();
                if (!dstyles.empty()) {
                        bool written = false;
@@ -2000,7 +2018,10 @@ int Buffer::runChktex()
 
        setBusy(false);
 
-       errors("ChkTeX");
+       if (runparams.silent)
+               d->errorLists["ChkTeX"].clear();
+       else
+               errors("ChkTeX");
 
        return res;
 }
@@ -2365,9 +2386,13 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
                break;
        }
 
-       case LFUN_BUILD_PROGRAM:
-               doExport("program", true);
+       case LFUN_BUILD_PROGRAM: {
+               ExportStatus const status = doExport("program", true);
+               dr.setError(status != ExportSuccess);
+               if (status != ExportSuccess)
+                       dr.setMessage(_("Error generating literate programming code."));
                break;
+       }
 
        case LFUN_BUFFER_CHKTEX:
                runChktex();
@@ -2481,6 +2506,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
                                        msg += ("\n");
                                msg += bformat(_("Branch \"%1$s\" already exists."), branch_name);
                        } else {
+                               undo().recordUndoFullDocument(CursorData());
                                branch_list.add(branch_name);
                                branch = branch_list.find(branch_name);
                                string const x11hexname = X11hexname(branch->color());
@@ -2556,7 +2582,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
                        break;
                }
 
-               if (!doExport("dvi", true)) {
+               if (doExport("dvi", true) != ExportSuccess) {
                        showPrintError(absFileName());
                        dr.setMessage(_("Error exporting to DVI."));
                        break;
@@ -3439,7 +3465,7 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to)
 
        string const paramName = "key";
        for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
-               if (it->lyxCode() != CITE_CODE) 
+               if (it->lyxCode() != CITE_CODE)
                        continue;
                InsetCommand * inset = it->asInsetCommand();
                docstring const oldValue = inset->getParam(paramName);
@@ -3968,17 +3994,21 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir
        // Emit the signal to show the error list or copy it back to the
        // cloned Buffer so that it can be emitted afterwards.
        if (format != backend_format) {
-               if (d->cloned_buffer_) {
+               if (runparams.silent)
+                       error_list.clear();
+               else if (d->cloned_buffer_)
                        d->cloned_buffer_->d->errorLists[error_type] =
                                d->errorLists[error_type];
-               else
+               else
                        errors(error_type);
                // also to the children, in case of master-buffer-view
                ListOfBuffers clist = getDescendents();
                ListOfBuffers::const_iterator cit = clist.begin();
                ListOfBuffers::const_iterator const cen = clist.end();
                for (; cit != cen; ++cit) {
-                       if (d->cloned_buffer_) {
+                       if (runparams.silent)
+                               (*cit)->d->errorLists[error_type].clear();
+                       else if (d->cloned_buffer_) {
                                // Enable reverse search by copying back the
                                // texrow object to the cloned buffer.
                                // FIXME: this is not thread safe.
@@ -4333,9 +4363,15 @@ void Buffer::updateBuffer(UpdateScope scope, UpdateType utype) const
                if (master != this) {
                        bufToUpdate.insert(this);
                        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_)
+                       // If the master buffer has no gui associated with it, then the TocModel is 
+                       // not updated during the updateBuffer call and TocModel::toc_ is invalid 
+                       // (bug 5699). The same happens if the master buffer is open in a different 
+                       // window. This test catches both possibilities.
+                       // See: http://marc.info/?l=lyx-devel&m=138590578911716&w=2
+                       // There remains a problem here: If there is another child open in yet a third
+                       // window, that TOC is not updated. So some more general solution is needed at
+                       // some point.
+                       if (master->d->gui_ != d->gui_)
                                structureChanged();
 
                        // was buf referenced from the master (i.e. not in bufToUpdate anymore)?
@@ -4671,16 +4707,16 @@ void Buffer::Impl::updateStatistics(DocIterator & from, DocIterator & to, bool s
        word_count_ = 0;
        char_count_ = 0;
        blank_count_ = 0;
+
        for (DocIterator dit = from ; dit != to && !dit.atEnd(); ) {
                if (!dit.inTexted()) {
                        dit.forwardPos();
                        continue;
                }
-               
+
                Paragraph const & par = dit.paragraph();
                pos_type const pos = dit.pos();
-               
+
                // Copied and adapted from isWordSeparator() in Paragraph
                if (pos == dit.lastpos()) {
                        inword = false;
@@ -4694,7 +4730,7 @@ void Buffer::Impl::updateStatistics(DocIterator & from, DocIterator & to, bool s
                                        break;
                                continue;
                        } else if (!par.isDeleted(pos)) {
-                               if (par.isWordSeparator(pos)) 
+                               if (par.isWordSeparator(pos))
                                        inword = false;
                                else if (!inword) {
                                        ++word_count_;
@@ -4736,7 +4772,7 @@ int Buffer::charCount(bool with_blanks) const
 }
 
 
-Buffer::ReadStatus Buffer::reload(bool clearUndo)
+Buffer::ReadStatus Buffer::reload()
 {
        setBusy(true);
        // c.f. bug http://www.lyx.org/trac/ticket/6587
@@ -4754,8 +4790,7 @@ Buffer::ReadStatus Buffer::reload(bool clearUndo)
                updateTitles();
                markClean();
                message(bformat(_("Document %1$s reloaded."), disp_fn));
-               if (clearUndo)
-                       d->undo_.clear();
+               d->undo_.clear();
        } else {
                message(bformat(_("Could not reload document %1$s."), disp_fn));
        }