Search in sources :

Example 1 with KeySequence

use of org.eclipse.jface.bindings.keys.KeySequence in project translationstudio8 by heartsome.

the class PluginConfigManageDialog method createShortcutKeyGoup.

/**
	 * 创建快捷键面板
	 * @param tparent
	 *            ;
	 */
private void createShortcutKeyGoup(Composite tparent) {
    Group group = new Group(tparent, SWT.None);
    group.setText(Messages.getString("dialog.PluginConfigManageDialog.group"));
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(group);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(group);
    Label keyLbl = new Label(group, SWT.NONE);
    keyLbl.setText(Messages.getString("dialog.PluginConfigManageDialog.keyLbl"));
    keyTxt = new Text(group, SWT.BORDER);
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(keyTxt);
    fKeySequenceText = new KeySequenceText(keyTxt);
    fKeySequenceText.setKeyStrokeLimit(4);
    fKeySequenceText.addPropertyChangeListener(new IPropertyChangeListener() {

        public final void propertyChange(final PropertyChangeEvent event) {
            if (!event.getOldValue().equals(event.getNewValue())) {
                final KeySequence keySequence = fKeySequenceText.getKeySequence();
                if (!keySequence.isComplete()) {
                    return;
                }
                keyTxt.setSelection(keyTxt.getTextLimit());
            }
        }
    });
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) Group(org.eclipse.swt.widgets.Group) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Label(org.eclipse.swt.widgets.Label) KeySequenceText(org.eclipse.jface.bindings.keys.KeySequenceText) Text(org.eclipse.swt.widgets.Text) KeySequenceText(org.eclipse.jface.bindings.keys.KeySequenceText) KeySequence(org.eclipse.jface.bindings.keys.KeySequence)

Example 2 with KeySequence

use of org.eclipse.jface.bindings.keys.KeySequence in project eclipse.platform.text by eclipse.

the class CompletionProposalPopup method addCommandSupport.

/**
 * Adds command support to the given control.
 *
 * @param control the control to watch for focus
 * @since 3.2
 */
private void addCommandSupport(final Control control) {
    final KeySequence commandSequence = fContentAssistant.getRepeatedInvocationKeySequence();
    if (commandSequence != null && !commandSequence.isEmpty() && fContentAssistant.isRepeatedInvocationMode()) {
        control.addFocusListener(new FocusListener() {

            private CommandKeyListener fCommandKeyListener;

            @Override
            public void focusGained(FocusEvent e) {
                if (Helper.okToUse(control)) {
                    if (fCommandKeyListener == null) {
                        fCommandKeyListener = new CommandKeyListener(commandSequence);
                        fProposalTable.addKeyListener(fCommandKeyListener);
                    }
                }
            }

            @Override
            public void focusLost(FocusEvent e) {
                if (fCommandKeyListener != null) {
                    control.removeKeyListener(fCommandKeyListener);
                    fCommandKeyListener = null;
                }
            }
        });
    }
    if (fAdditionalInfoController != null) {
        control.addFocusListener(new FocusListener() {

            private TraverseListener fTraverseListener;

            @Override
            public void focusGained(FocusEvent e) {
                if (Helper.okToUse(control)) {
                    if (fTraverseListener == null) {
                        fTraverseListener = new TraverseListener() {

                            @Override
                            public void keyTraversed(TraverseEvent event) {
                                if (event.detail == SWT.TRAVERSE_TAB_NEXT) {
                                    IInformationControl iControl = fAdditionalInfoController.getCurrentInformationControl2();
                                    if (fAdditionalInfoController.getInternalAccessor().canReplace(iControl)) {
                                        fAdditionalInfoController.getInternalAccessor().replaceInformationControl(true);
                                        event.doit = false;
                                    }
                                }
                            }
                        };
                        fProposalTable.addTraverseListener(fTraverseListener);
                    }
                }
            }

            @Override
            public void focusLost(FocusEvent e) {
                if (fTraverseListener != null) {
                    control.removeTraverseListener(fTraverseListener);
                    fTraverseListener = null;
                }
            }
        });
    }
}
Also used : TraverseEvent(org.eclipse.swt.events.TraverseEvent) IInformationControl(org.eclipse.jface.text.IInformationControl) TraverseListener(org.eclipse.swt.events.TraverseListener) KeySequence(org.eclipse.jface.bindings.keys.KeySequence) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 3 with KeySequence

use of org.eclipse.jface.bindings.keys.KeySequence in project archi by archimatetool.

the class FullScreenAction method addKeyBinding.

/**
 * Add a Key binding mapped to an Action
 */
private void addKeyBinding(ActionRegistry registry, IBindingService service, ActionFactory actionFactory) {
    KeySequence seq = (KeySequence) service.getBestActiveBindingFor(actionFactory.getCommandId());
    if (seq != null && seq.getKeyStrokes().length > 0) {
        KeyStroke ks = seq.getKeyStrokes()[0];
        keyBindings.add(new KeyBinding(ks.getModifierKeys(), Character.toLowerCase(ks.getNaturalKey()), registry.getAction(actionFactory.getId())));
    }
}
Also used : KeyStroke(org.eclipse.jface.bindings.keys.KeyStroke) KeySequence(org.eclipse.jface.bindings.keys.KeySequence)

Example 4 with KeySequence

use of org.eclipse.jface.bindings.keys.KeySequence 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;
}
Also used : TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) KeyStroke(org.eclipse.jface.bindings.keys.KeyStroke) IBindingService(org.eclipse.ui.keys.IBindingService) KeySequence(org.eclipse.jface.bindings.keys.KeySequence)

Example 5 with KeySequence

use of org.eclipse.jface.bindings.keys.KeySequence 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;
}
Also used : TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) IBindingService(org.eclipse.ui.keys.IBindingService) KeySequence(org.eclipse.jface.bindings.keys.KeySequence)

Aggregations

KeySequence (org.eclipse.jface.bindings.keys.KeySequence)14 TriggerSequence (org.eclipse.jface.bindings.TriggerSequence)7 IBindingService (org.eclipse.ui.keys.IBindingService)5 KeyStroke (org.eclipse.jface.bindings.keys.KeyStroke)3 ParseException (org.eclipse.jface.bindings.keys.ParseException)2 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)2 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)2 VerifyKeyListener (org.eclipse.swt.custom.VerifyKeyListener)2 VerifyEvent (org.eclipse.swt.events.VerifyEvent)2 Point (org.eclipse.swt.graphics.Point)2 BindingElement (org.eclipse.ui.internal.keys.model.BindingElement)2 Collection (java.util.Collection)1 MultipleCompilationErrorsException (org.codehaus.groovy.control.MultipleCompilationErrorsException)1 SyntaxException (org.codehaus.groovy.syntax.SyntaxException)1 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 Binding (org.eclipse.jface.bindings.Binding)1 KeyBinding (org.eclipse.jface.bindings.keys.KeyBinding)1 KeySequenceText (org.eclipse.jface.bindings.keys.KeySequenceText)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1