X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FBuffer.cpp;h=3a6ae648b25885b5009da363c47659c56098b58e;hb=33f9cfb7961501b38c573eede468b011687f46de;hp=940f30cd1cf4a10a46e9455bb733b026beff56c3;hpb=dbe35af5428a37a49030549ca15d809881f26511;p=lyx.git diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 940f30cd1c..3a6ae648b2 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -69,7 +69,6 @@ #include "insets/InsetBranch.h" #include "insets/InsetInclude.h" -#include "insets/InsetTabular.h" #include "insets/InsetText.h" #include "mathed/InsetMathHull.h" @@ -1183,9 +1182,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()))); @@ -1276,9 +1274,9 @@ void Buffer::updatePreviews() const if (!ploader) return; - InsetIterator it = inset_iterator_begin(*d->inset); - InsetIterator const end = inset_iterator_end(*d->inset); - for (; it != end; ++it) + InsetIterator it = begin(*d->inset); + InsetIterator const itend = end(*d->inset); + for (; it != itend; ++it) it->addPreview(it, *ploader); ploader->startLoading(); @@ -1773,7 +1771,7 @@ Buffer::ExportStatus Buffer::makeLaTeXFile(FileName const & fname, catch (EncodingException const & e) { docstring const failed(1, e.failed_char); ostringstream oss; - oss << "0x" << hex << e.failed_char << dec; + oss << "0x" << hex << static_cast(e.failed_char) << dec; if (getParFromID(e.par_id).paragraph().layout().pass_thru) { docstring msg = bformat(_("Uncodable character '%1$s'" " (code point %2$s)"), @@ -2322,7 +2320,7 @@ int Buffer::runChktex() // Generate the LaTeX file if neccessary OutputParams runparams(¶ms().encoding()); - runparams.flavor = OutputParams::LATEX; + runparams.flavor = Flavor::LaTeX; runparams.nice = false; runparams.linelen = lyxrc.plaintext_linelen; ExportStatus const retval = @@ -2582,7 +2580,7 @@ void Buffer::collectBibKeys(FileNameList & checkedFiles) const if (!parent()) clearIncludeList(); - for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) { + for (InsetIterator it = begin(inset()); it; ++it) { it->collectBibKeys(it, checkedFiles); if (it->lyxCode() == BIBITEM_CODE) { if (parent() != nullptr) @@ -2594,18 +2592,16 @@ void Buffer::collectBibKeys(FileNameList & checkedFiles) const } -void Buffer::addBiblioInfo(BiblioInfo const & bin) const +void Buffer::addBiblioInfo(BiblioInfo const & bi_in) const { - // We add the biblio info to the master buffer, - // if there is one, but also to every single buffer, - // in case a child is compiled alone. - BiblioInfo & bi = d->bibinfo_; - bi.mergeBiblioInfo(bin); + // We add the biblio info to the parent buffer, + // if there is one, but also to this buffer, in case + // it is compiled alone. + BiblioInfo & our_bi = d->bibinfo_; + our_bi.mergeBiblioInfo(bi_in); - if (parent() != nullptr) { - BiblioInfo & masterbi = parent()->d->bibinfo_; - masterbi.mergeBiblioInfo(bin); - } + if (parent()) + parent()->addBiblioInfo(bi_in); } @@ -2702,7 +2698,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; @@ -2731,7 +2727,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; } @@ -2893,7 +2889,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr) Buffer * buf = master ? const_cast(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; @@ -2921,7 +2917,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; @@ -2960,10 +2956,10 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr) docstring const oldname = from_utf8(func.getArg(0)); docstring const newname = from_utf8(func.getArg(1)); - InsetIterator it = inset_iterator_begin(inset()); - InsetIterator const end = inset_iterator_end(inset()); + InsetIterator it = begin(inset()); + InsetIterator const itend = end(inset()); bool success = false; - for (; it != end; ++it) { + for (; it != itend; ++it) { if (it->lyxCode() == BRANCH_CODE) { InsetBranch & ins = static_cast(*it); if (ins.branch() == oldname) { @@ -3140,6 +3136,11 @@ ParConstIterator Buffer::par_iterator_end() const return ParConstIterator(doc_iterator_end(this)); } +bool Buffer::empty() const +{ + return paragraphs().size() == 1 && paragraphs().front().empty(); +} + Language const * Buffer::language() const { @@ -3526,19 +3527,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(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); } } @@ -3727,7 +3728,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; @@ -3843,11 +3843,9 @@ void Buffer::updateMacros() const void Buffer::getUsedBranches(std::list & result, bool const from_master) const { - InsetIterator it = inset_iterator_begin(inset()); - InsetIterator const end = inset_iterator_end(inset()); - for (; it != end; ++it) { - if (it->lyxCode() == BRANCH_CODE) { - InsetBranch & br = static_cast(*it); + for (Inset const & it : inset()) { + if (it.lyxCode() == BRANCH_CODE) { + InsetBranch const & br = static_cast(it); docstring const name = br.branch(); if (!from_master && !params().branchlist().find(name)) result.push_back(name); @@ -3855,10 +3853,10 @@ void Buffer::getUsedBranches(std::list & result, bool const from_mast result.push_back(name); continue; } - if (it->lyxCode() == INCLUDE_CODE) { + if (it.lyxCode() == INCLUDE_CODE) { // get buffer of external file InsetInclude const & ins = - static_cast(*it); + static_cast(it); Buffer * child = ins.loadIfNeeded(); if (!child) continue; @@ -3884,9 +3882,9 @@ void Buffer::updateMacroInstances(UpdateType utype) const continue; // update macro in all cells of the InsetMathNest - DocIterator::idx_type n = minset->nargs(); + idx_type n = minset->nargs(); MacroContext mc = MacroContext(this, it); - for (DocIterator::idx_type i = 0; i < n; ++i) { + for (idx_type i = 0; i < n; ++i) { MathData & data = minset->cell(i); data.updateMacros(nullptr, mc, utype, 0); } @@ -4029,7 +4027,7 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to) string const paramName = "key"; UndoGroupHelper ugh(this); - InsetIterator it = inset_iterator_begin(inset()); + InsetIterator it = begin(inset()); for (; it; ++it) { if (it->lyxCode() != CITE_CODE) continue; @@ -4073,23 +4071,23 @@ unique_ptr Buffer::getSourceCode(odocstream & os, string const & format, << "\n\n"; } // output paragraphs - if (runparams.flavor == OutputParams::LYX) { + if (runparams.flavor == Flavor::LyX) { Paragraph const & par = text().paragraphs()[par_begin]; ostringstream ods; depth_type dt = par.getDepth(); par.write(ods, params(), dt); os << from_utf8(ods.str()); - } else if (runparams.flavor == OutputParams::HTML) { + } else if (runparams.flavor == Flavor::Html) { XMLStream xs(os); setMathFlavor(runparams); xhtmlParagraphs(text(), *this, xs, runparams); - } else if (runparams.flavor == OutputParams::TEXT) { + } else if (runparams.flavor == Flavor::Text) { bool dummy = false; // FIXME Handles only one paragraph, unlike the others. // Probably should have some routine with a signature like them. writePlaintextParagraph(*this, text().paragraphs()[par_begin], os, runparams, dummy); - } else if (runparams.flavor == OutputParams::DOCBOOK5) { + } else if (runparams.flavor == Flavor::DocBook5) { XMLStream xs{os}; docbookParagraphs(text(), *this, xs, runparams); } else { @@ -4127,7 +4125,7 @@ unique_ptr Buffer::getSourceCode(odocstream & os, string const & format, else if (output == OnlyBody) os << _("Preview body"); os << "\n\n"; - if (runparams.flavor == OutputParams::LYX) { + if (runparams.flavor == Flavor::LyX) { ostringstream ods; if (output == FullSource) write(ods); @@ -4136,14 +4134,14 @@ unique_ptr Buffer::getSourceCode(odocstream & os, string const & format, else if (output == OnlyBody) text().write(ods); os << from_utf8(ods.str()); - } else if (runparams.flavor == OutputParams::HTML) { + } else if (runparams.flavor == Flavor::Html) { writeLyXHTMLSource(os, runparams, output); - } else if (runparams.flavor == OutputParams::TEXT) { + } else if (runparams.flavor == Flavor::Text) { if (output == OnlyPreamble) { os << "% "<< _("Plain text does not have a preamble."); } else writePlaintextFile(*this, os, runparams); - } else if (runparams.flavor == OutputParams::DOCBOOK5) { + } else if (runparams.flavor == Flavor::DocBook5) { writeDocBookSource(os, runparams, output); } else { // latex or literate @@ -4378,7 +4376,7 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir } MarkAsExporting exporting(this); string backend_format; - runparams.flavor = OutputParams::LATEX; + runparams.flavor = Flavor::LaTeX; runparams.linelen = lyxrc.plaintext_linelen; runparams.includeall = includeall; vector backs = params().backends(); @@ -4422,13 +4420,13 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir LYXERR(Debug::FILES, "backend_format=" << backend_format); // FIXME: Don't hardcode format names here, but use a flag if (backend_format == "pdflatex") - runparams.flavor = OutputParams::PDFLATEX; + runparams.flavor = Flavor::PdfLaTeX; else if (backend_format == "luatex") - runparams.flavor = OutputParams::LUATEX; + runparams.flavor = Flavor::LuaTeX; else if (backend_format == "dviluatex") - runparams.flavor = OutputParams::DVILUATEX; + runparams.flavor = Flavor::DviLuaTeX; else if (backend_format == "xetex") - runparams.flavor = OutputParams::XETEX; + runparams.flavor = Flavor::XeTeX; } string filename = latexName(false); @@ -4439,7 +4437,7 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir // Plain text backend if (backend_format == "text") { - runparams.flavor = OutputParams::TEXT; + runparams.flavor = Flavor::Text; try { writePlaintextFile(*this, FileName(filename), runparams); } @@ -4447,7 +4445,7 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir } // HTML backend else if (backend_format == "xhtml") { - runparams.flavor = OutputParams::HTML; + runparams.flavor = Flavor::Html; setMathFlavor(runparams); if (makeLyXHTMLFile(FileName(filename), runparams) == ExportKilled) return ExportKilled; @@ -4455,7 +4453,7 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir writeFile(FileName(filename)); // DocBook backend else if (backend_format == "docbook5") { - runparams.flavor = OutputParams::DOCBOOK5; + runparams.flavor = Flavor::DocBook5; runparams.nice = false; if (makeDocBookFile(FileName(filename), runparams) == ExportKilled) return ExportKilled; @@ -5154,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);