On 26/09/2008 16:42, Jean-Marc Lasgouttes wrote:
Abdelrazak Younes<[EMAIL PROTECTED]> writes:
Because you want to get rid of addToToc() and let the decision be made
in textString()? IMO textString() is just a helper method that is
useful for toc but could be also used for other purpose (ex:
tooltips). And yes, optional should overload it as well :-)
No, because the needs of plaintext (plain text export) are not the same
as the needs of TOC. Therefore the insets should support the two
methods.
I think of plaintext as 'verbose export' and textString as 'compact export'.
OK, next iteration.
Abdel.
Index: insets/InsetIndex.cpp
===================================================================
--- insets/InsetIndex.cpp (revision 26576)
+++ insets/InsetIndex.cpp (working copy)
@@ -171,15 +171,19 @@
}
+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);
}
Index: insets/InsetIndex.h
===================================================================
--- insets/InsetIndex.h (revision 26576)
+++ insets/InsetIndex.h (working copy)
@@ -41,6 +41,8 @@
/// 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); }
Index: Text.cpp
===================================================================
--- Text.cpp (revision 26576)
+++ Text.cpp (working copy)
@@ -1489,6 +1489,25 @@
}
+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(), /**/);
Index: Text.h
===================================================================
--- Text.h (revision 26576)
+++ Text.h (working copy)
@@ -108,6 +108,17 @@
/// 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);