org.eclipse.jface.bindings.keys.KeySequence Java Examples

The following examples show how to use org.eclipse.jface.bindings.keys.KeySequence. 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: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
private void addSetKeySequenceListener() {
		addPropertyChangeListener(new IPropertyChangeListener() {
			public void propertyChange(PropertyChangeEvent event) {
				if (BindingElement.PROP_TRIGGER.equals(event.getProperty())) {
//					Bug #2740
					if (((KeySequence) event.getNewValue()) != null) {
						if (((KeySequence) event.getNewValue()).toString().endsWith("+")) {
							return;
						} else {
							updateTrigger((BindingElement) event.getSource(), (KeySequence) event.getOldValue(),
									(KeySequence) event.getNewValue());
						}
					}
				}
			}
		});
	}
 
Example #2
Source File: WithMinibuffer.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
protected boolean hasBinding(KeyEvent event, int mode) {
	boolean result = false;
	// ensure key is upper case
	KeyStroke key = KeyStroke.getInstance(mode, Character.toUpperCase(event.keyCode));
	boolean isFilterDisabled = !getKeyFilter();
	try {
		if (isFilterDisabled) {
			setKeyFilter(true);
		}
		result = bindingService.isPerfectMatch(KeySequence.getInstance(key));
	} finally {
		if (isFilterDisabled) {
			setKeyFilter(false);
		}
	}
	return result;
}
 
Example #3
Source File: KeyBindingHelper.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private static boolean internalMatchesKeybinding(int keyCode, int stateMask, TriggerSequence seq)
{
	KeySequence keySequence = (KeySequence) seq;
	KeyStroke[] keyStrokes = keySequence.getKeyStrokes();

	if (keyStrokes.length > 1)
	{
		return false; // Only handling one step binding... the code below does not support things as "CTRL+X R" for
						// redo.
	}
	for (KeyStroke keyStroke : keyStrokes)
	{
		if (keyStroke.getNaturalKey() == keyCode && keyStroke.getModifierKeys() == stateMask)
		{

			return true;
		}
	}
	return false;
}
 
Example #4
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 #5
Source File: KeyHandlerMinibuffer.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Check if the (accumulated) key strokes have a single binding
 * 
 * @param state
 * @param keyCode
 * @param character
 * 
 * @return true if most unique binding, else false
 */
protected boolean checkKey(int state, int keyCode, int character) {
	boolean result = true;
	keys.add(getKey(state,keyCode,character));
	trigger = KeySequence.getInstance(keys);
	binding = bindingService.getPerfectMatch(trigger);
	boolean partial = bindingService.isPartialMatch(trigger); 
	if (binding == null) {
		if (!partial) {
			keyCharacter = character;
			result = false; 
		}
	} else if (partial) {
		// keep looking when there are additional partial matches
		binding = null;
	}
	return result;
}
 
Example #6
Source File: KeysPreferencePage.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
		protected void setValue(Object element, Object value) {
			if (column == 1) {
				// BindingElement activeBinding = (BindingElement) model.getSelectedElement();
				BindingElement activeBinding = (BindingElement) element;
				if (activeBinding != null) {
					KeySequence keySequence = fKeySequenceText.getKeySequence();
//					Bug #2740
					if (keySequence == null || !keySequence.toString().endsWith("+")) {
						activeBinding.setTrigger(keySequence);
					}
				}
				changeBackground();
				// isValid();
			}
		}
 
Example #7
Source File: KbdMacroSupport.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Check for a binding that is not a full command and was not handled by the minibuffer
 * Remove the partial binding and add the command id entry
 * 
 * @param cmdId
 * @param trigger
 * @param onExit - it is the endMacro command, ignore id entry
 */

void checkTrigger(String cmdId, Map<?,?> parameters, Event trigger, boolean onExit) {
	int index = macro.size() -1;
	if (!macro.isEmpty() && trigger != null && macro.get(index).isSubCmd()) {
		Event event = macro.get(index).getEvent();
		// have trigger and previous entry is a subCmd type 
		KeyStroke key = KeyStroke.getInstance(event.stateMask, Character.toUpperCase(event.keyCode));
		IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
		Collection<Binding> values = EmacsPlusUtils.getPartialMatches(bindingService,KeySequence.getInstance(key)).values();
		// Check partial binding
		for (Binding v : values) {
			if (cmdId.equals((v.getParameterizedCommand().getId()))) {
				// remove (possibly partial) binding
				macro.remove(index);
				// flag for minibuffer exit
				macro.add(new KbdEvent(true));
				break;
			}
		}
	}
	if (!onExit) {
		macro.add(new KbdEvent(cmdId, parameters));
	}
}
 
Example #8
Source File: KeyController2.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
private void addSetKeySequenceListener() {
		addPropertyChangeListener(new IPropertyChangeListener() {
			public void propertyChange(PropertyChangeEvent event) {
				if (BindingElement.PROP_TRIGGER.equals(event.getProperty())) {
//					Bug #2740
					if (((KeySequence) event.getNewValue()) != null) {
						if (((KeySequence) event.getNewValue()).toString().endsWith("+")) {
							return;
						} else {
							updateTrigger((BindingElement) event.getSource(), (KeySequence) event.getOldValue(),
									(KeySequence) event.getNewValue());
						}
					}
				}
			}
		});
	}
 
Example #9
Source File: KeysPreferencePage.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
		protected void setValue(Object element, Object value) {
			if (column == 1) {
				// BindingElement activeBinding = (BindingElement) model.getSelectedElement();
				BindingElement activeBinding = (BindingElement) element;
				if (activeBinding != null) {
					KeySequence keySequence = fKeySequenceText.getKeySequence();
//					Bug #2740
					if (keySequence == null || !keySequence.toString().endsWith("+")) {
						activeBinding.setTrigger(keySequence);
					}
				}
				changeBackground();
				// isValid();
			}
		}
 
Example #10
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 #11
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
private void addSetKeySequenceListener() {
		addPropertyChangeListener(new IPropertyChangeListener() {
			public void propertyChange(PropertyChangeEvent event) {
				if (BindingElement.PROP_TRIGGER.equals(event.getProperty())) {
//					Bug #2740
					if (((KeySequence) event.getNewValue()) != null) {
						if (((KeySequence) event.getNewValue()).toString().endsWith("+")) {
							return;
						} else {
							updateTrigger((BindingElement) event.getSource(), (KeySequence) event.getOldValue(),
									(KeySequence) event.getNewValue());
						}
					}
				}
			}
		});
	}
 
Example #12
Source File: RestartLaunchAction.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void update() {
    IProcess process = console.getProcess();
    setEnabled(true);
    KeySequence binding = KeyBindingHelper
            .getCommandKeyBinding("org.python.pydev.debug.ui.actions.relaunchLastAction");
    String str = binding != null ? "(" + binding.format() + " with focus on editor)" : "(unbinded)";
    if (process.canTerminate()) {
        this.setImageDescriptor(
                ImageCache.asImageDescriptor(SharedUiPlugin.getImageCache().getDescriptor(UIConstants.RELAUNCH)));
        this.setToolTipText("Restart the current launch. " + str);

    } else {
        this.setImageDescriptor(
                ImageCache.asImageDescriptor(SharedUiPlugin.getImageCache().getDescriptor(UIConstants.RELAUNCH1)));
        this.setToolTipText("Relaunch with the same configuration." + str);
    }
}
 
Example #13
Source File: KbdMacroLoadHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Bind the loaded macro to its previous key binding, removing any conflicts
 * 
 * @param editor
 * @param command - the new kbd macro command
 * @param sequence - key sequence for binding
 * @param previous - conflicting binding
 */
private void bindMacro(ITextEditor editor, Command command, KeySequence sequence, Binding previous) {
	if (command != null && sequence != null) {
		
		IBindingService service = (editor != null) ? (IBindingService) editor.getSite().getService(IBindingService.class) :
			(IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
		if (service instanceof  BindingService) {
			BindingService bindingMgr = (BindingService) service;
			if (previous != null) {
				bindingMgr.removeBinding(previous);
			}
			ParameterizedCommand p = new ParameterizedCommand(command, null);
			Binding binding = new KeyBinding(sequence, p,
					KBD_SCHEMEID, KBD_CONTEXTID, null, null, null, Binding.USER);
			bindingMgr.addBinding(binding);
			// check for conflicts independent of the current Eclipse context
			checkConflicts(bindingMgr,sequence,binding);
		}
	}				
}
 
Example #14
Source File: LangContentAssistProcessor.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void assistSessionStarted(ContentAssistEvent event) {
	if(event.processor != LangContentAssistProcessor.this)
		return;
	
	invocationIteration = 0;
	isAutoActivation = event.isAutoActivated;
	
	if (event.assistant instanceof IContentAssistantExtension2) {
		IContentAssistantExtension2 extension = (IContentAssistantExtension2) event.assistant;
		
		KeySequence binding = getGroupingIterationBinding();
		boolean repeatedModeEnabled = categories.size() > 1;
		
		setRepeatedModeStatus(extension, repeatedModeEnabled, binding);
	}
	
	listener_assistSessionStarted();
}
 
Example #15
Source File: KeysPreferencePage.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
		protected void setValue(Object element, Object value) {
			if (column == 1) {
				// BindingElement activeBinding = (BindingElement) model.getSelectedElement();
				BindingElement activeBinding = (BindingElement) element;
				if (activeBinding != null) {
					KeySequence keySequence = fKeySequenceText.getKeySequence();
//					Bug #2740
					if (keySequence == null || !keySequence.toString().endsWith("+")) {
						activeBinding.setTrigger(keySequence);
					}
				}
				changeBackground();
				// isValid();
			}
		}
 
Example #16
Source File: KeyBindingHelper.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean matchesKeybinding(int keyCode, int stateMask, KeySequence keySequence) {
    KeyStroke[] keyStrokes = keySequence.getKeyStrokes();

    for (KeyStroke keyStroke : keyStrokes) {

        if (keyStroke.getNaturalKey() == keyCode
                && ((keyStroke.getModifierKeys() & stateMask) != 0 || keyStroke.getModifierKeys() == stateMask)) {

            return true;
        }
    }
    return false;
}
 
Example #17
Source File: KeyBindingHelper.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param commandId the command we want to know about
 * @return the 'best' key sequence that will activate the given command
 */
public static KeySequence getCommandKeyBinding(String commandId) {
    Assert.isNotNull(commandId);
    IBindingService bindingSvc;
    try {
        bindingSvc = PlatformUI.getWorkbench()
                .getAdapter(IBindingService.class);
    } catch (IllegalStateException e) {
        return null;
    }

    TriggerSequence keyBinding = bindingSvc.getBestActiveBindingFor(commandId);
    if (keyBinding instanceof KeySequence) {
        return (KeySequence) keyBinding;
    }

    List<Tuple<Binding, ParameterizedCommand>> matches = new ArrayList<Tuple<Binding, ParameterizedCommand>>();
    //Ok, it may be that the binding we're looking for is not active, so, let's give a spin on all
    //the bindings
    Binding[] bindings = bindingSvc.getBindings();
    for (Binding binding : bindings) {
        ParameterizedCommand command = binding.getParameterizedCommand();
        if (command != null) {
            if (commandId.equals(command.getId())) {
                matches.add(new Tuple<Binding, ParameterizedCommand>(binding, command));
            }
        }
    }
    for (Tuple<Binding, ParameterizedCommand> tuple : matches) {
        if (tuple.o1.getTriggerSequence() instanceof KeySequence) {
            KeySequence keySequence = (KeySequence) tuple.o1.getTriggerSequence();
            return keySequence;
        }
    }

    return null;
}
 
Example #18
Source File: TerminateAllLaunchesAction.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public TerminateAllLaunchesAction() {
    KeySequence binding = KeyBindingHelper
            .getCommandKeyBinding("org.python.pydev.debug.ui.actions.terminateAllLaunchesAction");
    String str = binding != null ? "(" + binding.format() + " with focus on editor)" : "(unbinded)";

    this.setImageDescriptor(
            ImageCache.asImageDescriptor(SharedUiPlugin.getImageCache().getDescriptor(UIConstants.TERMINATE_ALL)));
    this.setToolTipText("Terminate ALL." + str);

    update();
}
 
Example #19
Source File: LangContentAssistProcessor.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
protected void setRepeatedModeStatus(IContentAssistantExtension2 caExt2, boolean enabled, KeySequence binding) {
	caExt2.setShowEmptyList(enabled);
	
	caExt2.setRepeatedInvocationMode(enabled);
	caExt2.setStatusLineVisible(enabled);
	if(enabled) {
		caExt2.setStatusMessage(createIterationMessage());
	}
	if (caExt2 instanceof IContentAssistantExtension3) {
		IContentAssistantExtension3 ext3 = (IContentAssistantExtension3) caExt2;
		ext3.setRepeatedInvocationTrigger(binding);
	}
}
 
Example #20
Source File: LangContentAssistProcessor.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
protected KeySequence getGroupingIterationBinding() {
IBindingService bindingSvc = (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class);
TriggerSequence binding = bindingSvc.getBestActiveBindingFor(
	ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
if(binding instanceof KeySequence)
	return (KeySequence) binding;
return null;
  }
 
Example #21
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 #22
Source File: UniversalMinibuffer.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.minibuffer.KeyHandlerMinibuffer#getResult(Binding, KeySequence, String)
 */
@Override
protected IBindingResult getResult(final Binding binding, final KeySequence trigger, String triggerString) {

	// key character is only > 0 if it is stand alone
	int charpoint = getKeyCharacter();
	String character = null;
	if (binding == null && charpoint > 0 && triggerCount < 2) {
		if (charpoint == SWT.CR || charpoint == SWT.LF) {
			character = getEol();
		} else if (charpoint == SWT.BS) {
			character = new String(Character.toChars(charpoint));
		} else if ((Character.isWhitespace(charpoint)) || (charpoint > ' ')) {
			character = new String(Character.toChars(charpoint));
		}
	}
	if (countBuf.length() > 0) {
		try {
			if (countBuf.length() == 1 && countBuf.charAt(0)== '-') {
				;	// just use argument Count
			} else {
				setArgumentCount(Integer.parseInt(countBuf.toString()));
			}
		} catch (NumberFormatException e) {
				// bad count
				setArgumentCount(1);
		}
	}
	final String key = character;
	final boolean notNumeric = countBuf.length() == 0 && argumentCount == 4;	// flag whether a number was entered into the minibuffer

	return new IUniversalResult() {
		public Binding getKeyBinding() { return binding; }
		public String getKeyString() { return key; }
		public int getCount() { return argumentCount; }
		public boolean isNumeric() { return !notNumeric; }
		public KeySequence getTrigger() { return trigger; }
	};
}
 
Example #23
Source File: AbstractMenuContributionItem.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void appendShortcut(ParameterizedCommand parameterizedCommand, MenuItem item) {
    TriggerSequence triggerSequence = eBindingService.getBestSequenceFor(parameterizedCommand);
    if (triggerSequence != null && triggerSequence instanceof KeySequence) {
        KeySequence keySequence = (KeySequence) triggerSequence;
        String rawLabel = item.getText();
        item.setText(String.format("%s  %s%s", rawLabel, '\t', keySequence.format()));
    }
}
 
Example #24
Source File: BindKeysHelper.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param force if true, we'll create the user binding regardless of having some existing binding. Otherwise,
 * we'll not allow the creation if a binding already exists for it.
 *
 * Note: conflicting bindings should be removed before (through removeUserBindingsWithFilter). If they're
 * not removed, a conflict will be created in the bindings.
 */
public void addUserBindings(KeySequence keySequence, ParameterizedCommand command) throws Exception {
    Scheme activeScheme = bindingService.getActiveScheme();
    String schemeId = activeScheme.getId();

    localChangeManager.addBinding(new KeyBinding(keySequence, command,
            schemeId, contextId, null, null, null, Binding.USER));

}
 
Example #25
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 #26
Source File: UniversalHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
private Event makeEvent(IUniversalResult ua) {
	Event result = new Event();
	KeySequence keys = ua.getTrigger();
	if (keys != null) {
		Trigger[] triggers = keys.getTriggers();
		if (triggers[0] instanceof KeyStroke) {	// really, all it can be anyway
			KeyStroke ks = (KeyStroke)triggers[triggers.length - 1];
			result.keyCode = ks.getNaturalKey();
			result.stateMask = ks.getModifierKeys() & SWT.MODIFIER_MASK;
		}
	}
	return result;
}
 
Example #27
Source File: EmacsHelpHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

	EmacsPlusConsole console = EmacsPlusConsole.getInstance();
	console.clear();
	console.activate();
	IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
	String id = (event.getCommand() != null ? event.getCommand().getId() : null);
	if (id != null) {
		try {
			TriggerSequence trigger = bindingService.getBestActiveBindingFor(event.getCommand().getId());
			Trigger[] trigs = trigger.getTriggers();
			KeyStroke key = (KeyStroke)trigs[0];
			Collection<Binding> partials = EmacsPlusUtils.getPartialMatches(bindingService,KeySequence.getInstance(key)).values();

			for (Binding bind : partials) {
				ParameterizedCommand cmd = bind.getParameterizedCommand();
				if (cmd.getId().startsWith(EmacsPlusUtils.MULGASOFT)) {
					console.printBold(bind.getTriggerSequence().toString());
					console.print(SWT.TAB + cmd.getCommand().getName());
					String desc =  cmd.getCommand().getDescription();
					if (desc != null) {
						desc = desc.replaceAll(CR, EMPTY_STR);
						console.print(" - " + desc + CR);	//$NON-NLS-1$ 
					} else {
						console.print(CR);
					}
				}
			}
		} catch (Exception e) {}
		console.setFocus(true);
	}
	return null;
}
 
Example #28
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 #29
Source File: KbdMacroLoadHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check for binding conflicts independent of the current Eclipse context
 * If the load is called from a non-editing context, any potential binding conflict will
 * not be detected; so look for conflicts in a context independent set of bindings.  
 * 
 * @param service
 * @param sequence
 * @param binding
 */
private void checkConflicts(BindingService service, KeySequence sequence, Binding binding) {
	Collection<Binding> conflicts = getTotalBindings().get(sequence);
	if (conflicts != null) {
		for (Binding conflict : conflicts) {
			if (conflict != binding
					&& binding.getContextId().equals(conflict.getContextId())
					&& binding.getSchemeId().equals(conflict.getSchemeId())) {
				service.removeBinding(conflict);
			}
		}
	}
}
 
Example #30
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;
}