HaikuDepot: React to B_SELECT_ALL in custom text view

This commit is contained in:
Stephan Aßmus 2014-10-12 23:41:27 +02:00
parent 639756547d
commit 96ebc1d602
4 changed files with 28 additions and 1 deletions

View File

@ -52,6 +52,9 @@ TextDocumentView::MessageReceived(BMessage* message)
case B_COPY:
Copy(be_clipboard);
break;
case B_SELECT_ALL:
SelectAll();
break;
default:
BView::MessageReceived(message);
@ -334,6 +337,18 @@ TextDocumentView::SetCaret(BPoint location, bool extendSelection)
}
void
TextDocumentView::SelectAll()
{
if (fTextEditor.Get() == NULL)
return;
fTextEditor->SelectAll();
fShowCaret = false;
Invalidate();
}
bool
TextDocumentView::HasSelection() const
{
@ -344,7 +359,7 @@ TextDocumentView::HasSelection() const
void
TextDocumentView::GetSelection(int32& start, int32& end) const
{
if (fTextEditor.Get()) {
if (fTextEditor.Get() != NULL) {
start = fTextEditor->SelectionStart();
end = fTextEditor->SelectionEnd();
}

View File

@ -63,6 +63,7 @@ public:
void SetCaret(BPoint where, bool extendSelection);
void SelectAll();
bool HasSelection() const;
void GetSelection(int32& start, int32& end) const;

View File

@ -119,6 +119,16 @@ TextEditor::SetCaret(BPoint location, bool extendSelection)
}
void
TextEditor::SelectAll()
{
if (fDocument.Get() == NULL)
return;
SetSelection(TextSelection(0, fDocument->Length()));
}
void
TextEditor::SetSelection(TextSelection selection)
{

View File

@ -48,6 +48,7 @@ public:
{ return fEditingEnabled; }
void SetCaret(BPoint location, bool extendSelection);
void SelectAll();
void SetSelection(TextSelection selection);
inline TextSelection Selection() const
{ return fSelection; }