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: case B_COPY:
Copy(be_clipboard); Copy(be_clipboard);
break; break;
case B_SELECT_ALL:
SelectAll();
break;
default: default:
BView::MessageReceived(message); 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 bool
TextDocumentView::HasSelection() const TextDocumentView::HasSelection() const
{ {
@ -344,7 +359,7 @@ TextDocumentView::HasSelection() const
void void
TextDocumentView::GetSelection(int32& start, int32& end) const TextDocumentView::GetSelection(int32& start, int32& end) const
{ {
if (fTextEditor.Get()) { if (fTextEditor.Get() != NULL) {
start = fTextEditor->SelectionStart(); start = fTextEditor->SelectionStart();
end = fTextEditor->SelectionEnd(); end = fTextEditor->SelectionEnd();
} }

View File

@ -63,6 +63,7 @@ public:
void SetCaret(BPoint where, bool extendSelection); void SetCaret(BPoint where, bool extendSelection);
void SelectAll();
bool HasSelection() const; bool HasSelection() const;
void GetSelection(int32& start, int32& end) 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 void
TextEditor::SetSelection(TextSelection selection) TextEditor::SetSelection(TextSelection selection)
{ {

View File

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