diff --git a/src/Text.cpp b/src/Text.cpp index 0a4c1d1da7..f6b676b57d 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -1489,6 +1489,25 @@ docstring Text::getPossibleLabel(Cursor const & cur) const } +docstring Text::asString(int options) const +{ + return asString(0, pars_.size(), options); +} + + +docstring Text::asString(pit_type beg, pit_type end, int options) const +{ + size_t i = size_t(beg); + docstring str = pars_[i].asString(options); + for (++i; i != size_t(end); ++i) { + str += '\n'; + str += pars_[i].asString(options); + } + return str; +} + + + void Text::charsTranspose(Cursor & cur) { LASSERT(this == cur.text(), /**/); diff --git a/src/Text.h b/src/Text.h index 72f8b89902..62dc60979c 100644 --- a/src/Text.h +++ b/src/Text.h @@ -108,6 +108,17 @@ public: /// FIXME: replace Cursor with DocIterator. docstring getStringToIndex(Cursor const & cur); + /// Convert the paragraphs to a string. + /// \param AsStringParameter options. This can contain any combination of + /// asStringParameter values. Valid examples: + /// asString(AS_STR_LABEL) + /// asString(AS_STR_LABEL | AS_STR_INSETS) + /// asString(AS_STR_INSETS) + docstring asString(int options = AS_STR_NONE) const; + /// + docstring asString(pit_type beg, pit_type end, + int options = AS_STR_NONE) const; + /// insert a character at cursor position /// FIXME: replace Cursor with DocIterator. void insertChar(Cursor & cur, char_type c); diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index 12d5e4845e..d3fc212351 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -230,7 +230,7 @@ int InsetBranch::docbook(odocstream & os, void InsetBranch::textString(odocstream & os) const { if (isBranchSelected()) - os << paragraphs().begin()->asString(AS_STR_LABEL | AS_STR_INSETS); + os << text().asString(0, 1, AS_STR_LABEL | AS_STR_INSETS); } diff --git a/src/insets/InsetFlex.cpp b/src/insets/InsetFlex.cpp index 0d98f15fd1..d9c653af6b 100644 --- a/src/insets/InsetFlex.cpp +++ b/src/insets/InsetFlex.cpp @@ -109,7 +109,7 @@ int InsetFlex::docbook(odocstream & os, OutputParams const & runparams) const void InsetFlex::textString(odocstream & os) const { - os << paragraphs().begin()->asString(AS_STR_LABEL | AS_STR_INSETS); + os << text().asString(0, 1, AS_STR_LABEL | AS_STR_INSETS); } diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp index ce2b225d9d..4940c24f2c 100644 --- a/src/insets/InsetIndex.cpp +++ b/src/insets/InsetIndex.cpp @@ -171,15 +171,19 @@ void InsetIndex::write(ostream & os) const } +void InsetIndex::textString(odocstream & os) const +{ + os << text().asString(0, 1, AS_STR_LABEL | AS_STR_INSETS); +} + + void InsetIndex::addToToc(DocIterator const & cpit) { DocIterator pit = cpit; pit.push_back(CursorSlice(*this)); - - Toc & toc = buffer().tocBackend().toc("index"); - docstring str; - str = getNewLabel(str); - toc.push_back(TocItem(pit, 0, str)); + odocstringstream ods; + textString(ods); + buffer().tocBackend().toc("index").push_back(TocItem(pit, 0, ods.str())); // Proceed with the rest of the inset. InsetCollapsable::addToToc(cpit); } diff --git a/src/insets/InsetIndex.h b/src/insets/InsetIndex.h index 092311c64c..1f185172ae 100644 --- a/src/insets/InsetIndex.h +++ b/src/insets/InsetIndex.h @@ -41,6 +41,8 @@ private: /// should paragraph indendation be omitted in any case? bool neverIndent() const { return true; } /// + void textString(odocstream &) const; + /// void addToToc(DocIterator const &); /// Inset * clone() const { return new InsetIndex(*this); }