|
Lines 10-18
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.jface.bindings; |
11 |
package org.eclipse.jface.bindings; |
| 12 |
|
12 |
|
| 13 |
import java.io.BufferedWriter; |
|
|
| 14 |
import java.io.IOException; |
| 15 |
import java.io.StringWriter; |
| 16 |
import java.util.ArrayList; |
13 |
import java.util.ArrayList; |
| 17 |
import java.util.Arrays; |
14 |
import java.util.Arrays; |
| 18 |
import java.util.Collection; |
15 |
import java.util.Collection; |
|
Lines 42-47
Link Here
|
| 42 |
import org.eclipse.jface.bindings.keys.KeyLookupFactory; |
39 |
import org.eclipse.jface.bindings.keys.KeyLookupFactory; |
| 43 |
import org.eclipse.jface.bindings.keys.KeyStroke; |
40 |
import org.eclipse.jface.bindings.keys.KeyStroke; |
| 44 |
import org.eclipse.jface.contexts.IContextIds; |
41 |
import org.eclipse.jface.contexts.IContextIds; |
|
|
42 |
import org.eclipse.jface.internal.InternalPolicy; |
| 45 |
import org.eclipse.jface.util.Policy; |
43 |
import org.eclipse.jface.util.Policy; |
| 46 |
import org.eclipse.jface.util.Util; |
44 |
import org.eclipse.jface.util.Util; |
| 47 |
import org.eclipse.swt.SWT; |
45 |
import org.eclipse.swt.SWT; |
|
Lines 272-279
Link Here
|
| 272 |
*/ |
270 |
*/ |
| 273 |
private Map prefixTable = null; |
271 |
private Map prefixTable = null; |
| 274 |
|
272 |
|
| 275 |
private Set triggerConflicts = new HashSet(); |
|
|
| 276 |
|
| 277 |
/** |
273 |
/** |
| 278 |
* <p> |
274 |
* <p> |
| 279 |
* Constructs a new instance of <code>BindingManager</code>. |
275 |
* Constructs a new instance of <code>BindingManager</code>. |
|
Lines 438-444
Link Here
|
| 438 |
* This method completes in <code>O(1)</code>. |
434 |
* This method completes in <code>O(1)</code>. |
| 439 |
*/ |
435 |
*/ |
| 440 |
private final void clearSolution() { |
436 |
private final void clearSolution() { |
| 441 |
setActiveBindings(null, null, null); |
437 |
setActiveBindings(null, null, null, null); |
| 442 |
} |
438 |
} |
| 443 |
|
439 |
|
| 444 |
/** |
440 |
/** |
|
Lines 511-517
Link Here
|
| 511 |
* computed). |
507 |
* computed). |
| 512 |
*/ |
508 |
*/ |
| 513 |
private final void computeBindings(final Map activeContextTree, |
509 |
private final void computeBindings(final Map activeContextTree, |
| 514 |
final Map bindingsByTrigger, final Map triggersByCommandId) { |
510 |
final Map bindingsByTrigger, final Map triggersByCommandId, |
|
|
511 |
final Map conflictsByTrigger) { |
| 515 |
/* |
512 |
/* |
| 516 |
* FIRST PASS: Remove all of the bindings that are marking deletions. |
513 |
* FIRST PASS: Remove all of the bindings that are marking deletions. |
| 517 |
*/ |
514 |
*/ |
|
Lines 631-657
Link Here
|
| 631 |
final Binding winner = resolveConflicts((Collection) match, |
628 |
final Binding winner = resolveConflicts((Collection) match, |
| 632 |
activeContextTree); |
629 |
activeContextTree); |
| 633 |
if (winner == null) { |
630 |
if (winner == null) { |
| 634 |
// warn once ... so as not to flood the logs |
631 |
conflictsByTrigger.put(trigger, match); |
| 635 |
if (triggerConflicts.add(trigger)) { |
|
|
| 636 |
final StringWriter sw = new StringWriter(); |
| 637 |
final BufferedWriter buffer = new BufferedWriter(sw); |
| 638 |
try { |
| 639 |
buffer.write("A conflict occurred for "); //$NON-NLS-1$ |
| 640 |
buffer.write(trigger.toString()); |
| 641 |
buffer.write(':'); |
| 642 |
Iterator i = ((Collection) match).iterator(); |
| 643 |
while (i.hasNext()) { |
| 644 |
buffer.newLine(); |
| 645 |
buffer.write(i.next().toString()); |
| 646 |
} |
| 647 |
buffer.flush(); |
| 648 |
} catch (IOException e) { |
| 649 |
// we should not get this |
| 650 |
} |
| 651 |
conflicts.add(new Status(IStatus.WARNING, |
| 652 |
"org.eclipse.jface", //$NON-NLS-1$ |
| 653 |
sw.toString())); |
| 654 |
} |
| 655 |
if (DEBUG) { |
632 |
if (DEBUG) { |
| 656 |
Tracing.printTrace("BINDINGS", //$NON-NLS-1$ |
633 |
Tracing.printTrace("BINDINGS", //$NON-NLS-1$ |
| 657 |
"A conflict occurred for " + trigger); //$NON-NLS-1$ |
634 |
"A conflict occurred for " + trigger); //$NON-NLS-1$ |
|
Lines 997-1006
Link Here
|
| 997 |
// Compute the active bindings. |
974 |
// Compute the active bindings. |
| 998 |
commandIdsByTrigger = new HashMap(); |
975 |
commandIdsByTrigger = new HashMap(); |
| 999 |
final Map triggersByParameterizedCommand = new HashMap(); |
976 |
final Map triggersByParameterizedCommand = new HashMap(); |
|
|
977 |
final Map conflictsByTrigger = new HashMap(); |
| 1000 |
computeBindings(null, commandIdsByTrigger, |
978 |
computeBindings(null, commandIdsByTrigger, |
| 1001 |
triggersByParameterizedCommand); |
979 |
triggersByParameterizedCommand, conflictsByTrigger); |
| 1002 |
existingCache.setBindingsByTrigger(commandIdsByTrigger); |
980 |
existingCache.setBindingsByTrigger(commandIdsByTrigger); |
| 1003 |
existingCache.setTriggersByCommandId(triggersByParameterizedCommand); |
981 |
existingCache.setTriggersByCommandId(triggersByParameterizedCommand); |
|
|
982 |
existingCache.setConflictsByTrigger(conflictsByTrigger); |
| 1004 |
return Collections.unmodifiableMap(commandIdsByTrigger); |
983 |
return Collections.unmodifiableMap(commandIdsByTrigger); |
| 1005 |
} |
984 |
} |
| 1006 |
|
985 |
|
|
Lines 1057-1067
Link Here
|
| 1057 |
|
1036 |
|
| 1058 |
// Compute the active bindings. |
1037 |
// Compute the active bindings. |
| 1059 |
final Map commandIdsByTrigger = new HashMap(); |
1038 |
final Map commandIdsByTrigger = new HashMap(); |
|
|
1039 |
final Map conflictsByTrigger = new HashMap(); |
| 1060 |
triggersByParameterizedCommand = new HashMap(); |
1040 |
triggersByParameterizedCommand = new HashMap(); |
| 1061 |
computeBindings(null, commandIdsByTrigger, |
1041 |
computeBindings(null, commandIdsByTrigger, |
| 1062 |
triggersByParameterizedCommand); |
1042 |
triggersByParameterizedCommand, conflictsByTrigger); |
| 1063 |
existingCache.setBindingsByTrigger(commandIdsByTrigger); |
1043 |
existingCache.setBindingsByTrigger(commandIdsByTrigger); |
| 1064 |
existingCache.setTriggersByCommandId(triggersByParameterizedCommand); |
1044 |
existingCache.setTriggersByCommandId(triggersByParameterizedCommand); |
|
|
1045 |
existingCache.setConflictsByTrigger(conflictsByTrigger); |
| 1065 |
|
1046 |
|
| 1066 |
return Collections.unmodifiableMap(triggersByParameterizedCommand); |
1047 |
return Collections.unmodifiableMap(triggersByParameterizedCommand); |
| 1067 |
} |
1048 |
} |
|
Lines 1703-1709
Link Here
|
| 1703 |
if (bindings == null) { |
1684 |
if (bindings == null) { |
| 1704 |
// Not yet initialized. This is happening too early. Do nothing. |
1685 |
// Not yet initialized. This is happening too early. Do nothing. |
| 1705 |
setActiveBindings(Collections.EMPTY_MAP, Collections.EMPTY_MAP, |
1686 |
setActiveBindings(Collections.EMPTY_MAP, Collections.EMPTY_MAP, |
| 1706 |
Collections.EMPTY_MAP); |
1687 |
Collections.EMPTY_MAP, Collections.EMPTY_MAP); |
| 1707 |
return; |
1688 |
return; |
| 1708 |
} |
1689 |
} |
| 1709 |
|
1690 |
|
|
Lines 1732-1738
Link Here
|
| 1732 |
Tracing.printTrace("BINDINGS", "Cache hit"); //$NON-NLS-1$ //$NON-NLS-2$ |
1713 |
Tracing.printTrace("BINDINGS", "Cache hit"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 1733 |
} |
1714 |
} |
| 1734 |
setActiveBindings(commandIdsByTrigger, existingCache |
1715 |
setActiveBindings(commandIdsByTrigger, existingCache |
| 1735 |
.getTriggersByCommandId(), existingCache.getPrefixTable()); |
1716 |
.getTriggersByCommandId(), existingCache.getPrefixTable(), |
|
|
1717 |
existingCache.getConflictsByTrigger()); |
| 1736 |
return; |
1718 |
return; |
| 1737 |
} |
1719 |
} |
| 1738 |
|
1720 |
|
|
Lines 1744-1755
Link Here
|
| 1744 |
// Compute the active bindings. |
1726 |
// Compute the active bindings. |
| 1745 |
commandIdsByTrigger = new HashMap(); |
1727 |
commandIdsByTrigger = new HashMap(); |
| 1746 |
final Map triggersByParameterizedCommand = new HashMap(); |
1728 |
final Map triggersByParameterizedCommand = new HashMap(); |
|
|
1729 |
final Map conflictsByTrigger = new HashMap(); |
| 1747 |
computeBindings(activeContextTree, commandIdsByTrigger, |
1730 |
computeBindings(activeContextTree, commandIdsByTrigger, |
| 1748 |
triggersByParameterizedCommand); |
1731 |
triggersByParameterizedCommand, conflictsByTrigger); |
| 1749 |
existingCache.setBindingsByTrigger(commandIdsByTrigger); |
1732 |
existingCache.setBindingsByTrigger(commandIdsByTrigger); |
| 1750 |
existingCache.setTriggersByCommandId(triggersByParameterizedCommand); |
1733 |
existingCache.setTriggersByCommandId(triggersByParameterizedCommand); |
|
|
1734 |
existingCache.setConflictsByTrigger(conflictsByTrigger); |
| 1751 |
setActiveBindings(commandIdsByTrigger, triggersByParameterizedCommand, |
1735 |
setActiveBindings(commandIdsByTrigger, triggersByParameterizedCommand, |
| 1752 |
buildPrefixTable(commandIdsByTrigger)); |
1736 |
buildPrefixTable(commandIdsByTrigger), |
|
|
1737 |
conflictsByTrigger); |
| 1753 |
existingCache.setPrefixTable(prefixTable); |
1738 |
existingCache.setPrefixTable(prefixTable); |
| 1754 |
} |
1739 |
} |
| 1755 |
|
1740 |
|
|
Lines 2153-2163
Link Here
|
| 2153 |
* solution. |
2138 |
* solution. |
| 2154 |
*/ |
2139 |
*/ |
| 2155 |
private final void setActiveBindings(final Map activeBindings, |
2140 |
private final void setActiveBindings(final Map activeBindings, |
| 2156 |
final Map activeBindingsByCommandId, final Map prefixTable) { |
2141 |
final Map activeBindingsByCommandId, final Map prefixTable, |
|
|
2142 |
final Map conflicts) { |
| 2157 |
this.activeBindings = activeBindings; |
2143 |
this.activeBindings = activeBindings; |
| 2158 |
final Map previousBindingsByParameterizedCommand = this.activeBindingsByParameterizedCommand; |
2144 |
final Map previousBindingsByParameterizedCommand = this.activeBindingsByParameterizedCommand; |
| 2159 |
this.activeBindingsByParameterizedCommand = activeBindingsByCommandId; |
2145 |
this.activeBindingsByParameterizedCommand = activeBindingsByCommandId; |
| 2160 |
this.prefixTable = prefixTable; |
2146 |
this.prefixTable = prefixTable; |
|
|
2147 |
InternalPolicy.currentConflicts = conflicts; |
| 2161 |
|
2148 |
|
| 2162 |
fireBindingManagerChanged(new BindingManagerEvent(this, true, |
2149 |
fireBindingManagerChanged(new BindingManagerEvent(this, true, |
| 2163 |
previousBindingsByParameterizedCommand, false, null, false, |
2150 |
previousBindingsByParameterizedCommand, false, null, false, |