X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FBuffer.cpp;h=3a6ae648b25885b5009da363c47659c56098b58e;hb=33f9cfb7961501b38c573eede468b011687f46de;hp=acda58f46fc4a4ab7f2f586fec6c1458ac95fefe;hpb=01e673635b0701cd0cd19ef96bc5e4b3879b6db1;p=lyx.git diff --git a/src/Buffer.cpp b/src/Buffer.cpp index acda58f46f..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" @@ -1275,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(); @@ -1772,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)"), @@ -2321,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 = @@ -2581,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) @@ -2593,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); } @@ -2959,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) { @@ -3139,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 { @@ -3730,11 +3732,10 @@ void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope) for (auto const & insit : par.insetList()) { it.pos() = insit.pos; - switch (insit.inset->lyxCode()) { // is it a nested text inset? - case TEXT_CODE: { - InsetText const * itext = insit.inset->asInsetText(); + if (insit.inset->asInsetText()) { // Inset needs its own scope? + InsetText const * itext = insit.inset->asInsetText(); bool newScope = itext->isMacroScope(); // scope which ends just behind the inset @@ -3745,9 +3746,10 @@ void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope) it.push_back(CursorSlice(*insit.inset)); updateMacros(it, newScope ? insetScope : scope); it.pop_back(); - break; + continue; } - case TABULAR_CODE: { + + if (insit.inset->asInsetTabular()) { CursorSlice slice(*insit.inset); size_t const numcells = slice.nargs(); for (; slice.idx() < numcells; slice.forwardIdx()) { @@ -3755,10 +3757,11 @@ void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope) updateMacros(it, scope); it.pop_back(); } - break; + continue; } + // is it an external file? - case INCLUDE_CODE: { + if (insit.inset->lyxCode() == INCLUDE_CODE) { // get buffer of external file InsetInclude const & incinset = static_cast(*insit.inset); @@ -3766,7 +3769,7 @@ void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope) Buffer * child = incinset.loadIfNeeded(); macro_lock = false; if (!child) - break; + continue; // register its position, but only when it is // included first in the buffer @@ -3774,40 +3777,38 @@ void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope) // register child with its scope position_to_children[it] = Impl::ScopeBuffer(scope, child); - break; - } - case MATH_HULL_CODE: { - if (!doing_export) - break; - InsetMathHull * hull = insit.inset->asInsetMath()->asHullInset(); - hull->recordLocation(it); - break; - } - case MATHMACRO_CODE: { - // get macro data - InsetMathMacroTemplate & macroTemplate = - *insit.inset->asInsetMath()->asMacroTemplate(); - MacroContext mc(owner_, it); - macroTemplate.updateToContext(mc); - - // valid? - bool valid = macroTemplate.validMacro(); - // FIXME: Should be fixNameAndCheckIfValid() in fact, - // then the BufferView's cursor will be invalid in - // some cases which leads to crashes. - if (!valid) - break; - - // register macro - // FIXME (Abdel), I don't understand why we pass 'it' here - // instead of 'macroTemplate' defined above... is this correct? - macros[macroTemplate.name()][it] = - Impl::ScopeMacro(scope, MacroData(owner_, it)); - break; + continue; } - default: - break; + + InsetMath * im = insit.inset->asInsetMath(); + if (doing_export && im) { + InsetMathHull * hull = im->asHullInset(); + if (hull) + hull->recordLocation(it); } + + if (insit.inset->lyxCode() != MATHMACRO_CODE) + continue; + + // get macro data + InsetMathMacroTemplate & macroTemplate = + *insit.inset->asInsetMath()->asMacroTemplate(); + MacroContext mc(owner_, it); + macroTemplate.updateToContext(mc); + + // valid? + bool valid = macroTemplate.validMacro(); + // FIXME: Should be fixNameAndCheckIfValid() in fact, + // then the BufferView's cursor will be invalid in + // some cases which leads to crashes. + if (!valid) + continue; + + // register macro + // FIXME (Abdel), I don't understand why we pass 'it' here + // instead of 'macroTemplate' defined above... is this correct? + macros[macroTemplate.name()][it] = + Impl::ScopeMacro(scope, MacroData(const_cast(owner_), it)); } // next paragraph @@ -3842,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); @@ -3854,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; @@ -3883,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); } @@ -4028,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; @@ -4072,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 { @@ -4126,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); @@ -4135,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 @@ -4377,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(); @@ -4421,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); @@ -4438,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); } @@ -4446,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; @@ -4454,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;