Java 类org.eclipse.ui.internal.keys.BindingService 实例源码

项目:APICloud-Studio    文件:KeyBindingHelper.java   
public static void handleEvent(Event e)
{
    IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class);

    Listener keyDownFilter = ((BindingService) bindingService).getKeyboard().getKeyDownFilter();
    boolean enabled = bindingService.isKeyFilterEnabled();
    Control focusControl = e.display.getFocusControl();
    try
    {
        bindingService.setKeyFilterEnabled(true);
        keyDownFilter.handleEvent(e);
    }
    finally
    {
        if (focusControl == e.display.getFocusControl()) // $codepro.audit.disable useEquals
        {
            bindingService.setKeyFilterEnabled(enabled);
        }
    }
}
项目:translationstudio8    文件:KeyAssistHandler.java   
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbench workbench = PlatformUI.getWorkbench();
    IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
    BindingService service = (BindingService) bindingService;
    ArrayList<Binding> lstBinding = new ArrayList<Binding>(Arrays.asList(bindingService.getBindings()));
    List<String> lstRemove = Constants.lstRemove;
    Iterator<Binding> it = lstBinding.iterator();
    while (it.hasNext()) {
        Binding binding = it.next();
        ParameterizedCommand pCommand = binding.getParameterizedCommand();
        if (pCommand == null || lstRemove.contains(pCommand.getCommand().getId())) {
            it.remove();
        }
    }
    service.getKeyboard().openKeyAssistShell(lstBinding);
    return null;
}
项目:tmxeditor8    文件:KeyAssistHandler.java   
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbench workbench = PlatformUI.getWorkbench();
    IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
    BindingService service = (BindingService) bindingService;
    ArrayList<Binding> lstBinding = new ArrayList<Binding>(Arrays.asList(bindingService.getBindings()));
    List<String> lstRemove = Constants.lstRemove;
    Iterator<Binding> it = lstBinding.iterator();
    while (it.hasNext()) {
        Binding binding = it.next();
        ParameterizedCommand pCommand = binding.getParameterizedCommand();
        if (pCommand == null || lstRemove.contains(pCommand.getCommand().getId())) {
            it.remove();
        }
    }
    service.getKeyboard().openKeyAssistShell(lstBinding);
    return null;
}
项目:e4macs    文件:KbdMacroLoadHandler.java   
/**
 * 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);
        }
    }               
}
项目:translationstudio8    文件:KeyController2.java   
@SuppressWarnings("restriction")
public void filterDupliteBind(){
    IWorkbench workbench = PlatformUI.getWorkbench();
    IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
    BindingService service =(BindingService)bindingService;
    BindingManager bindingManager = service.getBindingManager();
    //service.getBindingManager().
    Binding[] bindings = bindingManager.getBindings();
     List<Binding> bindTemp = new ArrayList<Binding>();
     List<String> ids = new ArrayList<String>();
     for(Binding bind : bindings){
        if(null ==bind){
            continue;
        }
        ParameterizedCommand command = bind.getParameterizedCommand();
        if(null == command){
            continue;
        }
        String id = command.getId();
        if(!ids.contains(id)){
            ids.add(id);
            bindTemp.add(bind);
        }
    }

     bindingManager.setBindings(bindTemp.toArray(new Binding[ids.size()]));
}
项目:tmxeditor8    文件:KeyController2.java   
@SuppressWarnings("restriction")
public void filterDupliteBind(){
    IWorkbench workbench = PlatformUI.getWorkbench();
    IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
    BindingService service =(BindingService)bindingService;
    BindingManager bindingManager = service.getBindingManager();
    //service.getBindingManager().
    Binding[] bindings = bindingManager.getBindings();
     List<Binding> bindTemp = new ArrayList<Binding>();
     List<String> ids = new ArrayList<String>();
     for(Binding bind : bindings){
        if(null ==bind){
            continue;
        }
        ParameterizedCommand command = bind.getParameterizedCommand();
        if(null == command){
            continue;
        }
        String id = command.getId();
        if(!ids.contains(id)){
            ids.add(id);
            bindTemp.add(bind);
        }
    }

     bindingManager.setBindings(bindTemp.toArray(new Binding[ids.size()]));
}
项目:tmxeditor8    文件:KeyController2.java   
@SuppressWarnings("restriction")
public void filterDupliteBind(){
    IWorkbench workbench = PlatformUI.getWorkbench();
    IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
    BindingService service =(BindingService)bindingService;
    BindingManager bindingManager = service.getBindingManager();
    //service.getBindingManager().
    Binding[] bindings = bindingManager.getBindings();
     List<Binding> bindTemp = new ArrayList<Binding>();
     List<String> ids = new ArrayList<String>();
     for(Binding bind : bindings){
        if(null ==bind){
            continue;
        }
        ParameterizedCommand command = bind.getParameterizedCommand();
        if(null == command){
            continue;
        }
        String id = command.getId();
        if(!ids.contains(id)){
            ids.add(id);
            bindTemp.add(bind);
        }
    }

     bindingManager.setBindings(bindTemp.toArray(new Binding[ids.size()]));
}
项目:e4macs    文件:KbdMacroBindHandler.java   
/**
 * Add the binding to the Emacs+ scheme
 * 
 * @param editor
 * @param bindingResult
 */
private void addBinding(ITextEditor editor, IBindingResult bindingResult, String name) {
    IBindingService service = (IBindingService) editor.getSite().getService(IBindingService.class);
    if (service instanceof  BindingService) {
        try {
            BindingService bindingMgr = (BindingService) service;
            if (bindingResult.getKeyBinding() != null) {
                // we're overwriting a binding, out with the old
                bindingMgr.removeBinding(bindingResult.getKeyBinding());
            }
            Command command = null;
            if (name != null) {
                ICommandService ics = (ICommandService) editor.getSite().getService(ICommandService.class);
                String id = EmacsPlusUtils.kbdMacroId(name);
                // check first, as getCommand will create it if it doesn't already exist
                if (ics.getDefinedCommandIds().contains(id)) {
                    command = ics.getCommand(id);
                }
            } else {
                // use the unexposed category
                command = nameKbdMacro(KBD_LNAME + nameid++, editor, KBD_GAZONK);
            }
            if (command != null) {
                Binding binding = new KeyBinding(bindingResult.getTrigger(), new ParameterizedCommand(command, null),
                        KBD_SCHEMEID, KBD_CONTEXTID, null, null, null, Binding.USER);
                bindingMgr.addBinding(binding);
                asyncShowMessage(editor, String.format(BOUND, bindingResult.getKeyString()), false);
            } else {
                asyncShowMessage(editor, String.format(NO_NAME_UNO, name), true);                                   
            }
        } catch (Exception e) { 
            asyncShowMessage(editor, String.format(ABORT, bindingResult.getKeyString()), true);             
        }
    }
}
项目:e4macs    文件:KbdMacroLoadHandler.java   
/**
 * 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);
            }
        }
    }
}
项目:e4macs    文件:EmacsPlusUtils.java   
/**
 * Return the context free set of key bindings
 * 
 * @return A map of trigger (<code>TriggerSequence</code>) to bindings (
 *         <code>Collection</code> containing <code>Binding</code>).
 *         or an empty map
 */
public static Map<TriggerSequence,Collection<Binding>> getTotalBindings() {
    Map<TriggerSequence,Collection<Binding>> result = Collections.emptyMap(); 
    BindingService bs = getBindingService();
    if (bs != null) {
        @SuppressWarnings("unchecked")  // @see org.eclipse.jface.bindings.BindingManager#getActiveBindingsDisregardingContext()
        Map<TriggerSequence,Collection<Binding>> bindings = getBindingManager(bs).getActiveBindingsDisregardingContext();
        result = bindings;
    }
    return result;
}
项目:EclipseTypingLogger    文件:KeyStrokeLogger.java   
public static void setKeyListener() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    final Display display = workbench.getDisplay();
    final Listener listener = new Listener() {
        public void handleEvent(Event event) {
            if(logging){
                KeyStrokeLog.incrementLog();
                System.out.println("logged");
            }
        }
    };
    IBindingService iBindingService = (IBindingService) workbench.getService(IBindingService.class);
    if (iBindingService instanceof BindingService) {
        BindingService bindingService = (BindingService) iBindingService;
        try {
            if (bindingService.getKeyboard().getKeyDownFilter() != null) {
                display.removeFilter(SWT.KeyDown, bindingService
                        .getKeyboard().getKeyDownFilter());
            }
            display.addFilter(SWT.KeyDown, listener);
        } finally {
            if (bindingService.getKeyboard().getKeyDownFilter() != null) {
                display.addFilter(SWT.KeyDown, bindingService.getKeyboard()
                        .getKeyDownFilter());
            }
        }
    } else {
        display.addFilter(SWT.KeyDown, listener);
    }
}
项目:APICloud-Studio    文件:KeybindingsManager.java   
private void initBindings()
{
    WorkbenchJob workbenchJob = new WorkbenchJob("Installing KeybindingsManager") //$NON-NLS-1$
    {
        @Override
        public IStatus runInUIThread(IProgressMonitor monitor)
        {

            loadbindings();

            // Insert our key listener before the Eclipse's key listeners
            IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
            if (bindingService instanceof BindingService)
            {
                final BindingService theBindingService = (BindingService) bindingService;
                Display display = PlatformUI.getWorkbench().getDisplay();
                final WorkbenchKeyboard keyboard = theBindingService.getKeyboard();
                Listener keyDownFilter = keyboard.getKeyDownFilter();
                try
                {
                    if (keyDownFilter != null)
                    {
                        display.removeFilter(SWT.KeyDown, keyDownFilter);
                        display.removeFilter(SWT.Traverse, keyDownFilter);
                    }
                    display.addFilter(SWT.KeyDown, listener);
                    display.addFilter(SWT.Traverse, listener);
                }
                finally
                {
                    if (keyDownFilter != null)
                    {
                        display.addFilter(SWT.KeyDown, keyDownFilter);
                        display.addFilter(SWT.Traverse, keyDownFilter);
                    }
                }
            }

            // Set the initial enabled state of KeybindingsManager
            IContextService contextService = (IContextService) workbench.getService(IContextService.class);
            contextService.addContextManagerListener(contextManagerListener);
            setEnabled(contextService.getActiveContextIds().contains(ScriptingUIPlugin.SCRIPTING_CONTEXT_ID));

            return Status.OK_STATUS;
        }
    };
    workbenchJob.setRule(MUTEX_RULE);
    EclipseUtil.setSystemForJob(workbenchJob);
    workbenchJob.setPriority(Job.LONG);
    workbenchJob.schedule();
}