From ecef54500d4d77baf4fa47eac2253679875ac08c Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Fri, 8 Mar 2013 14:52:18 -0500 Subject: [PATCH] Introduce max_length parameter for plaintext() output routines, so we can write a limited amount when using this for TOC and tooltip output. This should solve the problem with slowness that Kornel noticed, which was caused by our trying to write an entire plaintext bibliography every time we updated the TOC. We did that because he had a bibliography inside a branch, and we use plaintext for creating the tooltip that goes with the branch list. Other related bugs were fixed along the way. E.g., it turns out that, if someone had an InsetInclude inside a branch, then we would have been writing a *plaintext file* for that inset every time we updated the TOC. I wonder if some of the other reports of slowness we have received might be due to this kind of issue? --- src/OutputParams.cpp | 2 +- src/OutputParams.h | 3 +++ src/Paragraph.cpp | 4 +++- src/TocBackend.cpp | 8 ++++++-- src/TocBackend.h | 3 ++- src/insets/Inset.h | 5 ++++- src/insets/InsetArgument.h | 2 +- src/insets/InsetBibitem.cpp | 3 ++- src/insets/InsetBibitem.h | 3 ++- src/insets/InsetBibtex.cpp | 6 +++++- src/insets/InsetBibtex.h | 3 ++- src/insets/InsetBox.cpp | 5 +++-- src/insets/InsetBox.h | 3 ++- src/insets/InsetBranch.cpp | 6 +++--- src/insets/InsetBranch.h | 3 ++- src/insets/InsetCaption.cpp | 10 +++++---- src/insets/InsetCaption.h | 3 ++- src/insets/InsetCitation.cpp | 7 +++++-- src/insets/InsetCitation.h | 3 ++- src/insets/InsetCommand.cpp | 3 ++- src/insets/InsetCommand.h | 3 ++- src/insets/InsetERT.cpp | 5 +++-- src/insets/InsetERT.h | 3 ++- src/insets/InsetExternal.cpp | 4 ++-- src/insets/InsetExternal.h | 3 ++- src/insets/InsetFloat.cpp | 4 ++-- src/insets/InsetFloat.h | 3 ++- src/insets/InsetFloatList.cpp | 5 +++-- src/insets/InsetFloatList.h | 3 ++- src/insets/InsetFoot.cpp | 5 +++-- src/insets/InsetFoot.h | 3 ++- src/insets/InsetGraphics.cpp | 3 ++- src/insets/InsetGraphics.h | 3 ++- src/insets/InsetHyperlink.cpp | 7 +++++-- src/insets/InsetHyperlink.h | 3 ++- src/insets/InsetIPAMacro.cpp | 12 ++++++----- src/insets/InsetIPAMacro.h | 6 ++++-- src/insets/InsetInclude.cpp | 6 ++++-- src/insets/InsetInclude.h | 3 ++- src/insets/InsetIndex.cpp | 2 +- src/insets/InsetLabel.cpp | 3 ++- src/insets/InsetLabel.h | 3 ++- src/insets/InsetLine.cpp | 3 ++- src/insets/InsetLine.h | 3 ++- src/insets/InsetMarginal.cpp | 6 +++--- src/insets/InsetMarginal.h | 3 ++- src/insets/InsetNewline.cpp | 3 ++- src/insets/InsetNewline.h | 3 ++- src/insets/InsetNewpage.cpp | 3 ++- src/insets/InsetNewpage.h | 3 ++- src/insets/InsetNote.cpp | 6 +++--- src/insets/InsetNote.h | 3 ++- src/insets/InsetPhantom.cpp | 6 +++--- src/insets/InsetPhantom.h | 3 ++- src/insets/InsetQuotes.cpp | 3 ++- src/insets/InsetQuotes.h | 3 ++- src/insets/InsetRef.cpp | 7 +++++-- src/insets/InsetRef.h | 3 ++- src/insets/InsetScript.cpp | 13 ++++++------ src/insets/InsetScript.h | 3 ++- src/insets/InsetSpace.cpp | 7 +++++-- src/insets/InsetSpace.h | 3 ++- src/insets/InsetSpecialChar.cpp | 8 ++++++-- src/insets/InsetSpecialChar.h | 3 ++- src/insets/InsetTOC.cpp | 5 +++-- src/insets/InsetTOC.h | 3 ++- src/insets/InsetTabular.cpp | 35 ++++++++++++++++++-------------- src/insets/InsetTabular.h | 16 ++++++++------- src/insets/InsetText.cpp | 12 +++++++---- src/insets/InsetText.h | 3 ++- src/insets/InsetVSpace.cpp | 3 ++- src/insets/InsetVSpace.h | 3 ++- src/insets/InsetWrap.cpp | 7 +++++-- src/insets/InsetWrap.h | 3 ++- src/mathed/InsetFormulaMacro.cpp | 2 +- src/mathed/InsetFormulaMacro.h | 2 +- src/mathed/InsetMath.cpp | 3 ++- src/mathed/InsetMath.h | 2 +- src/mathed/InsetMathHull.cpp | 9 +++++--- src/mathed/InsetMathHull.h | 3 ++- src/mathed/MathMacroTemplate.cpp | 4 ++-- src/mathed/MathMacroTemplate.h | 2 +- src/output_plaintext.cpp | 11 +++++++--- src/output_plaintext.h | 6 +++++- src/support/docstream.h | 3 --- src/support/strfwd.h | 5 +++++ 86 files changed, 267 insertions(+), 150 deletions(-) diff --git a/src/OutputParams.cpp b/src/OutputParams.cpp index f8af8ad375..0ef0c2c6dd 100644 --- a/src/OutputParams.cpp +++ b/src/OutputParams.cpp @@ -30,7 +30,7 @@ OutputParams::OutputParams(Encoding const * enc) par_begin(0), par_end(0), lastid(-1), lastpos(-1), isLastPar(false), dryrun(false), pass_thru(false), html_disable_captions(false), html_in_par(false), - html_make_pars(true), for_toc(false), includeall(false) + html_make_pars(true), for_toc(false), for_tooltip(false), includeall(false) { // Note: in PreviewLoader::Impl::dumpPreamble // OutputParams runparams(0); diff --git a/src/OutputParams.h b/src/OutputParams.h index 40857d5aa8..b345670144 100644 --- a/src/OutputParams.h +++ b/src/OutputParams.h @@ -261,6 +261,9 @@ public: /// Are we generating this material for inclusion in a TOC-like entity? bool for_toc; + /// Are we generating this material for inclusion in a tooltip? + bool for_tooltip; + /// Include all children notwithstanding the use of \includeonly bool includeall; diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index d025a80b3f..f039a71ed2 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -1046,7 +1046,9 @@ void Paragraph::Private::latexInset(BufferParams const & bparams, LASSERT(inset, /**/); if (style.pass_thru) { - inset->plaintext(os.os(), runparams); + odocstringstream ods; + inset->plaintext(ods, runparams); + os << ods.str(); return; } diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp index e3dcca1d0e..0b9f6b60e8 100644 --- a/src/TocBackend.cpp +++ b/src/TocBackend.cpp @@ -231,14 +231,18 @@ Toc::iterator Toc::item(int depth, docstring const & str) } -void TocBackend::writePlaintextTocList(string const & type, odocstream & os) const +void TocBackend::writePlaintextTocList(string const & type, + odocstringstream & os, size_t max_length) const { TocList::const_iterator cit = tocs_.find(type); if (cit != tocs_.end()) { TocIterator ccit = cit->second.begin(); TocIterator end = cit->second.end(); - for (; ccit != end; ++ccit) + for (; ccit != end; ++ccit) { os << ccit->asString() << from_utf8("\n"); + if (os.str().size() > max_length) + break; + } } } diff --git a/src/TocBackend.h b/src/TocBackend.h index 40d2dbafe1..f3bd1e8823 100644 --- a/src/TocBackend.h +++ b/src/TocBackend.h @@ -128,7 +128,8 @@ public: ) const; /// - void writePlaintextTocList(std::string const & type, odocstream & os) const; + void writePlaintextTocList(std::string const & type, + odocstringstream & os, size_t max_length) const; private: /// diff --git a/src/insets/Inset.h b/src/insets/Inset.h index b82234fbd6..a79ce38ac2 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -24,6 +24,8 @@ #include "support/strfwd.h" #include "support/types.h" +#include + namespace lyx { @@ -314,7 +316,8 @@ public: /// plain text output in ucs4 encoding /// return the number of characters; in case of multiple lines of /// output, add PLAINTEXT_NEWLINE to the number of chars in the last line - virtual int plaintext(odocstream &, OutputParams const &) const = 0; + virtual int plaintext(odocstringstream &, OutputParams const &, + size_t max_length = INT_MAX) const = 0; /// docbook output virtual int docbook(odocstream & os, OutputParams const &) const; /// XHTML output diff --git a/src/insets/InsetArgument.h b/src/insets/InsetArgument.h index 7ba81e37d9..b2693a49a0 100644 --- a/src/insets/InsetArgument.h +++ b/src/insets/InsetArgument.h @@ -49,7 +49,7 @@ public: /// void latex(otexstream &, OutputParams const &) const { } /// - int plaintext(odocstream &, OutputParams const &) const { return 0; } + int plaintext(odocstringstream &, OutputParams const &, int) const { return 0; } /// int docbook(odocstream &, OutputParams const &) const { return 0; } /// diff --git a/src/insets/InsetBibitem.cpp b/src/insets/InsetBibitem.cpp index a05b21d28b..9ec9de99bf 100644 --- a/src/insets/InsetBibitem.cpp +++ b/src/insets/InsetBibitem.cpp @@ -216,7 +216,8 @@ docstring InsetBibitem::screenLabel() const } -int InsetBibitem::plaintext(odocstream & os, OutputParams const &) const +int InsetBibitem::plaintext(odocstringstream & os, + OutputParams const &, int) const { odocstringstream oss; oss << '[' << bibLabel() << "] "; diff --git a/src/insets/InsetBibitem.h b/src/insets/InsetBibitem.h index 49388243ac..5d4ae9fe1e 100644 --- a/src/insets/InsetBibitem.h +++ b/src/insets/InsetBibitem.h @@ -55,7 +55,8 @@ public: /// void read(Lexer & lex); /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream &, OutputParams const &, + int max_length) const; /// docstring xhtml(XHTMLStream &, OutputParams const &) const; /// diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp index 9c51355a21..0392b9d233 100644 --- a/src/insets/InsetBibtex.cpp +++ b/src/insets/InsetBibtex.cpp @@ -928,12 +928,14 @@ void InsetBibtex::validate(LaTeXFeatures & features) const } -int InsetBibtex::plaintext(odocstream & os, OutputParams const &) const +int InsetBibtex::plaintext(odocstringstream & os, + OutputParams const &, size_t max_length) const { BiblioInfo bibinfo = buffer().masterBibInfo(); bibinfo.makeCitationLabels(buffer()); vector const & cites = bibinfo.citedEntries(); + size_t start_size = os.str().size(); docstring refoutput; docstring const reflabel = buffer().B_("References"); @@ -943,6 +945,8 @@ int InsetBibtex::plaintext(odocstream & os, OutputParams const &) const vector::const_iterator vit = cites.begin(); vector::const_iterator const ven = cites.end(); for (; vit != ven; ++vit) { + if (start_size + refoutput.size() >= max_length) + break; BiblioInfo::const_iterator const biit = bibinfo.find(*vit); if (biit == bibinfo.end()) continue; diff --git a/src/insets/InsetBibtex.h b/src/insets/InsetBibtex.h index 6883191ed6..8c4fa18d3d 100644 --- a/src/insets/InsetBibtex.h +++ b/src/insets/InsetBibtex.h @@ -52,7 +52,8 @@ public: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// void collectBibKeys(InsetIterator const &) const; /// diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp index f55abcdfa1..cdd3f37741 100644 --- a/src/insets/InsetBox.cpp +++ b/src/insets/InsetBox.cpp @@ -440,7 +440,8 @@ void InsetBox::latex(otexstream & os, OutputParams const & runparams) const } -int InsetBox::plaintext(odocstream & os, OutputParams const & runparams) const +int InsetBox::plaintext(odocstringstream & os, + OutputParams const & runparams, size_t max_length) const { BoxType const btype = boxtranslator().find(params_.type); @@ -466,7 +467,7 @@ int InsetBox::plaintext(odocstream & os, OutputParams const & runparams) const break; } - InsetText::plaintext(os, runparams); + InsetText::plaintext(os, runparams, max_length); int len = 0; switch (btype) { diff --git a/src/insets/InsetBox.h b/src/insets/InsetBox.h index cf0f689ed1..9c498b67e3 100644 --- a/src/insets/InsetBox.h +++ b/src/insets/InsetBox.h @@ -114,7 +114,8 @@ public: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index efdeea56a5..11774a390b 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -262,13 +262,13 @@ void InsetBranch::latex(otexstream & os, OutputParams const & runparams) const } -int InsetBranch::plaintext(odocstream & os, - OutputParams const & runparams) const +int InsetBranch::plaintext(odocstringstream & os, + OutputParams const & runparams, size_t max_length) const { if (!isBranchSelected()) return 0; - int len = InsetText::plaintext(os, runparams); + int len = InsetText::plaintext(os, runparams, max_length); return len; } diff --git a/src/insets/InsetBranch.h b/src/insets/InsetBranch.h index 6588bc61b3..f64f616b40 100644 --- a/src/insets/InsetBranch.h +++ b/src/insets/InsetBranch.h @@ -67,7 +67,8 @@ private: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp index 37913bc480..764e940a13 100644 --- a/src/insets/InsetCaption.cpp +++ b/src/insets/InsetCaption.cpp @@ -279,11 +279,11 @@ void InsetCaption::latex(otexstream & os, } -int InsetCaption::plaintext(odocstream & os, - OutputParams const & runparams) const +int InsetCaption::plaintext(odocstringstream & os, + OutputParams const & runparams, size_t max_length) const { os << '[' << full_label_ << "\n"; - InsetText::plaintext(os, runparams); + InsetText::plaintext(os, runparams, max_length); os << "\n]"; return PLAINTEXT_NEWLINE + 1; // one char on a separate line @@ -350,7 +350,9 @@ int InsetCaption::getCaptionAsPlaintext(odocstream & os, OutputParams const & runparams) const { os << full_label_ << ' '; - return InsetText::plaintext(os, runparams); + odocstringstream ods; + return InsetText::plaintext(ods, runparams); + os << ods.str(); } diff --git a/src/insets/InsetCaption.h b/src/insets/InsetCaption.h index d792d77640..58822435cd 100644 --- a/src/insets/InsetCaption.h +++ b/src/insets/InsetCaption.h @@ -71,7 +71,8 @@ private: /// void latex(otexstream & os, OutputParams const &) const; /// - int plaintext(odocstream & os, OutputParams const & runparams) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream & os, OutputParams const & runparams) const; /// diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp index 60e3bbe0fc..743bda69cb 100644 --- a/src/insets/InsetCitation.cpp +++ b/src/insets/InsetCitation.cpp @@ -342,7 +342,8 @@ void InsetCitation::addToToc(DocIterator const & cpit) const } -int InsetCitation::plaintext(odocstream & os, OutputParams const &) const +int InsetCitation::plaintext(odocstringstream & os, + OutputParams const &, size_t) const { string const & cmd = getCmdName(); if (cmd == "nocite") @@ -396,7 +397,9 @@ docstring InsetCitation::xhtml(XHTMLStream & xs, OutputParams const &) const void InsetCitation::toString(odocstream & os) const { - plaintext(os, OutputParams(0)); + odocstringstream ods; + plaintext(ods, OutputParams(0)); + os << ods.str(); } diff --git a/src/insets/InsetCitation.h b/src/insets/InsetCitation.h index 1b2f714bfa..0bd048ebfb 100644 --- a/src/insets/InsetCitation.h +++ b/src/insets/InsetCitation.h @@ -52,7 +52,8 @@ public: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetCommand.cpp b/src/insets/InsetCommand.cpp index 004f2f3283..b2fbc69000 100644 --- a/src/insets/InsetCommand.cpp +++ b/src/insets/InsetCommand.cpp @@ -126,7 +126,8 @@ void InsetCommand::latex(otexstream & os, OutputParams const & runparams_in) con } -int InsetCommand::plaintext(odocstream & os, OutputParams const &) const +int InsetCommand::plaintext(odocstringstream & os, + OutputParams const &, size_t) const { docstring const str = "[" + buffer().B_("LaTeX Command: ") + from_utf8(getCmdName()) + "]"; diff --git a/src/insets/InsetCommand.h b/src/insets/InsetCommand.h index 4d5066e33f..131beff900 100644 --- a/src/insets/InsetCommand.h +++ b/src/insets/InsetCommand.h @@ -78,7 +78,8 @@ public: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const & runparams) const; /// diff --git a/src/insets/InsetERT.cpp b/src/insets/InsetERT.cpp index d120a58114..eb9a808fbf 100644 --- a/src/insets/InsetERT.cpp +++ b/src/insets/InsetERT.cpp @@ -53,7 +53,8 @@ void InsetERT::write(ostream & os) const } -int InsetERT::plaintext(odocstream & os, OutputParams const & rp) const +int InsetERT::plaintext(odocstringstream & os, + OutputParams const & rp, size_t max_length) const { if (!rp.inIndexEntry) // do not output TeX code @@ -62,7 +63,7 @@ int InsetERT::plaintext(odocstream & os, OutputParams const & rp) const ParagraphList::const_iterator par = paragraphs().begin(); ParagraphList::const_iterator end = paragraphs().end(); - while (par != end) { + while (par != end && os.str().size() <= max_length) { pos_type siz = par->size(); for (pos_type i = 0; i < siz; ++i) { char_type const c = par->getChar(i); diff --git a/src/insets/InsetERT.h b/src/insets/InsetERT.h index 7d77bdafa4..f92304aa39 100644 --- a/src/insets/InsetERT.h +++ b/src/insets/InsetERT.h @@ -48,7 +48,8 @@ private: /// void write(std::ostream & os) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetExternal.cpp b/src/insets/InsetExternal.cpp index c0f7225664..e73a6c02f6 100644 --- a/src/insets/InsetExternal.cpp +++ b/src/insets/InsetExternal.cpp @@ -691,8 +691,8 @@ void InsetExternal::latex(otexstream & os, OutputParams const & runparams) const } -int InsetExternal::plaintext(odocstream & os, - OutputParams const & runparams) const +int InsetExternal::plaintext(odocstringstream & os, + OutputParams const & runparams, size_t) const { os << '\n'; // output external material on a new line external::writeExternal(params_, "Ascii", buffer(), os, diff --git a/src/insets/InsetExternal.h b/src/insets/InsetExternal.h index bbe2162fec..a875d37995 100644 --- a/src/insets/InsetExternal.h +++ b/src/insets/InsetExternal.h @@ -132,7 +132,8 @@ private: /// void read(Lexer & lex); /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// For now, this does nothing. Someone who knows about this diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index 333702a637..bd465fbc3e 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -389,11 +389,11 @@ void InsetFloat::latex(otexstream & os, OutputParams const & runparams_in) const } -int InsetFloat::plaintext(odocstream & os, OutputParams const & runparams) const +int InsetFloat::plaintext(odocstringstream & os, OutputParams const & runparams, size_t max_length) const { os << '[' << buffer().B_("float") << ' ' << floatName(params_.type) << ":\n"; - InsetText::plaintext(os, runparams); + InsetText::plaintext(os, runparams, max_length); os << "\n]"; return PLAINTEXT_NEWLINE + 1; // one char on a separate line diff --git a/src/insets/InsetFloat.h b/src/insets/InsetFloat.h index 502422a21b..f254bc48db 100644 --- a/src/insets/InsetFloat.h +++ b/src/insets/InsetFloat.h @@ -85,7 +85,8 @@ private: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetFloatList.cpp b/src/insets/InsetFloatList.cpp index 5e72ee386f..fcaf1b36c4 100644 --- a/src/insets/InsetFloatList.cpp +++ b/src/insets/InsetFloatList.cpp @@ -160,11 +160,12 @@ void InsetFloatList::latex(otexstream & os, OutputParams const &) const } -int InsetFloatList::plaintext(odocstream & os, OutputParams const &) const +int InsetFloatList::plaintext(odocstringstream & os, + OutputParams const &, size_t max_length) const { os << screenLabel() << "\n\n"; - buffer().tocBackend().writePlaintextTocList(to_ascii(getParam("type")), os); + buffer().tocBackend().writePlaintextTocList(to_ascii(getParam("type")), os, max_length); return PLAINTEXT_NEWLINE; } diff --git a/src/insets/InsetFloatList.h b/src/insets/InsetFloatList.h index 0b570766fd..46b294a0ab 100644 --- a/src/insets/InsetFloatList.h +++ b/src/insets/InsetFloatList.h @@ -42,7 +42,8 @@ public: /// int docbook(odocstream &, OutputParams const &) const { return 0; } /// - int plaintext(odocstream &, OutputParams const & runparams) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// docstring xhtml(XHTMLStream &, OutputParams const &) const; /// diff --git a/src/insets/InsetFoot.cpp b/src/insets/InsetFoot.cpp index 489358a110..a7139f9213 100644 --- a/src/insets/InsetFoot.cpp +++ b/src/insets/InsetFoot.cpp @@ -107,10 +107,11 @@ void InsetFoot::latex(otexstream & os, OutputParams const & runparams_in) const } -int InsetFoot::plaintext(odocstream & os, OutputParams const & runparams) const +int InsetFoot::plaintext(odocstringstream & os, + OutputParams const & runparams, size_t max_length) const { os << '[' << buffer().B_("footnote") << ":\n"; - InsetText::plaintext(os, runparams); + InsetText::plaintext(os, runparams, max_length); os << "\n]"; return PLAINTEXT_NEWLINE + 1; // one char on a separate line diff --git a/src/insets/InsetFoot.h b/src/insets/InsetFoot.h index f77ae3fedf..6106fcd352 100644 --- a/src/insets/InsetFoot.h +++ b/src/insets/InsetFoot.h @@ -34,7 +34,8 @@ private: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// Update the counters of this inset and of its contents diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp index 9962af6039..eec663e30b 100644 --- a/src/insets/InsetGraphics.cpp +++ b/src/insets/InsetGraphics.cpp @@ -809,7 +809,8 @@ void InsetGraphics::latex(otexstream & os, } -int InsetGraphics::plaintext(odocstream & os, OutputParams const &) const +int InsetGraphics::plaintext(odocstringstream & os, + OutputParams const &, size_t) const { // No graphics in ascii output. Possible to use gifscii to convert // images to ascii approximation. diff --git a/src/insets/InsetGraphics.h b/src/insets/InsetGraphics.h index bee9fe0884..d8ad8f8c71 100644 --- a/src/insets/InsetGraphics.h +++ b/src/insets/InsetGraphics.h @@ -74,7 +74,8 @@ private: */ void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetHyperlink.cpp b/src/insets/InsetHyperlink.cpp index 37692af97a..60c64f9421 100644 --- a/src/insets/InsetHyperlink.cpp +++ b/src/insets/InsetHyperlink.cpp @@ -209,7 +209,8 @@ void InsetHyperlink::latex(otexstream & os, } -int InsetHyperlink::plaintext(odocstream & os, OutputParams const &) const +int InsetHyperlink::plaintext(odocstringstream & os, + OutputParams const &, size_t) const { odocstringstream oss; @@ -250,7 +251,9 @@ docstring InsetHyperlink::xhtml(XHTMLStream & xs, OutputParams const &) const void InsetHyperlink::toString(odocstream & os) const { - plaintext(os, OutputParams(0)); + odocstringstream ods; + plaintext(ods, OutputParams(0), INT_MAX); + os << ods.str(); } diff --git a/src/insets/InsetHyperlink.h b/src/insets/InsetHyperlink.h index fb4c891979..b33665e96a 100644 --- a/src/insets/InsetHyperlink.h +++ b/src/insets/InsetHyperlink.h @@ -48,7 +48,8 @@ public: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetIPAMacro.cpp b/src/insets/InsetIPAMacro.cpp index 0806375efd..f8888ce96e 100644 --- a/src/insets/InsetIPAMacro.cpp +++ b/src/insets/InsetIPAMacro.cpp @@ -281,11 +281,11 @@ void InsetIPADeco::latex(otexstream & os, OutputParams const & runparams) const } -int InsetIPADeco::plaintext(odocstream & os, - OutputParams const & runparams) const +int InsetIPADeco::plaintext(odocstringstream & os, + OutputParams const & runparams, size_t max_length) const { odocstringstream ods; - int h = (int)(InsetCollapsable::plaintext(ods, runparams) / 2); + int h = (int)(InsetCollapsable::plaintext(ods, runparams, max_length) / 2); docstring result = ods.str(); docstring const before = result.substr(0, h); docstring const after = result.substr(h, result.size()); @@ -512,7 +512,7 @@ void InsetIPAChar::latex(otexstream & os, } -int InsetIPAChar::plaintext(odocstream & os, OutputParams const &) const +int InsetIPAChar::plaintext(odocstringstream & os, OutputParams const &, size_t) const { switch (kind_) { case TONE_FALLING: @@ -588,7 +588,9 @@ docstring InsetIPAChar::xhtml(XHTMLStream & xs, OutputParams const &) const void InsetIPAChar::toString(odocstream & os) const { - plaintext(os, OutputParams(0)); + odocstringstream ods; + plaintext(ods, OutputParams(0)); + os << ods.str(); } diff --git a/src/insets/InsetIPAMacro.h b/src/insets/InsetIPAMacro.h index d89d17a674..35039a195c 100644 --- a/src/insets/InsetIPAMacro.h +++ b/src/insets/InsetIPAMacro.h @@ -76,7 +76,8 @@ private: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// @@ -146,7 +147,8 @@ public: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 2a3a196708..2bf3ae722f 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -810,9 +810,11 @@ docstring InsetInclude::xhtml(XHTMLStream & xs, OutputParams const & rp) const } -int InsetInclude::plaintext(odocstream & os, OutputParams const & op) const +int InsetInclude::plaintext(odocstringstream & os, + OutputParams const & op, size_t) const { - if (isVerbatim(params()) || isListings(params())) { + // don't write the file just because we're making a tooltip or toc entry!! + if (op.for_tooltip || op.for_toc || isVerbatim(params()) || isListings(params())) { os << '[' << screenLabel() << '\n'; // FIXME: We don't know the encoding of the file, default to UTF-8. os << includedFileName(buffer(), params()).fileContents("UTF-8"); diff --git a/src/insets/InsetInclude.h b/src/insets/InsetInclude.h index 2583f41406..cbc2db02e7 100644 --- a/src/insets/InsetInclude.h +++ b/src/insets/InsetInclude.h @@ -91,7 +91,8 @@ public: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp index 4bb2d4dfa6..c754ac0e67 100644 --- a/src/insets/InsetIndex.cpp +++ b/src/insets/InsetIndex.cpp @@ -37,8 +37,8 @@ #include "frontends/alert.h" -#include #include +#include using namespace std; using namespace lyx::support; diff --git a/src/insets/InsetLabel.cpp b/src/insets/InsetLabel.cpp index e52540e89d..557548d84d 100644 --- a/src/insets/InsetLabel.cpp +++ b/src/insets/InsetLabel.cpp @@ -254,7 +254,8 @@ void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd) } -int InsetLabel::plaintext(odocstream & os, OutputParams const &) const +int InsetLabel::plaintext(odocstringstream & os, + OutputParams const &, size_t) const { docstring const str = getParam("name"); os << '<' << str << '>'; diff --git a/src/insets/InsetLabel.h b/src/insets/InsetLabel.h index 61bcc1f310..c28ef1c0b5 100644 --- a/src/insets/InsetLabel.h +++ b/src/insets/InsetLabel.h @@ -48,7 +48,8 @@ public: /// InsetCode lyxCode() const { return LABEL_CODE; } /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetLine.cpp b/src/insets/InsetLine.cpp index 353a24ef95..82960b262e 100644 --- a/src/insets/InsetLine.cpp +++ b/src/insets/InsetLine.cpp @@ -185,7 +185,8 @@ void InsetLine::latex(otexstream & os, OutputParams const &) const } -int InsetLine::plaintext(odocstream & os, OutputParams const &) const +int InsetLine::plaintext(odocstringstream & os, + OutputParams const &, size_t) const { os << "\n-------------------------------------------\n"; return PLAINTEXT_NEWLINE; diff --git a/src/insets/InsetLine.h b/src/insets/InsetLine.h index d1f6f52df0..f6b8a600a5 100644 --- a/src/insets/InsetLine.h +++ b/src/insets/InsetLine.h @@ -49,7 +49,8 @@ private: void metrics(MetricsInfo &, Dimension &) const; void draw(PainterInfo & pi, int x, int y) const; void latex(otexstream &, OutputParams const &) const; - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; void doDispatch(Cursor & cur, FuncRequest & cmd); bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const; Inset * clone() const { return new InsetLine(*this); } diff --git a/src/insets/InsetMarginal.cpp b/src/insets/InsetMarginal.cpp index 3f1aea0358..d7ec180de5 100644 --- a/src/insets/InsetMarginal.cpp +++ b/src/insets/InsetMarginal.cpp @@ -29,11 +29,11 @@ InsetMarginal::InsetMarginal(Buffer * buf) {} -int InsetMarginal::plaintext(odocstream & os, - OutputParams const & runparams) const +int InsetMarginal::plaintext(odocstringstream & os, + OutputParams const & runparams, size_t max_length) const { os << '[' << buffer().B_("margin") << ":\n"; - InsetText::plaintext(os, runparams); + InsetText::plaintext(os, runparams, max_length); os << "\n]"; return PLAINTEXT_NEWLINE + 1; // one char on a separate line diff --git a/src/insets/InsetMarginal.h b/src/insets/InsetMarginal.h index 67bd1e5a54..8f7c89a52a 100644 --- a/src/insets/InsetMarginal.h +++ b/src/insets/InsetMarginal.h @@ -31,7 +31,8 @@ public: /// docstring layoutName() const { return from_ascii("Marginal"); } /// - int plaintext(odocstream &, OutputParams const & runparams) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const & runparams) const; /// diff --git a/src/insets/InsetNewline.cpp b/src/insets/InsetNewline.cpp index 92f94eaaa7..0927c7e7d0 100644 --- a/src/insets/InsetNewline.cpp +++ b/src/insets/InsetNewline.cpp @@ -161,7 +161,8 @@ void InsetNewline::latex(otexstream & os, OutputParams const & rp) const } -int InsetNewline::plaintext(odocstream & os, OutputParams const &) const +int InsetNewline::plaintext(odocstringstream & os, + OutputParams const &, size_t) const { os << '\n'; return PLAINTEXT_NEWLINE; diff --git a/src/insets/InsetNewline.h b/src/insets/InsetNewline.h index 3dbbaa1085..2dc9c553ed 100644 --- a/src/insets/InsetNewline.h +++ b/src/insets/InsetNewline.h @@ -62,7 +62,8 @@ private: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetNewpage.cpp b/src/insets/InsetNewpage.cpp index 85e8d14dd3..15d45f071a 100644 --- a/src/insets/InsetNewpage.cpp +++ b/src/insets/InsetNewpage.cpp @@ -235,7 +235,8 @@ void InsetNewpage::latex(otexstream & os, OutputParams const &) const } -int InsetNewpage::plaintext(odocstream & os, OutputParams const &) const +int InsetNewpage::plaintext(odocstringstream & os, + OutputParams const &, size_t) const { os << '\n'; return PLAINTEXT_NEWLINE; diff --git a/src/insets/InsetNewpage.h b/src/insets/InsetNewpage.h index 6a1d639b07..51f640a097 100644 --- a/src/insets/InsetNewpage.h +++ b/src/insets/InsetNewpage.h @@ -65,7 +65,8 @@ private: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetNote.cpp b/src/insets/InsetNote.cpp index 874a6aaf1a..ea1299720d 100644 --- a/src/insets/InsetNote.cpp +++ b/src/insets/InsetNote.cpp @@ -253,8 +253,8 @@ void InsetNote::latex(otexstream & os, OutputParams const & runparams_in) const } -int InsetNote::plaintext(odocstream & os, - OutputParams const & runparams_in) const +int InsetNote::plaintext(odocstringstream & os, + OutputParams const & runparams_in, size_t max_length) const { if (params_.type == InsetNoteParams::Note) return 0; @@ -266,7 +266,7 @@ int InsetNote::plaintext(odocstream & os, runparams.exportdata.reset(new ExportData); } os << '[' << buffer().B_("note") << ":\n"; - InsetText::plaintext(os, runparams); + InsetText::plaintext(os, runparams, max_length); os << "\n]"; return PLAINTEXT_NEWLINE + 1; // one char on a separate line diff --git a/src/insets/InsetNote.h b/src/insets/InsetNote.h index 2deb84f0f8..255930fedc 100644 --- a/src/insets/InsetNote.h +++ b/src/insets/InsetNote.h @@ -85,7 +85,8 @@ private: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetPhantom.cpp b/src/insets/InsetPhantom.cpp index 5a63957ef8..f7a9b45d9a 100644 --- a/src/insets/InsetPhantom.cpp +++ b/src/insets/InsetPhantom.cpp @@ -320,8 +320,8 @@ void InsetPhantom::latex(otexstream & os, OutputParams const & runparams) const } -int InsetPhantom::plaintext(odocstream & os, - OutputParams const & runparams) const +int InsetPhantom::plaintext(odocstringstream & os, + OutputParams const & runparams, size_t max_length) const { if (params_.type == InsetPhantomParams::Phantom) os << '[' << buffer().B_("phantom") << ":"; @@ -329,7 +329,7 @@ int InsetPhantom::plaintext(odocstream & os, os << '[' << buffer().B_("hphantom") << ":"; else if (params_.type == InsetPhantomParams::VPhantom) os << '[' << buffer().B_("vphantom") << ":"; - InsetCollapsable::plaintext(os, runparams); + InsetCollapsable::plaintext(os, runparams, max_length); os << "]"; return PLAINTEXT_NEWLINE; diff --git a/src/insets/InsetPhantom.h b/src/insets/InsetPhantom.h index eb36274f6e..fad50637b2 100644 --- a/src/insets/InsetPhantom.h +++ b/src/insets/InsetPhantom.h @@ -78,7 +78,8 @@ private: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// Makes no sense fof XHTML. diff --git a/src/insets/InsetQuotes.cpp b/src/insets/InsetQuotes.cpp index 1295f27f07..70911fd659 100644 --- a/src/insets/InsetQuotes.cpp +++ b/src/insets/InsetQuotes.cpp @@ -298,7 +298,8 @@ void InsetQuotes::latex(otexstream & os, OutputParams const & runparams) const } -int InsetQuotes::plaintext(odocstream & os, OutputParams const &) const +int InsetQuotes::plaintext(odocstringstream & os, + OutputParams const &, size_t) const { docstring const str = displayString(); os << str; diff --git a/src/insets/InsetQuotes.h b/src/insets/InsetQuotes.h index af0136e939..743208ff39 100644 --- a/src/insets/InsetQuotes.h +++ b/src/insets/InsetQuotes.h @@ -80,7 +80,8 @@ public: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp index 49743ceea8..abfecbae12 100644 --- a/src/insets/InsetRef.cpp +++ b/src/insets/InsetRef.cpp @@ -172,7 +172,8 @@ void InsetRef::latex(otexstream & os, OutputParams const & rp) const } -int InsetRef::plaintext(odocstream & os, OutputParams const &) const +int InsetRef::plaintext(odocstringstream & os, + OutputParams const &, size_t) const { docstring const str = getParam("reference"); os << '[' << str << ']'; @@ -246,7 +247,9 @@ docstring InsetRef::xhtml(XHTMLStream & xs, OutputParams const &) const void InsetRef::toString(odocstream & os) const { - plaintext(os, OutputParams(0)); + odocstringstream ods; + plaintext(ods, OutputParams(0)); + os << ods.str(); } diff --git a/src/insets/InsetRef.h b/src/insets/InsetRef.h index 740bac3dc4..09122c1ebe 100644 --- a/src/insets/InsetRef.h +++ b/src/insets/InsetRef.h @@ -53,7 +53,8 @@ public: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetScript.cpp b/src/insets/InsetScript.cpp index 135962353a..c98a9bed48 100644 --- a/src/insets/InsetScript.cpp +++ b/src/insets/InsetScript.cpp @@ -313,11 +313,11 @@ docstring InsetScript::toolTip(BufferView const &, int, int) const { OutputParams rp(&buffer().params().encoding()); odocstringstream ods; - InsetText::plaintext(ods, rp); + InsetText::plaintext(ods, rp, 200); docstring content_tip = ods.str(); // shorten it if necessary - if (content_tip.size() > 200) - content_tip = content_tip.substr(0, 200) + "..."; + if (content_tip.size() >= 200) + content_tip = content_tip.substr(0, 197) + "..."; docstring res = scripttranslator_loc().find(params_.type); if (!content_tip.empty()) res += from_ascii(": ") + content_tip; @@ -325,10 +325,11 @@ docstring InsetScript::toolTip(BufferView const &, int, int) const } -int InsetScript::plaintext(odocstream & os, OutputParams const & runparams) const +int InsetScript::plaintext(odocstringstream & os, + OutputParams const & runparams, size_t max_length) const { odocstringstream oss; - InsetText::plaintext(oss, runparams); + InsetText::plaintext(oss, runparams, max_length); docstring const text = oss.str(); switch (params_.type) { case InsetScriptParams::Subscript: @@ -352,7 +353,7 @@ int InsetScript::plaintext(odocstream & os, OutputParams const & runparams) cons os << '[' << buffer().B_("superscript") << ':'; break; } - InsetText::plaintext(os, runparams); + InsetText::plaintext(os, runparams, max_length); os << ']'; return PLAINTEXT_NEWLINE; diff --git a/src/insets/InsetScript.h b/src/insets/InsetScript.h index 96597d2dac..decfee37ae 100644 --- a/src/insets/InsetScript.h +++ b/src/insets/InsetScript.h @@ -82,7 +82,8 @@ public: /// bool neverIndent() const { return true; } /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetSpace.cpp b/src/insets/InsetSpace.cpp index 90d171e2d4..4d0542dfbd 100644 --- a/src/insets/InsetSpace.cpp +++ b/src/insets/InsetSpace.cpp @@ -621,7 +621,8 @@ void InsetSpace::latex(otexstream & os, OutputParams const & runparams) const } -int InsetSpace::plaintext(odocstream & os, OutputParams const &) const +int InsetSpace::plaintext(odocstringstream & os, + OutputParams const &, size_t) const { switch (params_.kind) { case InsetSpaceParams::HFILL: @@ -813,7 +814,9 @@ void InsetSpace::validate(LaTeXFeatures & features) const void InsetSpace::toString(odocstream & os) const { - plaintext(os, OutputParams(0)); + odocstringstream ods; + plaintext(ods, OutputParams(0)); + os << ods.str(); } diff --git a/src/insets/InsetSpace.h b/src/insets/InsetSpace.h index 718a97ba17..7e32dc7cb5 100644 --- a/src/insets/InsetSpace.h +++ b/src/insets/InsetSpace.h @@ -124,7 +124,8 @@ public: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetSpecialChar.cpp b/src/insets/InsetSpecialChar.cpp index 0099fc4e1e..f342d0f20d 100644 --- a/src/insets/InsetSpecialChar.cpp +++ b/src/insets/InsetSpecialChar.cpp @@ -239,7 +239,8 @@ void InsetSpecialChar::latex(otexstream & os, } -int InsetSpecialChar::plaintext(odocstream & os, OutputParams const &) const +int InsetSpecialChar::plaintext(odocstringstream & os, + OutputParams const &, size_t) const { switch (kind_) { case HYPHENATION: @@ -329,8 +330,11 @@ void InsetSpecialChar::toString(odocstream & os) const // Spell checker would choke on it. return; default: - plaintext(os, OutputParams(0)); + break; } + odocstringstream ods; + plaintext(ods, OutputParams(0)); + os << ods.str(); } diff --git a/src/insets/InsetSpecialChar.h b/src/insets/InsetSpecialChar.h index 2d8401c2b5..c66dbc3e19 100644 --- a/src/insets/InsetSpecialChar.h +++ b/src/insets/InsetSpecialChar.h @@ -61,7 +61,8 @@ public: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetTOC.cpp b/src/insets/InsetTOC.cpp index 414d6780fd..1d8a05495f 100644 --- a/src/insets/InsetTOC.cpp +++ b/src/insets/InsetTOC.cpp @@ -110,10 +110,11 @@ void InsetTOC::validate(LaTeXFeatures & features) const } -int InsetTOC::plaintext(odocstream & os, OutputParams const &) const +int InsetTOC::plaintext(odocstringstream & os, + OutputParams const &, size_t max_length) const { os << screenLabel() << "\n\n"; - buffer().tocBackend().writePlaintextTocList(cmd2type(getCmdName()), os); + buffer().tocBackend().writePlaintextTocList(cmd2type(getCmdName()), os, max_length); return PLAINTEXT_NEWLINE; } diff --git a/src/insets/InsetTOC.h b/src/insets/InsetTOC.h index e6e932b3f1..f0f6169e75 100644 --- a/src/insets/InsetTOC.h +++ b/src/insets/InsetTOC.h @@ -38,7 +38,8 @@ public: /// virtual void validate(LaTeXFeatures &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 4285e4ac44..120eb13d31 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -64,10 +64,10 @@ #include -#include +#include #include #include -#include +#include using namespace std; using namespace lyx::support; @@ -3086,7 +3086,7 @@ docstring Tabular::xhtml(XHTMLStream & xs, OutputParams const & runparams) const } -bool Tabular::plaintextTopHLine(odocstream & os, row_type row, +bool Tabular::plaintextTopHLine(odocstringstream & os, row_type row, vector const & clen) const { idx_type const fcell = getFirstCellInRow(row); @@ -3134,7 +3134,7 @@ bool Tabular::plaintextTopHLine(odocstream & os, row_type row, } -bool Tabular::plaintextBottomHLine(odocstream & os, row_type row, +bool Tabular::plaintextBottomHLine(odocstringstream & os, row_type row, vector const & clen) const { idx_type const fcell = getFirstCellInRow(row); @@ -3181,14 +3181,14 @@ bool Tabular::plaintextBottomHLine(odocstream & os, row_type row, } -void Tabular::plaintextPrintCell(odocstream & os, +void Tabular::plaintextPrintCell(odocstringstream & os, OutputParams const & runparams, idx_type cell, row_type row, col_type column, vector const & clen, - bool onlydata) const + bool onlydata, size_t max_length) const { odocstringstream sstr; - cellInset(cell)->plaintext(sstr, runparams); + cellInset(cell)->plaintext(sstr, runparams, max_length); if (onlydata) { os << sstr.str(); @@ -3231,9 +3231,9 @@ void Tabular::plaintextPrintCell(odocstream & os, } -void Tabular::plaintext(odocstream & os, +void Tabular::plaintext(odocstringstream & os, OutputParams const & runparams, int const depth, - bool onlydata, char_type delim) const + bool onlydata, char_type delim, size_t max_length) const { // first calculate the width of the single columns vector clen(ncols()); @@ -3247,7 +3247,7 @@ void Tabular::plaintext(odocstream & os, if (isMultiColumn(cell)) continue; odocstringstream sstr; - cellInset(cell)->plaintext(sstr, runparams); + cellInset(cell)->plaintext(sstr, runparams, max_length); if (clen[c] < sstr.str().length()) clen[c] = sstr.str().length(); } @@ -3259,7 +3259,7 @@ void Tabular::plaintext(odocstream & os, if (cell_info[r][c].multicolumn != CELL_BEGIN_OF_MULTICOLUMN) continue; odocstringstream sstr; - cellInset(cell)->plaintext(sstr, runparams); + cellInset(cell)->plaintext(sstr, runparams, max_length); int len = int(sstr.str().length()); idx_type const n = columnSpan(cell); for (col_type k = c; len > 0 && k < c + n - 1; ++k) @@ -3280,8 +3280,10 @@ void Tabular::plaintext(odocstream & os, // we don't use operator<< for single UCS4 character. // see explanation in docstream.h os.put(delim); - plaintextPrintCell(os, runparams, cell, r, c, clen, onlydata); + plaintextPrintCell(os, runparams, cell, r, c, clen, onlydata, max_length); ++cell; + if (os.str().size() > max_length) + break; } os << endl; if (!onlydata) { @@ -3289,6 +3291,8 @@ void Tabular::plaintext(odocstream & os, if (plaintextBottomHLine(os, r, clen)) os << docstring(depth * 2, ' '); } + if (os.str().size() > max_length) + break; } } @@ -4954,11 +4958,12 @@ void InsetTabular::latex(otexstream & os, OutputParams const & runparams) const } -int InsetTabular::plaintext(odocstream & os, OutputParams const & runparams) const +int InsetTabular::plaintext(odocstringstream & os, + OutputParams const & runparams, size_t max_length) const { os << '\n'; // output table on a new line int const dp = runparams.linelen > 0 ? runparams.depth : 0; - tabular.plaintext(os, runparams, dp, false, 0); + tabular.plaintext(os, runparams, dp, false, 0, max_length); return PLAINTEXT_NEWLINE; } @@ -5999,7 +6004,7 @@ bool InsetTabular::copySelection(Cursor & cur) odocstringstream os; OutputParams const runparams(0); - paste_tabular->plaintext(os, runparams, 0, true, '\t'); + paste_tabular->plaintext(os, runparams, 0, true, '\t', INT_MAX); // Needed for the "Edit->Paste recent" menu and the system clipboard. cap::copySelection(cur, os.str()); diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h index 707ab01aee..2f0ff3b760 100644 --- a/src/insets/InsetTabular.h +++ b/src/insets/InsetTabular.h @@ -30,6 +30,7 @@ #include "support/shared_ptr.h" +#include #include #include @@ -500,9 +501,9 @@ public: /// docstring xhtml(XHTMLStream & os, OutputParams const &) const; /// - void plaintext(odocstream &, + void plaintext(odocstringstream &, OutputParams const & runparams, int const depth, - bool onlydata, char_type delim) const; + bool onlydata, char_type delim, size_t max_length = INT_MAX) const; /// bool isMultiColumn(idx_type cell) const; /// @@ -783,17 +784,17 @@ public: /// // helper functions for plain text /// - bool plaintextTopHLine(odocstream &, row_type row, + bool plaintextTopHLine(odocstringstream &, row_type row, std::vector const &) const; /// - bool plaintextBottomHLine(odocstream &, row_type row, + bool plaintextBottomHLine(odocstringstream &, row_type row, std::vector const &) const; /// - void plaintextPrintCell(odocstream &, + void plaintextPrintCell(odocstringstream &, OutputParams const &, idx_type cell, row_type row, col_type column, std::vector const &, - bool onlydata) const; + bool onlydata, size_t max_length) const; /// auxiliary function for docbook int docbookRow(odocstream & os, row_type, OutputParams const &) const; /// @@ -857,7 +858,8 @@ public: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 3ec6f40492..b3baf93ba1 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -507,7 +507,8 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const } -int InsetText::plaintext(odocstream & os, OutputParams const & runparams) const +int InsetText::plaintext(odocstringstream & os, + OutputParams const & runparams, size_t max_length) const { ParagraphList::const_iterator beg = paragraphs().begin(); ParagraphList::const_iterator end = paragraphs().end(); @@ -521,12 +522,14 @@ int InsetText::plaintext(odocstream & os, OutputParams const & runparams) const os << '\n'; } odocstringstream oss; - writePlaintextParagraph(buffer(), *it, oss, runparams, ref_printed); + writePlaintextParagraph(buffer(), *it, oss, runparams, ref_printed, max_length); docstring const str = oss.str(); os << str; // FIXME: len is not computed fully correctly; in principle, // we have to count the characters after the last '\n' len = str.size(); + if (os.str().size() >= max_length) + break; } return len; @@ -961,6 +964,7 @@ docstring InsetText::toolTipText(docstring prefix, { size_t const max_length = numlines * len; OutputParams rp(&buffer().params().encoding()); + rp.for_tooltip = true; odocstringstream oss; oss << prefix; @@ -973,9 +977,9 @@ docstring InsetText::toolTipText(docstring prefix, for (; it != end; ++it) { if (it != beg) oss << '\n'; - writePlaintextParagraph(buffer(), *it, oss, rp, ref_printed); + writePlaintextParagraph(buffer(), *it, oss, rp, ref_printed, max_length); str = oss.str(); - if (str.length() > max_length) + if (str.length() >= max_length) break; } return support::wrapParas(str, 4, len, numlines); diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index b1d1502393..a77bf92875 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -75,7 +75,8 @@ public: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetVSpace.cpp b/src/insets/InsetVSpace.cpp index 1e46425aa6..927980dcf3 100644 --- a/src/insets/InsetVSpace.cpp +++ b/src/insets/InsetVSpace.cpp @@ -207,7 +207,8 @@ void InsetVSpace::latex(otexstream & os, OutputParams const &) const } -int InsetVSpace::plaintext(odocstream & os, OutputParams const &) const +int InsetVSpace::plaintext(odocstringstream & os, + OutputParams const &, size_t) const { os << "\n\n"; return PLAINTEXT_NEWLINE; diff --git a/src/insets/InsetVSpace.h b/src/insets/InsetVSpace.h index 4724c7b567..03e8d59b5e 100644 --- a/src/insets/InsetVSpace.h +++ b/src/insets/InsetVSpace.h @@ -45,7 +45,8 @@ private: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// Note that this returns the inset rather than writing it, diff --git a/src/insets/InsetWrap.cpp b/src/insets/InsetWrap.cpp index f15b0dd43c..181474a889 100644 --- a/src/insets/InsetWrap.cpp +++ b/src/insets/InsetWrap.cpp @@ -35,6 +35,8 @@ #include "frontends/Application.h" +#include + using namespace std; @@ -201,11 +203,12 @@ void InsetWrap::latex(otexstream & os, OutputParams const & runparams_in) const } -int InsetWrap::plaintext(odocstream & os, OutputParams const & runparams) const +int InsetWrap::plaintext(odocstringstream & os, + OutputParams const & runparams, size_t max_length) const { os << '[' << buffer().B_("wrap") << ' ' << floatName(params_.type) << ":\n"; - InsetText::plaintext(os, runparams); + InsetText::plaintext(os, runparams, max_length); os << "\n]"; return PLAINTEXT_NEWLINE + 1; // one char on a separate line diff --git a/src/insets/InsetWrap.h b/src/insets/InsetWrap.h index bdd084b0ef..ce6b73eb03 100644 --- a/src/insets/InsetWrap.h +++ b/src/insets/InsetWrap.h @@ -67,7 +67,8 @@ private: /// void latex(otexstream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream & ods, OutputParams const & op, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/mathed/InsetFormulaMacro.cpp b/src/mathed/InsetFormulaMacro.cpp index 07ed683c55..88b54c28c5 100644 --- a/src/mathed/InsetFormulaMacro.cpp +++ b/src/mathed/InsetFormulaMacro.cpp @@ -84,7 +84,7 @@ void InsetFormulaMacro::latex(otexstream & os, } -int InsetFormulaMacro::plaintext(odocstream & os, OutputParams const & runparams) const +int InsetFormulaMacro::plaintext(odocstringstream & os, OutputParams const & runparams, int max_length) const { odocstringstream oss; WriteStream wi(oss, false, true, WriteStream::wsDefault, runparams.encoding); diff --git a/src/mathed/InsetFormulaMacro.h b/src/mathed/InsetFormulaMacro.h index 0e4e3ba700..25e8969580 100644 --- a/src/mathed/InsetFormulaMacro.h +++ b/src/mathed/InsetFormulaMacro.h @@ -46,7 +46,7 @@ public: /// int latex(otexstream & os, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream &, OutputParams const &, size_t) const; /// int docbook(odocstream &, OutputParams const &) const; diff --git a/src/mathed/InsetMath.cpp b/src/mathed/InsetMath.cpp index 5507a868c9..a4e310fc6e 100644 --- a/src/mathed/InsetMath.cpp +++ b/src/mathed/InsetMath.cpp @@ -84,7 +84,8 @@ void InsetMath::write(WriteStream & os) const } -int InsetMath::plaintext(odocstream &, OutputParams const &) const +int InsetMath::plaintext(odocstringstream &, + OutputParams const &, size_t) const { // all math plain text output shall take place in InsetMathHull LASSERT(false, /**/); diff --git a/src/mathed/InsetMath.h b/src/mathed/InsetMath.h index 80139ba08f..c1b1b05720 100644 --- a/src/mathed/InsetMath.h +++ b/src/mathed/InsetMath.h @@ -200,7 +200,7 @@ public: virtual void octave(OctaveStream &) const; /// plain text output in ucs4 encoding - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream &, OutputParams const &, size_t) const; /// dump content to stderr for debugging virtual void dump() const; diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index 6598bd913d..bbfda5aee5 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -1895,7 +1895,8 @@ bool InsetMathHull::readQuiet(Lexer & lex) } -int InsetMathHull::plaintext(odocstream & os, OutputParams const & op) const +int InsetMathHull::plaintext(odocstringstream & os, + OutputParams const & op, size_t max_length) const { // disables ASCII-art for export of equations. See #2275. if (0 && display()) { @@ -1923,7 +1924,7 @@ int InsetMathHull::plaintext(odocstream & os, OutputParams const & op) const wi << (c == 0 ? "" : "\t") << cell(index(r, c)); // if it's for the TOC, we write just the first line // and do not include the newline. - if (op.for_toc) + if (op.for_toc || op.for_tooltip || oss.str().size() >= max_length) break; wi << "\n"; } @@ -2239,7 +2240,9 @@ docstring InsetMathHull::xhtml(XHTMLStream & xs, OutputParams const & op) const void InsetMathHull::toString(odocstream & os) const { - plaintext(os, OutputParams(0)); + odocstringstream ods; + plaintext(ods, OutputParams(0)); + os << ods.str(); } diff --git a/src/mathed/InsetMathHull.h b/src/mathed/InsetMathHull.h index d37fe3af14..3ac17780b8 100644 --- a/src/mathed/InsetMathHull.h +++ b/src/mathed/InsetMathHull.h @@ -126,7 +126,8 @@ public: /// bool readQuiet(Lexer & lex); /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream &, OutputParams const &, + size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const &) const; /// diff --git a/src/mathed/MathMacroTemplate.cpp b/src/mathed/MathMacroTemplate.cpp index 8220aa68a6..3136b69ba9 100644 --- a/src/mathed/MathMacroTemplate.cpp +++ b/src/mathed/MathMacroTemplate.cpp @@ -1252,8 +1252,8 @@ docstring MathMacroTemplate::xhtml(XHTMLStream &, OutputParams const &) const return docstring(); } -int MathMacroTemplate::plaintext(odocstream & os, - OutputParams const &) const +int MathMacroTemplate::plaintext(odocstringstream & os, + OutputParams const &, size_t) const { static docstring const str = '[' + buffer().B_("math macro") + ']'; diff --git a/src/mathed/MathMacroTemplate.h b/src/mathed/MathMacroTemplate.h index 4e5fc72174..9bb7cfb3d7 100644 --- a/src/mathed/MathMacroTemplate.h +++ b/src/mathed/MathMacroTemplate.h @@ -56,7 +56,7 @@ public: /// Nothing happens. This is simply to suppress the default output. docstring xhtml(XHTMLStream &, OutputParams const &) const; /// - int plaintext(odocstream &, OutputParams const &) const; + int plaintext(odocstringstream &, OutputParams const &, size_t) const; /// bool inheritFont() const { return false; } diff --git a/src/output_plaintext.cpp b/src/output_plaintext.cpp index 476e62d368..2dfc836f1a 100644 --- a/src/output_plaintext.cpp +++ b/src/output_plaintext.cpp @@ -75,9 +75,9 @@ static pair addDepth(int depth, int ldepth) void writePlaintextParagraph(Buffer const & buf, Paragraph const & par, - odocstream & os, + odocstream & ods, OutputParams const & runparams, - bool & ref_printed) + bool & ref_printed, size_t max_length) { int ltype = 0; depth_type ltype_depth = 0; @@ -121,6 +121,7 @@ void writePlaintextParagraph(Buffer const & buf, string::size_type currlinelen = 0; + odocstringstream os; os << docstring(depth * 2, ' '); currlinelen += depth * 2; @@ -184,6 +185,9 @@ void writePlaintextParagraph(Buffer const & buf, if (par.isDeleted(i)) continue; + if (os.str().size() > max_length) + break; + char_type c = par.getUChar(buf.params(), i); if (par.isInset(i) || c == ' ') { @@ -202,7 +206,7 @@ void writePlaintextParagraph(Buffer const & buf, if (par.isInset(i)) { OutputParams rp = runparams; rp.depth = par.params().depth(); - int len = par.getInset(i)->plaintext(os, rp); + int len = par.getInset(i)->plaintext(os, rp, max_length); if (len >= Inset::PLAINTEXT_NEWLINE) currlinelen = len - Inset::PLAINTEXT_NEWLINE; else @@ -238,6 +242,7 @@ void writePlaintextParagraph(Buffer const & buf, } os << word; } + ods << os.str(); } diff --git a/src/output_plaintext.h b/src/output_plaintext.h index b047c9cf26..ebecc5ceba 100644 --- a/src/output_plaintext.h +++ b/src/output_plaintext.h @@ -13,6 +13,9 @@ #define OUTPUT_PLAINTEXT_H #include "support/strfwd.h" +#include "support/types.h" + +#include namespace lyx { @@ -36,7 +39,8 @@ void writePlaintextParagraph(Buffer const & buf, Paragraph const & paragraphs, odocstream & ofs, OutputParams const &, - bool & ref_printed); + bool & ref_printed, + size_t max_length = INT_MAX); } // namespace lyx diff --git a/src/support/docstream.h b/src/support/docstream.h index b7e30409b3..6da05e36a8 100644 --- a/src/support/docstream.h +++ b/src/support/docstream.h @@ -80,9 +80,6 @@ public: /// UCS4 input stringstream typedef std::basic_istringstream idocstringstream; -/// UCS4 output stringstream -typedef std::basic_ostringstream odocstringstream; - /// UCS4 output manipulator typedef odocstream & (*odocstream_manip)(odocstream &); diff --git a/src/support/strfwd.h b/src/support/strfwd.h index 069357ff9c..f1dcb0bca9 100644 --- a/src/support/strfwd.h +++ b/src/support/strfwd.h @@ -44,9 +44,11 @@ typedef basic_string, allocator > string; template class basic_istream; template class basic_ostream; +template class basic_ostringstream; typedef basic_istream > istream; typedef basic_ostream > ostream; +typedef basic_ostringstream, allocator > ostringstream; } // namepace std @@ -63,6 +65,9 @@ typedef std::basic_istream > idocstream; /// Base class for UCS4 output streams typedef std::basic_ostream > odocstream; +/// UCS4 output stringstream +typedef std::basic_ostringstream, std::allocator > odocstringstream; + #if ! defined(USE_WCHAR_T) extern odocstream & operator<<(odocstream &, char); #endif