Example usage for org.eclipse.jface.bindings.keys KeyStroke getInstance

List of usage examples for org.eclipse.jface.bindings.keys KeyStroke getInstance

Introduction

In this page you can find the example usage for org.eclipse.jface.bindings.keys KeyStroke getInstance.

Prototype

public static final KeyStroke getInstance(final int modifierKeys, final int naturalKey) 

Source Link

Document

Creates an instance of KeyStroke given a set of modifier keys and a natural key.

Usage

From source file:com.aptana.editor.findbar.impl.FindBarActions.java

License:Open Source License

/**
 * Updates the list of commands -> binding available.
 *//*from ww  w  .  j a va2s.co m*/
public void updateCommandToBinding() {
    fCommandToBinding = getCommandToBindings();
    FindBarDecorator dec = findBarDecorator.get();
    if (dec != null) {
        // Whenever we get the bindings, update the tooltips accordingly.
        updateTooltip(TOGGLE_WORD_MATCHING_COMMAND_ID, Messages.FindBarDecorator_LABEL_WholeWord,
                dec.wholeWord);
        updateTooltip(TOGGLE_CASE_MATCHING_COMMAND_ID, Messages.FindBarDecorator_LABEL_CaseSensitive,
                dec.caseSensitive);
        if (dec.regularExpression != null) {
            updateTooltip(TOGGLE_REGEXP_MATCHING_COMMAND_ID, Messages.FindBarDecorator_LABEL_RegularExpression,
                    dec.regularExpression);
        }
        updateTooltip(TOGGLE_SEARCH_BACKWARD_COMMAND_ID, Messages.FindBarDecorator_LABEL_SearchBackward,
                dec.searchBackward);
        updateTooltip(TOGGLE_COUNT_MATCHES_COMMAND_ID, Messages.FindBarDecorator_TOOLTIP_ShowMatchCount,
                dec.countMatches);
        updateTooltip(TOGGLE_SEARCH_SELECTION_COMMAND_ID, Messages.FindBarDecorator_LABEL_SearchSelection,
                dec.searchSelection);
        updateTooltip(SHOW_OPTIONS_COMMAND_ID, Messages.FindBarDecorator_LABEL_ShowOptions, dec.options);

        String prevHistoryKey = KeySequence.getInstance(KeyStroke.getInstance(SWT.MOD1, SWT.ARROW_UP))
                .toString();
        String nextHistoryKey = KeySequence.getInstance(KeyStroke.getInstance(SWT.MOD1, SWT.ARROW_DOWN))
                .toString();

        List<TriggerSequence> bindings = fCommandToBinding.get(FOCUS_REPLACE_COMMAND_ID);
        if (!CollectionsUtil.isEmpty(bindings)) {
            List<TriggerSequence> newlineTriggers = fCommandToBinding.get(INPUT_NEWLINE_COMMAND_ID);
            List<String> triggers = new ArrayList<String>(newlineTriggers.size() + 1);
            triggers.add(bindings.get(0).toString());
            for (TriggerSequence sequence : newlineTriggers) {
                triggers.add(sequence.toString());
            }

            if (triggers.size() < 3) {
                triggers.add(StringUtil.EMPTY);
            }

            triggers.add(prevHistoryKey);
            triggers.add(nextHistoryKey);

            dec.textReplace
                    .setToolTipText(MessageFormat.format(Messages.FindBarActions_TOOLTIP_FocusReplaceCombo,
                            triggers.toArray(new Object[triggers.size()])));
        }

        bindings = fCommandToBinding.get(FOCUS_FIND_COMMAND_ID);
        if (!CollectionsUtil.isEmpty(bindings)) {
            List<TriggerSequence> newlineTriggers = fCommandToBinding.get(INPUT_NEWLINE_COMMAND_ID);
            List<String> triggers = new ArrayList<String>(newlineTriggers.size() + 1);
            triggers.add(bindings.get(0).toString());
            for (TriggerSequence sequence : newlineTriggers) {
                triggers.add(sequence.toString());
            }

            if (triggers.size() < 3) {
                triggers.add(StringUtil.EMPTY);
            }

            triggers.add(prevHistoryKey);
            triggers.add(nextHistoryKey);

            dec.textFind.setToolTipText(MessageFormat.format(Messages.FindBarActions_TOOLTIP_FocusFindCombo,
                    triggers.toArray(new Object[triggers.size()])));
        }
    }

}

From source file:com.aptana.git.ui.dialogs.CompareWithDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);

    // The explanatory message
    Label description = new Label(composite, SWT.WRAP);
    description.setText(Messages.CompareWithDialog_Message);
    description.setLayoutData(GridDataFactory.fillDefaults().hint(250, 70).create());

    // A label and combo with CA for choosing the ref to compare with
    Composite group = new Composite(composite, SWT.NONE);
    group.setLayout(new GridLayout(2, false));
    group.setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BEGINNING).hint(250, 30).create());

    Label label = new Label(group, SWT.NONE);
    label.setText(Messages.CompareWithDialog_Ref_label);

    refText = new Combo(group, SWT.SINGLE | SWT.BORDER | SWT.DROP_DOWN);
    refText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
    refText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            refValue = refText.getText();

            // In case they picked a commit, grab only the SHA (shortened)
            int index = refValue.indexOf(' ');
            if (index != -1) {
                refValue = refValue.substring(0, index);
            }/*www.j  a v  a  2s . c o m*/
            validate();
        }
    });

    // populate possible common values: HEAD, branches, tags, commits
    refText.add(GitRepository.HEAD);
    for (GitRef ref : simpleRefs) {
        refText.add(ref.shortName());
    }
    for (GitCommit commit : commits) {
        refText.add(commitMessage(commit));
    }
    // set default value of HEAD
    refText.setText(refValue = GitRepository.HEAD);

    SearchingContentProposalProvider proposalProvider = new SearchingContentProposalProvider();
    ContentProposalAdapter adapter = new ContentProposalAdapter(refText, new ComboContentAdapter(),
            proposalProvider, KeyStroke.getInstance(SWT.CONTROL, ' '), null);
    adapter.setPropagateKeys(true);
    adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);

    ControlDecoration decoration = new ControlDecoration(refText, SWT.LEFT);
    decoration.setImage(FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL).getImage());

    updateStatus(Status.OK_STATUS);
    return composite;
}

From source file:com.aptana.git.ui.dialogs.CreateBranchDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    // Add an advanced section so users can specify a start point ref (so they can create a branch that
    // tracks a remote branch!)
    Composite composite = (Composite) super.createDialogArea(parent);

    // TODO Add a minimize/maximize button for the advanced section
    Group group = new Group(composite, SWT.DEFAULT);
    group.setText(Messages.CreateBranchDialog_AdvancedOptions_label);
    group.setLayout(new GridLayout(1, false));
    group.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));

    Label label = new Label(group, SWT.NONE);
    label.setText(Messages.CreateBranchDialog_StartPoint_label);

    startPointText = new Text(group, getInputTextStyle());
    startPointText.setText(repo.headRef().simpleRef().shortName());
    startPointText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
    startPointText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            startPoint = startPointText.getText();
            // TODO Validate the start point. Must be branch name, commit id or tag ref

            if (startPoint.indexOf('/') != -1 && autoTrack) {
                // If name is a remote branch, turn on track by default?
                for (String remoteName : repo.remotes()) {
                    if (startPoint.startsWith(remoteName + '/')) {
                        trackButton.setSelection(true);
                        track = true;/*from  w w  w.j a v  a2 s.co  m*/
                        break;
                    }
                }
            }
        }
    });

    Set<String> simpleRefs = repo.allSimpleRefs();
    String[] proposals = simpleRefs.toArray(new String[simpleRefs.size()]);

    new AutoCompleteField(startPointText, new TextContentAdapter(), proposals);

    // Have CTRL+SPACE also trigger content assist
    SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider(proposals);
    proposalProvider.setFiltering(true);
    ContentProposalAdapter adapter = new ContentProposalAdapter(startPointText, new TextContentAdapter(),
            proposalProvider, KeyStroke.getInstance(SWT.CONTROL, ' '), null);
    adapter.setPropagateKeys(true);
    adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);

    ControlDecoration decoration = new ControlDecoration(startPointText, SWT.LEFT);
    decoration.setImage(FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL).getImage());

    trackButton = new Button(group, SWT.CHECK);
    trackButton.setText(Messages.CreateBranchDialog_Track_label);
    trackButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            track = trackButton.getSelection();
            autoTrack = false; // don't change the value since user modified it here.
        }
    });
    return composite;
}

From source file:com.aptana.git.ui.dialogs.CreateTagDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);

    Label tagNameLabel = new Label(composite, SWT.NONE);
    tagNameLabel.setText(Messages.CreateTagDialog_Message);

    tagNameText = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
    tagNameText.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(300, 100).create());
    tagNameText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            tagName = tagNameText.getText();
            validate();/*from   www. jav a  2s.  c o  m*/
        }
    });

    Label tagMessageLabel = new Label(composite, SWT.NONE);
    tagMessageLabel.setText(Messages.CreateTagDialog_Message_label);

    messageText = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
    messageText.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(300, 100).create());
    messageText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            message = messageText.getText();
            validate();
        }
    });

    // TODO Add a minimize/maximize button for the advanced section
    Group group = new Group(composite, SWT.DEFAULT);
    group.setText(Messages.CreateTagDialog_AdvancedOptions_label);
    group.setLayout(new GridLayout(1, false));
    group.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));

    Label tagRevLabel = new Label(group, SWT.NONE);
    tagRevLabel.setText(Messages.CreateTagDialog_StartPoint_label);

    startPointText = new Combo(group, SWT.SINGLE | SWT.BORDER | SWT.DROP_DOWN);
    startPointText.setText(startPoint = GitRepository.HEAD);
    startPointText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
    startPointText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            startPoint = startPointText.getText();
            // In case they picked a commit, grab only the SHA (shortened)
            int index = startPoint.indexOf(' ');
            if (index != -1) {
                startPoint = startPoint.substring(0, index);
            }
            validate();
        }
    });

    for (GitCommit commit : commits) {
        startPointText.add(commitMessage(commit));
    }

    SearchingContentProposalProvider proposalProvider = new SearchingContentProposalProvider(commits);
    ContentProposalAdapter adapter = new ContentProposalAdapter(startPointText, new ComboContentAdapter(),
            proposalProvider, KeyStroke.getInstance(SWT.CONTROL, ' '), null);
    adapter.setPropagateKeys(true);
    adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);

    ControlDecoration decoration = new ControlDecoration(startPointText, SWT.LEFT);
    decoration.setImage(FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL).getImage());

    return composite;
}

From source file:com.mulgasoft.emacsplus.commands.IndentForTabHandler.java

License:Open Source License

/**
 * Return the exact binding if it exists and is enabled, else null
 * //from  w  w  w .  ja  v a2  s  .co  m
 * @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;
}

From source file:com.mulgasoft.emacsplus.EmacsPlusActivation.java

License:Open Source License

/**
 * Disable bindings that would interfere with Ctrl digit-argument bindings
 * If disableEmacs is true, then disable Emacs+ Ctrl arguments instead
 * This requires the internal BindingService.removeBinding method
 * /*from  w ww .j  ava 2s . c  o  m*/
 * @param editor
 * @param stateMask
 * @param keys
 * @param disableEmacs - if true, invert interpretation
 * @return the collection of disabled bindings
 */
private Collection<Binding> disableBindings(IEditorPart editor, int stateMask, char[] keys,
        boolean disableEmacs) {
    Collection<Binding> removed = null;
    BindingService bs = getBindingService();
    // only works if we get access to internal Binding Service
    if (bs != null) {
        // cache this as its a bit expensive to compute
        Map<TriggerSequence, Collection<Binding>> total = (disableEmacs ? getTotalBindings() : null);
        for (char key : keys) {
            KeySequence trigger = KeySequence.getInstance(KeyStroke.getInstance(stateMask, key));
            Binding b = bs.getPerfectMatch(trigger);
            boolean ise;
            if (b != null) {
                if ((!(ise = isEmacsBinding(b)) && !disableEmacs)
                        || (ise && disableEmacs && hasVariants(bs, total, trigger))) {
                    bs.removeBinding(b);
                    if (removed == null) {
                        removed = new ArrayList<Binding>();
                    }
                    removed.add(b);
                    b = bs.getPerfectMatch(trigger);
                }
            }
            if (!disableEmacs) {
                Map<TriggerSequence, Binding> bindings = EmacsPlusUtils.getPartialMatches(bs, trigger);
                if (!bindings.isEmpty()) {
                    Collection<Binding> r = removeBindings(bindings.values(), bs, editor);
                    if (r != null) {
                        if (removed == null) {
                            removed = r;
                        } else {
                            removed.addAll(r);
                        }
                    }
                }
            }
        }
    }
    return removed;
}

From source file:com.mulgasoft.emacsplus.EmacsPlusActivation.java

License:Open Source License

/**
 * Check for presence of digit-argument bindings
 * /*  w ww. j a  va2  s  .c  o m*/
 * @return true if digit-argument is relevant
 */
public boolean hasDigitBindings(boolean force) {
    boolean result = false;
    // The normal binding service returns the 'current' bindings, so we must get the context free set
    if (force || ctrlBindings == null) {
        Map<TriggerSequence, Collection<Binding>> bindings = getTotalBindings();
        if (!bindings.isEmpty()) {
            int modifier = EmacsPlusUtils.isMac() ? SWT.COMMAND : SWT.CTRL;
            // kludge: just see of <MODIFIER>+0 is bound in our binding scheme (universal-argument)
            Collection<Binding> binds = bindings
                    .get(KeySequence.getInstance(KeyStroke.getInstance(modifier, '0')));
            if (binds != null) {
                for (Binding b : binds) {
                    if (IEmacsPlusCommandDefinitionIds.UNIVERSAL_ARGUMENT
                            .equals(b.getParameterizedCommand().getId())) {
                        result = true;
                        break;
                    }
                }
            }
            ctrlBindings = result;
        }
    } else {
        result = ctrlBindings;
    }
    return result;
}

From source file:com.mulgasoft.emacsplus.minibuffer.ISearchMinibuffer.java

License:Open Source License

/**
 * Dynamically determine the bindings for forward and reverse i-search
 * For repeat search, Emacs treats i-search and i-search-regexp identically
 * /*from  w  w  w .  j  a  v  a 2  s. c o  m*/
 * @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;
}

From source file:com.mulgasoft.emacsplus.minibuffer.KeyHandlerMinibuffer.java

License:Open Source License

private KeyStroke getKey(int state, int keyCode, int character) {
    int result = keyCode;
    if (state == 0 && keys.size() == 0) {
        result = keyCode;//  w w  w . j  a  v a2 s  . com
    } else if (state == SWT.SHIFT) {
        // handle characters with different shift values
        state = 0;
        result = character;
    } else {
        result = Character.toUpperCase(keyCode);
    }
    return KeyStroke.getInstance(state, result);
}

From source file:com.mulgasoft.emacsplus.minibuffer.UniversalMinibuffer.java

License:Open Source License

/**
 * Adapt the prefix display in the minibuffer to the actual key binding
 * /*from  w ww .j  a v a  2s .  c  o m*/
 * @param keyCode
 * @param stateMask
 * @return the trigger string
 */
public String getTrigger(int keyCode, int stateMask) {
    StringBuilder result = new StringBuilder();
    String c = new String(Character.toChars(keyCode));
    switch (stateMask) {
    case SWT.CTRL:
        result.append(CPREFIX);
        result.append(c);
        break;
    case SWT.ALT:
        result.append(MPREFIX);
        result.append(c);
        break;
    case SWT.CTRL | SWT.ALT:
        result.append(CPREFIX);
        result.append(MPREFIX);
        result.append(c);
        break;
    default:
        result.append(KeyStroke.getInstance(stateMask, keyCode).format());
    }
    if (result.length() > 0) {
        result.append(' ');
    }
    return result.toString();
}