org.eclipse.ui.keys.IBindingService Java Examples

The following examples show how to use org.eclipse.ui.keys.IBindingService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CodeAssistAdvancedConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static String getKeyboardShortcut(ParameterizedCommand command) {
	IBindingService bindingService= (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class);
	fgLocalBindingManager.setBindings(bindingService.getBindings());
	try {
		Scheme activeScheme= bindingService.getActiveScheme();
		if (activeScheme != null)
			fgLocalBindingManager.setActiveScheme(activeScheme);
	} catch (NotDefinedException e) {
		JavaPlugin.log(e);
	}

	TriggerSequence[] bindings= fgLocalBindingManager.getActiveBindingsDisregardingContextFor(command);
	if (bindings.length > 0)
		return bindings[0].format();
	return null;
}
 
Example #2
Source File: KbdMacroSupport.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Check for a binding that is not a full command and was not handled by the minibuffer
 * Remove the partial binding and add the command id entry
 * 
 * @param cmdId
 * @param trigger
 * @param onExit - it is the endMacro command, ignore id entry
 */

void checkTrigger(String cmdId, Map<?,?> parameters, Event trigger, boolean onExit) {
	int index = macro.size() -1;
	if (!macro.isEmpty() && trigger != null && macro.get(index).isSubCmd()) {
		Event event = macro.get(index).getEvent();
		// have trigger and previous entry is a subCmd type 
		KeyStroke key = KeyStroke.getInstance(event.stateMask, Character.toUpperCase(event.keyCode));
		IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
		Collection<Binding> values = EmacsPlusUtils.getPartialMatches(bindingService,KeySequence.getInstance(key)).values();
		// Check partial binding
		for (Binding v : values) {
			if (cmdId.equals((v.getParameterizedCommand().getId()))) {
				// remove (possibly partial) binding
				macro.remove(index);
				// flag for minibuffer exit
				macro.add(new KbdEvent(true));
				break;
			}
		}
	}
	if (!onExit) {
		macro.add(new KbdEvent(cmdId, parameters));
	}
}
 
Example #3
Source File: KeyBindingHelper.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public static boolean matchesKeybinding(int keyCode, int stateMask, String commandId) {
    final IBindingService bindingSvc = PlatformUI.getWorkbench()
            .getAdapter(IBindingService.class);
    TriggerSequence[] activeBindingsFor = bindingSvc.getActiveBindingsFor(commandId);

    for (TriggerSequence seq : activeBindingsFor) {
        if (seq instanceof KeySequence) {
            KeySequence keySequence = (KeySequence) seq;
            if (matchesKeybinding(keyCode, stateMask, keySequence)) {
                return true;
            }
        }
    }

    return false;
}
 
Example #4
Source File: KbdMacroLoadHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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);
		}
	}				
}
 
Example #5
Source File: KeyBindingHelper.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public static boolean matchesKeybinding(int keyCode, int stateMask, String commandId)
{
	final IBindingService bindingSvc = (IBindingService) PlatformUI.getWorkbench()
			.getAdapter(IBindingService.class);
	TriggerSequence[] activeBindingsFor = bindingSvc.getActiveBindingsFor(commandId);

	for (TriggerSequence seq : activeBindingsFor)
	{
		if (seq instanceof KeySequence)
		{
			if (matchesKeybinding(keyCode, stateMask, seq))
			{
				return true;
			}
		}
	}

	return false;
}
 
Example #6
Source File: KeyBindingHelper.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
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);
		}
	}
}
 
Example #7
Source File: ShieldStartup.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public void earlyStartup() {
	final IWorkbench workbench = PlatformUI.getWorkbench();
	workbench.getDisplay().asyncExec(new Runnable() {
		
		public void run() {
			// 在工作台初始化后,移除平台默认的 scheme
			IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
			
			Scheme[] schemes = bindingService.getDefinedSchemes();
			for (int i = 0; i < schemes.length; i++) {
				String id = schemes[i].getId();
				if (id.equals(platformDefaultScheme) || id.equals(platformEmacsScheme)) {
					schemes[i].undefine();
				}
			}
		}
	});
}
 
Example #8
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets the bindings to default.
 * @param bindingService
 * @throws NotDefinedException
 */
public void setDefaultBindings(IBindingService bindingService, List<String> lstRemove) throws NotDefinedException {
	// Fix the scheme in the local changes.
	final String defaultSchemeId = bindingService.getDefaultSchemeId();
	final Scheme defaultScheme = fBindingManager.getScheme(defaultSchemeId);
	try {
		fBindingManager.setActiveScheme(defaultScheme);
	} catch (final NotDefinedException e) {
		// At least we tried....
	}

	// Restore any User defined bindings
	Binding[] bindings = fBindingManager.getBindings();
	for (int i = 0; i < bindings.length; i++) {
		ParameterizedCommand pCommand = bindings[i].getParameterizedCommand();
		String commandId = null;
		if (pCommand != null) {
			commandId = pCommand.getCommand().getId();
		}
		if (bindings[i].getType() == Binding.USER || (commandId != null && lstRemove.contains(commandId))) {
			fBindingManager.removeBinding(bindings[i]);
		}
	}
	bindingModel.refresh(contextModel, lstRemove);
	saveBindings(bindingService);
}
 
Example #9
Source File: KeyAssistHandler.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #10
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
private static BindingManager loadModelBackend(IServiceLocator locator) {
	IBindingService bindingService = (IBindingService) locator.getService(IBindingService.class);
	BindingManager bindingManager = new BindingManager(new ContextManager(), new CommandManager());
	final Scheme[] definedSchemes = bindingService.getDefinedSchemes();
	try {
		Scheme modelActiveScheme = null;
		for (int i = 0; i < definedSchemes.length; i++) {
			final Scheme scheme = definedSchemes[i];
			final Scheme copy = bindingManager.getScheme(scheme.getId());
			copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
			if (definedSchemes[i] == bindingService.getActiveScheme()) {
				modelActiveScheme = copy;
			}
		}
		bindingManager.setActiveScheme(modelActiveScheme);
	} catch (final NotDefinedException e) {
		StatusManager.getManager()
				.handle(new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH,
						"Keys page found an undefined scheme", e)); //$NON-NLS-1$
	}
	bindingManager.setLocale(bindingService.getLocale());
	bindingManager.setPlatform(bindingService.getPlatform());
	bindingManager.setBindings(bindingService.getBindings());
	return bindingManager;
}
 
Example #11
Source File: KeyController2.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
private static BindingManager loadModelBackend(IServiceLocator locator) {
	IBindingService bindingService = (IBindingService) locator.getService(IBindingService.class);
	BindingManager bindingManager = new BindingManager(new ContextManager(), new CommandManager());
	final Scheme[] definedSchemes = bindingService.getDefinedSchemes();
	try {
		Scheme modelActiveScheme = null;
		for (int i = 0; i < definedSchemes.length; i++) {
			final Scheme scheme = definedSchemes[i];
			final Scheme copy = bindingManager.getScheme(scheme.getId());
			copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
			if (definedSchemes[i] == bindingService.getActiveScheme()) {
				modelActiveScheme = copy;
			}
		}
		bindingManager.setActiveScheme(modelActiveScheme);
	} catch (final NotDefinedException e) {
		StatusManager.getManager()
				.handle(new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH,
						"Keys page found an undefined scheme", e)); //$NON-NLS-1$
	}
	bindingManager.setLocale(bindingService.getLocale());
	bindingManager.setPlatform(bindingService.getPlatform());
	bindingManager.setBindings(bindingService.getBindings());
	return bindingManager;
}
 
Example #12
Source File: KeyController2.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets the bindings to default.
 * @param bindingService
 * @throws NotDefinedException
 */
public void setDefaultBindings(IBindingService bindingService, List<String> lstRemove) throws NotDefinedException {
	// Fix the scheme in the local changes.
	final String defaultSchemeId = bindingService.getDefaultSchemeId();
	final Scheme defaultScheme = fBindingManager.getScheme(defaultSchemeId);
	try {
		fBindingManager.setActiveScheme(defaultScheme);
	} catch (final NotDefinedException e) {
		// At least we tried....
	}

	// Restore any User defined bindings
	Binding[] bindings = fBindingManager.getBindings();
	for (int i = 0; i < bindings.length; i++) {
		ParameterizedCommand pCommand = bindings[i].getParameterizedCommand();
		String commandId = null;
		if (pCommand != null) {
			commandId = pCommand.getCommand().getId();
		}
		if (bindings[i].getType() == Binding.USER || (commandId != null && lstRemove.contains(commandId))) {
			fBindingManager.removeBinding(bindings[i]);
		}
	}
	bindingModel.refresh(contextModel, lstRemove);
	saveBindings(bindingService);
}
 
Example #13
Source File: KeyAssistHandler.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #14
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
private static BindingManager loadModelBackend(IServiceLocator locator) {
	IBindingService bindingService = (IBindingService) locator.getService(IBindingService.class);
	BindingManager bindingManager = new BindingManager(new ContextManager(), new CommandManager());
	final Scheme[] definedSchemes = bindingService.getDefinedSchemes();
	try {
		Scheme modelActiveScheme = null;
		for (int i = 0; i < definedSchemes.length; i++) {
			final Scheme scheme = definedSchemes[i];
			final Scheme copy = bindingManager.getScheme(scheme.getId());
			copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
			if (definedSchemes[i] == bindingService.getActiveScheme()) {
				modelActiveScheme = copy;
			}
		}
		bindingManager.setActiveScheme(modelActiveScheme);
	} catch (final NotDefinedException e) {
		StatusManager.getManager()
				.handle(new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH,
						"Keys page found an undefined scheme", e)); //$NON-NLS-1$
	}
	bindingManager.setLocale(bindingService.getLocale());
	bindingManager.setPlatform(bindingService.getPlatform());
	bindingManager.setBindings(bindingService.getBindings());
	return bindingManager;
}
 
Example #15
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets the bindings to default.
 * @param bindingService
 * @throws NotDefinedException
 */
public void setDefaultBindings(IBindingService bindingService, List<String> lstRemove) throws NotDefinedException {
	// Fix the scheme in the local changes.
	final String defaultSchemeId = bindingService.getDefaultSchemeId();
	final Scheme defaultScheme = fBindingManager.getScheme(defaultSchemeId);
	try {
		fBindingManager.setActiveScheme(defaultScheme);
	} catch (final NotDefinedException e) {
		// At least we tried....
	}

	// Restore any User defined bindings
	Binding[] bindings = fBindingManager.getBindings();
	for (int i = 0; i < bindings.length; i++) {
		ParameterizedCommand pCommand = bindings[i].getParameterizedCommand();
		String commandId = null;
		if (pCommand != null) {
			commandId = pCommand.getCommand().getId();
		}
		if (bindings[i].getType() == Binding.USER || (commandId != null && lstRemove.contains(commandId))) {
			fBindingManager.removeBinding(bindings[i]);
		}
	}
	bindingModel.refresh(contextModel, lstRemove);
	saveBindings(bindingService);
}
 
Example #16
Source File: IndentForTabHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Return the exact binding if it exists and is enabled, else null
 * 
 * @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;
}
 
Example #17
Source File: KbdMacroSaveHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
private void saveMacro(ITextEditor editor,String name, File file) {
	IBindingService service = (IBindingService) editor.getSite().getService(IBindingService.class);
	KbdMacro kbdMacro = KbdMacroSupport.getInstance().getKbdMacro(name);
	TriggerSequence sequence = service.getBestActiveBindingFor(EmacsPlusUtils.kbdMacroId(name));
	if (sequence != null && sequence instanceof KeySequence) {
		kbdMacro.setBindingKeys(((KeySequence)sequence).toString());
	}
	writeMacro(editor,file,kbdMacro);
	kbdMacro.setBindingKeys(null);
}
 
Example #18
Source File: EmacsMovementHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Does the trigger for this movement command contain the SHIFT key?
 * 
 * Enforce that the <binding> and <binding>+SHIFT belong to the same Command. 
 * If not, don't apply shift selection (if enabled) for this command (i.e. return false).
 *  
 * @param event the Execution event that invoked this command
 * 
 * @return true if SHIFT modifier was set, else false
 */
private boolean getShifted(ExecutionEvent event) {
	// NB: only single keystroke commands are valid 
	boolean result = false;
	Object trigger = event.getTrigger();
	Event e = null;
	if (trigger != null && trigger instanceof Event && ((e = (Event)trigger).stateMask & SWT.SHIFT )!= 0) {
		String cmdId = event.getCommand().getId();
		int mask = (e.stateMask & SWT.MODIFIER_MASK) ^ SWT.SHIFT;
		int u_code = Character.toUpperCase((char)e.keyCode);
		IBindingService bs = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
		if (cmdId != null && bs != null) {
			TriggerSequence[] sequences = bs.getActiveBindingsFor(cmdId);
			for (TriggerSequence s : sequences) {
				if (s instanceof KeySequence) {
					KeyStroke[] strokes = ((KeySequence)s).getKeyStrokes();
					if (strokes.length == 1) {
						KeyStroke k = strokes[strokes.length - 1];
						// if keyCode is alpha, then we test uppercase, else keyCode
						if (k.getModifierKeys() == mask
								&& (k.getNaturalKey() == u_code || k.getNaturalKey() == e.keyCode)) {
							result = true;
							break;
						}
					}
				}
			}
		} 
	}
	return result;
}
 
Example #19
Source File: TextWidget.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private Optional<KeyStroke> retrieveEclipseContentAssistKeyStroke() {
    IBindingService bindingService = PlatformUI.getWorkbench().getService(IBindingService.class);
    return Optional
            .ofNullable(bindingService.getBestActiveBindingFor("org.eclipse.ui.edit.text.contentAssist.proposals"))
            .map(triggerSequence -> {
                List<Trigger> triggers = Arrays.asList(triggerSequence.getTriggers());
                return triggers.size() > 1
                        ? null // auto complete cell editor doesn't handle sequence
                        : triggers.stream()
                                .filter(KeyStroke.class::isInstance)
                                .map(KeyStroke.class::cast)
                                .findFirst()
                                .orElse(null);
            });
}
 
Example #20
Source File: WithMinibuffer.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Installs this target. I.e. adds all required listeners.
 */
private boolean install() {
	if (editor instanceof AbstractTextEditor && !isInstalled()) {
		bindingService = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
		viewer = findSourceViewer(editor);
		if (viewer != null) {
			widget = viewer.getTextWidget();
			if (widget == null || widget.isDisposed()) {
				viewer = null;
				widget = null;
				return false;
			}
			widget.addMouseListener(this);
			widget.addFocusListener(this);
			viewer.addTextListener(this);

			ISelectionProvider selectionProvider = viewer.getSelectionProvider();
			if (selectionProvider != null)
				selectionProvider.addSelectionChangedListener(this);

			if (viewer instanceof ITextViewerExtension){
				((ITextViewerExtension) viewer).prependVerifyKeyListener(this);
				KbdMacroSupport.getInstance().continueKbdMacro(this,editor);
			} else {
				widget.addVerifyKeyListener(this);
			}
			addOtherListeners(page,viewer, widget);
			installed = true;
		}
	}
	addStatusContribution(editor);		
	return installed;
}
 
Example #21
Source File: WindowDeclOtherCmd.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * A bit of hackery that tries to get the correct open-declaration command for the buffer 
 * @param editor
 * @return the best match Command definition
 */
private Command getOpenCmd(IEditorPart editor) {
	Command result = null;
	try {
		IBindingService bs = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
		ICommandService ics = (ICommandService) editor.getSite().getService(ICommandService.class);
		List<Command> cans = new ArrayList<Command>();
		List<Command> nocans = new ArrayList<Command>();
		Command[] commands = ics.getDefinedCommands();
		for (Command c : commands) {
			if (OD.equals(c.getName()) && c.isEnabled()) {
				TriggerSequence[] b = bs.getActiveBindingsFor(c.getId());
				if (b.length > 0) {
					cans.add(c);
				} else {
					nocans.add(c);
				}
			}
		}
		// TODO: when > 1 try to refine the result heuristically?
		// if Eclipse returned more than one, then chose a bound command over non-bound
		if (cans.isEmpty()) {
			if (!nocans.isEmpty()) {
				// just grab first one
				result = nocans.get(0);
			}
		} else {
			// grab the first bound one
			result = cans.get(0);
		}
	} catch (Exception e) { }
	return result;
}
 
Example #22
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@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()]));
}
 
Example #23
Source File: KeyBindingHelper.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param commandId the command we want to know about
 * @return the 'best' key sequence that will activate the given command
 */
public static KeySequence getCommandKeyBinding(String commandId) {
    Assert.isNotNull(commandId);
    IBindingService bindingSvc;
    try {
        bindingSvc = PlatformUI.getWorkbench()
                .getAdapter(IBindingService.class);
    } catch (IllegalStateException e) {
        return null;
    }

    TriggerSequence keyBinding = bindingSvc.getBestActiveBindingFor(commandId);
    if (keyBinding instanceof KeySequence) {
        return (KeySequence) keyBinding;
    }

    List<Tuple<Binding, ParameterizedCommand>> matches = new ArrayList<Tuple<Binding, ParameterizedCommand>>();
    //Ok, it may be that the binding we're looking for is not active, so, let's give a spin on all
    //the bindings
    Binding[] bindings = bindingSvc.getBindings();
    for (Binding binding : bindings) {
        ParameterizedCommand command = binding.getParameterizedCommand();
        if (command != null) {
            if (commandId.equals(command.getId())) {
                matches.add(new Tuple<Binding, ParameterizedCommand>(binding, command));
            }
        }
    }
    for (Tuple<Binding, ParameterizedCommand> tuple : matches) {
        if (tuple.o1.getTriggerSequence() instanceof KeySequence) {
            KeySequence keySequence = (KeySequence) tuple.o1.getTriggerSequence();
            return keySequence;
        }
    }

    return null;
}
 
Example #24
Source File: KeysPreferencePage.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void init(IWorkbench workbench) {
	keyController = new KeyController2();
	keyController.init(workbench, lstRemove);
	model = keyController.getBindingModel();
	
	commandService = (ICommandService) workbench.getService(ICommandService.class);
	Collection definedCommandIds = commandService.getDefinedCommandIds();
	
	fDefaultCategory = commandService.getCategory(null);
	fBindingService = (IBindingService) workbench.getService(IBindingService.class);

	commandImageService = (ICommandImageService) workbench.getService(ICommandImageService.class);
}
 
Example #25
Source File: LangContentAssistProcessor.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
protected KeySequence getGroupingIterationBinding() {
IBindingService bindingSvc = (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class);
TriggerSequence binding = bindingSvc.getBestActiveBindingFor(
	ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
if(binding instanceof KeySequence)
	return (KeySequence) binding;
return null;
  }
 
Example #26
Source File: TmMatchEditDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean close() {
	IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
	bindingService.setKeyFilterEnabled(true);
	srcSegmentViewer.reset();
	tgtSegmentViewer.reset();
	return super.close();
}
 
Example #27
Source File: AutoCompleteTextCellEditor.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private Optional<KeyStroke> retrieveEclipseContentAssistKeyStroke() {
    IBindingService bindingService = PlatformUI.getWorkbench().getService(IBindingService.class);
    return Optional
            .ofNullable(bindingService.getBestActiveBindingFor("org.eclipse.ui.edit.text.contentAssist.proposals"))
            .map(triggerSequence -> {
                List<Trigger> triggers = Arrays.asList(triggerSequence.getTriggers());
                return triggers.size() > 1
                        ? null // auto complete cell editor doesn't handle sequence
                        : triggers.stream()
                                .filter(KeyStroke.class::isInstance)
                                .map(KeyStroke.class::cast)
                                .findFirst()
                                .orElse(null);
            });
}
 
Example #28
Source File: TmMatchEditDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create the dialog.
 * @param parentShell
 */
public TmMatchEditDialog(Shell parentShell, FuzzySearchResult fuzzyResult) {
	super(parentShell);
	this.fuzzyResult = fuzzyResult;
	setShellStyle(getShellStyle() | SWT.RESIZE);
	IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
	bindingService.setKeyFilterEnabled(false);
}
 
Example #29
Source File: WorkspaceWizardPage.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #30
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Replaces all the current bindings with the bindings in the local copy of the binding manager.
 * @param bindingService
 *            The binding service that saves the changes made to the local copy of the binding manager
 */
public void saveBindings(IBindingService bindingService) {
	try {
		bindingService.savePreferences(fBindingManager.getActiveScheme(), fBindingManager.getBindings());
	} catch (IOException e) {
		logPreferenceStoreException(e);
	}
}