From b936fc6770af22734362f39cdaa7c22b05925c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 7 Apr 2009 09:03:29 +0000 Subject: [PATCH] * Watch the system clipboard for changes. * On the event of a clipboard change, check if the clipboard contains text now and replace the contents of the internal "mouse clipboard". So when right/middle clicking into the Terminal, the current system clipboard contents are inserted. As soon as the user selects text in the Terminal again, that text will have priority over the system clipboard, as before. Fixes ticket #3700. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29989 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/terminal/TermView.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index b8726c4ca1..7c06cbb30c 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -937,12 +937,16 @@ TermView::AttachedToWindow() fTextBuffer->SetListener(thisMessenger); _SynchronizeWithTextBuffer(0, -1); } + + be_clipboard->StartWatching(thisMessenger); } void TermView::DetachedFromWindow() { + be_clipboard->StopWatching(BMessenger(this)); + delete fWinchRunner; fWinchRunner = NULL; @@ -1398,6 +1402,29 @@ TermView::MessageReceived(BMessage *msg) break; } + case B_CLIPBOARD_CHANGED: + // This message originates from the system clipboard. Overwrite + // the contents of the mouse clipboard with the ones from the + // system clipboard, in case it contains text data. + if (be_clipboard->Lock()) { + if (gMouseClipboard->Lock()) { + BMessage* clipMsgA = be_clipboard->Data(); + const char* text; + ssize_t numBytes; + if (clipMsgA->FindData("text/plain", B_MIME_TYPE, + (const void**)&text, &numBytes) == B_OK ) { + gMouseClipboard->Clear(); + BMessage* clipMsgB = gMouseClipboard->Data(); + clipMsgB->AddData("text/plain", B_MIME_TYPE, + text, numBytes); + gMouseClipboard->Commit(); + } + gMouseClipboard->Unlock(); + } + be_clipboard->Unlock(); + } + break; + case B_SELECT_ALL: SelectAll(); break;