From ab49b58c80317e34c3db367a370b24aed82c33cb Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Tue, 14 Jul 2009 04:03:12 +0000 Subject: [PATCH] Copy to clipboard now works. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31550 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../debugger/gui/team_window/SourceView.cpp | 35 +++++++++++++++---- .../debugger/gui/team_window/SourceView.h | 3 +- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/apps/debugger/gui/team_window/SourceView.cpp b/src/apps/debugger/gui/team_window/SourceView.cpp index fc0d30cafc..15ab5dd717 100644 --- a/src/apps/debugger/gui/team_window/SourceView.cpp +++ b/src/apps/debugger/gui/team_window/SourceView.cpp @@ -201,6 +201,8 @@ class SourceView::TextView : public BaseView { public: TextView(SourceView* sourceView, FontInfo* fontInfo); + + void CopySelectionToClipboard() const; virtual void SetSourceCode(SourceCode* sourceCode); @@ -234,7 +236,6 @@ private: BString& formattedLine); SelectionPoint _SelectionPointAt(BPoint where) const; void _GetSelectionRegion(BRegion& region) const; - void _CopySelectionToClipboard() const; private: @@ -1053,6 +1054,9 @@ SourceView::TextView::_SelectionPointAt(BPoint where) const { int32 line = LineAtOffset(where.y); int32 offset = (int32)max_c((where.x - kLeftTextMargin) / fCharacterWidth, 0); + int32 lineLength = strlen(fSourceCode->LineAt(line)); + if (offset > lineLength) + offset = (lineLength > 0) ? lineLength - 1 : 0; return SelectionPoint(line, offset); } @@ -1104,29 +1108,31 @@ SourceView::TextView::_GetSelectionRegion(BRegion ®ion) const void -SourceView::TextView::_CopySelectionToClipboard(void) const +SourceView::TextView::CopySelectionToClipboard(void) const { if (fSelectionStart.line == -1 || fSelectionEnd.line == -1) return; BString text; - if (fSelectionStart.line == fSelectionEnd.line) + if (fSelectionStart.line == fSelectionEnd.line) text.SetTo(fSourceCode->LineAt(fSelectionStart.line) + fSelectionStart.offset, fSelectionEnd.offset - fSelectionStart.offset); else { - text << (fSourceCode->LineAt(fSelectionStart.line) + text.SetTo(fSourceCode->LineAt(fSelectionStart.line) + fSelectionStart.offset); - for (int32 i = fSelectionStart.line + 1; i < fSelectionEnd.line; i++) - text += fSourceCode->LineAt(i); + text << "\n"; + for (int32 i = fSelectionStart.line + 1; i < fSelectionEnd.line; i++) + text << fSourceCode->LineAt(i) << "\n"; text.Append(fSourceCode->LineAt(fSelectionEnd.line), fSelectionEnd.offset); } be_clipboard->Lock(); - be_clipboard->Clear(); + be_clipboard->Data()->RemoveData("text/plain"); be_clipboard->Data()->AddData ("text/plain", B_MIME_TYPE, text.String(), text.Length()); + be_clipboard->Commit(); be_clipboard->Unlock(); } @@ -1330,6 +1336,21 @@ SourceView::TargetedByScrollView(BScrollView* scrollView) } +void +SourceView::MessageReceived(BMessage *message) +{ + switch (message->what) + { + case B_COPY: + fTextView->CopySelectionToClipboard(); + break; + + default: + BView::MessageReceived(message); + break; + } +} + BSize SourceView::MinSize() { diff --git a/src/apps/debugger/gui/team_window/SourceView.h b/src/apps/debugger/gui/team_window/SourceView.h index c42e87a8e5..49b9b77603 100644 --- a/src/apps/debugger/gui/team_window/SourceView.h +++ b/src/apps/debugger/gui/team_window/SourceView.h @@ -45,7 +45,8 @@ public: void HighlightBorder(bool state); virtual void TargetedByScrollView(BScrollView* scrollView); - + virtual void MessageReceived(BMessage *message); + virtual BSize MinSize(); virtual BSize MaxSize(); virtual BSize PreferredSize();