SerialConnect: implement clipboard paste

Change-Id: Iaddb6588afa774bcffad9713f280a0078784605a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6770
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
PulkoMandy
2023-08-02 21:16:56 +00:00
committed by Adrien Destugues
parent 4ae33413f2
commit 3a6bc1cf65
3 changed files with 46 additions and 1 deletions
+8 -1
View File
@@ -127,9 +127,12 @@ SerialWindow::SerialWindow()
// Items for the edit menu
BMenuItem* clearScreen = new BMenuItem(B_TRANSLATE("Clear history"),
new BMessage(kMsgClear));
new BMessage(kMsgClear), 'L');
editMenu->AddItem(clearScreen);
BMenuItem* paste = new BMenuItem(B_TRANSLATE("Paste"), new BMessage(B_PASTE), 'V');
editMenu->AddItem(paste);
// TODO copy (when we have selection), paste
// Configuring all this by menus may be a bit unhandy. Make a setting
@@ -468,6 +471,10 @@ void SerialWindow::MessageReceived(BMessage* message)
fTermView->Clear();
return;
}
case B_PASTE:
{
fTermView->PasteFromClipboard();
}
case kMsgProgress:
{
// File transfer progress
+36
View File
@@ -8,6 +8,7 @@
#include <stdio.h>
#include <Clipboard.h>
#include <Entry.h>
#include <File.h>
#include <Font.h>
@@ -235,6 +236,21 @@ TermView::KeyDown(const char* bytes, int32 numBytes)
}
void
TermView::MouseDown(BPoint where)
{
int32 buttons = B_PRIMARY_MOUSE_BUTTON;
int32 clicks = 1;
if (Looper() != NULL && Looper()->CurrentMessage() != NULL) {
Looper()->CurrentMessage()->FindInt32("buttons", &buttons);
Looper()->CurrentMessage()->FindInt32("clicks", &clicks);
}
if (buttons == B_TERTIARY_MOUSE_BUTTON && clicks == 1)
PasteFromClipboard();
}
void
TermView::MessageReceived(BMessage* message)
{
@@ -284,6 +300,26 @@ TermView::Clear()
}
void
TermView::PasteFromClipboard()
{
if (!be_clipboard->Lock())
return;
BMessage* message = be_clipboard->Data();
const void *data;
ssize_t size;
if (message->FindData("text/plain", B_MIME_TYPE, &data, &size) == B_OK) {
BMessage* keyEvent = new BMessage(kMsgDataWrite);
keyEvent->AddData("data", B_RAW_TYPE, data, size);
be_app_messenger.SendMessage(keyEvent);
}
be_clipboard->Unlock();
}
// #pragma mark -
+2
View File
@@ -24,11 +24,13 @@ class TermView: public BView
void FrameResized(float width, float height);
void GetPreferredSize(float* width, float* height);
void KeyDown(const char* bytes, int32 numBytes);
void MouseDown(BPoint where);
void MessageReceived(BMessage* message);
void SetLineTerminator(BString bytes);
void PushBytes(const char* bytes, const size_t length);
void Clear();
void PasteFromClipboard();
private:
void _Init();