use of org.eclipse.jface.bindings.TriggerSequence in project translationstudio8 by heartsome.
the class BindingModel2 method restoreBinding.
/**
* Restores the specified BindingElement. A refresh should be performed afterwards. The refresh may be done after
* several elements have been restored.
* @param element
*/
public void restoreBinding(BindingElement element) {
if (element == null) {
return;
}
Object modelObject = element.getModelObject();
ParameterizedCommand cmd = null;
if (modelObject instanceof ParameterizedCommand) {
cmd = (ParameterizedCommand) modelObject;
TriggerSequence trigger = bindingManager.getBestActiveBindingFor(cmd.getId());
Binding binding = bindingManager.getPerfectMatch(trigger);
if (binding != null && binding.getType() == Binding.SYSTEM) {
return;
}
} else if (modelObject instanceof KeyBinding) {
cmd = ((KeyBinding) modelObject).getParameterizedCommand();
}
// Remove any USER bindings
Binding[] managerBindings = bindingManager.getBindings();
ArrayList systemBindings = new ArrayList();
ArrayList removalBindings = new ArrayList();
for (int i = 0; i < managerBindings.length; i++) {
if (managerBindings[i].getParameterizedCommand() == null) {
removalBindings.add(managerBindings[i]);
} else if (managerBindings[i].getParameterizedCommand().equals(cmd)) {
if (managerBindings[i].getType() == Binding.USER) {
bindingManager.removeBinding(managerBindings[i]);
} else if (managerBindings[i].getType() == Binding.SYSTEM) {
systemBindings.add(managerBindings[i]);
}
}
}
// Clear the USER bindings for parameterized commands
Iterator i = systemBindings.iterator();
while (i.hasNext()) {
Binding sys = (Binding) i.next();
Iterator j = removalBindings.iterator();
while (j.hasNext()) {
Binding del = (Binding) j.next();
if (deletes(del, sys) && del.getType() == Binding.USER) {
bindingManager.removeBinding(del);
}
}
}
setSelectedElement(null);
bindingElements.remove(element);
bindingToElement.remove(modelObject);
commandToElement.remove(modelObject);
controller.firePropertyChange(this, PROP_BINDING_REMOVE, null, element);
}
use of org.eclipse.jface.bindings.TriggerSequence in project n4js by eclipse.
the class WorkspaceWizardPage method getActiveContentAssistBinding.
/**
* 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;
}
use of org.eclipse.jface.bindings.TriggerSequence in project egit by eclipse.
the class UIUtils method getKeystrokeOfBestActiveBindingFor.
/**
* Look up best active binding's keystroke for the given command
*
* @param commandId
* The identifier of the command for which the best active
* binding's keystroke should be retrieved; must not be null.
* @return {@code KeyStroke} for the best active binding for the specified
* commandId or {@code null} if no binding is defined or if the
* binding service returns a {@code TriggerSequence} containing more
* than one {@code Trigger}.
*/
@Nullable
public static KeyStroke getKeystrokeOfBestActiveBindingFor(String commandId) {
IBindingService bindingService = AdapterUtils.adapt(PlatformUI.getWorkbench(), IBindingService.class);
if (bindingService == null) {
return null;
}
TriggerSequence ts = bindingService.getBestActiveBindingFor(commandId);
if (ts == null)
return null;
Trigger[] triggers = ts.getTriggers();
if (triggers.length == 1 && triggers[0] instanceof KeyStroke)
return (KeyStroke) triggers[0];
else
return null;
}
use of org.eclipse.jface.bindings.TriggerSequence in project webtools.sourceediting by eclipse.
the class StructuredContentAssistProcessor method getIterationBinding.
/**
* @return {@link KeySequence} used by user to iterate to the next page
*/
private KeySequence getIterationBinding() {
final IBindingService bindingSvc = PlatformUI.getWorkbench().getAdapter(IBindingService.class);
TriggerSequence binding = bindingSvc.getBestActiveBindingFor(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
if (binding instanceof KeySequence)
return (KeySequence) binding;
return null;
}
use of org.eclipse.jface.bindings.TriggerSequence in project dbeaver by serge-rider.
the class ActionUtils method findCommandDescription.
@Nullable
public static String findCommandDescription(String commandId, IServiceLocator serviceLocator, boolean shortcutOnly, String paramName, String paramValue) {
String commandName = null;
String shortcut = null;
ICommandService commandService = serviceLocator.getService(ICommandService.class);
if (commandService != null) {
Command command = commandService.getCommand(commandId);
if (command != null && command.isDefined()) {
try {
commandName = command.getName();
} catch (NotDefinedException e) {
log.debug(e);
}
}
}
IBindingService bindingService = serviceLocator.getService(IBindingService.class);
if (bindingService != null) {
TriggerSequence sequence = null;
for (Binding b : bindingService.getBindings()) {
ParameterizedCommand parameterizedCommand = b.getParameterizedCommand();
if (parameterizedCommand != null && commandId.equals(parameterizedCommand.getId())) {
if (paramName != null) {
Object cmdParamValue = parameterizedCommand.getParameterMap().get(paramName);
if (!CommonUtils.equalObjects(cmdParamValue, paramValue)) {
continue;
}
}
sequence = b.getTriggerSequence();
break;
}
}
if (sequence == null) {
sequence = bindingService.getBestActiveBindingFor(commandId);
}
if (sequence != null) {
shortcut = sequence.format();
}
}
if (shortcutOnly) {
return shortcut == null ? "" : shortcut;
}
if (shortcut == null) {
return commandName;
}
if (commandName == null) {
return shortcut;
}
return commandName + " (" + shortcut + ")";
}
Aggregations