diff --git a/src/apps/terminal/Globals.cpp b/src/apps/terminal/Globals.cpp new file mode 100644 index 0000000000..e59fd51a5e --- /dev/null +++ b/src/apps/terminal/Globals.cpp @@ -0,0 +1,11 @@ +/* + * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include + +#include "Globals.h" + + +BClipboard* gMouseClipboard = NULL; diff --git a/src/apps/terminal/Globals.h b/src/apps/terminal/Globals.h new file mode 100644 index 0000000000..7acad62a83 --- /dev/null +++ b/src/apps/terminal/Globals.h @@ -0,0 +1,15 @@ +/* + * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. + * 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 diff --git a/src/apps/terminal/Jamfile b/src/apps/terminal/Jamfile index 0675ef27c7..86af72ef53 100644 --- a/src/apps/terminal/Jamfile +++ b/src/apps/terminal/Jamfile @@ -11,6 +11,7 @@ Application Terminal : CodeConv.cpp Coding.cpp FindWindow.cpp + Globals.cpp HistoryBuffer.cpp MenuUtil.cpp Terminal.cpp diff --git a/src/apps/terminal/TermApp.cpp b/src/apps/terminal/TermApp.cpp index c1ff07719d..209f99d0f9 100644 --- a/src/apps/terminal/TermApp.cpp +++ b/src/apps/terminal/TermApp.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 diff --git a/src/apps/terminal/TermConst.h b/src/apps/terminal/TermConst.h index 266f340b48..88e0613188 100644 --- a/src/apps/terminal/TermConst.h +++ b/src/apps/terminal/TermConst.h @@ -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 diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index 33f4b7c68d..dc18181969 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -41,6 +41,7 @@ #include #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; } diff --git a/src/apps/terminal/TermView.h b/src/apps/terminal/TermView.h index 4063d408a8..a6a4d0e89f 100644 --- a/src/apps/terminal/TermView.h +++ b/src/apps/terminal/TermView.h @@ -191,6 +191,8 @@ private: // Cursor position. TermPos fCursor; + int32 fMouseButtons; + // Terminal rows and columns. int fTermRows; int fTermColumns;