Bug 137091 - [KeyBindings] Toggle Mark Occurrences shortcut is broken
Summary: [KeyBindings] Toggle Mark Occurrences shortcut is broken
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: All All
: P2 major (vote)
Target Milestone: 3.2 RC5   Edit
Assignee: Paul Webster CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 139958
  Show dependency tree
 
Reported: 2006-04-17 17:21 EDT by Zorzella Mising name CLA
Modified: 2006-05-22 19:46 EDT (History)
9 users (show)

See Also:


Attachments
Workaround for the two Java editor actions (1.27 KB, patch)
2006-05-11 13:54 EDT, Dani Megert CLA
no flags Details | Diff
right direction workbench patch v01 (27.63 KB, patch)
2006-05-12 14:48 EDT, Paul Webster CLA
no flags Details | Diff
editor action bar patch v02 (10.55 KB, patch)
2006-05-15 14:53 EDT, Paul Webster CLA
no flags Details | Diff
editor action bar patch v03 (10.36 KB, patch)
2006-05-16 10:04 EDT, Paul Webster CLA
no flags Details | Diff
Alternate fix without API addition (9.62 KB, patch)
2006-05-16 15:47 EDT, John Arthorne CLA
no flags Details | Diff
editor action bar patch v05 - no API (10.21 KB, patch)
2006-05-17 08:04 EDT, Paul Webster CLA
no flags Details | Diff
Confilct for toggle mark occurrences (579.48 KB, text/plain)
2006-05-19 13:53 EDT, Paul Webster CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zorzella Mising name CLA 2006-04-17 17:21:09 EDT
As of some milestone after M3, SHIFT-ALT-O does not work at all.
Comment 1 Dani Megert CLA 2006-04-18 04:23:23 EDT
Works for me using plain Eclipse SDK 3.2 RC1.
Comment 2 Zorzella Mising name CLA 2006-04-19 14:03:21 EDT
I think something was hosed in my GNOME. I apologize. I restarted GNOME, and it works fine, now.
Comment 3 Zorzella Mising name CLA 2006-05-05 00:56:48 EDT
Just for correcness sake: this bug is a real issue -- but it's a duplicate of 135535.
Comment 4 Zorzella Mising name CLA 2006-05-09 16:03:54 EDT
Sorry for the back and forth. I upgraded to RC3, and the problem is still there (linux, gtk2). A typical reproducing scenario is:

1) start Eclipse against my project

2) Test ALT-SHIFT-O. It works.

3) F11 (and run the last test -- a simple unit test). 

4) ALT-SHIFT-O does not work anymore

No entries are generated in the logm by the way.

Thanks,

Z
Comment 5 Dani Megert CLA 2006-05-10 01:57:19 EDT

*** This bug has been marked as a duplicate of 135535 ***
Comment 6 Zorzella Mising name CLA 2006-05-11 12:30:05 EDT
That bug 135535 is marked as closed, and the reporter verified the problem is fixed, but I still have *this* problem with RC3 (and I can't reopen that bug).
Comment 7 Dani Megert CLA 2006-05-11 13:50:32 EDT
Test Case:

1. open A.java
   ==> Alt+Shift+O works
2. open B.java
   ==> Alt+Shift+O does not work

==> it only works in the very first editor.
Same problem with the 'Show Selected Element Only' command if a key binding is assigned to it.

Since day one we register our global action BasicTextEditorActionContributor.IActionBars, IWorkbenchPage) follows:
bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, fTogglePresentation);
		bars.setGlobalActionHandler(IJavaEditorActionDefinitionIds.TOGGLE_MARK_OCCURRENCES, fToggleMarkOccurrencesAction);

We didn't change that code. It looks like a regression in the key binding / command story in Platform UI which got introduced after 3.2 M4.

Marking as 'major' since this affects all clients that register their action in that way. Note that the action handler itself is still present under its registered ID but the key binding got lost.
Comment 8 Dani Megert CLA 2006-05-11 13:54:57 EDT
Created attachment 41170 [details]
Workaround for the two Java editor actions

The attached patch works around the bug by hammering the identical global action handler into the action bar every time the a new editor is set. This does no harm and fixes the problem for the two JDT Text actions. The bug should still be investigated for 3.2 since other clients might be affected.

Martin, Mike please cast your vote.
Comment 9 Mike Wilson CLA 2006-05-11 14:01:33 EDT
I'd rather we actually fixed the real problem, than apply the patch, but the
workaround in the patch seems pretty innocuous. I'll investigate the real
problem, but +1 to applying the workaround in the mean time.
Comment 10 Martin Aeschlimann CLA 2006-05-11 14:03:07 EDT
+1 to release the workaround in the mean time.  
Comment 11 Paul Webster CLA 2006-05-11 14:53:04 EDT
It looks like the back end handler of the legacy action is including a "too specific" expression ... i.e. it's tied the to the part, when it should be tied to that partId.

We're investigating a fix for it, but it will not be included in RC4.

PW
Comment 12 Mike Wilson CLA 2006-05-11 15:51:21 EDT
Agree that this is P2, and I'd really like to see it fixed for R3.2.
Comment 13 Dani Megert CLA 2006-05-12 03:04:34 EDT
Verified in I20060512-0010 that the workaround brings back the two broken key bindings for 'Toggle Mark Occurrences' and 'Show Selected Element Only'.
Comment 14 Alex Bernstein CLA 2006-05-12 09:37:39 EDT
I am not sure I understand the workaround. can somebody please explain the difference?
Comment 15 Dani Megert CLA 2006-05-12 09:50:47 EDT
Sure, but let me first correct the scrambled part of comment 7:
>Since day one we register our global action
>BasicTextEditorActionContributor.IActionBars, IWorkbenchPage) follows:

should read: 
  Since day one we register our global action
  BasicJavaEditorActionContributor.init(IActionBars, IWorkbenchPage) follows:


The problem seems that the command framework looses (or explicitly clears?) the key binding for the action that got registered in init(...) even though the action is still there i.e. when calling
  actionBars.getGlobalActionHandler(myActionId)
you get back your action but the key binding is not hooked. Setting the global action handler again when setActiveEditor(IEditorPart) is called hammers back the key binding.
Comment 16 Paul Webster CLA 2006-05-12 14:48:25 EDT
Created attachment 41357 [details]
right direction workbench patch v01

This patch is for looking, not for touching!

The problem was the editor action bars were being tied to the service locator for the first editor part.  Any actions that were registered were being evaluated if that first editor part was active.

The right direction is to step back a level, tie the editor action bars to workbench window level service locator, and add an EditorActionBarExpression that evalutes to true when any editor of that type is active.

This has highlighted some strange behaviour in the SlaveHandlerService that needs careful examination.

PW
Comment 17 Paul Webster CLA 2006-05-15 14:53:54 EDT
Created attachment 41492 [details]
editor action bar patch v02

This fixes the problem with Toggle Mark Occurences.  It ensures that EditorActionBar actions (that are turned into handlers) are activated with the correct expression (Part ID active and Workbench Window active).

It adds a protected API method to org.eclipse.ui.SubActionBars to expose the expression used to active handlers.  I don't believe this will cause a downstream problem, as all of the code dealing with services and service locators and expressions is new in 3.2.

This fix is restricted to the org.eclipse.ui.workbench plugin.

PW
Comment 18 Paul Webster CLA 2006-05-15 14:58:37 EDT
John, Boris, could I please get you to review "editor action bar patch v02"

Thanx,
PW
Comment 19 Mike Wilson CLA 2006-05-15 18:16:15 EDT
I discussed this with Paul, and have checked out the patch. It seems to be doing something reasonable, but I'm still somewhat distressed about the API addition. John and Boris will both have to say that it's an acceptable risk, and we need to do full disclosure on the mailing list.
Comment 20 Boris Bokowski CLA 2006-05-15 22:15:12 EDT
I don't fully understand the patch yet, but I found a debugging statement (call to System.out.println) in LegacyEditorActionBarExpression.evaluate() that needs to be removed.

Paul, can we go through the patch together tomorrow?
Comment 21 Mike Wilson CLA 2006-05-16 07:28:45 EDT
Guys: It's _too_late_ to be putting out patches with bogus print statements in them.
Comment 22 Paul Webster CLA 2006-05-16 10:04:20 EDT
Created attachment 41588 [details]
editor action bar patch v03

(with print removed :-)

Dani, could I also get you to review this patch, it's on org.eclipse.ui.workbench.

PW
Comment 23 Paul Webster CLA 2006-05-16 11:08:34 EDT
This patch provided a negligible improvement in the editor performance tests.

PW
Comment 24 Mike Wilson CLA 2006-05-16 11:14:28 EDT
I took another quick look at the patch, but don't have time to go through it thoroughly. I do want this fixed though, so I will +1 for the pmc if you can get 3 other component leads to review.
Comment 25 Dani Megert CLA 2006-05-16 12:17:17 EDT
I will look at the patch tomorrow first thing in the morning. How good is the test coverage for the area that gets changed by this patch?
Comment 26 John Arthorne CLA 2006-05-16 15:27:26 EDT
Paul, I would like to go over the patch with you, but could you fix a few things first to minimize the size of the patch to review noise for reviewers:

 - Remove the change to PartSite.  This appears to be just extra info in the toString for debugging purposes.  If you think this is important, please explain.
 - Remove the change in in SubActionBars.EXPRESSION - this appears to just be a resorting of the methods, but it adds noise to the patch

Also, I noticed in the two fields you added, you adopted the convention of adding the "f" prefix (fEditorHandlerExpression and fActiveEditorId). This should be made consistent with UI conventions (ditch the "f").
Comment 27 John Arthorne CLA 2006-05-16 15:47:25 EDT
Created attachment 41637 [details]
Alternate fix without API addition

Just throwing this out as an idea, but here is a slight twist on Paul's latest patch that avoids the API addition.  I think we should avoid adding API at this stage unless we believe it is absolutely essential, and I'm not sure it is in this case.  This change removes the added API method SubActionBars.getHandlerExpression and downcasts to obtain the correct handler for the EditorActionBars case.  Not elegant, but the API could be added in the next release and this downcast removed.
Comment 28 Mike Wilson CLA 2006-05-16 16:58:24 EDT
We have done hacks like the one John describes in other places. That would be a reasonable way to proceed as long as we have a TODO to fix the code once we ship.
Comment 29 Paul Webster CLA 2006-05-16 22:02:36 EDT
(In reply to comment #26)
>  - Remove the change to PartSite.  This appears to be just extra info in the
> toString for debugging purposes.  If you think this is important, please
> explain.

This one is important debugging information for tracing.  It's necessary for tracking down bugs like this one and bug 135535 (I actually meant to release it with 135535 but it slipped through the cracks).

PW
Comment 30 Dani Megert CLA 2006-05-17 05:23:45 EDT
Reviewed John's version of the patch since we shouldn't add new API at this point if not absolutely needed.

The patch makes sense and I verified that it fixes the problem but like John, I'd also like to go over it together with Paul. Paul, John, can we do this directly after today's arch call (reuse the phone line)?

Comments to the code itself:
- serviceLocator is now only set in Editor/SubActionBars and
  setServiceLocator(IServiceLocator) is now never called by Eclipse SDK code
- I would add "editorHandlerExpression= null;" to EditorActionBars.dispose()
- LegacyEditorActionBarExpression constructor:
    I'd throw an IAE and not an NPE if the argument is null (
- LegacyEditorActionBarExpression.equals(...) could directly compare the
  two activeEditorId which are guaranteed to be non-null instead of 
  calling Expression.equals(...) which performs unneeded null-checks.
Comment 31 Paul Webster CLA 2006-05-17 08:04:09 EDT
Created attachment 41713 [details]
editor action bar patch v05 - no API

Updated the non-API patch with Dani's comments:
- I would add "editorHandlerExpression= null;" to EditorActionBars.dispose()
- LegacyEditorActionBarExpression constructor:
    I'd throw an IAE and not an NPE if the argument is null (
- LegacyEditorActionBarExpression.equals(...) could directly compare the
  two activeEditorId which are guaranteed to be non-null instead of 
  calling Expression.equals(...) which performs unneeded null-checks.
Plus added the hashCode debugging back.

PW
Comment 32 Paul Webster CLA 2006-05-17 08:06:02 EDT
Mike Valenta, could I please get you to review this patch?

Thanx,
PW
Comment 33 Michael Valenta CLA 2006-05-17 09:28:57 EDT
+1
Comment 34 Boris Bokowski CLA 2006-05-17 10:58:36 EDT
The patch ("editor action bar patch v05 - no API") looks good. I have reviewed it together with Paul.
Comment 35 Dani Megert CLA 2006-05-17 11:57:06 EDT
Talked to Paul about latest patchv05. Approving for 3.2 RC3.
Comment 36 John Arthorne CLA 2006-05-17 12:02:36 EDT
I have also reviewed patch v05 with Paul and Boris.  +1 for RC5.
Comment 37 Mike Wilson CLA 2006-05-17 12:32:33 EDT
+1
Comment 38 Paul Webster CLA 2006-05-18 13:33:21 EDT
Released into HEAD >20060518

PW
Comment 39 Paul Webster CLA 2006-05-19 13:52:26 EDT
After use in RC5, eventually the toggle mark occurrences stopped working with a:

HANDLERS >>> Unresolved conflict detected for 'org.eclipse.ui.edit.text.toggleShowSelectedElementOnly'
HANDLERS >>>     resolveConflicts: eval: HandlerActivation(commandId=org.eclipse.jdt.ui.edit.text.java.toggleMarkOccurrences,handler=ActionHandler(org.eclipse.jdt.internal.ui.javaeditor.ToggleMarkOccurrencesAction@1beb199),expression=AndExpression(LegacyEditorActionBarExpression(org.eclipse.jdt.ui.CompilationUnitEditor),WorkbenchWindowExpression(org.eclipse.ui.internal.WorkbenchWindow@19fe451)),sourcePriority=278529)
HANDLERS >>>     resolveConflicts: eval: HandlerActivation(commandId=org.eclipse.jdt.ui.edit.text.java.toggleMarkOccurrences,handler=ActionHandler(org.eclipse.jdt.internal.ui.javaeditor.ToggleMarkOccurrencesAction@8ee5c0),expression=AndExpression(LegacyEditorActionBarExpression(org.eclipse.jdt.ui.CompilationUnitEditor),WorkbenchWindowExpression(org.eclipse.ui.internal.WorkbenchWindow@19fe451)),sourcePriority=278529)
HANDLERS >>> Unresolved conflict detected for 'org.eclipse.jdt.ui.edit.text.java.toggleMarkOccurrences'

PW
Comment 40 Paul Webster CLA 2006-05-19 13:53:15 EDT
Created attachment 42049 [details]
Confilct for toggle mark occurrences

log containing conflict
PW
Comment 41 Paul Webster CLA 2006-05-22 14:09:50 EDT
This happens when you have a couple of java editors open, do a CTRL+SHIFT+W, and then open some more java editors.  The dispose() of the EditorActionBars is calling setActiveEditor(null), but it's interacting badly with the workaround in BasicJavaEditorActionContributor#setActiveEditor(*).  Opening a new java editor creates a new EditorActionBars, which also adds its own activation and causes the conflict.

All of the other calls to setGlobalActionHandler(*) go through getAction(*) which returns null if the active editor is null.

If we remove the workaround in BasicJavaEditorActionContributor
// XXX: Workaround for Platform UI bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=137091
then this should fix it.

PW
Comment 42 Dani Megert CLA 2006-05-22 15:13:51 EDT
Can you explain why it's not working with the workaround in place? AFAIK there's no need to explicitly clear a global action handler and setGlobalActionHandler will be called when switching to the next Java editor.

It sounds like removing the workaround is again a workaround ;-)
Comment 43 Paul Webster CLA 2006-05-22 16:01:26 EDT
So the problem is that in the dispose it's calling setGlobalActionHandler() ... after the call to super.dispose().  The super.dispose() is what cleans up all of the action handlers that EditorActionBars knows about.

It's a leak.  It's is correct to remove it.

PW
Comment 44 Dani Megert CLA 2006-05-22 17:22:52 EDT
OK, I see. The problem is different from the one reported in this bug: after closing the last Java editor and then reopening a new one breaks the key binding. This is caused by the workaround (bug 137091).

I suggest to close this bug again and fix bug 137091 for RC6.
Comment 45 Dani Megert CLA 2006-05-22 17:25:04 EDT
Re comment 44: I mentioned the wrong bug. The bug which mentions the workaround is bug 142266.
Comment 46 Dani Megert CLA 2006-05-22 17:33:17 EDT
Just for the records: the workaround worked in 3.2 RC4 when this bug was in place.
Comment 47 Paul Webster CLA 2006-05-22 19:46:23 EDT
I've resolved this and am monitoring the change of bug 142266

Re-open this bug as needed :-)

PW