git clone http://danamlund/git/eclipse-quick-launch/.git
Log | Files | Refs | LICENSE

commit dabbe7a3d7c9041f91571a4e87db5e1bfc438d3d
parent 9f2017c9f3ff79218e26b17ffa0af54e4d28c2d2
Author: Dan Amlund <dan@danamlund.dk>
Date:   Thu, 19 Oct 2017 21:44:32 +0200

dont block when launching. Reuse dialog. Keep list of launchers that is kept up-to-date

Diffstat:
Mdk.danamlund.quicklaunch/META-INF/MANIFEST.MF | 2+-
Mdk.danamlund.quicklaunch/src/dk/danamlund/quicklaunch/QuickDebugLaunchConfigurationHandler.java | 14++++++++------
Mdk.danamlund.quicklaunch/src/dk/danamlund/quicklaunch/QuickLaunchConfigurationDialog.java | 37+++----------------------------------
Adk.danamlund.quicklaunch/src/dk/danamlund/quicklaunch/QuickLauncher.java | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdk.danamlund.quicklaunch/src/dk/danamlund/quicklaunch/QuickRunLaunchConfigurationHandler.java | 14++++++++------
Mreadme.txt | 2+-
6 files changed, 83 insertions(+), 48 deletions(-)

diff --git a/dk.danamlund.quicklaunch/META-INF/MANIFEST.MF b/dk.danamlund.quicklaunch/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Quick Launch Configuration Bundle-SymbolicName: dk.danamlund.quicklaunch;singleton:=true -Bundle-Version: 1.0.0.qualifier +Bundle-Version: 1.1 Require-Bundle: org.eclipse.ui, org.eclipse.debug.core;bundle-version="3.10.100", org.eclipse.equinox.common;bundle-version="3.8.0", diff --git a/dk.danamlund.quicklaunch/src/dk/danamlund/quicklaunch/QuickDebugLaunchConfigurationHandler.java b/dk.danamlund.quicklaunch/src/dk/danamlund/quicklaunch/QuickDebugLaunchConfigurationHandler.java @@ -3,15 +3,17 @@ package dk.danamlund.quicklaunch; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.debug.core.ILaunchManager; public class QuickDebugLaunchConfigurationHandler extends AbstractHandler { + private QuickLauncher quickLauncher = null; + @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); - QuickLaunchConfigurationDialog dialog = QuickLaunchConfigurationDialog.newDebugDialog(window.getShell()); - dialog.open(); + public synchronized Object execute(ExecutionEvent event) throws ExecutionException { + if (quickLauncher == null) { + quickLauncher = new QuickLauncher(ILaunchManager.DEBUG_MODE); + } + quickLauncher.showQuickLaunchDialog(); return null; } } diff --git a/dk.danamlund.quicklaunch/src/dk/danamlund/quicklaunch/QuickLaunchConfigurationDialog.java b/dk.danamlund.quicklaunch/src/dk/danamlund/quicklaunch/QuickLaunchConfigurationDialog.java @@ -1,19 +1,13 @@ package dk.danamlund.quicklaunch; -import java.util.ArrayList; -import java.util.List; - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.IDebugModelPresentation; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.dialogs.ElementListSelectionDialog; import org.eclipse.ui.dialogs.FilteredList; import org.eclipse.ui.dialogs.FilteredList.FilterMatcher; @@ -21,36 +15,11 @@ import org.eclipse.ui.dialogs.FilteredList.FilterMatcher; public class QuickLaunchConfigurationDialog extends ElementListSelectionDialog { private final String runMode; - public static QuickLaunchConfigurationDialog newRunDialog(Shell parent) { - QuickLaunchConfigurationDialog dialog = new QuickLaunchConfigurationDialog(parent, ILaunchManager.RUN_MODE); - dialog.setTitle("Run Launch Configuration"); - return dialog; - } - - public static QuickLaunchConfigurationDialog newDebugDialog(Shell parent) { - QuickLaunchConfigurationDialog dialog = new QuickLaunchConfigurationDialog(parent, ILaunchManager.DEBUG_MODE); - dialog.setTitle("Debug Launch Configuration"); - return dialog; - } - - private QuickLaunchConfigurationDialog(Shell parent, String runMode) { - super(parent, new QuickLaunchConfigurationLabelProvider()); + public QuickLaunchConfigurationDialog(String runMode) { + super(null, new QuickLaunchConfigurationLabelProvider()); this.runMode = runMode; - try { - ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); - List<ILaunchConfiguration> launchConfigurations = new ArrayList<>(); - for (ILaunchConfiguration launchConfiguration : launchManager.getLaunchConfigurations()) { - if (launchConfiguration.supportsMode(runMode)) { - launchConfigurations.add(launchConfiguration); - } - } - setElements(launchConfigurations.toArray()); - setInitialSelections(new Object[] { launchConfigurations.get(launchConfigurations.size() - 1) }); - } catch (CoreException e) { - throw new IllegalStateException(e); - } - setBlockOnOpen(true); + setBlockOnOpen(false); } @Override diff --git a/dk.danamlund.quicklaunch/src/dk/danamlund/quicklaunch/QuickLauncher.java b/dk.danamlund.quicklaunch/src/dk/danamlund/quicklaunch/QuickLauncher.java @@ -0,0 +1,62 @@ +package dk.danamlund.quicklaunch; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationListener; +import org.eclipse.debug.core.ILaunchManager; + +public class QuickLauncher { + private final String runMode; + private final QuickLaunchConfigurationDialog dialog; + + public QuickLauncher(String runMode) { + this.runMode = runMode; + this.dialog = new QuickLaunchConfigurationDialog(runMode); + + reloadLaunchers(); + + ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); + launchManager.addLaunchConfigurationListener(new ReloadLaunchersListener()); + } + + public void showQuickLaunchDialog() throws ExecutionException { + dialog.open(); + } + + private void reloadLaunchers() { + try { + ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); + List<ILaunchConfiguration> launchConfigurations = new ArrayList<>(); + for (ILaunchConfiguration launchConfiguration : launchManager.getLaunchConfigurations()) { + if (launchConfiguration.supportsMode(runMode)) { + launchConfigurations.add(launchConfiguration); + } + } + dialog.setElements(launchConfigurations.toArray()); + } catch (CoreException e) { + throw new IllegalStateException(e); + } + } + + private class ReloadLaunchersListener implements ILaunchConfigurationListener { + @Override + public void launchConfigurationAdded(ILaunchConfiguration configuration) { + reloadLaunchers(); + } + + @Override + public void launchConfigurationChanged(ILaunchConfiguration configuration) { + reloadLaunchers(); + } + + @Override + public void launchConfigurationRemoved(ILaunchConfiguration configuration) { + reloadLaunchers(); + } + } +} diff --git a/dk.danamlund.quicklaunch/src/dk/danamlund/quicklaunch/QuickRunLaunchConfigurationHandler.java b/dk.danamlund.quicklaunch/src/dk/danamlund/quicklaunch/QuickRunLaunchConfigurationHandler.java @@ -3,15 +3,17 @@ package dk.danamlund.quicklaunch; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.debug.core.ILaunchManager; public class QuickRunLaunchConfigurationHandler extends AbstractHandler { + private QuickLauncher quickLauncher = null; + @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); - QuickLaunchConfigurationDialog dialog = QuickLaunchConfigurationDialog.newRunDialog(window.getShell()); - dialog.open(); + public synchronized Object execute(ExecutionEvent event) throws ExecutionException { + if (quickLauncher == null) { + quickLauncher = new QuickLauncher(ILaunchManager.RUN_MODE); + } + quickLauncher.showQuickLaunchDialog(); return null; } } diff --git a/readme.txt b/readme.txt @@ -1,6 +1,6 @@ Eclipse quick launch -Run launch configurations like Ctrl-Shfit-T +Run launch configurations like Ctrl-Shift-T Launch with Ctrl-Shift-Y or (debug) with Ctrl-Shift-D