]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
Fix screen display of parts and chapters in default classes
[lyx.git] / src / Buffer.cpp
index 9de281daf35a5ed505541b6f1482664e8b759727..23f6315f5f63dc69cdc1878977dc6112883a3751 100644 (file)
@@ -14,7 +14,6 @@
 #include "Buffer.h"
 
 #include "Author.h"
-#include "LayoutFile.h"
 #include "BiblioInfo.h"
 #include "BranchList.h"
 #include "buffer_funcs.h"
@@ -67,9 +66,7 @@
 #include "VCBackend.h"
 #include "version.h"
 #include "WordLangTuple.h"
-#include "WordList.h"
 
-#include "insets/InsetBibtex.h"
 #include "insets/InsetBranch.h"
 #include "insets/InsetInclude.h"
 #include "insets/InsetTabular.h"
@@ -80,7 +77,6 @@
 #include "mathed/InsetMathMacroTemplate.h"
 #include "mathed/MathSupport.h"
 
-#include "graphics/GraphicsCache.h"
 #include "graphics/PreviewLoader.h"
 
 #include "frontends/Application.h"
 #include "support/FileName.h"
 #include "support/FileNameList.h"
 #include "support/filetools.h"
-#include "support/ForkedCalls.h"
 #include "support/gettext.h"
 #include "support/gzstream.h"
 #include "support/lstrings.h"
-#include "support/lyxalgo.h"
 #include "support/mutex.h"
 #include "support/os.h"
 #include "support/Package.h"
@@ -664,7 +658,6 @@ void Buffer::cloneWithChildren(BufferMap & bufmap, CloneList_ptr clones) const
                buffer_clone->setChild(dit, child_clone);
        }
        buffer_clone->d->macro_lock = false;
-       return;
 }
 
 
@@ -1190,9 +1183,8 @@ bool Buffer::readString(string const & s)
 
 Buffer::ReadStatus Buffer::readFile(FileName const & fn)
 {
-       FileName fname(fn);
        Lexer lex;
-       if (!lex.setFile(fname)) {
+       if (!lex.setFile(fn)) {
                Alert::error(_("File Not Found"),
                        bformat(_("Unable to open file `%1$s'."),
                                from_utf8(fn.absFileName())));
@@ -1357,7 +1349,7 @@ Buffer::ReadStatus Buffer::convertLyXFormat(FileName const & fn,
        LYXERR(Debug::INFO, "Running '" << command_str << '\'');
 
        cmd_ret const ret = runCommand(command_str);
-       if (ret.first != 0) {
+       if (!ret.valid) {
                if (from_format < LYX_FORMAT) {
                        Alert::error(_("Conversion script failed"),
                                bformat(_("%1$s is from an older version"
@@ -1549,9 +1541,8 @@ bool Buffer::save() const
                // time stamp is invalidated by copying/moving
                saveCheckSum();
                markClean();
-               if (d->file_format != LYX_FORMAT)
-                       // the file associated with this buffer is now in the current format
-                       d->file_format = LYX_FORMAT;
+               // the file associated with this buffer is now in the current format
+               d->file_format = LYX_FORMAT;
                return true;
        }
        // else we saved the file, but failed to move it to the right location.
@@ -1618,7 +1609,7 @@ bool Buffer::writeFile(FileName const & fname) const
 }
 
 
-docstring Buffer::emergencyWrite()
+docstring Buffer::emergencyWrite() const
 {
        // No need to save if the buffer has not changed.
        if (isClean())
@@ -1905,9 +1896,9 @@ Buffer::ExportStatus Buffer::writeLaTeXSource(otexstream & os,
                        docstring uncodable_glyphs;
                        Encoding const * const enc = runparams.encoding;
                        if (enc) {
-                               for (size_t n = 0; n < inputpath.size(); ++n) {
-                                       if (!enc->encodable(inputpath[n])) {
-                                               docstring const glyph(1, inputpath[n]);
+                               for (char_type n : inputpath) {
+                                       if (!enc->encodable(n)) {
+                                               docstring const glyph(1, n);
                                                LYXERR0("Uncodable character '"
                                                        << glyph
                                                        << "' in input path!");
@@ -2138,9 +2129,7 @@ Buffer::ExportStatus Buffer::writeDocBookSource(odocstream & os,
        bool const output_preamble =
                output == FullSource || output == OnlyPreamble;
        bool const output_body =
-         output == FullSource || output == OnlyBody;
-
-       XMLStream xs(os);
+         output == FullSource || output == OnlyBody || output == IncludedFile;
 
        if (output_preamble) {
                // XML preamble, no doctype needed.
@@ -2164,16 +2153,17 @@ Buffer::ExportStatus Buffer::writeDocBookSource(odocstream & os,
        }
 
        if (output_body) {
-               params().documentClass().counters().reset();
-
                // Start to output the document.
+               XMLStream xs(os);
                docbookParagraphs(text(), *this, xs, runparams);
        }
 
        if (output_preamble) {
-               // Close the root element.
-               os << "\n</" << from_ascii(tclass.docbookroot()) << ">";
+               // Close the root element. No need for a line break, as free text is never allowed
+               // in a root element, it must always be wrapped in some container.
+               os << "</" << from_ascii(tclass.docbookroot()) << ">";
        }
+
        return ExportSuccess;
 }
 
@@ -2711,7 +2701,7 @@ bool Buffer::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                break;
 
        case LFUN_BUFFER_EXPORT: {
-               docstring const arg = cmd.argument();
+               docstring const arg = cmd.argument();
                if (arg == "custom") {
                        enable = true;
                        break;
@@ -2740,7 +2730,7 @@ bool Buffer::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                                     || cmd.action() == LFUN_BRANCH_MASTER_DEACTIVATE);
                BranchList const & branchList = master ? masterBuffer()->params().branchlist()
                        : params().branchlist();
-               docstring const branchName = cmd.argument();
+               docstring const branchName = cmd.argument();
                flag.setEnabled(!branchName.empty() && branchList.find(branchName));
                break;
        }
@@ -2902,7 +2892,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
                Buffer * buf = master ? const_cast<Buffer *>(masterBuffer())
                                      : this;
 
-               docstring const branch_name = func.argument();
+               docstring const branch_name = func.argument();
                // the case without a branch name is handled elsewhere
                if (branch_name.empty()) {
                        dispatched = false;
@@ -2930,7 +2920,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
        }
 
        case LFUN_BRANCH_ADD: {
-               docstring branchnames = func.argument();
+               docstring const & branchnames = func.argument();
                if (branchnames.empty()) {
                        dispatched = false;
                        break;
@@ -3535,19 +3525,19 @@ bool Buffer::hasChildren() const
 }
 
 
-void Buffer::collectChildren(ListOfBuffers & clist, bool grand_children) const
+void Buffer::collectChildren(ListOfBuffers & children, bool grand_children) const
 {
        // loop over children
        for (auto const & p : d->children_positions) {
                Buffer * child = const_cast<Buffer *>(p.first);
                // No duplicates
-               ListOfBuffers::const_iterator bit = find(clist.begin(), clist.end(), child);
-               if (bit != clist.end())
+               ListOfBuffers::const_iterator bit = find(children.begin(), children.end(), child);
+               if (bit != children.end())
                        continue;
-               clist.push_back(child);
+               children.push_back(child);
                if (grand_children)
                        // there might be grandchildren
-                       child->collectChildren(clist, true);
+                       child->collectChildren(children, true);
        }
 }
 
@@ -3736,7 +3726,6 @@ void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope)
        while (it.pit() <= lastpit) {
                Paragraph & par = it.paragraph();
 
-               // FIXME Can this be done with the new-style iterators?
                // iterate over the insets of the current paragraph
                for (auto const & insit : par.insetList()) {
                        it.pos() = insit.pos;
@@ -3782,9 +3771,7 @@ void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope)
 
                                // register its position, but only when it is
                                // included first in the buffer
-                               if (children_positions.find(child) ==
-                                       children_positions.end())
-                                               children_positions[child] = it;
+                               children_positions.insert({child, it});
 
                                // register child with its scope
                                position_to_children[it] = Impl::ScopeBuffer(scope, child);
@@ -4012,10 +3999,7 @@ InsetLabel const * Buffer::insetLabel(docstring const & label,
 
 bool Buffer::activeLabel(docstring const & label) const
 {
-       if (!insetLabel(label, true))
-               return false;
-
-       return true;
+       return insetLabel(label, true) != nullptr;
 }
 
 
@@ -4470,7 +4454,7 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir
        // DocBook backend
        else if (backend_format == "docbook5") {
                runparams.flavor = OutputParams::DOCBOOK5;
-               runparams.nice = !put_in_tempdir;
+               runparams.nice = false;
                if (makeDocBookFile(FileName(filename), runparams) == ExportKilled)
                        return ExportKilled;
        }
@@ -5168,9 +5152,9 @@ void Buffer::Impl::setLabel(ParIterator & it, UpdateType utype) const
                }
 
                if (needEnumCounterReset(it)) {
-                       // Increase the master counter?
-                       if (layout.stepmastercounter)
-                               counters.stepMaster(enumcounter, utype);
+                       // Increase the parent counter?
+                       if (layout.stepparentcounter)
+                               counters.stepParent(enumcounter, utype);
                        // Maybe we have to reset the enumeration counter.
                        if (!layout.resumecounter)
                                counters.reset(enumcounter);