Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 185523 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/keys/WorkbenchKeyboard.java (-7 / +45 lines)
Lines 11-16 Link Here
11
package org.eclipse.ui.internal.keys;
11
package org.eclipse.ui.internal.keys;
12
12
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.Collection;
14
import java.util.Iterator;
15
import java.util.Iterator;
15
import java.util.List;
16
import java.util.List;
16
import java.util.ResourceBundle;
17
import java.util.ResourceBundle;
Lines 29-34 Link Here
29
import org.eclipse.jface.bindings.keys.KeyStroke;
30
import org.eclipse.jface.bindings.keys.KeyStroke;
30
import org.eclipse.jface.bindings.keys.ParseException;
31
import org.eclipse.jface.bindings.keys.ParseException;
31
import org.eclipse.jface.bindings.keys.SWTKeySupport;
32
import org.eclipse.jface.bindings.keys.SWTKeySupport;
33
import org.eclipse.jface.internal.InternalPolicy;
32
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.SWT;
33
import org.eclipse.swt.custom.StyledText;
35
import org.eclipse.swt.custom.StyledText;
34
import org.eclipse.swt.widgets.Combo;
36
import org.eclipse.swt.widgets.Combo;
Lines 50-55 Link Here
50
import org.eclipse.ui.internal.handlers.HandlerService;
52
import org.eclipse.ui.internal.handlers.HandlerService;
51
import org.eclipse.ui.internal.misc.Policy;
53
import org.eclipse.ui.internal.misc.Policy;
52
import org.eclipse.ui.internal.misc.StatusUtil;
54
import org.eclipse.ui.internal.misc.StatusUtil;
55
import org.eclipse.ui.internal.util.StatusLineContributionItem;
53
import org.eclipse.ui.internal.util.Util;
56
import org.eclipse.ui.internal.util.Util;
54
import org.eclipse.ui.keys.IBindingService;
57
import org.eclipse.ui.keys.IBindingService;
55
import org.eclipse.ui.statushandlers.StatusManager;
58
import org.eclipse.ui.statushandlers.StatusManager;
Lines 463-469 Link Here
463
		}
466
		}
464
467
465
		try {
468
		try {
466
			final IHandlerService handlerService = (IHandlerService) workbench.getService(IHandlerService.class);
469
			final IHandlerService handlerService = (IHandlerService) workbench
470
					.getService(IHandlerService.class);
467
			handlerService.executeCommand(parameterizedCommand, trigger);
471
			handlerService.executeCommand(parameterizedCommand, trigger);
468
		} catch (final NotDefinedException e) {
472
		} catch (final NotDefinedException e) {
469
			// The command is not defined. Forwarded to the IExecutionListener.
473
			// The command is not defined. Forwarded to the IExecutionListener.
Lines 590-600 Link Here
590
	 */
594
	 */
591
	private Binding getPerfectMatch(KeySequence keySequence) {
595
	private Binding getPerfectMatch(KeySequence keySequence) {
592
		if (bindingService == null) {
596
		if (bindingService == null) {
593
			bindingService = (IBindingService) workbench.getService(IBindingService.class);
597
			bindingService = (IBindingService) workbench
598
					.getService(IBindingService.class);
594
		}
599
		}
595
		return bindingService.getPerfectMatch(keySequence);
600
		return bindingService.getPerfectMatch(keySequence);
596
	}
601
	}
597
	
602
598
	final KeySequence getBuffer() {
603
	final KeySequence getBuffer() {
599
		return state.getCurrentSequence();
604
		return state.getCurrentSequence();
600
	}
605
	}
Lines 643-649 Link Here
643
	 */
648
	 */
644
	private boolean isPartialMatch(KeySequence keySequence) {
649
	private boolean isPartialMatch(KeySequence keySequence) {
645
		if (bindingService == null) {
650
		if (bindingService == null) {
646
			bindingService = (IBindingService) workbench.getService(IBindingService.class);
651
			bindingService = (IBindingService) workbench
652
					.getService(IBindingService.class);
647
		}
653
		}
648
		return bindingService.isPartialMatch(keySequence);
654
		return bindingService.isPartialMatch(keySequence);
649
	}
655
	}
Lines 660-666 Link Here
660
	 */
666
	 */
661
	private boolean isPerfectMatch(KeySequence keySequence) {
667
	private boolean isPerfectMatch(KeySequence keySequence) {
662
		if (bindingService == null) {
668
		if (bindingService == null) {
663
			bindingService = (IBindingService) workbench.getService(IBindingService.class);
669
			bindingService = (IBindingService) workbench
670
					.getService(IBindingService.class);
664
		}
671
		}
665
		return bindingService.isPerfectMatch(keySequence);
672
		return bindingService.isPerfectMatch(keySequence);
666
	}
673
	}
Lines 758-764 Link Here
758
			final Widget widget = event.widget;
765
			final Widget widget = event.widget;
759
766
760
			// Update the contexts.
767
			// Update the contexts.
761
			final ContextService contextService = (ContextService) workbench.getService(IContextService.class);
768
			final ContextService contextService = (ContextService) workbench
769
					.getService(IContextService.class);
762
			if ((widget instanceof Control) && (!widget.isDisposed())) {
770
			if ((widget instanceof Control) && (!widget.isDisposed())) {
763
				final Shell shell = ((Control) widget).getShell();
771
				final Shell shell = ((Control) widget).getShell();
764
				contextService.updateShellKludge(shell);
772
				contextService.updateShellKludge(shell);
Lines 767-773 Link Here
767
			}
775
			}
768
776
769
			// Update the handlers.
777
			// Update the handlers.
770
			final HandlerService handlerService = (HandlerService) workbench.getService(IHandlerService.class);
778
			final HandlerService handlerService = (HandlerService) workbench
779
					.getService(IHandlerService.class);
771
			if ((widget instanceof Control) && (!widget.isDisposed())) {
780
			if ((widget instanceof Control) && (!widget.isDisposed())) {
772
				final Shell shell = ((Control) widget).getShell();
781
				final Shell shell = ((Control) widget).getShell();
773
				handlerService.updateShellKludge(shell);
782
				handlerService.updateShellKludge(shell);
Lines 776-781 Link Here
776
			}
785
			}
777
		}
786
		}
778
787
788
		KeySequence errorSequence = null;
789
		Collection errorMatch = null;
790
779
		KeySequence sequenceBeforeKeyStroke = state.getCurrentSequence();
791
		KeySequence sequenceBeforeKeyStroke = state.getCurrentSequence();
780
		for (Iterator iterator = potentialKeyStrokes.iterator(); iterator
792
		for (Iterator iterator = potentialKeyStrokes.iterator(); iterator
781
				.hasNext();) {
793
				.hasNext();) {
Lines 806-815 Link Here
806
				// We don't want to swallow keyboard navigation keys.
818
				// We don't want to swallow keyboard navigation keys.
807
				return false;
819
				return false;
808
820
821
			} else {
822
				Collection match = (InternalPolicy.currentConflicts==null?null:(Collection) InternalPolicy.currentConflicts
823
						.get(sequenceAfterKeyStroke));
824
				if (match != null) {
825
					errorSequence = sequenceAfterKeyStroke;
826
					errorMatch = match;
827
				}
809
			}
828
			}
810
		}
829
		}
811
830
812
		resetState(true);
831
		resetState(true);
832
		if (sequenceBeforeKeyStroke.isEmpty() && errorSequence != null) {
833
			StringBuffer b = new StringBuffer();
834
			Iterator i = errorMatch.iterator();
835
			while (i.hasNext()) {
836
				if (b.length() > 0) {
837
					b.append(", "); //$NON-NLS-1$
838
				}
839
				try {
840
					b.append(((Binding) i.next()).getParameterizedCommand()
841
							.getName());
842
				} catch (NotDefinedException e) {
843
					// well, he won't play nice
844
				}
845
			}
846
			StatusLineContributionItem statusLine = state.getStatusLine();
847
			if (statusLine!=null) {
848
				statusLine.setText("Conflict of " + b.toString()); //$NON-NLS-1$
849
			}
850
		}
813
		return !sequenceBeforeKeyStroke.isEmpty();
851
		return !sequenceBeforeKeyStroke.isEmpty();
814
	}
852
	}
815
853
(-)src/org/eclipse/jface/bindings/CachedBindingSet.java (+14 lines)
Lines 61-66 Link Here
61
	 * This value may be <code>null</code> if it has not yet been initialized.
61
	 * This value may be <code>null</code> if it has not yet been initialized.
62
	 */
62
	 */
63
	private Map bindingsByTrigger = null;
63
	private Map bindingsByTrigger = null;
64
	
65
	private Map conflictsByTrigger = null;
64
66
65
	/**
67
	/**
66
	 * The hash code for this object. This value is computed lazily, and marked
68
	 * The hash code for this object. This value is computed lazily, and marked
Lines 229-234 Link Here
229
	final Map getBindingsByTrigger() {
231
	final Map getBindingsByTrigger() {
230
		return bindingsByTrigger;
232
		return bindingsByTrigger;
231
	}
233
	}
234
	
235
	final Map getConflictsByTrigger() {
236
		return conflictsByTrigger;
237
	}
232
238
233
	/**
239
	/**
234
	 * Returns the map of prefixes to a map of trigger sequence to command
240
	 * Returns the map of prefixes to a map of trigger sequence to command
Lines 294-299 Link Here
294
300
295
		this.bindingsByTrigger = commandIdsByTrigger;
301
		this.bindingsByTrigger = commandIdsByTrigger;
296
	}
302
	}
303
	
304
	final void setConflictsByTrigger(final Map c) {
305
		if (c == null) {
306
			throw new NullPointerException(
307
					"Cannot set a null binding conflicts"); //$NON-NLS-1$
308
		}
309
		conflictsByTrigger = c;
310
	}
297
311
298
	/**
312
	/**
299
	 * Sets the map of prefixes to a map of trigger sequence to command
313
	 * Sets the map of prefixes to a map of trigger sequence to command
(-)src/org/eclipse/jface/bindings/BindingManager.java (-35 / +22 lines)
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,
(-)src/org/eclipse/jface/internal/InternalPolicy.java (+8 lines)
Lines 10-15 Link Here
10
 ******************************************************************************/
10
 ******************************************************************************/
11
package org.eclipse.jface.internal;
11
package org.eclipse.jface.internal;
12
12
13
import java.util.HashMap;
14
import java.util.Map;
15
13
/**
16
/**
14
 * Internal class used for non-API debug flags.
17
 * Internal class used for non-API debug flags.
15
 * 
18
 * 
Lines 25-28 Link Here
25
	 */
28
	 */
26
	public static boolean DEBUG_LOG_REENTRANT_VIEWER_CALLS = false;
29
	public static boolean DEBUG_LOG_REENTRANT_VIEWER_CALLS = false;
27
30
31
	/**
32
	 * (NON-API) Instead of logging current conflicts they can be
33
	 * held here.  If there is a problem, they can be reported then.
34
	 */
35
	public static Map currentConflicts = new HashMap();
28
}
36
}

Return to bug 185523