use of org.eclipse.jface.bindings.TriggerSequence in project dbeaver by dbeaver.
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 + ")";
}
use of org.eclipse.jface.bindings.TriggerSequence in project hale by halestudio.
the class SourceViewerKeyBindings method installDeleteLine.
/**
* Install the ability to delete a line through <code>CTRL+D</code> on a
* text viewer.
*
* @param viewer the text viewer
*/
public static void installDeleteLine(final TextViewer viewer) {
try {
final TriggerSequence trigger = KeySequence.getInstance("CTRL+D");
viewer.appendVerifyKeyListener(new VerifyKeyListener() {
@Override
public void verifyKey(VerifyEvent event) {
int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(event);
KeySequence sequence = KeySequence.getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator));
if (trigger.equals(sequence)) {
// determine the current selection
int startOffset;
int endOffset;
Point sel = viewer.getTextWidget().getSelectionRange();
if (sel != null) {
startOffset = sel.x;
endOffset = startOffset + sel.y;
} else {
startOffset = viewer.getTextWidget().getCaretOffset();
endOffset = startOffset;
}
try {
// determine the involved lines
IDocument doc = viewer.getDocument();
int startLine = doc.getLineOfOffset(startOffset);
int endLine = doc.getLineOfOffset(endOffset);
// derive start and end offset
startOffset = doc.getLineOffset(startLine);
if (startLine != endLine) {
// delete multiple lines
endOffset = doc.getLineOffset(endLine) + doc.getLineLength(endLine);
} else {
// delete one line
endOffset = startOffset + doc.getLineLength(endLine);
}
// delete the line
doc.replace(startOffset, endOffset - startOffset, "");
event.doit = false;
} catch (Exception e) {
log.warn("Failed to delete line in document", e);
}
}
}
});
} catch (ParseException e) {
log.error("Failed to install delete line listener on source viewer", e);
}
}
use of org.eclipse.jface.bindings.TriggerSequence in project hale by halestudio.
the class SourceViewerUndoSupport method install.
/**
* Adds undo support to the given source viewer. Should only be called if
* for this viewer the undo/redo support is not provided through the
* workbench.
*
* @param viewer the source viewer
*/
public static void install(final SourceViewer viewer) {
IBindingService bs = PlatformUI.getWorkbench().getService(IBindingService.class);
TriggerSequence undo = null;
TriggerSequence redo = null;
if (bs != null) {
undo = bs.getBestActiveBindingFor(IWorkbenchCommandConstants.EDIT_UNDO);
redo = bs.getBestActiveBindingFor(IWorkbenchCommandConstants.EDIT_REDO);
/*
* Note: Curiously this need not be the same as what is displayed in
* the main menu. When testing on Linux, CTRL+SHIT+Z was the binding
* in the main menu, but here CTRL+Y was returned.
*/
}
try {
// fall-back bindings
if (undo == null) {
undo = KeySequence.getInstance("M1+Z");
}
if (redo == null) {
redo = KeySequence.getInstance("M1+Y");
}
final TriggerSequence undoSeq = undo;
final TriggerSequence redoSeq = redo;
viewer.getTextWidget().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(e);
KeySequence sequence = KeySequence.getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator));
if (sequence.equals(undoSeq)) {
IUndoManager um = viewer.getUndoManager();
if (um.undoable()) {
um.undo();
}
} else if (sequence.equals(redoSeq)) {
IUndoManager um = viewer.getUndoManager();
if (um.redoable()) {
um.redo();
}
}
}
});
} catch (ParseException e) {
log.error("Could not created key sequences for source viewer undo/redo support", e);
}
}
use of org.eclipse.jface.bindings.TriggerSequence in project hale by halestudio.
the class GroovyScriptPage method addActions.
@Override
protected void addActions(ToolBar toolbar, final CompilingSourceViewer<GroovyAST> viewer) {
super.addActions(toolbar, viewer);
try {
final TriggerSequence astTrigger = KeySequence.getInstance("F8");
viewer.appendVerifyKeyListener(new VerifyKeyListener() {
@Override
public void verifyKey(VerifyEvent event) {
int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(event);
KeySequence sequence = KeySequence.getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator));
if (astTrigger.equals(sequence)) {
GroovyASTTray.showTray(GroovyScriptPage.this, viewer);
event.doit = false;
}
}
});
} catch (Exception e) {
log.error("Error installing AST view listener", e);
}
}
use of org.eclipse.jface.bindings.TriggerSequence in project translationstudio8 by heartsome.
the class ConflictModel2 method updateConflictsFor.
public void updateConflictsFor(BindingElement newValue, TriggerSequence oldTrigger, TriggerSequence newTrigger, boolean removal) {
Collection matches = (Collection) conflictsMap.get(newValue);
if (matches != null) {
if (newTrigger == null || removal) {
// we need to clear this match
matches.remove(newValue);
conflictsMap.remove(newValue);
if (matches == conflicts) {
controller.firePropertyChange(this, PROP_CONFLICTS_REMOVE, null, newValue);
}
if (matches.size() == 1) {
BindingElement tbe = (BindingElement) matches.iterator().next();
conflictsMap.remove(tbe);
tbe.setConflict(Boolean.FALSE);
if (matches == conflicts) {
setConflicts(null);
}
}
return;
} else if (oldTrigger != null && !newTrigger.equals(oldTrigger)) {
// we need to clear this match
matches.remove(newValue);
conflictsMap.remove(newValue);
if (matches == conflicts) {
controller.firePropertyChange(this, PROP_CONFLICTS_REMOVE, null, newValue);
}
if (matches.size() == 1) {
BindingElement tbe = (BindingElement) matches.iterator().next();
conflictsMap.remove(tbe);
tbe.setConflict(Boolean.FALSE);
if (matches == conflicts) {
setConflicts(null);
}
}
} else {
return;
}
}
if (newValue.getTrigger() == null || !(newValue.getModelObject() instanceof Binding)) {
return;
}
Binding binding = (Binding) newValue.getModelObject();
TriggerSequence trigger = binding.getTriggerSequence();
matches = (Collection) bindingManager.getActiveBindingsDisregardingContext().get(trigger);
ArrayList localConflicts = new ArrayList();
if (matches != null) {
localConflicts.add(newValue);
Iterator i = matches.iterator();
while (i.hasNext()) {
Binding b = (Binding) i.next();
// Bug #2740 快捷键--快捷键设置问题:修改验证冲突快捷键的方法,使用以下的方式,原来使用的是上面注释的方式
if (binding != b && !b.getParameterizedCommand().getCommand().toString().equals(binding.getParameterizedCommand().getCommand().toString())) {
Object element = bindingModel.getBindingToElement().get(b);
if (element != null) {
localConflicts.add(element);
}
}
}
}
if (localConflicts.size() > 1) {
// first find if it is already a conflict collection
Collection knownConflicts = null;
Iterator i = localConflicts.iterator();
while (i.hasNext() && knownConflicts == null) {
BindingElement tbe = (BindingElement) i.next();
knownConflicts = (Collection) conflictsMap.get(tbe);
}
if (knownConflicts != null) {
knownConflicts.add(newValue);
conflictsMap.put(newValue, knownConflicts);
newValue.setConflict(Boolean.TRUE);
if (knownConflicts == conflicts) {
controller.firePropertyChange(this, PROP_CONFLICTS_ADD, null, newValue);
} else if (newValue == getSelectedElement()) {
setConflicts(knownConflicts);
}
return;
}
boolean isSelected = false;
i = localConflicts.iterator();
while (i.hasNext()) {
BindingElement tbe = (BindingElement) i.next();
if (tbe != null) {
conflictsMap.put(tbe, localConflicts);
tbe.setConflict(Boolean.TRUE);
}
if (tbe == getSelectedElement()) {
isSelected = true;
}
}
if (isSelected) {
setConflicts(localConflicts);
}
}
}
Aggregations