From 4b810a1e92178747688488db78f468b5dc902937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Thu, 5 Sep 2013 13:24:01 +0200 Subject: [PATCH] HaikuDepot: TextDocument: Added Paragraph access by index. --- src/apps/haiku-depot/textview/TextDocument.cpp | 9 +++++++++ src/apps/haiku-depot/textview/TextDocument.h | 9 ++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/apps/haiku-depot/textview/TextDocument.cpp b/src/apps/haiku-depot/textview/TextDocument.cpp index e77d51b7b2..b8cbb2d2bc 100644 --- a/src/apps/haiku-depot/textview/TextDocument.cpp +++ b/src/apps/haiku-depot/textview/TextDocument.cpp @@ -178,6 +178,15 @@ TextDocument::ParagraphAt(int32 textOffset, int32& paragraphOffset) const } +const Paragraph& +TextDocument::ParagraphAt(int32 index) const +{ + if (index >= 0 && index < fParagraphs.CountItems()) + return fParagraphs.ItemAtFast(index); + return fEmptyLastParagraph; +} + + bool TextDocument::Append(const Paragraph& paragraph) { diff --git a/src/apps/haiku-depot/textview/TextDocument.h b/src/apps/haiku-depot/textview/TextDocument.h index 0dbe42e254..5bb23c48bf 100644 --- a/src/apps/haiku-depot/textview/TextDocument.h +++ b/src/apps/haiku-depot/textview/TextDocument.h @@ -5,6 +5,8 @@ #ifndef TEXT_DOCUMENT_H #define TEXT_DOCUMENT_H +#include + #include "CharacterStyle.h" #include "List.h" #include "Paragraph.h" @@ -13,7 +15,7 @@ typedef List ParagraphList; -class TextDocument { +class TextDocument : public BReferenceable { public: TextDocument(); TextDocument( @@ -56,6 +58,8 @@ public: const Paragraph& ParagraphAt(int32 textOffset, int32& paragraphOffset) const; + const Paragraph& ParagraphAt(int32 index) const; + bool Append(const Paragraph& paragraph); private: @@ -65,4 +69,7 @@ private: }; +typedef BReference TextDocumentRef; + + #endif // TEXT_DOCUMENT_H