Skip to content

Commit

Permalink
HaikuDepot: Make MarkupParser a bit more flexible...
Browse files Browse the repository at this point in the history
 ... by allowing to append markup to an existing document.
  • Loading branch information
stippi committed Sep 8, 2013
1 parent 97c332e commit cb97f23
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/apps/haiku-depot/textview/MarkupParser.cpp
Expand Up @@ -64,9 +64,20 @@ MarkupParser::SetStyles(const CharacterStyle& characterStyle,
TextDocumentRef TextDocumentRef
MarkupParser::CreateDocumentFromMarkup(const BString& text) MarkupParser::CreateDocumentFromMarkup(const BString& text)
{ {
fTextDocument.SetTo(new(std::nothrow) TextDocument(), true); TextDocumentRef document(new(std::nothrow) TextDocument(), true);
if (fTextDocument.Get() == NULL) if (document.Get() == NULL)
return fTextDocument; return document;

AppendMarkup(document, text);

return document;
}


void
MarkupParser::AppendMarkup(const TextDocumentRef& document, const BString& text)
{
fTextDocument.SetTo(document);


fCurrentCharacterStyle = &fNormalStyle; fCurrentCharacterStyle = &fNormalStyle;
fCurrentParagraphStyle = &fParagraphStyle; fCurrentParagraphStyle = &fParagraphStyle;
Expand All @@ -76,7 +87,7 @@ MarkupParser::CreateDocumentFromMarkup(const BString& text)


_ParseText(text); _ParseText(text);


return fTextDocument; fTextDocument.Unset();
} }




Expand Down
7 changes: 7 additions & 0 deletions src/apps/haiku-depot/textview/MarkupParser.h
Expand Up @@ -19,7 +19,14 @@ class MarkupParser {
const CharacterStyle& characterStyle, const CharacterStyle& characterStyle,
const ParagraphStyle& paragraphStyle); const ParagraphStyle& paragraphStyle);


const CharacterStyle& HeadingCharacterStyle() const
{ return fHeadingStyle; }
const ParagraphStyle& HeadingParagraphStyle() const
{ return fHeadingParagraphStyle; }

TextDocumentRef CreateDocumentFromMarkup(const BString& text); TextDocumentRef CreateDocumentFromMarkup(const BString& text);
void AppendMarkup(const TextDocumentRef& document,
const BString& text);


private: private:
void _InitStyles(); void _InitStyles();
Expand Down

0 comments on commit cb97f23

Please sign in to comment.