Bug 379162 - Command.define doesn't add MCommand model element
Summary: Command.define doesn't add MCommand model element
Status: CLOSED DUPLICATE of bug 407749
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2   Edit
Hardware: All All
: P3 major with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: candidate43
Keywords: api
Depends on:
Blocks:
 
Reported: 2012-05-10 13:13 EDT by Chris Williams CLA
Modified: 2013-09-25 15:47 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Williams CLA 2012-05-10 13:13:14 EDT
Build Identifier: 

I'm attempting to define new commands, hook up bindings for them and add
expressions for enablement that are dynamic - all programmatically. When I
attempt to add the bindings, that part is failing. It looks up
application.getCommands() and doesn't find the programmatically defined command
in BindingService.createMKeyBinding, line 679. It looks like the
programmatcially defined commands got to a different set than the 

Here's the basic code I'm running to set this up. (Am I doing things wrong?)

// Define our commandElement model as an Eclipse command
String commandId = "com.example.command." + commandElement.getDisplayName();
Command c = cs.getCommand(commandId);
if (!c.isDefined())
{
    c.define(commandElement.getDisplayName(), commandElement.getDisplayName(),
cat);
    Expression expression = new Expression()
    {
        @Override
        public EvaluationResult evaluate(IEvaluationContext context) throws
CoreException
        {
            IWorkbenchPart workbenchPart = (IWorkbenchPart)
context.getVariable(ISources.ACTIVE_PART_NAME);
            if (workbenchPart instanceof IEditorPart)
            {
      // do more checking
                    return EvaluationResult.TRUE;
            }
            return EvaluationResult.FALSE;
        }
    };
}

KeySequence[] keySequences = commandElement.getKeySequences();
if (!ArrayUtil.isEmpty(keySequences))
{
    if (bindingService instanceof BindingService)
    {
        final BindingService theBindingService = (BindingService)
bindingService;
        // Add to the set
        for (KeySequence keySequence : keySequences)
        {
            KeyBinding binding = new KeyBinding(keySequence, new
ParameterizedCommand(c, null),
                    "org.eclipse.ui.defaultAcceleratorConfiguration",
                    "myContext", null, null, null, Binding.USER);
            theBindingService.addBinding(binding);
        }
    }
}

Reproducible: Always
Comment 1 Paul Webster CLA 2013-09-25 15:47:41 EDT

*** This bug has been marked as a duplicate of bug 407749 ***