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

Bug 142812

Summary: [KeyBindings] Keybindings incorrectly disabled and not re-enabled (keybindings lost)
Product: [Eclipse Project] Platform Reporter: Mark Melvin <mark.melvin>
Component: UIAssignee: Paul Webster <pwebster>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: abuehler, daniel_megert
Version: 3.2   
Target Milestone: 3.3   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Patch for ActionDelegateHandlerProxy none

Description Mark Melvin CLA 2006-05-19 14:02:14 EDT
This was found in Eclipse 3.2 RC4.


I'm unsure if this bug is going to be a different manifestation of Bug #135535 or not, but I will describe what is happening and let the experts decide.

I have some build actions that I have bound to keys.  Let's just talk about one of them because they are essentially all the same.  I have a build/clean action for my particular project builder that is bound to M1+M2+C (Ctrl+Shift+C on Windows XP).  I am not using handlers right now.  I have an action which provides a class that implements IWorkbenchWindowActionDelegate, and it is tied to a command/keybinding pair through its "definitionId".
I have set up a fairly simple expression to enable the action based on the nature of the project it is on, and whether or not the project is open, and lastly, since I want the action enabled while in an editor (I handle the logic in my IWorkbenchWindowActionDelegate), it also has to deal with TextSelections.  So, my enablement expression is as follows:

<enablement>
  <or>
    <and>
      <objectClass name="org.eclipse.core.resources.IResource"/>
      <objectState 
        name="projectNature" 
        value="com.amis.skt.ui.SKProjectNature"/>
      <or>
        <and>
          <objectClass name="org.eclipse.core.resources.IProject"/>
          <objectState
            name="open"
            value="true"/>
        </and>
        <not>
          <objectClass name="org.eclipse.core.resources.IProject"/>
        </not>
      </or>
    </and>
    <not>
      <objectClass name="org.eclipse.core.resources.IResource"/>
    </not>
  </or>
</enablement>

While this looks a little convoluted, it works quite well, and my action enablement always appears to be correct, and is not the source of this bug.  I think there is a bug in the platform that disables the key bindings inappropriately.

OK, so running a runtime workbench, everything works fine and just as it should. 

If I execute my action on a project with the com.amis.skt.ui.SKProjectNature nature (Project A) the key binding works and the actions are enabled.  GOOD

If I execute my action on a project without that nature (Project B) the key binding does not work, and the actions are diabled.  GOOD

If I execute my action on a closed project (with or without the nature) the key binding does not work, and the actions are diabled.  GOOD

If I open an editor in Project A the actions are enabled, and the keybindings work.  GOOD

If I open an editor in Project B (without the nature), the actions are disabled in my menu, but wait!  The keybinding works, and actually executes the action on the last-selected project.  Huh?  OK, I hit the keybinding again, and it doesn't work anymore.  It is disabled.  BAD

OK, weird.  Now clicking around between projects and editors I can see my enablement of actions in the menu follows along nicely and everything is good, but my keybinding is completely hosed.  I can't get it to execute anymore not matter what I do.

I posted to the newsgroups and Paul Webster helped me out a bit.  I enabled tracing on the options he recommended and did some tests.  Here are the tracing options I enabled:

org.eclipse.ui/debug=true
org.eclipse.ui/trace/keyBindings=true
org.eclipse.ui/trace/keyBindings.verbose=true
org.eclipse.ui/trace/sources=true
org.eclipse.ui/trace/handlers=true
org.eclipse.ui/trace/handlers.verbose=true
org.eclipse.ui/trace/handlers.verbose.commandId=com.amis.skt.build.ui.buildCleanCommand
org.eclipse.ui/trace/contexts=true
org.eclipse.ui/trace/contexts.verbose=true


And here is the trace, with my comments on what I did at certain points in the trace encoded as ## MY COMMENTS:

## START OF TRACE
##
## THE INITIAL STATE OF MY WORKBENCH WAS TWO EDITORS OPEN.  THE FIRST EDITOR
## (SK3SourceEditor) HAS THE APPROPRIATE NATURE ASSOCIATED WITH ITS PARENT
## PROJECT, THUS THE ACTIONS ARE ENABLED AND THE KEYBINDINGS SHOULD WORK.
## THE SECOND EDITOR (SK2xSourceEditor) DOES NOT HAVE A NATURE ASSOCIATED WITH
## THE PARENT PROJECT SO THE ACTIONS ARE DISABLED AND THE KEYBINDINGS SHOULD
## *NOT* WORK.
##
## WHEN THE WORKBENCH FIRST STARTS UP, BOTH EDITORS ARE OPEN AND THE
## SK3SourceEditor IS SELECTED.
##

Configuration location:
    file:/C:/eclipse/eclipseSDK3.2RC4/config/
Configuration file:
    file:/C:/eclipse/eclipseSDK3.2RC4/config/config.ini loaded
Install location:
    file:/C:/eclipse/eclipseSDK3.2RC4/feature_workspace/
Configuration file:
    file:/C:/eclipse/eclipseSDK3.2RC4/feature_workspace/configuration/config.ini loaded
Shared configuration location:
    file:/C:/eclipse/eclipseSDK3.2RC4/feature_workspace/configuration/
Framework located:
    file:/C:/eclipse/eclipseSDK3.2RC4/feature_workspace/plugins/org.eclipse.osgi/
Framework classpath:
    file:/C:/eclipse/eclipseSDK3.2RC4/feature_workspace/plugins/org.eclipse.osgi/bin/
    file:/C:/eclipse/eclipseSDK3.2RC4/feature_workspace/plugins/org.eclipse.osgi/
Splash location:
    C:\eclipse\eclipseSDK3.2RC4\feature_workspace\plugins\com.amis.platform\splash.bmp
runCommand:
    <C:\eclipse\eclipseSDK3.2RC4\eclipse\eclipse><-name><Eclipse><-showsplash><600><C:\eclipse\eclipseSDK3.2RC4\feature_workspace\plugins\com.amis.platform\splash.bmp>
Debug options:
    file:/C:/eclipse/eclipseSDK3.2RC4/config/.options loaded
Time to load bundles: 47
Starting application: 3422
HANDLERS >>> Command('com.amis.skt.build.ui.buildCleanCommand') has changed to 'com.amis.skt.build.ui.actions.BuildCleanActionHandler' as its handler
HANDLERS >>> Unresolved conflict detected for 'org.eclipse.ui.examples.command1'
BINDINGS >>> Clearing cache
HANDLERS >>>     resolveConflicts: eval: HandlerActivation(commandId=com.amis.skt.build.ui.buildCleanCommand,handler=com.amis.skt.build.ui.actions.BuildCleanActionHandler,expression=null,sourcePriority=0)
HANDLERS >>> Resolved conflict detected.  The following activation won: 
HANDLERS >>>     HandlerActivation(commandId=com.amis.skt.build.ui.buildCleanCommand,handler=com.amis.skt.build.ui.actions.BuildCleanActionHandler,expression=null,sourcePriority=0)
CONTEXTS >>> register shell 'Shell {SignaKlara Development Platform}' as window
BINDINGS >>> Cache miss
BINDINGS >>> There are 1 deletion markers
SOURCES >>> 	ASSP:lastActiveShell: null
SOURCES >>> 	ASSP:lastActiveWorkbenchWindowShellnull
SOURCES >>> Active shell changed to Shell {SignaKlara Development - a.cfs - SignaKlara Development Platform}
SOURCES >>> Active workbench window changed to org.eclipse.ui.internal.WorkbenchWindow@b125bd
SOURCES >>> Active workbench window shell changed to Shell {SignaKlara Development - a.cfs - SignaKlara Development Platform}
CONTEXTS >>> [org.eclipse.ui.contexts.dialogAndWindow]
SOURCES >>> Action sets changed to [Team, Configuration Manager, SignaKlara Utilities, Annotation Navigation, Launch, SignaKlara Coding, Resource Navigation, SignaKlara Build Settings Action Set, Editor Navigation, Cheat Sheets, External Tools, Open Files, Convert Line Delimiters, Debug Utilities Action Set, Working Sets, Software Updates, Keyboard Shortcuts, Breakpoints, Search]
HANDLERS >>>     resolveConflicts: eval: HandlerActivation(commandId=com.amis.skt.build.ui.buildCleanCommand,handler=com.amis.skt.build.ui.actions.BuildCleanActionHandler,expression=null,sourcePriority=0)
HANDLERS >>>     resolveConflicts: eval: HandlerActivation(commandId=com.amis.skt.build.ui.buildCleanCommand,handler=ActionDelegateHandlerProxy(null,com.amis.skt.build.ui.actions.BuildCleanAction),expression=AndExpression(ActionSetExpression(com.amis.skt.build.ui.buildSettingsActionSet,org.eclipse.ui.internal.WorkbenchWindow@b125bd),WorkbenchWindowExpression(org.eclipse.ui.internal.WorkbenchWindow@b125bd)),sourcePriority=16640)
HANDLERS >>> Resolved conflict detected.  The following activation won: 
HANDLERS >>>     HandlerActivation(commandId=com.amis.skt.build.ui.buildCleanCommand,handler=ActionDelegateHandlerProxy(null,com.amis.skt.build.ui.actions.BuildCleanAction),expression=AndExpression(ActionSetExpression(com.amis.skt.build.ui.buildSettingsActionSet,org.eclipse.ui.internal.WorkbenchWindow@b125bd),WorkbenchWindowExpression(org.eclipse.ui.internal.WorkbenchWindow@b125bd)),sourcePriority=16640)
HANDLERS >>> Command('com.amis.skt.build.ui.buildCleanCommand') has changed to 'ActionDelegateHandlerProxy(null,com.amis.skt.build.ui.actions.BuildCleanAction)' as its handler
BINDINGS >>> Cache miss
BINDINGS >>> There are 1 deletion markers
SOURCES >>> Contexts changed to [org.eclipse.ui.contexts.dialogAndWindow]
CONTEXTS >>> [org.eclipse.ui.contexts.dialogAndWindow, org.eclipse.ui.contexts.window]
BINDINGS >>> Cache miss
BINDINGS >>> There are 1 deletion markers
SOURCES >>> Contexts changed to [org.eclipse.ui.contexts.dialogAndWindow, org.eclipse.ui.contexts.window]
SOURCES >>> Active part changed to com.amis.sk3.ui.editor.SK3SourceEditor@4cc81c
SOURCES >>> Active part id changed to com.amis.sk3.ui.editor.SK3SourceEditor
SOURCES >>> Active site changed to PartSite(id=com.amis.sk3.ui.editor.SK3SourceEditor,pluginId=com.amis.sk3.ui,registeredName=SignaKlara 3 Source Code Editor)
SOURCES >>> Active editor changed to com.amis.sk3.ui.editor.SK3SourceEditor@4cc81c
SOURCES >>> Active editor id changed to com.amis.sk3.ui.editor.SK3SourceEditor
CONTEXTS >>> [org.eclipse.ui.contexts.dialogAndWindow, com.amis.skt.ui.defaultEditorScope, org.eclipse.ui.contexts.window]
BINDINGS >>> Cache miss
BINDINGS >>> There are 1 deletion markers
SOURCES >>> Contexts changed to [org.eclipse.ui.contexts.dialogAndWindow, com.amis.skt.ui.defaultEditorScope, org.eclipse.ui.contexts.window]
SOURCES >>> Selection changed to org.eclipse.jface.text.TextSelection@1e7a4d0
SOURCES >>> ASSP: passOnEvent: StyledText {}
SOURCES >>> ASSP: passOnEvent: Canvas {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> Selection changed to org.eclipse.jface.text.TextSelection@1e7a4d0
Application Started: 10391

## HERE THE WORKBENCH IS UP, AND I AM IN THE FIRST EDITOR.  I PRESS CTRL+SHIFT+C
## AND THE CLEAN-AND-REBUILD ACTION OCCURS AS EXPECTED.

KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x0, keyCode = 0x40000, time = 14452437, character = 0x0)
KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x40000, keyCode = 0x20000, time = 14452531, character = 0x0)
KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x60000, keyCode = 0x63, time = 14452812, character = 0x3)
KEYS >>> WorkbenchKeyboard.press(potentialKeyStrokes = [CTRL+SHIFT+C])
KEYS >>> WorkbenchKeyboard.executeCommand(commandId = 'com.amis.skt.build.ui.buildCleanCommand', parameters = {})
[Enablement Expression] - evaluation time: 0 ms.
[Enablement Expression] - evaluation time: 0 ms.

## I TRY IT AGAIN FOR GOO MEASURE AND IT WORKS AS EXPECTED.

KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x0, keyCode = 0x40000, time = 14460390, character = 0x0)
KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x40000, keyCode = 0x20000, time = 14460468, character = 0x0)
KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x60000, keyCode = 0x63, time = 14460703, character = 0x3)
KEYS >>> WorkbenchKeyboard.press(potentialKeyStrokes = [CTRL+SHIFT+C])
KEYS >>> WorkbenchKeyboard.executeCommand(commandId = 'com.amis.skt.build.ui.buildCleanCommand', parameters = {})
[Enablement Expression] - evaluation time: 0 ms.
[Enablement Expression] - evaluation time: 0 ms.

## HERE I AM SWITCHING EDITORS TO THE *OTHER* EDITOR WHERE I EXPECT THE
## KEYBINDINGS SHOULD *NOT* WORK

SOURCES >>> ASSP: passOnEvent: CTabFolder {}
SOURCES >>> ASSP: passOnEvent: ToolBar {}
SOURCES >>> ASSP: passOnEvent: CoolBar {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: CBanner {}
SOURCES >>> ASSP: passOnEvent: StyledText {}
SOURCES >>> ASSP: passOnEvent: Canvas {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> Active editor changed to com.amis.sk2x.ui.editor.SK2xSourceEditor@246607
SOURCES >>> Active editor id changed to com.amis.sk2x.ui.editor.SK2xSourceEditor
SOURCES >>> ASSP: passOnEvent: StyledText {}
SOURCES >>> ASSP: passOnEvent: Canvas {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> Active part changed to com.amis.sk2x.ui.editor.SK2xSourceEditor@246607
SOURCES >>> Active part id changed to com.amis.sk2x.ui.editor.SK2xSourceEditor
SOURCES >>> Active site changed to PartSite(id=com.amis.sk2x.ui.editor.SK2xSourceEditor,pluginId=com.amis.sk2x.ui,registeredName=SignaKlara 2.x Source Editor)
SOURCES >>> Selection changed to org.eclipse.jface.text.TextSelection@4c442b

## I AM NOW IN THE OTHER EDITOR.  IF I WERE TO LOOK AT MY ACTIONS IN THE
## PROJECT MENU, THEY WOULD BE DISABLED AS EXPECTED.  I NOW PRESS CTRL+SHIFT+C
## AGAIN AND EXPECT IT TO DO NOTHING....BUT IT WORKS!  WHAT!?

KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x0, keyCode = 0x40000, time = 14469015, character = 0x0)
KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x40000, keyCode = 0x20000, time = 14469078, character = 0x0)
KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x60000, keyCode = 0x63, time = 14469359, character = 0x3)
KEYS >>> WorkbenchKeyboard.press(potentialKeyStrokes = [CTRL+SHIFT+C])
KEYS >>> WorkbenchKeyboard.executeCommand(commandId = 'com.amis.skt.build.ui.buildCleanCommand', parameters = {})
[Enablement Expression] - evaluation time: 0 ms.
[Enablement Expression] - evaluation time: 0 ms.

## OK, WHY DID THAT WORK?  I PRESS CTRL+SHIFT+C AGAIN, AND LO AND BEHOLD, NOW IT
## DOES NOT WORK.  FINE - LET'S SWITCH BACK TO THE ORIGINAL EDITOR AND SEE IF
## IT STILL WORKS OVER THERE

KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x0, keyCode = 0x40000, time = 14474000, character = 0x0)
KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x40000, keyCode = 0x20000, time = 14474046, character = 0x0)
KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x60000, keyCode = 0x63, time = 14474296, character = 0x3)
KEYS >>> WorkbenchKeyboard.press(potentialKeyStrokes = [CTRL+SHIFT+C])
KEYS >>> WorkbenchKeyboard.executeCommand(commandId = 'com.amis.skt.build.ui.buildCleanCommand', parameters = {})
KEYS >>>     not enabled

## I AM SWITCHING EDITORS AGAIN

SOURCES >>> ASSP: passOnEvent: CTabFolder {}
SOURCES >>> Active editor changed to com.amis.sk3.ui.editor.SK3SourceEditor@4cc81c
SOURCES >>> Active editor id changed to com.amis.sk3.ui.editor.SK3SourceEditor
SOURCES >>> ASSP: passOnEvent: StyledText {}
SOURCES >>> ASSP: passOnEvent: Canvas {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> Active part changed to com.amis.sk3.ui.editor.SK3SourceEditor@4cc81c
SOURCES >>> Active part id changed to com.amis.sk3.ui.editor.SK3SourceEditor
SOURCES >>> Active site changed to PartSite(id=com.amis.sk3.ui.editor.SK3SourceEditor,pluginId=com.amis.sk3.ui,registeredName=SignaKlara 3 Source Code Editor)
SOURCES >>> Selection changed to org.eclipse.jface.text.TextSelection@a3e7a4d0

## I PRESS CTRL+SHIFT+C AND NOW IT DOESN'T WORK IN THE ORIGINAL EDITOR. GRRR.
## MAYBE IT WILL WORK ON A PROJECT?

KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x0, keyCode = 0x40000, time = 14479500, character = 0x0)
KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x40000, keyCode = 0x20000, time = 14479531, character = 0x0)
KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x60000, keyCode = 0x63, time = 14479796, character = 0x3)
KEYS >>> WorkbenchKeyboard.press(potentialKeyStrokes = [CTRL+SHIFT+C])
KEYS >>> WorkbenchKeyboard.executeCommand(commandId = 'com.amis.skt.build.ui.buildCleanCommand', parameters = {})
KEYS >>>     not enabled

## I AM NOW SWITCHING TO A PROJECT IN THE NAVIGATOR VIEW

SOURCES >>> ASSP: passOnEvent: Tree {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> ASSP: passOnEvent: Composite {}
SOURCES >>> Active part changed to org.eclipse.ui.views.navigator.ResourceNavigator@7f65f2
SOURCES >>> Active part id changed to org.eclipse.ui.views.ResourceNavigator
SOURCES >>> Active site changed to PartSite(id=org.eclipse.ui.views.ResourceNavigator,pluginId=org.eclipse.ui.ide,registeredName=Navigator)
CONTEXTS >>> [org.eclipse.ui.contexts.dialogAndWindow, org.eclipse.ui.contexts.window]
BINDINGS >>> Cache hit
SOURCES >>> Contexts changed to [org.eclipse.ui.contexts.dialogAndWindow, org.eclipse.ui.contexts.window]
SOURCES >>> Selection changed to [L/TestSK3/a.cfs]
SOURCES >>> Selection changed to [P/TestSK3]

## NOPE.  STILL DOESN'T WORK.  MY KEYBINDINGS ARE HOSED!

KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x0, keyCode = 0x40000, time = 14482359, character = 0x0)
KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x40000, keyCode = 0x20000, time = 14482453, character = 0x0)
KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x60000, keyCode = 0x63, time = 14482687, character = 0x3)
KEYS >>> WorkbenchKeyboard.press(potentialKeyStrokes = [CTRL+SHIFT+C])
KEYS >>> WorkbenchKeyboard.executeCommand(commandId = 'com.amis.skt.build.ui.buildCleanCommand', parameters = {})
KEYS >>>     not enabled
SOURCES >>> Selection changed to null

## END OF TRACE ##

Please take note of the fact that all this time the enablement of my actions is still working fine, and I can in fact execute all of my actions from the Project menu when I have a project selected, or an editor is selected.  If the project nature is missing, my actions are appropriately disabled and I cannot execute them.

Anything else I should be trying?
Comment 1 Paul Webster CLA 2006-05-19 14:22:56 EDT
Thanx for the tracing.

I'm interested in every mention of com.amis.skt.build.ui.buildCleanCommand (and the few lines surrounding it) between:
## HERE I AM SWITCHING EDITORS TO THE *OTHER* EDITOR WHERE I EXPECT THE
and
## I PRESS CTRL+SHIFT+C AND NOW IT DOESN'T WORK IN THE ORIGINAL EDITOR. GRRR.

Could you attach those as well (please put your ## comments in, if you could, that helps give me context)?

Thanx,
PW
Comment 2 Mark Melvin CLA 2006-05-19 14:24:21 EDT
A little more information on this bug.  I have put a breakpoint on the
"setEnabled" method of the specific instance of CommandLegacyActionWrapper that
corresponds to my action and preventing the keybinding from executing (via
CommandLegacyActionWrapper#isEnabledDisregardingCommand returning false).  It
is interesting because what is actually disabling the
CommandLegacyActionWrapper is my action delegate, from its "selectionChanged"
method.

The stack trace shows that the first time the keybinding is erroneously
executed in the editor in which the actions are already disabled, the
ActionDelegateHandlerProxy#execute method manually fires my delegate's
selectionChanged method (line 249), thus disabling the
CommandLegacyActionWrapper, and hosing the keybinding.  It will never be
re-enabled because the ActionDelegateHandlerProxy is never executed again.

It seems like this would be a nightmare to keep the enablement of the
CommandLegacyActionWrapper synchronized with the enablement of the real action.

I'll give you more context in a few minutes...
Comment 3 Mark Melvin CLA 2006-05-19 14:27:03 EDT
Hey Paul,

Actually, that is my entire trace.  I didn't leave anything out, and all I did between the two points you mention was switch editors, and press Ctrl+Shift+C.  What sort of additional info were you looking for?
Comment 4 Mark Melvin CLA 2006-05-19 15:58:12 EDT
I guess the other key point here is that my delegate is enabling/disabling the action when the selection changes.  The problem seems to be that the ActionDelegateHandlerProxy is passing its action (an instance of CommandLegacyActionWrapper) to my delegate as well and the action wrapped by the keybinding is getting disabled.  I can see this by printing the instance of IAction passed to my delegate's selectionChanged method to the console (note I have three separate actions that all use a common action delegate superclass):

## change selection in the platform
selectionChanged called with: org.eclipse.ui.internal.WWinPluginAction@a3cf3e
selectionChanged called with: org.eclipse.ui.internal.WWinPluginAction@1635a89
selectionChanged called with: org.eclipse.ui.internal.WWinPluginAction@124527f

## change selection in the platform
selectionChanged called with: org.eclipse.ui.internal.WWinPluginAction@a3cf3e
selectionChanged called with: org.eclipse.ui.internal.WWinPluginAction@1635a89
selectionChanged called with: org.eclipse.ui.internal.WWinPluginAction@124527f

## Press Ctrl+Shift+C in a normal editor and a build occurs
selectionChanged called with: org.eclipse.ui.internal.handlers.CommandLegacyActionWrapper@5be0a8

## Press Ctrl+Shift+C in a bad editor and a build erroneously occurs
## (here I lose my keybindings)
selectionChanged called with: org.eclipse.ui.internal.handlers.CommandLegacyActionWrapper@5be0a8

## Press Ctrl+Shift+C again and nothing happens

## change selection in the platform
selectionChanged called with: org.eclipse.ui.internal.WWinPluginAction@a3cf3e
selectionChanged called with: org.eclipse.ui.internal.WWinPluginAction@1635a89
selectionChanged called with: org.eclipse.ui.internal.WWinPluginAction@124527f

## Press Ctrl+Shift+C again and nothing happens

## change selection in the platform
selectionChanged called with: org.eclipse.ui.internal.WWinPluginAction@a3cf3e
selectionChanged called with: org.eclipse.ui.internal.WWinPluginAction@1635a89
selectionChanged called with: org.eclipse.ui.internal.WWinPluginAction@124527f

## Press Ctrl+Shift+C again and nothing happens

..etc.

So, one option would be to not enable/disable the action from my delegate if it looks like an instance of org.eclipse.ui.internal.handlers.CommandLegacyActionWrapper, but that makes me depend on an internal class, and is a hack.
I'm wondering if the ActionDelegateHandlerProxy needs to call refreshEnablement() somewhere more regularly...

One other odd thing I noted is that ActionDelegateHandlerProxy.selectionChanged() is not called when a selection change occurs.  Should this not be called whenever a selection change occurs in the platform?  If it was, I think the problem I am seeing would go away.
Comment 5 Mark Melvin CLA 2006-05-25 17:02:09 EDT
Created attachment 42643 [details]
Patch for ActionDelegateHandlerProxy

Here is a patch that solves my problem.  Not knowing enough about the command/handler infrastructure, I'm not sure if this is the right way to deal with this or not.  It seemed that the enablement of the action maintained by this proxy was "one behind" the actual enablement of my action, and disabling it in the ActionDelegateHandlerProxy#execute method is what hoses the keybinding (there are two issues - the "one behind" issue, as well as the "forever disabled" issue).  Calling refreshEnablement() as the first step whenever ActionDelegateHandlerProxy#isEnabled is called clears up both issues, but could involve a performance hit for applications other than mine.  I'm not sure.  I'll let the experts decide. ;o)
Comment 6 Mark Melvin CLA 2006-11-27 12:53:54 EST
Any thoughts on this bug?  We are still having this issue on Eclipse 3.2.1.
Comment 7 Paul Webster CLA 2006-11-27 13:05:16 EST
Yes, this looks like it's part of the more general problems introduced by the CommandLegacyActionWrapper ... it's part of a bridge back to the menu item that wasn't completely connected.

I've been investigating it under bug 151612

We're working to finish the new Menu story in 3.3, which will have the menu items/toolbar items going through the same framework as the keybindings (and eliminate the CommandLegacyActionWrapper and its disconnect).  The plan item is bug 154130

Later,
PW
Comment 8 Paul Webster CLA 2007-06-22 06:45:46 EDT
This item has been fixed/superceded by the menu contribution mechanism - bug
154130

ActionDelegateHandlerProxy updates the enablement of the action delegate while responding to both isEnabled and execute requests

PW