org.eclipse.jface.bindings.Binding Java Examples

The following examples show how to use org.eclipse.jface.bindings.Binding. 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: KeyBindings.java    From workspacemechanic with Eclipse Public License 1.0 6 votes vote down vote up
KeyBindings(MechanicLog log, Binding[] bindings) {
  this.log = log;
  List<Binding> ub = new ArrayList<Binding>();
  List<Binding> sb = new ArrayList<Binding>();

  for (Binding binding : bindings) {
    if (binding.getType() == Binding.USER) {
      ub.add(binding);
    } else if (binding.getType() == Binding.SYSTEM) {
      sb.add(binding);
    } else {
      throw new UnsupportedOperationException("Unexpected binding type: " + binding.getType());
    }
  }
  this.userBindings = ub;
  this.systemBindings = Collections.unmodifiableList(sb);
  this.userBindingsMap = buildQualifierToBindingMap(userBindings);
  this.systemBindingsMap = buildQualifierToBindingMap(systemBindings);
}
 
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: KbdMacroSupport.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Check for a full command binding that was executed directly by the minibuffer
 * Remove the binding entry and add the command id entry
 * 
 * @param binding
 */
void checkBinding(Binding binding) {
	boolean processed = false;
	int index = macro.size() -1;
	Event keyevent = macro.get(index).getEvent();
	if (keyevent != null) {
		KeyStroke keyStroke = KeyStroke.getInstance(keyevent.stateMask, (int)Character.toUpperCase((char)keyevent.keyCode));
		if (keyStroke.equals(binding.getTriggerSequence().getTriggers()[0])) {
			// remove (possibly partial) binding
			macro.remove(index);
			// flag for minibuffer exit
			addExit();
			// and insert command
			macro.add(new KbdEvent(binding.getParameterizedCommand().getId()));
			processed = true;
		}
	}			
	if (!processed) {
		// then it's a command unto itself (e.g. ARROW_RIGHT) 
		// flag for minibuffer exit
		addExit();
		// and insert command
		macro.add(new KbdEvent(binding.getParameterizedCommand().getId()));
		processed = true;	
	}
}
 
Example #4
Source File: BindKeysHelper.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Saves the changes (if any change was done to the bindings).
 */
public void saveIfChanged() {
    try {
        Binding[] newBindings = localChangeManager.getBindings();
        Set<Object> newState = new HashSet<>();
        for (Binding binding : newBindings) {
            newState.add(binding);
        }
        if (newState.equals(initialState)) {
            return;
        }

        bindingService.savePreferences(localChangeManager.getActiveScheme(), newBindings);
    } catch (Exception e) {
        Log.log(e);
    }

}
 
Example #5
Source File: CommandHelp.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Get the displayable key-binding information for the parameterized command
 * 
 * @param com the command
 * @param activep - if true, return only active bindings
 * 
 * @return a String array of binding sequence binding context information
 */
public static String[] getKeyBindingStrings(ParameterizedCommand com, boolean activep) {
	TriggerSequence trigger;
	// Get platform bindings for the ParameterizedCommand's Command 
	Binding[] bindings = getBindings(com.getCommand(),activep);

	List<String> bindingInfo = new ArrayList<String>();
	ParameterizedCommand c;
	for (Binding bind : bindings) {
		c = bind.getParameterizedCommand();
		if (c != null && c.equals(com)) {
			trigger = bind.getTriggerSequence();
			bindingInfo.add(trigger.toString());
			bindingInfo.add(bind.getContextId());
		}
	}
	return bindingInfo.toArray(new String[0]);
}
 
Example #6
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 #7
Source File: WithMinibuffer.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
protected boolean executeBinding(ITextEditor ed, int mode, VerifyEvent event) {
	boolean result = false;
	Binding binding = getBinding(event, mode, true);
	if (binding != null && ed != null) { 
		// inform kbd macro of direct execution by minibuffer
		if (KbdMacroSupport.getInstance().isExecuting(binding)) {
			// when kbd macro is executing, do it now
			callBinding(ed,binding);
		} else {
			// else 'schedule' it for when this command completes
			asyncCallBinding(ed,binding);
		}
		event.doit = false;
		result = true;
	} else {
		// queue event
		resendEvent(event);
	}
	return result;
}
 
Example #8
Source File: IndentForTabHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.commands.EmacsPlusCmdHandler#execute(org.eclipse.core.commands.ExecutionEvent)
 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	Object result = null;
	ITextEditor editor = getTextEditor(event);
	extractUniversalCount(event);		// side effect sets up isUniversalPresent
	Binding indent = null;
	// ^U or no binding results in transform behavior
	if (!isUniversalPresent() && (indent = getBinding(editor,indentKey,indentMode)) != null) {
		String id = indent.getParameterizedCommand().getId(); 
		if (id != null && id.matches(indentExp) && !id.equals(IEmacsPlusCommandDefinitionIds.INDENT_FOR_TAB)) {
			try {
				result = executeCommand(id, null, editor);
			} catch (CommandException e) {
			}
		} else {
			super.execute(event);
		}
	} else {
		super.execute(event);
	}
	return result;
}
 
Example #9
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 #10
Source File: CommandBriefKeyHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.minibuffer.IMinibufferExecutable#executeResult(org.eclipse.ui.texteditor.ITextEditor, java.lang.Object)
 */
public boolean executeResult(ITextEditor editor, Object minibufferResult) {
	
	String summary = EMPTY_STR;
	if (minibufferResult != null) {

		IBindingResult bindingR = (IBindingResult) minibufferResult;
		String name = bindingR.getKeyString();
		if (bindingR == null || bindingR.getKeyBinding() == null) {
			summary = String.format(CMD_NO_RESULT, name) + CMD_NO_BINDING;
		} else {
			summary = String.format(CMD_KEY_RESULT,name); 
			Binding binding = bindingR.getKeyBinding();
			try {
				Command com = getCommand(binding);
				if (com != null) {
					summary += normalizeCommandName(com.getName());
				}
			} catch (NotDefinedException e) {
				// can't happen as the Command will be null or valid
			}
		}
	}
	showResultMessage(editor, summary, false);
	return true;
}
 
Example #11
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 #12
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 #13
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 #14
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 #15
Source File: UniversalMinibuffer.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isUniversalBinding() {
	boolean result = false;
	Binding bind = getBinding();
	if (bind != null) {
		Command cmd = bind.getParameterizedCommand().getCommand();
		result = (cmd != null && cmd.getId().equals(IEmacsPlusCommandDefinitionIds.UNIVERSAL_ARGUMENT));
	}
	return result;
}
 
Example #16
Source File: UniversalMinibuffer.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.minibuffer.KeyHandlerMinibuffer#getResult(Binding, KeySequence, String)
 */
@Override
protected IBindingResult getResult(final Binding binding, final KeySequence trigger, String triggerString) {

	// key character is only > 0 if it is stand alone
	int charpoint = getKeyCharacter();
	String character = null;
	if (binding == null && charpoint > 0 && triggerCount < 2) {
		if (charpoint == SWT.CR || charpoint == SWT.LF) {
			character = getEol();
		} else if (charpoint == SWT.BS) {
			character = new String(Character.toChars(charpoint));
		} else if ((Character.isWhitespace(charpoint)) || (charpoint > ' ')) {
			character = new String(Character.toChars(charpoint));
		}
	}
	if (countBuf.length() > 0) {
		try {
			if (countBuf.length() == 1 && countBuf.charAt(0)== '-') {
				;	// just use argument Count
			} else {
				setArgumentCount(Integer.parseInt(countBuf.toString()));
			}
		} catch (NumberFormatException e) {
				// bad count
				setArgumentCount(1);
		}
	}
	final String key = character;
	final boolean notNumeric = countBuf.length() == 0 && argumentCount == 4;	// flag whether a number was entered into the minibuffer

	return new IUniversalResult() {
		public Binding getKeyBinding() { return binding; }
		public String getKeyString() { return key; }
		public int getCount() { return argumentCount; }
		public boolean isNumeric() { return !notNumeric; }
		public KeySequence getTrigger() { return trigger; }
	};
}
 
Example #17
Source File: WithMinibuffer.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param editor
 * @param binding
 * @throws ExecutionException
 * @throws NotDefinedException
 * @throws NotEnabledException
 * @throws NotHandledException
 */
private void callBinding(final ITextEditor editor,
		final Binding binding) {
	try {
		IHandlerService service = (IHandlerService) editor.getSite().getService(IHandlerService.class);
		ParameterizedCommand pcommand = binding.getParameterizedCommand();
		service.executeCommand(pcommand, null);
	} catch (Exception e) {
		// Shouldn't happen, but fail quietly
	} 
}
 
Example #18
Source File: WithMinibuffer.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Add an asynchronous call to execute the command after current command completes
 */
protected void asyncCallBinding(final ITextEditor editor, final Binding binding) {
	if (binding != null) {
		PlatformUI.getWorkbench().getDisplay().asyncExec(() -> {
				callBinding(editor, binding);
		});
	}
}
 
Example #19
Source File: EmacsPlusUtils.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
	public static Map<TriggerSequence,Binding> getPartialMatches(IBindingService ibs, KeySequence ks) {
//		 juno e4 code was hosed, so temporarily use a different path to the results we need
//		return getBindingManager(((ibs instanceof BindingService) ? (BindingService)ibs : getBindingService())).getPartialMatches(ks);
		// original version is supposed to be fixed in Kepler+ - not sure I trust it
		return ibs.getPartialMatches(ks);
	}
 
Example #20
Source File: ISearchMinibuffer.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Dynamically determine the bindings for forward and reverse i-search
 * For repeat search, Emacs treats i-search and i-search-regexp identically
 * 
 * @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;
}
 
Example #21
Source File: KbdMacroSupport.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * When defining, add the command binding to the definition 
 * Should only be called from a minibuffer
 *  
 * @param binding
 * @return true is kbd macro is executing
 */
public boolean isExecuting(Binding binding) {
	// If called with binding while defining, look for extraneous 
	// Key event in macro for removal
	if (isDefining() && !kbdMacro.isEmpty()) {
		kbdMacro.checkBinding(binding);
	}
	return isExecuting();
}
 
Example #22
Source File: CommandKeyHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.minibuffer.IMinibufferExecutable#executeResult(org.eclipse.ui.texteditor.ITextEditor, java.lang.Object)
 */
public boolean executeResult(final ITextEditor editor, final Object minibufferResult) {
	
	if (minibufferResult != null) {
		final EmacsPlusConsole console = EmacsPlusConsole.getInstance();
		console.clear();
		console.activate();

		EmacsPlusUtils.asyncUiRun(new Runnable() {
			public void run() {
				String summary = EMPTY_STR;

				IBindingResult bindingR = (IBindingResult) minibufferResult;
				String name = bindingR.getKeyString();
				if (bindingR == null || bindingR.getKeyBinding() == null) {
					summary = String.format(CMD_NO_RESULT, name) + CMD_NO_BINDING;
					console.print(summary);
				} else {
					Binding binding = bindingR.getKeyBinding();
					summary = String.format(CMD_KEY_RESULT,name); 
					console.print(summary);
					try {
						Command com = getCommand(binding);
						if (com != null) {
							name = normalizeCommandName(com.getName());
							summary += name;
							console.printBinding(name + CR);
							printCmdDetails(getPCommand(binding),console);
						}
					} catch (NotDefinedException e) {
						// can't happen as the Command will be null or valid
					}
				}
				showResultMessage(editor, summary, false);
			}});
	}
	return true;
}
 
Example #23
Source File: KbdMacroBindHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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);				
		}
	}
}
 
Example #24
Source File: KbdMacroBindHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check for C-x C-k <key> binding conflict
 * 
 * @param editor
 * @param c
 * @return IBindingResult with C-x C-k <key> information
 */
private IBindingResult getBinding(ITextEditor editor, char c) {
	IBindingResult result = null;
	try {
		final KeySequence sequence = KeySequence.getInstance(KeySequence.getInstance(STD_KBD_PREFIX), KeyStroke.getInstance(c));
		final Binding binding = checkForBinding(editor, sequence);
		result = new IBindingResult() {
			public Binding getKeyBinding() { return binding; }
			public String getKeyString() { return sequence.format(); }
			public KeySequence getTrigger() { return sequence; }
		};
	} catch (ParseException e) { }
	return result;
}
 
Example #25
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
private void updateBindingContext(ContextElement context) {
	if (context == null) {
		return;
	}
	BindingElement activeBinding = (BindingElement) bindingModel.getSelectedElement();
	if (activeBinding == null) {
		return;
	}
	String activeSchemeId = fSchemeModel.getSelectedElement().getId();
	Object obj = activeBinding.getModelObject();
	if (obj instanceof KeyBinding) {
		KeyBinding keyBinding = (KeyBinding) obj;
		if (!keyBinding.getContextId().equals(context.getId())) {
			final KeyBinding binding = new KeyBinding(keyBinding.getKeySequence(),
					keyBinding.getParameterizedCommand(), activeSchemeId, context.getId(), null, null, null,
					Binding.USER);
			if (keyBinding.getType() == Binding.USER) {
				fBindingManager.removeBinding(keyBinding);
			} else {
				fBindingManager.addBinding(new KeyBinding(keyBinding.getKeySequence(), null, keyBinding
						.getSchemeId(), keyBinding.getContextId(), null, null, null, Binding.USER));
			}
			bindingModel.getBindingToElement().remove(activeBinding.getModelObject());

			fBindingManager.addBinding(binding);
			activeBinding.fill(binding, contextModel);
			bindingModel.getBindingToElement().put(binding, activeBinding);
		}
	}
}
 
Example #26
Source File: BindKeysHelper.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param force if true, we'll create the user binding regardless of having some existing binding. Otherwise,
 * we'll not allow the creation if a binding already exists for it.
 *
 * Note: conflicting bindings should be removed before (through removeUserBindingsWithFilter). If they're
 * not removed, a conflict will be created in the bindings.
 */
public void addUserBindings(KeySequence keySequence, ParameterizedCommand command) throws Exception {
    Scheme activeScheme = bindingService.getActiveScheme();
    String schemeId = activeScheme.getId();

    localChangeManager.addBinding(new KeyBinding(keySequence, command,
            schemeId, contextId, null, null, null, Binding.USER));

}
 
Example #27
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 #28
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void init(IServiceLocator locator, List<String> lstRemove) {
	getEventManager().clear();
	this.serviceLocator = locator;
//	filterDupliteBind();
	fBindingManager = loadModelBackend(serviceLocator);
	contextModel = new ContextModel(this);
	contextModel.init(serviceLocator);
	fSchemeModel = new SchemeModel(this);
	fSchemeModel.init(fBindingManager);
	bindingModel = new BindingModel2(this);
	bindingModel.init(serviceLocator, fBindingManager, contextModel);

	HashSet<BindingElement> set = bindingModel.getBindings();
	Iterator<BindingElement> iterator = set.iterator();
	while (iterator.hasNext()) {
		BindingElement bindingElement = iterator.next();
		if (lstRemove.contains(bindingElement.getId())) {
			iterator.remove();
		}
	}
	bindingModel.setBindings(set);
	Map<Binding, BindingElement> mapBBe = bindingModel.getBindingToElement();
	Iterator<Entry<Binding, BindingElement>> it = mapBBe.entrySet().iterator();
	while (it.hasNext()) {
		Entry<Binding, BindingElement> entry = (Entry<Binding, BindingElement>) it.next();
		if (lstRemove.contains(entry.getValue().getId())) {
			it.remove();
		}
	}
	bindingModel.setBindingToElement(mapBBe);

	conflictModel = new ConflictModel2(this);
	conflictModel.init(fBindingManager, bindingModel);
	addSetContextListener();
	addSetBindingListener();
	addSetConflictListener();
	addSetKeySequenceListener();
	addSetSchemeListener();
	addSetModelObjectListener();
}
 
Example #29
Source File: BindingModel2.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Makes a copy of the
 * @param element
 */
public void copy(BindingElement element) {
	if (element == null || !(element.getModelObject() instanceof Binding)) {
		return;
	}
	BindingElement be = new BindingElement(controller);
	ParameterizedCommand parameterizedCommand = ((Binding) element.getModelObject()).getParameterizedCommand();
	be.init(parameterizedCommand);
	be.setParent(this);
	bindingElements.add(be);
	commandToElement.put(parameterizedCommand, be);
	controller.firePropertyChange(this, PROP_BINDING_ADD, null, be);
	setSelectedElement(be);
}
 
Example #30
Source File: KbdMacroLoadHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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);
			}
		}
	}
}