# HG changeset patch # User Ed Swartz # Date 1278078016 18000 # Node ID 6615e5b1e0837a3e817eb586c6e44e8f3f76a70c # Parent 1c3ed56966df409da7b4ed1df840ae99714f9e13 Bug 11279: support showing launch wizard if you use debug/run shortcut while Shift is pressed diff -r 1c3ed56966df -r 6615e5b1e083 debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/AbstractSymbianLaunchShortcut.java --- a/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/AbstractSymbianLaunchShortcut.java Wed Jun 30 15:34:24 2010 -0500 +++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/AbstractSymbianLaunchShortcut.java Fri Jul 02 08:40:16 2010 -0500 @@ -18,6 +18,10 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IFileEditorInput; @@ -68,32 +72,36 @@ public void launch(ISelection selection, String mode) { - // launch an existing config if one exists - ILaunchConfiguration[] configs = getLaunchConfigurations(selection); - if (configs != null && configs.length > 0) { - // find all the ones that support the mode and shortcut (#11013) - List matches = new ArrayList(); - for (int i = 0; i < configs.length; i++) { - ILaunchConfiguration config = configs[i]; - try { - if (config.supportsMode(mode) && isSupportedConfiguration(config)) { - matches.add(config); + // if user holds down SHIFT, do not use existing launch (bug 11279) + if (!isShiftKeyPressed()) { + + // launch an existing config if one exists + ILaunchConfiguration[] configs = getLaunchConfigurations(selection); + if (configs != null && configs.length > 0) { + // find all the ones that support the mode and shortcut (#11013) + List matches = new ArrayList(); + for (int i = 0; i < configs.length; i++) { + ILaunchConfiguration config = configs[i]; + try { + if (config.supportsMode(mode) && isSupportedConfiguration(config)) { + matches.add(config); + } + } catch (CoreException e) { + e.printStackTrace(); } - } catch (CoreException e) { - e.printStackTrace(); } - } - // if only one matches, just launch - if (matches.size() > 0) { - if (matches.size() == 1 || WorkbenchUtils.isJUnitRunning()) { - DebugUITools.launch(matches.get(0), mode); - } else { - // else, ask the user - ILaunchConfiguration selected = chooseConfiguration(matches, mode); - if (selected != null) - DebugUITools.launch(selected, mode); + // if only one matches, just launch + if (matches.size() > 0) { + if (matches.size() == 1 || WorkbenchUtils.isJUnitRunning()) { + DebugUITools.launch(matches.get(0), mode); + } else { + // else, ask the user + ILaunchConfiguration selected = chooseConfiguration(matches, mode); + if (selected != null) + DebugUITools.launch(selected, mode); + } + return; } - return; } } @@ -140,6 +148,44 @@ } /** + * Tell whether a shift key is pressed or released in a 1/4 second period. + * @return + */ + private boolean isShiftKeyPressed() { + final boolean[] pressed = { false }; + Display.getDefault().syncExec(new Runnable() { + public void run() { + final boolean[] event = { false }; + Listener listener = new Listener() { + @Override + public void handleEvent(Event arg0) { + if ((arg0.stateMask & SWT.SHIFT) != 0 || arg0.keyCode == SWT.SHIFT) + pressed[0] = true; + event[0] = true; + } + }; + Display display = Display.getDefault(); + display.addFilter(SWT.KeyDown, listener); + display.addFilter(SWT.KeyUp, listener); + display.addFilter(SWT.MouseMove, listener); // mouse move carries keyboard state + + try { + long end = System.currentTimeMillis() + 250; + while (System.currentTimeMillis() < end && !pressed[0] && !event[0]) { + if (!display.readAndDispatch()) + display.sleep(); + } + } finally { + display.removeFilter(SWT.MouseMove, listener); + display.removeListener(SWT.KeyDown, listener); + display.removeListener(SWT.KeyUp, listener); + } + } + }); + return pressed[0]; + } + + /** * Show a selection dialog that allows the user to choose one of the specified * launch configurations. Return the chosen config, or null if the * user cancelled the dialog.