Copy to clipboard now works.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31550 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -202,6 +202,8 @@ public:
|
|||||||
TextView(SourceView* sourceView,
|
TextView(SourceView* sourceView,
|
||||||
FontInfo* fontInfo);
|
FontInfo* fontInfo);
|
||||||
|
|
||||||
|
void CopySelectionToClipboard() const;
|
||||||
|
|
||||||
virtual void SetSourceCode(SourceCode* sourceCode);
|
virtual void SetSourceCode(SourceCode* sourceCode);
|
||||||
|
|
||||||
virtual BSize MinSize();
|
virtual BSize MinSize();
|
||||||
@@ -234,7 +236,6 @@ private:
|
|||||||
BString& formattedLine);
|
BString& formattedLine);
|
||||||
SelectionPoint _SelectionPointAt(BPoint where) const;
|
SelectionPoint _SelectionPointAt(BPoint where) const;
|
||||||
void _GetSelectionRegion(BRegion& region) const;
|
void _GetSelectionRegion(BRegion& region) const;
|
||||||
void _CopySelectionToClipboard() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@@ -1053,6 +1054,9 @@ SourceView::TextView::_SelectionPointAt(BPoint where) const
|
|||||||
{
|
{
|
||||||
int32 line = LineAtOffset(where.y);
|
int32 line = LineAtOffset(where.y);
|
||||||
int32 offset = (int32)max_c((where.x - kLeftTextMargin) / fCharacterWidth, 0);
|
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);
|
return SelectionPoint(line, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1104,7 +1108,7 @@ SourceView::TextView::_GetSelectionRegion(BRegion ®ion) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SourceView::TextView::_CopySelectionToClipboard(void) const
|
SourceView::TextView::CopySelectionToClipboard(void) const
|
||||||
{
|
{
|
||||||
if (fSelectionStart.line == -1 || fSelectionEnd.line == -1)
|
if (fSelectionStart.line == -1 || fSelectionEnd.line == -1)
|
||||||
return;
|
return;
|
||||||
@@ -1115,18 +1119,20 @@ SourceView::TextView::_CopySelectionToClipboard(void) const
|
|||||||
+ fSelectionStart.offset, fSelectionEnd.offset
|
+ fSelectionStart.offset, fSelectionEnd.offset
|
||||||
- fSelectionStart.offset);
|
- fSelectionStart.offset);
|
||||||
else {
|
else {
|
||||||
text << (fSourceCode->LineAt(fSelectionStart.line)
|
text.SetTo(fSourceCode->LineAt(fSelectionStart.line)
|
||||||
+ fSelectionStart.offset);
|
+ fSelectionStart.offset);
|
||||||
|
text << "\n";
|
||||||
for (int32 i = fSelectionStart.line + 1; i < fSelectionEnd.line; i++)
|
for (int32 i = fSelectionStart.line + 1; i < fSelectionEnd.line; i++)
|
||||||
text += fSourceCode->LineAt(i);
|
text << fSourceCode->LineAt(i) << "\n";
|
||||||
text.Append(fSourceCode->LineAt(fSelectionEnd.line),
|
text.Append(fSourceCode->LineAt(fSelectionEnd.line),
|
||||||
fSelectionEnd.offset);
|
fSelectionEnd.offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
be_clipboard->Lock();
|
be_clipboard->Lock();
|
||||||
be_clipboard->Clear();
|
be_clipboard->Data()->RemoveData("text/plain");
|
||||||
be_clipboard->Data()->AddData ("text/plain",
|
be_clipboard->Data()->AddData ("text/plain",
|
||||||
B_MIME_TYPE, text.String(), text.Length());
|
B_MIME_TYPE, text.String(), text.Length());
|
||||||
|
be_clipboard->Commit();
|
||||||
be_clipboard->Unlock();
|
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
|
BSize
|
||||||
SourceView::MinSize()
|
SourceView::MinSize()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ public:
|
|||||||
|
|
||||||
void HighlightBorder(bool state);
|
void HighlightBorder(bool state);
|
||||||
virtual void TargetedByScrollView(BScrollView* scrollView);
|
virtual void TargetedByScrollView(BScrollView* scrollView);
|
||||||
|
virtual void MessageReceived(BMessage *message);
|
||||||
|
|
||||||
virtual BSize MinSize();
|
virtual BSize MinSize();
|
||||||
virtual BSize MaxSize();
|
virtual BSize MaxSize();
|
||||||
|
|||||||
Reference in New Issue
Block a user