Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 406640 - Focus goes back to previous view after double click on file
Summary: Focus goes back to previous view after double click on file
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.3   Edit
Hardware: PC Windows 7
: P3 major (vote)
Target Milestone: 4.3 RC1   Edit
Assignee: Eric Moffatt CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-26 06:37 EDT by Markus Keller CLA
Modified: 2013-05-24 13:54 EDT (History)
3 users (show)

See Also:
pwebster: review+


Attachments
stacktraces (13.06 KB, text/plain)
2013-04-26 06:37 EDT, Markus Keller CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2013-04-26 06:37:12 EDT
Created attachment 230166 [details]
stacktraces

4.3.0.N20130424-2000

I don't have steps to reproduce this in a fresh workspace, but it happens consistently in my dev workspace with these steps:
- open two text files from the Package Explorer or Navigator view
- make sure an editor is active
- double-click the other file
=> expected: other file's editor is brought to top and active
=> was: other file's editor is brought to top, but then the view is activated again

Bug 312568 and bug 394462 sound related, but they're both on GTK, and at least the latter is a bug in SWT.

In this bug, E4's StackRenderer$ActivationJob is wrongly setting the focus here:

java.lang.Exception
        at org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart.setFocus(PackageExplorerPart.java:779)
        at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.delegateSetFocus(CompatibilityPart.java:190)
        at sun.reflect.GeneratedMethodAccessor22.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
        at java.lang.reflect.Method.invoke(Method.java:613)
        at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
        at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:231)
        at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:237)
        at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:208)
        at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:107)
        at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.focusGui(PartRenderingEngine.java:759)
        at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.activate(PartServiceImpl.java:585)
        at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.activate(PartServiceImpl.java:548)
        at org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer.activate(AbstractPartRenderer.java:104)
        at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer$ActivationJob.run(StackRenderer.java:221)
        at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
        at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
        at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4145)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3762)
...
Comment 1 Paul Webster CLA 2013-04-26 07:07:18 EDT
I can reproduce this on linux in 4.3.0.I20130423-0800

PW
Comment 2 Markus Keller CLA 2013-04-26 07:32:25 EDT
> I can reproduce this on linux in 4.3.0.I20130423-0800
> 
> PW

On Linux, you probably run into bug 312568, which has similar effects, but is not exactly the same as this bug.
Comment 3 Eric Moffatt CLA 2013-05-07 15:04:11 EDT
Markus, I'm looking into what might be different between old and new workspaces...do you by chance have the 'single click' mode on in your dev ws ?

I've just turned this on locally and now I see what you report...the first click opens the editor and the second one is putting the focus back onto the PE...
Comment 4 Markus Keller CLA 2013-05-07 15:41:19 EDT
No, I exclusively work with double click mode, and my workspace still has this setting. Dani is the single-click guy :-)

According to bug 45186 comment 33, single click mode should not activate the editor on the first click, but should also activate the editor on the second click.


I attached a debugger again to ensure that I'm not tricked by a bouncy mouse button and that I really only press the mouse twice. For that, I installed a breakpoint in org.eclipse.swt.widgets.Widget#sendEvent(Event) line 1056 with condition:

if (event.type == SWT.MouseDown) {
	System.out.println("down: " + new java.util.Date());
}
return false;

And here's the clue: With this breakpoint, I can also reproduce it in a runtime workbench! Looks like the delay from the condition evaluation is enough to trigger the bug in an otherwise unladen workbench.
Comment 5 Eric Moffatt CLA 2013-05-08 10:06:31 EDT
Thanks for the info Markus, I'll give this a whirl...
Comment 6 Eric Moffatt CLA 2013-05-08 10:31:46 EDT
Yep, I can repro now. It's interesting that if you make the PE the active view *before* issuing the double click that the bug doesn't manifest. I think you're correct that the activationJob seems to miss the second activation (first it sees the PE going active but then it should also see the editor going active after that...
Comment 7 Eric Moffatt CLA 2013-05-08 13:41:17 EDT
The current 'asynch' code was introduced to prevent recursion when clicking on a tab that is *not* the currently selected tab in the stack (see bug 307199 for details).

I've pushed a potential fix for this that removes the asynch code altogether:

https://git.eclipse.org/r/12643

The new approach determines whether or not the tab is going to eventually switch and, if so, skip the SWT.Activate handling and allow it to be handled by the subsequent tab change...
Comment 9 Eric Moffatt CLA 2013-05-09 15:09:23 EDT
Paul, should I mark this one FIXED since you've pushed the changes ?
Comment 10 Paul Webster CLA 2013-05-09 18:12:49 EDT
Sure.  We should verify it in tonight's I build as soon as possible.

PW
Comment 11 Paul Webster CLA 2013-05-10 07:32:47 EDT
Paul, could you please test this with last night's build as well?

PW
Comment 12 Markus Keller CLA 2013-05-13 09:38:20 EDT
Verified on Windows 7
- in I20130512-2000 with my dev workspace
- in master with the slowdown breakpoint from comment 4

The code is also much nicer without the asyncExec.
Comment 13 Eric Moffatt CLA 2013-05-24 13:54:29 EDT
As per Markus' comments, thanks !