Fixed mouse copy'n'paste support. We use a separate clipboard for mouse
selection which we update whenever the first mouse button is released. This also enables copy'n'paste between Terminals. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26044 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Copyright 2008, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "Globals.h"
|
||||
|
||||
|
||||
BClipboard* gMouseClipboard = NULL;
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright 2008, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef GLOBALS_H
|
||||
#define GLOBALS_H
|
||||
|
||||
|
||||
class BClipboard;
|
||||
|
||||
extern BClipboard* gMouseClipboard;
|
||||
// clipboard used for mouse copy'n'paste
|
||||
|
||||
|
||||
#endif // GLOBALS_H
|
||||
@@ -11,6 +11,7 @@ Application Terminal :
|
||||
CodeConv.cpp
|
||||
Coding.cpp
|
||||
FindWindow.cpp
|
||||
Globals.cpp
|
||||
HistoryBuffer.cpp
|
||||
MenuUtil.cpp
|
||||
Terminal.cpp
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include "Arguments.h"
|
||||
#include "CodeConv.h"
|
||||
#include "Globals.h"
|
||||
#include "PrefHandler.h"
|
||||
#include "TermWindow.h"
|
||||
#include "TermConst.h"
|
||||
@@ -94,6 +95,9 @@ TermApp::ReadyToRun()
|
||||
// continue anyway
|
||||
}
|
||||
|
||||
// init the mouse copy'n'paste clipboard
|
||||
gMouseClipboard = new BClipboard(MOUSE_CLIPBOARD_NAME, true);
|
||||
|
||||
status_t status = _MakeTermWindow(fTermFrame);
|
||||
|
||||
// failed spawn, print stdout and open alert panel
|
||||
|
||||
@@ -31,13 +31,16 @@
|
||||
#ifndef TERMCONST_H_INCLUDED
|
||||
#define TERMCONST_H_INCLUDED
|
||||
|
||||
// Application signature (Must same in Muterminal.rsrc)//
|
||||
// Application signature (Must same in Muterminal.rsrc)
|
||||
#define TERM_SIGNATURE "application/x-vnd.Haiku-Terminal"
|
||||
#define PREFFILE_MIMETYPE "text/x-terminal-pref"
|
||||
|
||||
// Signature of R5's Terminal. Needed for proper drop-in window count support
|
||||
#define R5_TERM_SIGNATURE "application/x-vnd.Be-SHEL"
|
||||
|
||||
// Name of the clipboard used for mouse copy'n'paste.
|
||||
#define MOUSE_CLIPBOARD_NAME TERM_SIGNATURE "/mouse"
|
||||
|
||||
// Message constants for menu items
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <Window.h>
|
||||
|
||||
#include "CodeConv.h"
|
||||
#include "Globals.h"
|
||||
#include "Shell.h"
|
||||
#include "TermConst.h"
|
||||
#include "TerminalCharClassifier.h"
|
||||
@@ -949,6 +950,8 @@ TermView::_UpdateSIGWINCH()
|
||||
void
|
||||
TermView::AttachedToWindow()
|
||||
{
|
||||
fMouseButtons = 0;
|
||||
|
||||
MakeFocus(true);
|
||||
if (fScrollBar) {
|
||||
fScrollBar->SetSteps(fFontHeight, fFontHeight * fTermRows);
|
||||
@@ -1801,19 +1804,11 @@ TermView::MouseDown(BPoint where)
|
||||
int32 buttons;
|
||||
Window()->CurrentMessage()->FindInt32("buttons", &buttons);
|
||||
|
||||
fMouseButtons = buttons;
|
||||
|
||||
// paste button
|
||||
if ((buttons & (B_SECONDARY_MOUSE_BUTTON | B_TERTIARY_MOUSE_BUTTON)) != 0) {
|
||||
if (_HasSelection()) {
|
||||
// copy text from region
|
||||
BString copy;
|
||||
fTextBuffer->Lock();
|
||||
fTextBuffer->GetStringFromRegion(copy, fSelStart, fSelEnd);
|
||||
fTextBuffer->Unlock();
|
||||
_WritePTY(copy.String(), copy.Length());
|
||||
} else {
|
||||
// copy text from clipboard.
|
||||
Paste(be_clipboard);
|
||||
}
|
||||
Paste(gMouseClipboard);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1956,6 +1951,17 @@ TermView::MouseUp(BPoint where)
|
||||
delete fAutoScrollRunner;
|
||||
fAutoScrollRunner = NULL;
|
||||
}
|
||||
|
||||
// When releasing the first mouse button, we copy the selected text to the
|
||||
// clipboard.
|
||||
int32 buttons;
|
||||
Window()->CurrentMessage()->FindInt32("buttons", &buttons);
|
||||
if ((buttons & B_PRIMARY_MOUSE_BUTTON) == 0
|
||||
&& (fMouseButtons & B_PRIMARY_MOUSE_BUTTON) != 0) {
|
||||
Copy(gMouseClipboard);
|
||||
}
|
||||
|
||||
fMouseButtons = buttons;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -191,6 +191,8 @@ private:
|
||||
// Cursor position.
|
||||
TermPos fCursor;
|
||||
|
||||
int32 fMouseButtons;
|
||||
|
||||
// Terminal rows and columns.
|
||||
int fTermRows;
|
||||
int fTermColumns;
|
||||
|
||||
Reference in New Issue
Block a user