1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

Update LaunchBar APIs to deal with multiple target types per desc.

Also fixed up the case in new workspaces.

Change-Id: Ibbabc549034614c8095510c630da73f7eec171e3
Reviewed-on: https://git.eclipse.org/r/29427
Reviewed-by: Doug Schaefer <dschaefer@qnx.com>
Tested-by: Doug Schaefer <dschaefer@qnx.com>
This commit is contained in:
Doug Schaefer 2014-07-03 15:43:09 -04:00
parent b87b828496
commit 67939973fb
13 changed files with 235 additions and 146 deletions

View file

@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: LaunchBar for CDT Core Bundle-Name: LaunchBar for CDT Core
Bundle-SymbolicName: org.eclipse.cdt.launchbar.cdt.core;singleton:=true Bundle-SymbolicName: org.eclipse.cdt.launchbar.cdt.core;singleton:=true
Bundle-Version: 1.0.0.qualifier Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.eclipse.cdt.launchbar.cdt.core.Activator Bundle-Activator: org.eclipse.cdt.launchbar.cdt.core.internal.Activator
Bundle-Vendor: Eclipse CDT Bundle-Vendor: Eclipse CDT
Require-Bundle: org.eclipse.core.runtime, Require-Bundle: org.eclipse.core.runtime,
org.eclipse.cdt.launchbar.core, org.eclipse.cdt.launchbar.core,

View file

@ -1,4 +1,4 @@
package org.eclipse.cdt.launchbar.cdt.core; package org.eclipse.cdt.launchbar.cdt.core.internal;
import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;

View file

@ -1,7 +1,12 @@
package org.eclipse.cdt.launchbar.cdt.core.internal; package org.eclipse.cdt.launchbar.cdt.core.internal;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.launchbar.core.DefaultLaunchConfigurationDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
@ -11,18 +16,23 @@ import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.ILaunchMode;
public class CDTLaunchConfigDescriptor extends DefaultLaunchConfigurationDescriptor { public class CDTLaunchConfigDescriptor implements ILaunchConfigurationDescriptor {
private final ILaunchBarManager manager;
private String projectName; private String projectName;
private ILaunchConfiguration config;
private ILaunchMode[] launchModes;
public CDTLaunchConfigDescriptor(IProject project) { public CDTLaunchConfigDescriptor(ILaunchBarManager manager, IProject project) {
super(null); this.manager = manager;
projectName = project.getName(); this.projectName = project.getName();
} }
public CDTLaunchConfigDescriptor(ILaunchConfiguration config) { public CDTLaunchConfigDescriptor(ILaunchBarManager manager, ILaunchConfiguration config) {
super(config); this.manager = manager;
this.config = config;
} }
@Override @Override
@ -41,15 +51,10 @@ public class CDTLaunchConfigDescriptor extends DefaultLaunchConfigurationDescrip
return ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); return ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
} }
@Override
public ILaunchConfigurationType getLaunchConfigurationType() throws CoreException {
return getLaunchManager().getLaunchConfigurationType(ICDTLaunchConfigurationConstants.ID_LAUNCH_C_APP);
}
@Override @Override
public ILaunchConfiguration getLaunchConfiguration() throws CoreException { public ILaunchConfiguration getLaunchConfiguration() throws CoreException {
if (config == null) { if (config == null) {
ILaunchConfigurationType configType = getLaunchConfigurationType(); ILaunchConfigurationType configType = config.getType();
ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, getLaunchManager().generateLaunchConfigurationName(projectName)); ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, getLaunchManager().generateLaunchConfigurationName(projectName));
wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName); wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
wc.setMappedResources(new IResource[] { getProject() }); wc.setMappedResources(new IResource[] { getProject() });
@ -63,9 +68,61 @@ public class CDTLaunchConfigDescriptor extends DefaultLaunchConfigurationDescrip
} }
@Override @Override
public boolean matches(ILaunchConfiguration launchConfiguration) { public boolean matches(ILaunchConfiguration launchConfiguration) throws CoreException {
// TODO matches if it's the same project if (config == launchConfiguration)
return false; return true;
String pname = launchConfiguration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, "");
return pname.equals(projectName);
}
@Override
public ILaunchTarget[] getLaunchTargets() {
return new ILaunchTarget[] { manager.getLocalLaunchTarget() };
}
@Override
public ILaunchTarget getLaunchTarget(String id) {
ILaunchTarget localTarget = manager.getLocalLaunchTarget();
if (localTarget.getId().equals(id))
return localTarget;
return null;
}
@Override
public void setActiveLaunchTarget(ILaunchTarget target) {
// TODO Auto-generated method stub
}
@Override
public ILaunchMode[] getLaunchModes() throws CoreException {
if (launchModes == null) {
List<ILaunchMode> mymodes = new ArrayList<>();
ILaunchConfigurationType type = config.getType();
ILaunchMode[] modes = DebugPlugin.getDefault().getLaunchManager().getLaunchModes();
for (ILaunchMode mode : modes) {
if (type.supportsMode(mode.getIdentifier())) {
mymodes.add(mode);
}
}
launchModes = mymodes.toArray(new ILaunchMode[mymodes.size()]);
}
return launchModes;
}
@Override
public ILaunchMode getLaunchMode(String id) throws CoreException {
for (ILaunchMode mode : getLaunchModes())
if (mode.getIdentifier().equals(id))
return mode;
return null;
}
@Override
public void setActiveLaunchMode(ILaunchMode mode) {
// TODO Auto-generated method stub
} }
} }

View file

@ -17,7 +17,7 @@ public class CDTLaunchConfigProvider implements ILaunchConfigurationsProvider {
} }
@Override @Override
public ILaunchConfigurationDescriptor filterDescriptor(ILaunchConfigurationDescriptor descriptor) { public ILaunchConfigurationDescriptor filterDescriptor(ILaunchBarManager manager, ILaunchConfigurationDescriptor descriptor) {
return descriptor; return descriptor;
} }

View file

@ -9,4 +9,5 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.debug.core;bundle-version="3.9.0" org.eclipse.debug.core;bundle-version="3.9.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.cdt.launchbar.core Export-Package: org.eclipse.cdt.launchbar.core,
org.eclipse.cdt.launchbar.core.internal;x-friends:="org.eclipse.cdt.launchbar.ui"

View file

@ -27,16 +27,12 @@ public interface ILaunchBarManager extends IAdaptable {
void removeLaunchConfigurationDescriptor(ILaunchConfigurationDescriptor configDesc); void removeLaunchConfigurationDescriptor(ILaunchConfigurationDescriptor configDesc);
ILaunchConfigurationDescriptor getLaunchConfigurationDescriptor(ILaunchConfiguration configuration); ILaunchConfigurationDescriptor getLaunchConfigurationDescriptor(ILaunchConfiguration configuration) throws CoreException;
ILaunchMode[] getLaunchModes() throws CoreException;
ILaunchMode getActiveLaunchMode(); ILaunchMode getActiveLaunchMode();
void setActiveLaunchMode(ILaunchMode mode); void setActiveLaunchMode(ILaunchMode mode);
ILaunchTarget[] getLaunchTargets();
ILaunchTarget getActiveLaunchTarget(); ILaunchTarget getActiveLaunchTarget();
void setActiveLaunchTarget(ILaunchTarget target); void setActiveLaunchTarget(ILaunchTarget target);
@ -45,6 +41,8 @@ public interface ILaunchBarManager extends IAdaptable {
void removeLaunchTarget(ILaunchTarget target); void removeLaunchTarget(ILaunchTarget target);
ILaunchTarget getLocalLaunchTarget();
interface Listener { interface Listener {
void activeConfigurationDescriptorChanged(); void activeConfigurationDescriptorChanged();

View file

@ -12,7 +12,6 @@ package org.eclipse.cdt.launchbar.core;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchMode; import org.eclipse.debug.core.ILaunchMode;
public interface ILaunchConfigurationDescriptor { public interface ILaunchConfigurationDescriptor {
@ -24,13 +23,6 @@ public interface ILaunchConfigurationDescriptor {
*/ */
String getName(); String getName();
/**
* The type of launch configuration supported by this descriptor.
*
* @return
*/
ILaunchConfigurationType getLaunchConfigurationType() throws CoreException;
/** /**
* The corresponding launch configuration. * The corresponding launch configuration.
* If this launch config hasn't been created yet, it will be * If this launch config hasn't been created yet, it will be
@ -45,8 +37,9 @@ public interface ILaunchConfigurationDescriptor {
* *
* @param launchConfiguration * @param launchConfiguration
* @return * @return
* @throws CoreException
*/ */
boolean matches(ILaunchConfiguration launchConfiguration); boolean matches(ILaunchConfiguration launchConfiguration) throws CoreException;
/** /**
* Return the list of launch targets this configuration can launcht to. * Return the list of launch targets this configuration can launcht to.
@ -63,14 +56,6 @@ public interface ILaunchConfigurationDescriptor {
*/ */
ILaunchTarget getLaunchTarget(String id); ILaunchTarget getLaunchTarget(String id);
/**
* Set the active launch mode. Allows the descriptor to prepare for a
* launch in that mode.
*
* @param mode the new active launch mode
*/
void setActiveLaunchMode(ILaunchMode mode);
/** /**
* Set the active launch target. Allows the descriptor to prepare for * Set the active launch target. Allows the descriptor to prepare for
* a launch on that target. * a launch on that target.
@ -79,4 +64,29 @@ public interface ILaunchConfigurationDescriptor {
*/ */
void setActiveLaunchTarget(ILaunchTarget target); void setActiveLaunchTarget(ILaunchTarget target);
/**
* Return the launch modes supported by this descriptor.
*
* @return launch modes
* @throws CoreException
*/
ILaunchMode[] getLaunchModes() throws CoreException;
/**
* Returns the launch mode with the given identifier.
*
* @param id
* @return launch mode with id
* @throws CoreException
*/
ILaunchMode getLaunchMode(String id) throws CoreException;
/**
* Set the active launch mode. Allows the descriptor to prepare for a
* launch in that mode.
*
* @param mode the new active launch mode
*/
void setActiveLaunchMode(ILaunchMode mode);
} }

View file

@ -29,6 +29,6 @@ public interface ILaunchConfigurationsProvider {
* @param descriptor candidate descriptor * @param descriptor candidate descriptor
* @return the best descriptor * @return the best descriptor
*/ */
ILaunchConfigurationDescriptor filterDescriptor(ILaunchConfigurationDescriptor descriptor); ILaunchConfigurationDescriptor filterDescriptor(ILaunchBarManager manager, ILaunchConfigurationDescriptor descriptor);
} }

View file

@ -8,20 +8,28 @@
* Contributors: * Contributors:
* Doug Schaefer * Doug Schaefer
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.launchbar.core; package org.eclipse.cdt.launchbar.core.internal;
import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager; import java.util.ArrayList;
import org.eclipse.cdt.launchbar.core.internal.LocalTarget; import java.util.List;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchMode; import org.eclipse.debug.core.ILaunchMode;
public class DefaultLaunchConfigurationDescriptor implements ILaunchConfigurationDescriptor { public class DefaultLaunchConfigurationDescriptor implements ILaunchConfigurationDescriptor {
protected ILaunchConfiguration config; private final ILaunchBarManager manager;
private ILaunchConfiguration config;
private ILaunchMode[] launchModes;
public DefaultLaunchConfigurationDescriptor(ILaunchConfiguration config) { public DefaultLaunchConfigurationDescriptor(ILaunchBarManager manager, ILaunchConfiguration config) {
this.manager = manager;
this.config = config; this.config = config;
} }
@ -35,11 +43,6 @@ public class DefaultLaunchConfigurationDescriptor implements ILaunchConfiguratio
return config; return config;
} }
@Override
public ILaunchConfigurationType getLaunchConfigurationType() throws CoreException{
return config.getType();
}
@Override @Override
public boolean matches(ILaunchConfiguration launchConfiguration) { public boolean matches(ILaunchConfiguration launchConfiguration) {
return config.equals(launchConfiguration); return config.equals(launchConfiguration);
@ -47,12 +50,12 @@ public class DefaultLaunchConfigurationDescriptor implements ILaunchConfiguratio
@Override @Override
public ILaunchTarget getLaunchTarget(String id) { public ILaunchTarget getLaunchTarget(String id) {
return LocalTarget.ID.equals(id) ? LaunchBarManager.getLocalLaunchTarget() : null; return LocalTarget.ID.equals(id) ? manager.getLocalLaunchTarget() : null;
} }
@Override @Override
public ILaunchTarget[] getLaunchTargets() { public ILaunchTarget[] getLaunchTargets() {
return new ILaunchTarget[] { LaunchBarManager.getLocalLaunchTarget() }; return new ILaunchTarget[] { manager.getLocalLaunchTarget() };
} }
@Override @Override
@ -60,6 +63,31 @@ public class DefaultLaunchConfigurationDescriptor implements ILaunchConfiguratio
// nothing to do // nothing to do
} }
@Override
public ILaunchMode[] getLaunchModes() throws CoreException {
if (launchModes == null) {
List<ILaunchMode> mymodes = new ArrayList<>();
ILaunchConfigurationType type = config.getType();
ILaunchMode[] modes = DebugPlugin.getDefault().getLaunchManager().getLaunchModes();
for (ILaunchMode mode : modes) {
if (type.supportsMode(mode.getIdentifier())) {
mymodes.add(mode);
}
}
launchModes = mymodes.toArray(new ILaunchMode[mymodes.size()]);
}
return launchModes;
}
@Override
public ILaunchMode getLaunchMode(String id) throws CoreException {
for (ILaunchMode mode : getLaunchModes()) {
if (mode.getIdentifier().equals(id))
return mode;
}
return null;
}
@Override @Override
public void setActiveLaunchMode(ILaunchMode mode) { public void setActiveLaunchMode(ILaunchMode mode) {
// nothing to do // nothing to do

View file

@ -19,7 +19,6 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.launchbar.core.DefaultLaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager; import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationsProvider; import org.eclipse.cdt.launchbar.core.ILaunchConfigurationsProvider;
@ -35,7 +34,6 @@ import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationListener; import org.eclipse.debug.core.ILaunchConfigurationListener;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.ILaunchMode; import org.eclipse.debug.core.ILaunchMode;
import org.osgi.service.prefs.BackingStoreException; import org.osgi.service.prefs.BackingStoreException;
@ -47,7 +45,6 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
private List<ProviderExtensionDescriptor> providers = new ArrayList<>(); private List<ProviderExtensionDescriptor> providers = new ArrayList<>();
private Map<String, ILaunchConfigurationDescriptor> configDescs = new HashMap<>(); private Map<String, ILaunchConfigurationDescriptor> configDescs = new HashMap<>();
private ILaunchConfigurationDescriptor lastConfigDesc; private ILaunchConfigurationDescriptor lastConfigDesc;
private ILaunchMode[] launchModes = new ILaunchMode[0];
private ILaunchConfigurationDescriptor activeConfigDesc; private ILaunchConfigurationDescriptor activeConfigDesc;
private ILaunchMode activeLaunchMode; private ILaunchMode activeLaunchMode;
@ -115,11 +112,11 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
for (ILaunchConfiguration configuration : launchManager.getLaunchConfigurations()) { for (ILaunchConfiguration configuration : launchManager.getLaunchConfigurations()) {
ILaunchConfigurationDescriptor configDesc = new DefaultLaunchConfigurationDescriptor(configuration); ILaunchConfigurationDescriptor configDesc = new DefaultLaunchConfigurationDescriptor(this, configuration);
for (ProviderExtensionDescriptor provider : providers) { for (ProviderExtensionDescriptor provider : providers) {
configDesc = provider.getProvider().filterDescriptor(configDesc); configDesc = provider.getProvider().filterDescriptor(this, configDesc);
} }
configDescs.put(configDesc.getName(), configDesc); configDescs.put(configDesc.getName(), configDesc);
} }
@ -147,9 +144,9 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
@Override @Override
public void launchConfigurationAdded(ILaunchConfiguration configuration) { public void launchConfigurationAdded(ILaunchConfiguration configuration) {
ILaunchConfigurationDescriptor configDesc = new DefaultLaunchConfigurationDescriptor(configuration); ILaunchConfigurationDescriptor configDesc = new DefaultLaunchConfigurationDescriptor(this, configuration);
for (ProviderExtensionDescriptor provider : providers) { for (ProviderExtensionDescriptor provider : providers) {
configDesc = provider.getProvider().filterDescriptor(configDesc); configDesc = provider.getProvider().filterDescriptor(this, configDesc);
} }
try { try {
addLaunchConfigurationDescriptor(configDesc); addLaunchConfigurationDescriptor(configDesc);
@ -166,9 +163,13 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
@Override @Override
public void launchConfigurationRemoved(ILaunchConfiguration configuration) { public void launchConfigurationRemoved(ILaunchConfiguration configuration) {
ILaunchConfigurationDescriptor configDesc = getLaunchConfigurationDescriptor(configuration); try {
if (configDesc != null) ILaunchConfigurationDescriptor configDesc = getLaunchConfigurationDescriptor(configuration);
removeLaunchConfigurationDescriptor(configDesc); if (configDesc != null)
removeLaunchConfigurationDescriptor(configDesc);
} catch (CoreException e) {
Activator.log(e.getStatus());
}
} }
@Override @Override
@ -189,7 +190,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
} }
@Override @Override
public ILaunchConfigurationDescriptor getLaunchConfigurationDescriptor(ILaunchConfiguration configuration) { public ILaunchConfigurationDescriptor getLaunchConfigurationDescriptor(ILaunchConfiguration configuration) throws CoreException {
// Check by name // Check by name
ILaunchConfigurationDescriptor configDesc = configDescs.get(configuration.getName()); ILaunchConfigurationDescriptor configDesc = configDescs.get(configuration.getName());
if (configDesc.matches(configuration)) if (configDesc.matches(configuration))
@ -231,20 +232,6 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
return; return;
} }
// Get the launch modes
List<ILaunchMode> mymodes = new ArrayList<>();
ILaunchConfigurationType type = activeConfigDesc.getLaunchConfigurationType();
ILaunchMode[] modes = DebugPlugin.getDefault().getLaunchManager().getLaunchModes();
for (ILaunchMode mode : modes) {
if (type.supportsMode(mode.getIdentifier())) {
mymodes.add(mode);
}
}
launchModes = mymodes.toArray(new ILaunchMode[mymodes.size()]);
// Get the launch targets
// TODO
// Send notifications // Send notifications
for (Listener listener : listeners) { for (Listener listener : listeners) {
listener.activeConfigurationDescriptorChanged(); listener.activeConfigurationDescriptorChanged();
@ -252,6 +239,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
// Set active mode // Set active mode
String activeModeName = store.node(activeConfigDesc.getName()).get(PREF_ACTIVE_LAUNCH_MODE, null); String activeModeName = store.node(activeConfigDesc.getName()).get(PREF_ACTIVE_LAUNCH_MODE, null);
ILaunchMode[] launchModes = activeConfigDesc.getLaunchModes();
boolean foundMode = false; boolean foundMode = false;
if (activeModeName != null) { if (activeModeName != null) {
for (ILaunchMode mode : launchModes) { for (ILaunchMode mode : launchModes) {
@ -264,9 +252,9 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
} }
if (!foundMode) { if (!foundMode) {
if (launchModes.length > 0) { if (launchModes.length > 0) {
ILaunchMode mode = getLaunchMode("debug"); ILaunchMode mode = activeConfigDesc.getLaunchMode("debug");
if (mode == null) { if (mode == null) {
mode = getLaunchMode("run"); mode = activeConfigDesc.getLaunchMode("run");
} }
if (mode == null) { if (mode == null) {
mode = launchModes[0]; mode = launchModes[0];
@ -321,18 +309,6 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
} }
} }
@Override
public ILaunchMode[] getLaunchModes() throws CoreException {
return launchModes;
}
public ILaunchMode getLaunchMode(String id) {
for (ILaunchMode mode : launchModes)
if (id.equals(mode.getIdentifier()))
return mode;
return null;
}
@Override @Override
public ILaunchMode getActiveLaunchMode() { public ILaunchMode getActiveLaunchMode() {
return activeLaunchMode; return activeLaunchMode;
@ -344,6 +320,9 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
return; return;
activeLaunchMode = mode; activeLaunchMode = mode;
if (activeConfigDesc == null)
return;
Preferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).node(activeConfigDesc.getName()); Preferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).node(activeConfigDesc.getName());
if (mode != null) { if (mode != null) {
store.put(PREF_ACTIVE_LAUNCH_MODE, mode.getIdentifier()); store.put(PREF_ACTIVE_LAUNCH_MODE, mode.getIdentifier());
@ -362,14 +341,6 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
listener.activeLaunchModeChanged(); listener.activeLaunchModeChanged();
} }
@Override
public ILaunchTarget[] getLaunchTargets() {
if (activeConfigDesc != null)
return activeConfigDesc.getLaunchTargets();
else
return new ILaunchTarget[0];
}
@Override @Override
public ILaunchTarget getActiveLaunchTarget() { public ILaunchTarget getActiveLaunchTarget() {
return activeLaunchTarget; return activeLaunchTarget;
@ -380,6 +351,10 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
if (activeLaunchTarget == target) return; if (activeLaunchTarget == target) return;
activeLaunchTarget = target; activeLaunchTarget = target;
if (activeConfigDesc == null)
return;
Preferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).node(activeConfigDesc.getName()); Preferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).node(activeConfigDesc.getName());
if (target != null) { if (target != null) {
store.put(PREF_ACTIVE_LAUNCH_TARGET, target.getId()); store.put(PREF_ACTIVE_LAUNCH_TARGET, target.getId());
@ -398,7 +373,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
listener.activeLaunchTargetChanged(); listener.activeLaunchTargetChanged();
} }
public static LocalTarget getLocalLaunchTarget() { public LocalTarget getLocalLaunchTarget() {
return localLaunchTarget; return localLaunchTarget;
} }

View file

@ -16,6 +16,7 @@ import java.util.Map;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager; import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.core.internal.DefaultLaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager; import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager;
import org.eclipse.cdt.launchbar.ui.internal.dialogs.LaunchConfigurationEditDialog; import org.eclipse.cdt.launchbar.ui.internal.dialogs.LaunchConfigurationEditDialog;
@ -61,6 +62,8 @@ public class ConfigSelector extends CSelector {
private LaunchBarUIManager uiManager; private LaunchBarUIManager uiManager;
private static final String[] noConfigs = new String[] { "No Launch Configurations" };
public ConfigSelector(Composite parent, int style) { public ConfigSelector(Composite parent, int style) {
super(parent, style); super(parent, style);
@ -76,11 +79,9 @@ public class ConfigSelector extends CSelector {
@Override @Override
public Object[] getElements(Object inputElement) { public Object[] getElements(Object inputElement) {
ILaunchConfigurationDescriptor[] descs = getManager().getLaunchConfigurationDescriptors(); ILaunchConfigurationDescriptor[] descs = getManager().getLaunchConfigurationDescriptors();
if (descs.length == 0) { if (descs.length > 0)
return new String[] { "No Launch Configurations" };
} else {
return descs; return descs;
} return noConfigs;
} }
}); });
@ -103,19 +104,21 @@ public class ConfigSelector extends CSelector {
} }
// Default // Default
try { if (element instanceof DefaultLaunchConfigurationDescriptor) {
ILaunchConfigurationType type = configDesc.getLaunchConfigurationType(); try {
ImageDescriptor imageDescriptor = DebugUITools.getDefaultImageDescriptor(type); ILaunchConfigurationType type = configDesc.getLaunchConfiguration().getType();
if (imageDescriptor != null) { ImageDescriptor imageDescriptor = DebugUITools.getDefaultImageDescriptor(type);
Image image = images.get(imageDescriptor); if (imageDescriptor != null) {
if (image == null) { Image image = images.get(imageDescriptor);
image = imageDescriptor.createImage(); if (image == null) {
images.put(imageDescriptor, image); image = imageDescriptor.createImage();
images.put(imageDescriptor, image);
}
return image;
} }
return image; } catch (CoreException e) {
Activator.log(e);
} }
} catch (CoreException e) {
Activator.log(e);
} }
} }
// Default // Default
@ -275,4 +278,11 @@ public class ConfigSelector extends CSelector {
uiManager = (LaunchBarUIManager) ((ILaunchBarManager) input).getAdapter(LaunchBarUIManager.class); uiManager = (LaunchBarUIManager) ((ILaunchBarManager) input).getAdapter(LaunchBarUIManager.class);
} }
@Override
public void setSelection(Object element) {
if (element == null)
element = noConfigs[0];
super.setSelection(element);
}
} }

View file

@ -32,6 +32,8 @@ import org.eclipse.swt.widgets.Composite;
@SuppressWarnings("restriction") @SuppressWarnings("restriction")
public class ModeSelector extends CSelector { public class ModeSelector extends CSelector {
private static final String[] noModes = new String[] { "---" };
public ModeSelector(Composite parent, int style) { public ModeSelector(Composite parent, int style) {
super(parent, style); super(parent, style);
@ -47,11 +49,13 @@ public class ModeSelector extends CSelector {
@Override @Override
public Object[] getElements(Object inputElement) { public Object[] getElements(Object inputElement) {
try { try {
return getManager().getLaunchModes(); ILaunchMode[] modes = getManager().getActiveLaunchConfigurationDescriptor().getLaunchModes();
if (modes.length > 0)
return modes;
} catch (CoreException e) { } catch (CoreException e) {
Activator.log(e); Activator.log(e);
return new Object[0];
} }
return noModes;
} }
}); });
@ -69,20 +73,15 @@ public class ModeSelector extends CSelector {
ILaunchConfigurationDescriptor config = getManager().getActiveLaunchConfigurationDescriptor(); ILaunchConfigurationDescriptor config = getManager().getActiveLaunchConfigurationDescriptor();
if (config != null && element instanceof ILaunchMode) { if (config != null && element instanceof ILaunchMode) {
ILaunchMode mode = (ILaunchMode) element; ILaunchMode mode = (ILaunchMode) element;
try { ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getDefaultLaunchGroup(mode.getIdentifier());
ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager() if (group != null) {
.getLaunchGroup(config.getLaunchConfigurationType(), mode.getIdentifier()); ImageDescriptor imageDesc = group.getImageDescriptor();
if (group != null) { Image image = images.get(imageDesc);
ImageDescriptor imageDesc = group.getImageDescriptor(); if (image == null) {
Image image = images.get(imageDesc); image = imageDesc.createImage();
if (image == null) { images.put(imageDesc, image);
image = imageDesc.createImage();
images.put(imageDesc, image);
}
return image;
} }
} catch (CoreException e) { return image;
Activator.log(e);
} }
} }
return super.getImage(element); return super.getImage(element);
@ -92,14 +91,9 @@ public class ModeSelector extends CSelector {
ILaunchConfigurationDescriptor config = getManager().getActiveLaunchConfigurationDescriptor(); ILaunchConfigurationDescriptor config = getManager().getActiveLaunchConfigurationDescriptor();
if (config != null && element instanceof ILaunchMode) { if (config != null && element instanceof ILaunchMode) {
ILaunchMode mode = (ILaunchMode) element; ILaunchMode mode = (ILaunchMode) element;
try { ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getDefaultLaunchGroup(mode.getIdentifier());
ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager() if (group != null) {
.getLaunchGroup(config.getLaunchConfigurationType(), mode.getIdentifier()); return group.getLabel().replace("&", "");
if (group != null) {
return group.getLabel().replace("&", "");
}
} catch (CoreException e) {
Activator.log(e);
} }
} }
return super.getText(element); return super.getText(element);
@ -153,4 +147,11 @@ public class ModeSelector extends CSelector {
return (ILaunchBarManager) getInput(); return (ILaunchBarManager) getInput();
} }
@Override
public void setSelection(Object element) {
if (element == null)
element = noModes[0];
super.setSelection(element);
}
} }

View file

@ -19,10 +19,8 @@ import org.eclipse.cdt.launchbar.ui.ILaunchBarUIConstants;
import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager; import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager;
import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseAdapter;
@ -44,7 +42,8 @@ public class TargetSelector extends CSelector {
private final LaunchBarUIManager uiManager; private final LaunchBarUIManager uiManager;
private static final ISelection nullSelection = new StructuredSelection("---"); private static final String[] noTargets = new String[] { "---" };
public TargetSelector(Composite parent, int style) { public TargetSelector(Composite parent, int style) {
super(parent, style); super(parent, style);
@ -64,7 +63,10 @@ public class TargetSelector extends CSelector {
@Override @Override
public Object[] getElements(Object inputElement) { public Object[] getElements(Object inputElement) {
return getManager().getLaunchTargets(); ILaunchTarget[] targets = getManager().getActiveLaunchConfigurationDescriptor().getLaunchTargets();
if (targets.length > 0)
return targets;
return noTargets;
} }
}); });
@ -89,7 +91,7 @@ public class TargetSelector extends CSelector {
if (labelProvider != null) { if (labelProvider != null) {
return labelProvider.getText(element); return labelProvider.getText(element);
} }
return target.getId(); return target.getName();
} }
return super.getText(element); return super.getText(element);
} }
@ -227,4 +229,11 @@ public class TargetSelector extends CSelector {
return (ILaunchBarManager) getInput(); return (ILaunchBarManager) getInput();
} }
@Override
public void setSelection(Object element) {
if (element == null)
element = noTargets[0];
super.setSelection(element);
}
} }