tags:

views:

474

answers:

1

Hi all,

I am extending eclipse's platform with my own view. This view contains one action in its toolbar.

I want to create a key binding shortcut associated to Ctrl+R for this actions. To do that I created a my.context (my context extends org.eclipse.ui.window context), my.command and a my.command.binding extensions.

Then when my view is created, in the createPartControl(*) method, I activate my context:

IContextService contextService = (IContextService) getSite()
    .getService(IContextService.class);
contextService.activateContext(VIEW_CONTEXT_ID);

When my view is opened in a debug perspective I have the following warning:

    Warning: A conflict occurred for CTRL+R:
    Binding(CTRL+R,
    ParameterizedCommand(Command(org.eclipse.debug.ui.commands.RunToLine,Run to Line,
    Resume and break when execution reaches the current line,
    Category(org.eclipse.debug.ui.category.run,Run/Debug,Run/Debug command category,true),
 ActionDelegateHandlerProxy(null,org.eclipse.debug.internal.ui.actions.RetargetRunToLineAction),
    ,,true),null),
    org.eclipse.ui.defaultAcceleratorConfiguration,
    org.eclipse.debug.ui.debugging,,,system)
    Binding(CTRL+R,
    ParameterizedCommand(Command(RestoreAction,Restore Chart (T-Charts),
    Restore the initial chart display,
    Category(TChartsActions,T-Charts Actions,null,true),
    ActionHandler(com.st.tcharts.internal.actions.RestoreChartAction@1997b8a),
    ,,true),null),
    org.eclipse.ui.defaultAcceleratorConfiguration,
    com.st.tcharts.ui.view,,,system)

I am not sure to understand why I have this warning ....

Is there several active contexts at a given time ?

If I change my shortcut to Ctrl+C for example, I don't have this warning but Ctrl+C is also binded to another command (copy) in the debugg context ... why ?

I didn't find clear ressources delaing about Eclipse contexts on the web ...

Thanks in advance

Manu

+1  A: 

I am not sure why your context does not isolate your bindings from the eclipse one, but if CTRL+R is already associated with "Run to Line" command, you could simply change its handler by yours, as described in this thread:

(Example to adapt to your case)

 <handler
       class="test.handlers.DeleteFooHandler"
       commandId="org.eclipse.ui.edit.delete">
    <activeWhen>
       <iterate
             ifEmpty="false"
             operator="and">
          <instanceof
                value="test.model.Foo">
          </instanceof>
       </iterate></activeWhen>
 </handler>

Note: this approach is also illustrated by this thread:

IHandlerService handlerService =
  getSite().getService(IHandlerService.class);


IHandler myPaste = new org.eclipse.core.commands.AbstractHandler() {
  public Object execute(ExecutionEvent event) throws ExecutionException{
    System.out.println("This is MyPaste");
  }
};


Now, since it does not explain why your own IContext does not deactivate Eclipse bindings, I can only find for now this thread, explaining when your context is or is not actually active:

If you are opening your own window (dialog or shell) and that makes the workbench window not active, your context will also not be active.
You can try setting your window shell to type == window also using IContextService#registerShell(*) ... that should leave the standard window contexts valid.
You still might have to activate the context while your SW window shell is active (with matching deactivates).

To which the OP replied:

I got the solution of it by activating that context on the focus gain of required window and deactivate that context on focus lost and dispose of the same window.

May be that could help.
In the meantime, you can look at "Platform Command Framework" in order to activate the "Tracing Option" and see exactly what binding is activated and for which command.

VonC
Thanks for the answer but I think this solution is a kind of a "hack".As you said what I want is to have "my context isolating my bindings from the eclipse one" It should work but ....
Manuel Selva
Thanks again for these additions.I am not openning my own window so it doesn't help me more. My context is activated in my view.createPartCOntrol method and the view is opened programatically. I think there is a bug somewhere .. In eclipse or in my own code ...I'll try to investigate more and let you know.Thanks again for your time.
Manuel Selva