mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 22:22:11 +02:00
Bug 434294 Implement processing of Eclipse key bindings
Any special key stroke which does not map to an escape code is now processed as an Eclipse key binding. This enables key bindings like Ctrl+Insert, Ctrl+F7, etc. Change-Id: I05ea201b0b23e068d4e1d48011761cca64f7c012 Signed-off-by: Anton Leherbauer <anton.leherbauer@windriver.com>
This commit is contained in:
parent
3fd851b50e
commit
bfbf83fa80
2 changed files with 48 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.0"?>
|
||||
<!--
|
||||
# Copyright (c) 2006, 2012 Wind River Systems, Inc. and others.
|
||||
# Copyright (c) 2006, 2014 Wind River Systems, Inc. and others.
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are made available under the terms of the Eclipse Public License v1.0
|
||||
# which accompanies this distribution, and is available at
|
||||
|
@ -135,6 +135,11 @@
|
|||
contextId="org.eclipse.tm.terminal.EditContext"
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
|
||||
sequence="CTRL+SHIFT+V"/>
|
||||
<key
|
||||
commandId="org.eclipse.tm.terminal.paste"
|
||||
contextId="org.eclipse.tm.terminal.EditContext"
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
|
||||
sequence="SHIFT+INSERT"/>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
|
|
|
@ -43,12 +43,17 @@ import java.io.OutputStream;
|
|||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.SocketException;
|
||||
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.commands.ParameterizedCommand;
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.jface.bindings.Binding;
|
||||
import org.eclipse.jface.bindings.keys.KeySequence;
|
||||
import org.eclipse.jface.bindings.keys.KeyStroke;
|
||||
import org.eclipse.jface.bindings.keys.SWTKeySupport;
|
||||
import org.eclipse.jface.resource.JFaceResources;
|
||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||
|
@ -97,6 +102,7 @@ import org.eclipse.tm.terminal.model.TerminalTextDataFactory;
|
|||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.contexts.IContextActivation;
|
||||
import org.eclipse.ui.contexts.IContextService;
|
||||
import org.eclipse.ui.handlers.IHandlerService;
|
||||
import org.eclipse.ui.keys.IBindingService;
|
||||
|
||||
/**
|
||||
|
@ -1038,10 +1044,11 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
break;
|
||||
}
|
||||
|
||||
if (escSeq == null)
|
||||
if (escSeq == null) {
|
||||
// Any unmapped key should be handled locally by Eclipse
|
||||
event.doit = true;
|
||||
else
|
||||
processKeyBinding(event, accelerator);
|
||||
} else
|
||||
sendString(escSeq);
|
||||
|
||||
// It's ok to return here, because we never locally echo special keys.
|
||||
|
@ -1109,6 +1116,39 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
writeToTerminal(charBuffer.toString());
|
||||
}
|
||||
|
||||
/*
|
||||
* Process given event as Eclipse key binding.
|
||||
*/
|
||||
private void processKeyBinding(KeyEvent event, int accelerator) {
|
||||
IBindingService bindingService = (IBindingService) PlatformUI
|
||||
.getWorkbench().getAdapter(IBindingService.class);
|
||||
KeyStroke keyStroke = SWTKeySupport.convertAcceleratorToKeyStroke(accelerator);
|
||||
Binding binding = bindingService.getPerfectMatch(KeySequence.getInstance(keyStroke));
|
||||
if (binding != null) {
|
||||
ParameterizedCommand cmd = binding.getParameterizedCommand();
|
||||
if (cmd != null) {
|
||||
IHandlerService handlerService = (IHandlerService) PlatformUI
|
||||
.getWorkbench().getAdapter(IHandlerService.class);
|
||||
Event cmdEvent = new Event();
|
||||
cmdEvent.display = event.display;
|
||||
cmdEvent.widget = event.widget;
|
||||
cmdEvent.character = event.character;
|
||||
cmdEvent.keyCode = event.keyCode;
|
||||
cmdEvent.keyLocation = event.keyLocation;
|
||||
cmdEvent.stateMask = event.stateMask;
|
||||
event.doit = false;
|
||||
try {
|
||||
handlerService.executeCommand(cmd, cmdEvent);
|
||||
} catch (ExecutionException e) {
|
||||
TerminalPlugin.getDefault().getLog().log(
|
||||
new Status(IStatus.ERROR,TerminalPlugin.PLUGIN_ID,e.getLocalizedMessage(),e));
|
||||
} catch (Exception e) {
|
||||
// ignore other exceptions from cmd execution
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setTerminalTitle(String title) {
|
||||
|
|
Loading…
Add table
Reference in a new issue