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

The following examples show how to use org.eclipse.ui.keys.IBindingService#getActiveBindingsFor() . 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: KeyBindingHelper.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public static boolean matchesKeybinding(int keyCode, int stateMask, String commandId)
{
	final IBindingService bindingSvc = (IBindingService) PlatformUI.getWorkbench()
			.getAdapter(IBindingService.class);
	TriggerSequence[] activeBindingsFor = bindingSvc.getActiveBindingsFor(commandId);

	for (TriggerSequence seq : activeBindingsFor)
	{
		if (seq instanceof KeySequence)
		{
			if (matchesKeybinding(keyCode, stateMask, seq))
			{
				return true;
			}
		}
	}

	return false;
}
 
Example 2
Source File: KeyBindingHelper.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public static boolean matchesKeybinding(int keyCode, int stateMask, String commandId) {
    final IBindingService bindingSvc = PlatformUI.getWorkbench()
            .getAdapter(IBindingService.class);
    TriggerSequence[] activeBindingsFor = bindingSvc.getActiveBindingsFor(commandId);

    for (TriggerSequence seq : activeBindingsFor) {
        if (seq instanceof KeySequence) {
            KeySequence keySequence = (KeySequence) seq;
            if (matchesKeybinding(keyCode, stateMask, keySequence)) {
                return true;
            }
        }
    }

    return false;
}
 
Example 3
Source File: WorkspaceWizardPage.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the active key binding for content assist.
 *
 * If no binding is set null is returned.
 */
private KeyStroke getActiveContentAssistBinding() {
	IBindingService bindingService = PlatformUI.getWorkbench().getService(IBindingService.class);
	TriggerSequence[] activeBindingsFor = bindingService
			.getActiveBindingsFor(CONTENT_ASSIST_ECLIPSE_COMMAND_ID);

	if (activeBindingsFor.length > 0 && activeBindingsFor[0] instanceof KeySequence) {
		KeyStroke[] strokes = ((KeySequence) activeBindingsFor[0]).getKeyStrokes();
		if (strokes.length == 1) {
			return strokes[0];
		}
	}
	return null;
}
 
Example 4
Source File: CorrectionCommandHandler.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static String getShortCutString(String proposalId) {
	if (proposalId != null) {
		IBindingService bindingService= (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class);
		if (bindingService != null) {
			TriggerSequence[] activeBindingsFor= bindingService.getActiveBindingsFor(proposalId);
			if (activeBindingsFor.length > 0) {
				return activeBindingsFor[0].format();
			}
		}
	}
	return null;
}
 
Example 5
Source File: EmacsMovementHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Does the trigger for this movement command contain the SHIFT key?
 * 
 * Enforce that the <binding> and <binding>+SHIFT belong to the same Command. 
 * If not, don't apply shift selection (if enabled) for this command (i.e. return false).
 *  
 * @param event the Execution event that invoked this command
 * 
 * @return true if SHIFT modifier was set, else false
 */
private boolean getShifted(ExecutionEvent event) {
	// NB: only single keystroke commands are valid 
	boolean result = false;
	Object trigger = event.getTrigger();
	Event e = null;
	if (trigger != null && trigger instanceof Event && ((e = (Event)trigger).stateMask & SWT.SHIFT )!= 0) {
		String cmdId = event.getCommand().getId();
		int mask = (e.stateMask & SWT.MODIFIER_MASK) ^ SWT.SHIFT;
		int u_code = Character.toUpperCase((char)e.keyCode);
		IBindingService bs = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
		if (cmdId != null && bs != null) {
			TriggerSequence[] sequences = bs.getActiveBindingsFor(cmdId);
			for (TriggerSequence s : sequences) {
				if (s instanceof KeySequence) {
					KeyStroke[] strokes = ((KeySequence)s).getKeyStrokes();
					if (strokes.length == 1) {
						KeyStroke k = strokes[strokes.length - 1];
						// if keyCode is alpha, then we test uppercase, else keyCode
						if (k.getModifierKeys() == mask
								&& (k.getNaturalKey() == u_code || k.getNaturalKey() == e.keyCode)) {
							result = true;
							break;
						}
					}
				}
			}
		} 
	}
	return result;
}
 
Example 6
Source File: WindowDeclOtherCmd.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * A bit of hackery that tries to get the correct open-declaration command for the buffer 
 * @param editor
 * @return the best match Command definition
 */
private Command getOpenCmd(IEditorPart editor) {
	Command result = null;
	try {
		IBindingService bs = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
		ICommandService ics = (ICommandService) editor.getSite().getService(ICommandService.class);
		List<Command> cans = new ArrayList<Command>();
		List<Command> nocans = new ArrayList<Command>();
		Command[] commands = ics.getDefinedCommands();
		for (Command c : commands) {
			if (OD.equals(c.getName()) && c.isEnabled()) {
				TriggerSequence[] b = bs.getActiveBindingsFor(c.getId());
				if (b.length > 0) {
					cans.add(c);
				} else {
					nocans.add(c);
				}
			}
		}
		// TODO: when > 1 try to refine the result heuristically?
		// if Eclipse returned more than one, then chose a bound command over non-bound
		if (cans.isEmpty()) {
			if (!nocans.isEmpty()) {
				// just grab first one
				result = nocans.get(0);
			}
		} else {
			// grab the first bound one
			result = cans.get(0);
		}
	} catch (Exception e) { }
	return result;
}