Java Code Examples for org.eclipse.ui.keys.IBindingService#getPerfectMatch()

The following examples show how to use org.eclipse.ui.keys.IBindingService#getPerfectMatch() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndentForTabHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Return the exact binding if it exists and is enabled, else null
 * 
 * @param editor
 * @param keyCode
 * @param mode
 * @return binding if it exists and is enabled, else null
 */
private Binding getBinding(ITextEditor editor, char keyCode, int mode) {

	Binding result = null;
	// ensure key is upper case
	IBindingService bindingService = (IBindingService) editor.getSite().getService(IBindingService.class);
	KeyStroke key = KeyStroke.getInstance(mode, Character.toUpperCase(keyCode));
	result = bindingService.getPerfectMatch(KeySequence.getInstance(key));
	if (result != null && !result.getParameterizedCommand().getCommand().isEnabled()) {
		result = null;
	}
	return result;
}
 
Example 2
Source File: ISearchMinibuffer.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Dynamically determine the bindings for forward and reverse i-search
 * For repeat search, Emacs treats i-search and i-search-regexp identically
 * 
 * @param event
 * @return the FORWARD, REVERSE, or the source keyCode
 */
private int checkKeyCode(VerifyEvent event) {
	int result = event.keyCode;
	Integer val = keyHash.get(Integer.valueOf(event.keyCode + event.stateMask));
	if (val == null) { 
		KeyStroke keyst = KeyStroke.getInstance(event.stateMask, Character.toUpperCase(result));
		IBindingService bindingService = getBindingService();
		Binding binding = bindingService.getPerfectMatch(KeySequence.getInstance(keyst));
		if (binding != null) {
			if (ISF.equals(binding.getParameterizedCommand().getId())){
				result = FORWARD;
				keyHash.put(Integer.valueOf(event.keyCode + event.stateMask),Integer.valueOf(FORWARD));
			} else if (ISB.equals(binding.getParameterizedCommand().getId())) {
				result = REVERSE;
				keyHash.put(Integer.valueOf(event.keyCode + event.stateMask),Integer.valueOf(REVERSE));
			} else if (ISRF.equals(binding.getParameterizedCommand().getId())) {
				result = FORWARD;
				keyHash.put(Integer.valueOf(event.keyCode + event.stateMask),Integer.valueOf(FORWARD));
			} else if (ISRB.equals(binding.getParameterizedCommand().getId())) {
				result = REVERSE;
				keyHash.put(Integer.valueOf(event.keyCode + event.stateMask),Integer.valueOf(REVERSE));
			} 
		}
	} else {
		result = val;
	}
	return result;
}
 
Example 3
Source File: KeybindingsManager.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private boolean processKeyStroke(Event event, KeyStroke keyStroke)
{
	IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
	KeySequence sequenceBeforeKeyStroke = state.getCurrentSequence();
	KeySequence sequenceAfterKeyStroke = KeySequence.getInstance(sequenceBeforeKeyStroke, keyStroke);

	if (uniqueKeySequences.contains(sequenceAfterKeyStroke))
	{
		IEvaluationService evaluationService = (IEvaluationService) workbench.getService(IEvaluationService.class);
		IEvaluationContext evaluationContext = evaluationService.getCurrentState();
		IWorkbenchPart workbenchPart = (IWorkbenchPart) evaluationContext.getVariable(ISources.ACTIVE_PART_NAME);
		ICommandElementsProvider commandElementsProvider = (ICommandElementsProvider) workbenchPart
				.getAdapter(ICommandElementsProvider.class);
		if (commandElementsProvider != null)
		{
			// Is there a Eclipse binding that matches the key sequence?
			Binding binding = null;
			if (bindingService.isPerfectMatch(sequenceAfterKeyStroke))
			{
				// Record it
				binding = bindingService.getPerfectMatch(sequenceAfterKeyStroke);
			}

			List<CommandElement> commandElements = commandElementsProvider
					.getCommandElements(sequenceAfterKeyStroke);
			if (commandElements.size() == 0)
			{
				if (binding == null)
				{
					// Remember the prefix
					incrementState(sequenceAfterKeyStroke);
				}
				else
				{
					// Reset our state
					resetState();
				}

				// Do not consume the event. Let Eclipse handle it.
				return false;
			}
			else
			{
				if (binding == null && commandElements.size() == 1)
				{
					// We have a unique scripting command to execute
					executeCommandElement(commandElementsProvider, commandElements.get(0));

					// Reset our state
					resetState();

					// The event should be consumed
					return true;
				}
				else
				{
					// We need to show commands menu to the user
					IContextService contextService = (IContextService) workbench.getService(IContextService.class);
					popup(workbenchPart.getSite().getShell(), bindingService, contextService,
							commandElementsProvider, commandElements, event, binding,
							getInitialLocation(commandElementsProvider));

					// Reset our state
					resetState();

					// The event should be consumed
					return true;
				}
			}
		}
	}
	else if (uniqueKeySequencesPrefixes.contains(sequenceAfterKeyStroke))
	{
		// Prefix match

		// Is there a Eclipse command with a perfect match
		if (bindingService.isPerfectMatch(sequenceAfterKeyStroke))
		{
			// Reset our state
			resetState();
		}
		else
		{
			// Remember the prefix
			incrementState(sequenceAfterKeyStroke);
		}
	}
	else
	{
		// Reset our state
		resetState();
	}

	// We did not handle the event. Do not consume the event. Let Eclipse handle it.
	return false;
}
 
Example 4
Source File: KbdMacroDefineHandler.java    From e4macs with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Check for perfect binding match to key sequence
 * 
 * @param editor
 * @param sequence
 * @return Binding if perfect match found, else null
 */
protected Binding checkForBinding(ITextEditor editor, KeySequence sequence) {
	IBindingService service = (editor != null) ? (IBindingService) editor.getSite().getService(IBindingService.class) :
		(IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
	return service.getPerfectMatch(sequence);
}