Skip to content

Commit 4065aee

Browse files
committed
[eclipse-platform#2968] Fix wrong key binding displayed in MenuItem
Consider the Binding context when there is more than one Binding for a ParametrizedCommand. The deeper/specialized context will be preferred. fixes eclipse-platform#2968
1 parent 0368ee5 commit 4065aee

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

bundles/org.eclipse.e4.ui.bindings/src/org/eclipse/e4/ui/bindings/internal/BindingTable.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import java.util.Map;
2525
import org.eclipse.core.commands.ParameterizedCommand;
2626
import org.eclipse.core.commands.contexts.Context;
27+
import org.eclipse.core.commands.contexts.ContextManager;
2728
import org.eclipse.e4.core.services.contributions.IContributionFactory;
29+
import org.eclipse.e4.ui.bindings.internal.ContextSet.CComp;
2830
import org.eclipse.e4.ui.model.application.MApplication;
2931
import org.eclipse.jface.bindings.Binding;
3032
import org.eclipse.jface.bindings.Trigger;
@@ -56,6 +58,7 @@ private static int compareSchemes(String[] activeSchemeIds, final String schemeI
5658

5759
static class BindingComparator implements Comparator<Binding> {
5860
private String[] activeSchemeIds;
61+
private ContextManager contextManager;
5962

6063
public void setActiveSchemes(String[] activeSchemeIds) {
6164
this.activeSchemeIds = activeSchemeIds;
@@ -65,13 +68,30 @@ public String[] getActiveSchemes() {
6568
return this.activeSchemeIds;
6669
}
6770

71+
public void setContextManager(ContextManager contextManager) {
72+
this.contextManager = contextManager;
73+
}
74+
6875
@Override
6976
public int compare(Binding o1, Binding o2) {
7077
int rc = compareSchemes(activeSchemeIds, o1.getSchemeId(), o2.getSchemeId());
7178
if (rc != 0) {
7279
return rc;
7380
}
7481

82+
/*
83+
* Check to see which has the deeper context. The deeper context is the one that
84+
* is preferred.
85+
*/
86+
if (contextManager != null) {
87+
CComp cComp = new ContextSet.CComp(contextManager);
88+
int contextDepth = cComp.compare(contextManager.getContext(o2.getContextId()),
89+
contextManager.getContext(o1.getContextId())); // deeper is better
90+
if (contextDepth != 0) {
91+
return contextDepth;
92+
}
93+
}
94+
7595
/*
7696
* Check to see which has the least number of triggers in the trigger sequence.
7797
*/

bundles/org.eclipse.e4.ui.bindings/src/org/eclipse/e4/ui/bindings/internal/BindingTableManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.ListIterator;
2222
import org.eclipse.core.commands.ParameterizedCommand;
2323
import org.eclipse.core.commands.contexts.Context;
24+
import org.eclipse.core.commands.contexts.ContextManager;
2425
import org.eclipse.e4.core.contexts.IEclipseContext;
2526
import org.eclipse.jface.bindings.Binding;
2627
import org.eclipse.jface.bindings.TriggerSequence;
@@ -34,6 +35,9 @@ public class BindingTableManager {
3435
@Inject
3536
private IEclipseContext eclipseContext;
3637

38+
@Inject
39+
private ContextManager contextManager;
40+
3741
private ContextSet definedTables = ContextSet.EMPTY;
3842

3943
private String[] activeSchemeIds;
@@ -235,6 +239,7 @@ public Collection<Binding> getPartialMatches(ContextSet contextSet, TriggerSeque
235239
public void setActiveSchemes(String[] activeSchemeIds) {
236240
this.activeSchemeIds = activeSchemeIds;
237241
BindingTable.BEST_SEQUENCE.setActiveSchemes(activeSchemeIds);
242+
BindingTable.BEST_SEQUENCE.setContextManager(contextManager);
238243
}
239244

240245
/*

0 commit comments

Comments
 (0)