Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 335021

Summary: [terminal] Middle mouse button copy/paste does not work with the terminal
Product: [Tools] Target Management Reporter: Anton Leherbauer <aleherb+eclipse>
Component: TerminalAssignee: Martin Oberhuber <mober.at+eclipse>
Status: RESOLVED FIXED QA Contact: Martin Oberhuber <mober.at+eclipse>
Severity: normal    
Priority: P3 CC: eclipse
Version: 3.2   
Target Milestone: 3.3 M5   
Hardware: All   
OS: Unix All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 300809, 335408    
Attachments:
Description Flags
Suggested fix
mober.at+eclipse: review-
Backport fix
none
Backport fix (2) mober.at+eclipse: iplog+

Description Anton Leherbauer CLA 2011-01-21 09:33:22 EST
It is not possible to paste text using the middle mouse button from the terminal somewhere outside the terminal itself.
Comment 1 Anton Leherbauer CLA 2011-01-24 09:16:51 EST
Created attachment 187421 [details]
Suggested fix

This patch adds support for the clipboard type DND.SELECTION_CLIPBOARD which is used to handle the middle mouse button copy/paste feature.
Comment 2 Martin Oberhuber CLA 2011-01-24 12:48:52 EST
Comment on attachment 187421 [details]
Suggested fix

CQ:WIND00250102 

With the change, the "paste on middle mouse button" doesn't work for me on Windows any more.

I also have a couple other concerns especially wrt backporting this to 3.2.2: 
a) In the backport, we need to live with the possibility that only tm.terminal
   gets updated but tm.terminal.view might remain the old version. That way, it
   can happen that a MouseAdapter is registered twice for the Terminal widget.
b) In the backport, some container might have expected to be able and register
   its own MouseAdapter on the Terminal Widget for handling middle click 
   differently than doing a Paste (unlikely but possible).

Can we live with this situation? Or could you come up with a different patch for the backport, perhaps at the expense of supporting the "middle button paste" only after a right-click > copy operation?

Retaining the middle button "paste" support on Windows is a must-have I think since I believe that users got used to it already. Could we, perhaps, copy into BOTH the DND.CLIPBOARD and the DND.SELECTION_CLIPBOARD style buffers ?

I believe that the other version clash possibility (of tm.terminal.view getting updated but the tm.terminal widget not getting updated) can be prohibited by forcing a narrow lower bounds on the "require-bundle" version range of terminal.view.
Comment 3 Anton Leherbauer CLA 2011-01-25 05:17:56 EST
Created attachment 187504 [details]
Backport fix

This is a backwards compatible fix which also restores the middle mouse button support on Windows.
Comment 4 Martin Oberhuber CLA 2011-01-25 05:39:48 EST
The new patch looks mostly OK, I'm only concerned about introducing the Platform-specific code. We won't be able to test on all Platforms (eg Mac) so there is a small risk of introducing a regression.

In TerminalViewConnection, could you try 

  getContents(textTransfer, DND.CLIPBOARD | DND.SELECTION_CLIPBOARD)

since bitwise OR'ing the constants is allowed as per the Clipboard#getContents Javadocs. If this does what we want on both Windows and Linux, we should be good on all Platforms.
Comment 5 Anton Leherbauer CLA 2011-01-25 06:57:30 EST
Created attachment 187511 [details]
Backport fix (2)

(In reply to comment #4)
>   getContents(textTransfer, DND.CLIPBOARD | DND.SELECTION_CLIPBOARD)

This works on Windows, but under Linux/GTK the DND.CLIPBOARD is preferred over DND.SELECTION_CLIPBOARD, ie. the content from the last copy operation is used instead of the last selection event.

Attached patch now uses Clipboard.getAvailableTypes(int) to determine whether the selection clipboard is available or not.  This should work on all platforms.
Comment 6 Martin Oberhuber CLA 2011-01-25 12:13:45 EST
Patch applied - thanks!