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

Bug 258511

Summary: [EditorMgmt] Middle click to close tab switches editor before close
Product: [Eclipse Project] Platform Reporter: Andrew Niefer <aniefer>
Component: UIAssignee: Platform UI Triaged <platform-ui-triaged>
Status: RESOLVED WORKSFORME QA Contact: Remy Suen <remy.suen>
Severity: enhancement    
Priority: P3 CC: eclipse.felipe, emoffatt, markus.kell.r, remy.suen
Version: 3.5Keywords: helpwanted
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on: 258727    
Bug Blocks:    
Attachments:
Description Flags
Activate part only on first mouse click patch v1
none
Activate part only on first mouse click patch v2 none

Description Andrew Niefer CLA 2008-12-11 13:31:19 EST
Middle clicking on an editor tab closes that tab, however, before the close, the editor first switches to the about-to-be-closed editor.

It would be nice if the tab closed without first switching editors.  (Like closing tabs in firefox with middle-click).

Note that if I middle click but don't release right away, then I get a switch to that tab, but the tab doesn't close.
Comment 1 Boris Bokowski CLA 2008-12-12 12:52:04 EST
Yeah, I'd like to see this too. The same applies to views, and what's really bad is that if I want to close a view that I haven't used or brought to the front in the current session, it will first be materialized (activating plugins etc...) before it will be closed.
Comment 2 Remy Suen CLA 2008-12-13 01:17:39 EST
For referencing purposes, this is very much related to bug 60833.
Comment 3 Remy Suen CLA 2008-12-13 02:23:16 EST
Upon investigation, SWT will need to "ignore" secondary mouse clicks on unselected tab items for this to be possible. Please see bug 258727.
Comment 4 Felipe Heidrich CLA 2009-01-30 17:07:13 EST
This works for me on 3.5 M5.

Modern mouses configure the middle click (or clicking on the wheel) to some functions specific to mouse (free spinning mode, zoom, flip window, etc). Application shouldn't use middle click anymore.
Comment 5 Remy Suen CLA 2009-02-05 17:03:33 EST
(In reply to comment #4)
> This works for me on 3.5 M5.

Clicking on the mouse wheel works for me on I20090203-1200. Andrew?
Comment 6 Felipe Heidrich CLA 2009-02-05 17:22:06 EST
> (In reply to comment #4)
> > This works for me on 3.5 M5.
> Clicking on the mouse wheel works for me on I20090203-1200. Andrew?

Can you please run Snippet62.java from org.eclipse.swt.snippets.
what does it print to the console when you click on the wheel ?
Comment 7 Remy Suen CLA 2009-02-05 17:25:55 EST
(In reply to comment #6)
> Can you please run Snippet62.java from org.eclipse.swt.snippets.
> what does it print to the console when you click on the wheel ?

Your wish is my command.

DOWN: button: 2, stateMask=0x0, x=29, y=10
UP: button: 2, stateMask=0x100000, x=29, y=10 BUTTON2
DOWN: button: 2, stateMask=0x0, x=29, y=10
UP: button: 2, stateMask=0x100000, x=29, y=10 BUTTON2
DOWN: button: 2, stateMask=0x0, x=29, y=10
UP: button: 2, stateMask=0x100000, x=29, y=10 BUTTON2
DOWN: button: 2, stateMask=0x0, x=29, y=10
UP: button: 2, stateMask=0x100000, x=29, y=10 BUTTON2
Comment 8 Felipe Heidrich CLA 2009-02-05 17:33:59 EST
Thanks. I see, we copied this behaviour from IE and Firefox.
This is probably a side effect of Bug 60833, workbench should only switch tab when button==1.
Comment 9 Andrew Niefer CLA 2009-02-05 17:42:15 EST
In M5 I'm still seeing a tab switch before close, both in editors and in views.
This is a wheel click on my logitech mouse, and the same for the middle bottom
above the trackpad on my thinkpad.

If it helps anything, I tried a spy and see
WM_MBUTTONDOWN  wparam=0x00000010 lparam=0x0007001b
WM_MBUTTONUP wParam=0x00000000 lParam=0x0007001b

I'll try the Snippet62
Comment 10 Andrew Niefer CLA 2009-02-05 17:50:04 EST
My Snippet62 on wheel click is the same as Remy's
Comment 11 Remy Suen CLA 2009-02-05 17:55:45 EST
Created attachment 124900 [details]
Activate part only on first mouse click patch v1

(In reply to comment #8)
> Thanks. I see, we copied this behaviour from IE and Firefox.
> This is probably a side effect of Bug 60833, workbench should only switch tab
> when button==1.

(In reply to comment #9)
> In M5 I'm still seeing a tab switch before close, both in editors and in views.

Thank you Andrew and Felipe for your input.
Comment 12 Felipe Heidrich CLA 2009-02-05 18:07:01 EST
Does your patch fixes Bug 60833 ?
Comment 13 Remy Suen CLA 2009-02-05 18:41:26 EST
(In reply to comment #12)
> Does your patch fixes Bug 60833 ?

No, that includes changes that doesn't affect the middle click. I will provide details on that bug.
Comment 14 Eric Moffatt CLA 2009-02-17 16:38:39 EST
Remy, the patch is simple and -appears- to have no regressive effects (as well as fixing the activation issue). The context menu still activates the part when it is shown but as discussed in this morning's meeting that's likely OK.

I've been tracing through the code and still can't figure out how the right click handling sends the same event "EVENT_GIVE_FOCUS_TO_PART" but doesn't end up activating the part (it's actually activated as part of showing the context menu) but that's OK, there are many parts of the event cascades that I don't understand...;-)

Comment 15 Remy Suen CLA 2009-02-17 17:39:21 EST
(In reply to comment #14)
> I've been tracing through the code and still can't figure out how the right
> click handling sends the same event "EVENT_GIVE_FOCUS_TO_PART" but doesn't end
> up activating the part (it's actually activated as part of showing the context
> menu) but that's OK, there are many parts of the event cascades that I don't
> understand...;-)

Since the part has been activated when the context menu was brought up, the WorkbenchPage class simply returns. Is this what you are talking about?

private void setActivePart(IWorkbenchPart newPart) {
    // Optimize it.
    if (getActivePart() == newPart) {
        return;
    }

    /* ... */
}
Comment 16 Remy Suen CLA 2009-02-17 17:58:50 EST
Created attachment 125958 [details]
Activate part only on first mouse click patch v2

Problem with attachment 124900 [details]:
1. Click on one view in one view stack to activate it.
2. Click on another view in another view stack to activate it.
3. Bring up the context menu on the first view's view tab.
4. The view will _not_ get the blue outline but stays white.
Comment 17 Eric Moffatt CLA 2009-02-18 16:10:37 EST
Thanks Remy, I was looking at this when I got side swiped by the CPD issues...I'll get back to it tomorrow.
Comment 18 Remy Suen CLA 2009-05-03 07:45:00 EDT
Apr 24 10:14:27 *       borisb6i1 is sniping views using the middle mouse button
Apr 24 10:14:55 <borisb6i1>     Thanks rcjsuen for fixing this!
Apr 24 10:15:11 <rcjsuen>       borisb6i1: what, that's not committed yet
Apr 24 10:15:15 <rcjsuen>       at least,  Idon't think it is
Apr 24 10:15:30 <rcjsuen>       unless Eric pushed it without telling me

Guess we all forgot about this bug.
Comment 19 Eric Moffatt CLA 2009-05-03 19:57:54 EDT
Sorry Remy, I didn't tag it. Boris this looks simple/safe enough for inclusion in RC1, any objections?
Comment 20 Boris Bokowski CLA 2009-05-04 12:18:18 EDT
Doesn't look safe as is (because it also affects the right mouse button), but I just tested on Win32 and the middle click no longer activates editors or views before closing them. Something else must have changed between 3.4 and 3.5.
Comment 21 Remy Suen CLA 2009-05-04 12:59:59 EDT
I have not had much luck getting the debugger to stop when I place breakpoints in createPartControl or the one in WorkbenchPart's constructor. Thus, it seems classes are no longer being loaded (which would imply that bundles are not being eagerly activated).

From a preliminary investigation, one behaviour that this patch _will_ change is the following:

1. Have two parts, A in front and B behind, in one stack.
2. Have the active part (C) in another stack.
3. Middle-click on the hidden part B from step 1.
4. Focus/Blue outline transfers from C to A. With the patch, the focus stays on C.

This seems rather trivial and insignificant by comparison in my opinion so I would support deferring to 3.6.
Comment 22 Eric Moffatt CLA 2009-05-04 14:54:44 EDT
+1 for leaving until 3.6...I have a number of defects that only occur when the editor area is split so this area could use a close look overall in 3.6...
Comment 23 Eric Moffatt CLA 2009-05-04 15:11:22 EDT
BTW, the transfer of the stack's focus is likely caused by the stack itself trapping the SWT.Activate event (to allow clicking inside a view to activate it) so this artifact may be difficult to fix cleanly...
Comment 24 Boris Bokowski CLA 2009-05-06 16:38:02 EDT
(In reply to comment #22)
> +1 for leaving until 3.6...I have a number of defects that only occur when the
> editor area is split so this area could use a close look overall in 3.6...

Also, I just checked and middle-clicking no longer activates before close, on Win32 and Linux GTK. Not sure how you can middle-click on a Mac :-/
Comment 25 Boris Bokowski CLA 2009-11-17 12:59:02 EST
Remy is now responsible for watching the [EditorMgmt] component area.
Comment 26 Remy Suen CLA 2009-11-24 11:30:49 EST
Andrew, do you still see this problem on 3.6? I cannot observe the described behaviour on  I20091118-1342 (unless it is switching/closing really fast).

(In reply to comment #0)
> Note that if I middle click but don't release right away, then I get a switch
> to that tab, but the tab doesn't close.

I don't see this. For me, if I hold it down a bit (or a lot) and then release, it is a no-op. My active editor does not change and the hovered-over editor is _not_ closed.
Comment 27 Andrew Niefer CLA 2009-11-26 13:42:38 EST
(In reply to comment #26)
> Andrew, do you still see this problem on 3.6? I cannot observe the described
> behaviour on  I20091118-1342 (unless it is switching/closing really fast).
> 
> (In reply to comment #0)
> > Note that if I middle click but don't release right away, then I get a switch
> > to that tab, but the tab doesn't close.
> 
> I don't see this. For me, if I hold it down a bit (or a lot) and then release,
> it is a no-op. My active editor does not change and the hovered-over editor is
> _not_ closed.

Sorry I missed this before Remy, with recent IBuilds I no longer see the switch before close.  As well, holding down the click is also a no-op.

The only thing I notice is that if I am closing a number of editors this way (middle clicking on tabs), if I go too quickly then sometimes nothing happens on the click.
Comment 28 Eric Moffatt CLA 2009-11-26 15:56:34 EST
Likely the event is getting swallowed as a double-click...
Comment 29 Eric Moffatt CLA 2010-06-21 11:17:07 EDT
Is this an issue in E4? For me clicking the close on a non-active part doesn't appear to activate it...
Comment 30 Markus Keller CLA 2012-11-15 10:35:10 EST
Works for me in I20121113-0800 and 3.8 on Windows 7.

Right-click still activates the part (bug 60833), but that's OK for me.