mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-26 18:35:32 +02:00
Terminal: Bug 434478 Stop capturing key events in disconnected state
In disconnected state no input is accepted by the terminal, therefore key bindings are allowed to be processed by Eclipse. Change-Id: I119a25ce9cf366eefe92d2d9490472280e6dfd79 Signed-off-by: Anton Leherbauer <anton.leherbauer@windriver.com>
This commit is contained in:
parent
e116111b80
commit
0e02e7fcf3
1 changed files with 51 additions and 30 deletions
|
@ -133,7 +133,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
||||||
private KeyListener fKeyHandler;
|
private KeyListener fKeyHandler;
|
||||||
private final ITerminalListener fTerminalListener;
|
private final ITerminalListener fTerminalListener;
|
||||||
private String fMsg = ""; //$NON-NLS-1$
|
private String fMsg = ""; //$NON-NLS-1$
|
||||||
private FocusListener fFocusListener;
|
private TerminalFocusListener fFocusListener;
|
||||||
private ITerminalConnector fConnector;
|
private ITerminalConnector fConnector;
|
||||||
private final ITerminalConnector[] fConnectors;
|
private final ITerminalConnector[] fConnectors;
|
||||||
private final boolean fUseCommonPrefs;
|
private final boolean fUseCommonPrefs;
|
||||||
|
@ -456,9 +456,13 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
||||||
disconnectTerminal();
|
disconnectTerminal();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (getCtlText().isFocusControl()) {
|
||||||
|
if (getState() == TerminalState.CONNECTED)
|
||||||
|
fFocusListener.captureKeyEvents(true);
|
||||||
|
} else {
|
||||||
getCtlText().setFocus();
|
getCtlText().setFocus();
|
||||||
|
}
|
||||||
startReaderJob();
|
startReaderJob();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void startReaderJob() {
|
private synchronized void startReaderJob() {
|
||||||
|
@ -804,8 +808,8 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
||||||
return fTerminalText;
|
return fTerminalText;
|
||||||
}
|
}
|
||||||
protected class TerminalFocusListener implements FocusListener {
|
protected class TerminalFocusListener implements FocusListener {
|
||||||
private IContextActivation contextActivation = null;
|
private IContextActivation terminalContextActivation = null;
|
||||||
private IContextActivation contextActivation1 = null;
|
private IContextActivation editContextActivation = null;
|
||||||
|
|
||||||
protected TerminalFocusListener() {
|
protected TerminalFocusListener() {
|
||||||
super();
|
super();
|
||||||
|
@ -815,40 +819,50 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
||||||
// Disable all keyboard accelerators (e.g., Control-B) so the Terminal view
|
// Disable all keyboard accelerators (e.g., Control-B) so the Terminal view
|
||||||
// can see every keystroke. Without this, Emacs, vi, and Bash are unusable
|
// can see every keystroke. Without this, Emacs, vi, and Bash are unusable
|
||||||
// in the Terminal view.
|
// in the Terminal view.
|
||||||
|
if (getState() == TerminalState.CONNECTED)
|
||||||
IBindingService bindingService = (IBindingService) PlatformUI
|
captureKeyEvents(true);
|
||||||
.getWorkbench().getAdapter(IBindingService.class);
|
|
||||||
bindingService.setKeyFilterEnabled(false);
|
|
||||||
|
|
||||||
// The above code fails to cause Eclipse to disable menu-activation
|
|
||||||
// accelerators (e.g., Alt-F for the File menu), so we set the command
|
|
||||||
// context to be the Terminal view's command context. This enables us to
|
|
||||||
// override menu-activation accelerators with no-op commands in our
|
|
||||||
// plugin.xml file, which enables the Terminal view to see absolutly _all_
|
|
||||||
// key-presses.
|
|
||||||
|
|
||||||
IContextService contextService = (IContextService) PlatformUI
|
IContextService contextService = (IContextService) PlatformUI
|
||||||
.getWorkbench().getAdapter(IContextService.class);
|
.getWorkbench().getAdapter(IContextService.class);
|
||||||
contextActivation = contextService
|
editContextActivation = contextService
|
||||||
.activateContext("org.eclipse.tm.terminal.TerminalContext"); //$NON-NLS-1$
|
|
||||||
contextActivation1 = contextService
|
|
||||||
.activateContext("org.eclipse.tm.terminal.EditContext"); //$NON-NLS-1$
|
.activateContext("org.eclipse.tm.terminal.EditContext"); //$NON-NLS-1$
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void focusLost(FocusEvent event) {
|
public void focusLost(FocusEvent event) {
|
||||||
// Enable all keybindings.
|
// Enable all keybindings.
|
||||||
|
captureKeyEvents(false);
|
||||||
IBindingService bindingService = (IBindingService) PlatformUI
|
|
||||||
.getWorkbench().getAdapter(IBindingService.class);
|
|
||||||
bindingService.setKeyFilterEnabled(true);
|
|
||||||
|
|
||||||
// Restore the command context to its previous value.
|
// Restore the command context to its previous value.
|
||||||
|
|
||||||
IContextService contextService = (IContextService) PlatformUI
|
IContextService contextService = (IContextService) PlatformUI
|
||||||
.getWorkbench().getAdapter(IContextService.class);
|
.getWorkbench().getAdapter(IContextService.class);
|
||||||
contextService.deactivateContext(contextActivation);
|
contextService.deactivateContext(editContextActivation);
|
||||||
contextService.deactivateContext(contextActivation1);
|
}
|
||||||
|
|
||||||
|
protected void captureKeyEvents(boolean capture) {
|
||||||
|
IBindingService bindingService = (IBindingService) PlatformUI
|
||||||
|
.getWorkbench().getAdapter(IBindingService.class);
|
||||||
|
IContextService contextService = (IContextService) PlatformUI
|
||||||
|
.getWorkbench().getAdapter(IContextService.class);
|
||||||
|
|
||||||
|
boolean enableKeyFilter = !capture;
|
||||||
|
if (bindingService.isKeyFilterEnabled() != enableKeyFilter)
|
||||||
|
bindingService.setKeyFilterEnabled(enableKeyFilter);
|
||||||
|
|
||||||
|
if (capture && terminalContextActivation == null) {
|
||||||
|
// The above code fails to cause Eclipse to disable menu-activation
|
||||||
|
// accelerators (e.g., Alt-F for the File menu), so we set the command
|
||||||
|
// context to be the Terminal view's command context. This enables us to
|
||||||
|
// override menu-activation accelerators with no-op commands in our
|
||||||
|
// plugin.xml file, which enables the Terminal view to see absolutely _all_
|
||||||
|
// key-presses.
|
||||||
|
terminalContextActivation = contextService
|
||||||
|
.activateContext("org.eclipse.tm.terminal.TerminalContext"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
} else if (!capture && terminalContextActivation != null) {
|
||||||
|
contextService.deactivateContext(terminalContextActivation);
|
||||||
|
terminalContextActivation = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1179,9 +1193,17 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
||||||
// enable the (blinking) cursor if the terminal is connected
|
// enable the (blinking) cursor if the terminal is connected
|
||||||
runAsyncInDisplayThread(new Runnable() {
|
runAsyncInDisplayThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if(fCtlText!=null && !fCtlText.isDisposed())
|
if(fCtlText!=null && !fCtlText.isDisposed()) {
|
||||||
fCtlText.setCursorEnabled(isConnected());
|
if (isConnected()) {
|
||||||
}});
|
fCtlText.setCursorEnabled(true);
|
||||||
|
} else {
|
||||||
|
fCtlText.setCursorEnabled(false);
|
||||||
|
// Stop capturing all key events
|
||||||
|
fFocusListener.captureKeyEvents(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param runnable run in display thread
|
* @param runnable run in display thread
|
||||||
|
@ -1266,5 +1288,4 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
||||||
return getTerminalText().isVT100LineWrapping();
|
return getTerminalText().isVT100LineWrapping();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue