mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-10 18:45:26 +02:00
launchbar: track non launch bar launches
- when user runs something not from launch bar, launch bar won't updade which creates unplesent gap in experience. This fix makes launchbar track launches and update active descriptor/mode/target depending on what was launched. Change-Id: Ie70c6927997bba8ee06a393e767e02ccb4cf4cb7
This commit is contained in:
parent
ca538d05a5
commit
3eb77d17f6
4 changed files with 162 additions and 60 deletions
|
@ -47,6 +47,14 @@ public abstract class AbstractLaunchConfigProvider implements ILaunchConfigurati
|
||||||
workingCopy.setAttribute(ATTR_PROVIDER_CLASS, getClass().getName());
|
workingCopy.setAttribute(ATTR_PROVIDER_CLASS, getClass().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean launchDescriptorMatches(ILaunchDescriptor descriptor, ILaunchConfiguration configuration, ILaunchTarget target) throws CoreException {
|
||||||
|
ILaunchConfiguration lc = descriptor.getAdapter(ILaunchConfiguration.class);
|
||||||
|
if (lc == null)
|
||||||
|
return false;
|
||||||
|
return configuration.getName().equals(lc.getName());
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException {
|
protected boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException {
|
||||||
if (!configuration.exists()) {
|
if (!configuration.exists()) {
|
||||||
// can't own it if it doesn't exist
|
// can't own it if it doesn't exist
|
||||||
|
|
|
@ -19,12 +19,11 @@ import org.eclipse.launchbar.core.target.ILaunchTargetManager;
|
||||||
/**
|
/**
|
||||||
* The launch config provider for the default descriptor which is the launch
|
* The launch config provider for the default descriptor which is the launch
|
||||||
* config itself.
|
* config itself.
|
||||||
*
|
*
|
||||||
* Override this class and register an extension if you want to support targets
|
* Override this class and register an extension if you want to support targets
|
||||||
* other than the local connection.
|
* other than the local connection.
|
||||||
*/
|
*/
|
||||||
public class DefaultLaunchConfigProvider implements ILaunchConfigurationProvider {
|
public class DefaultLaunchConfigProvider implements ILaunchConfigurationProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException {
|
public boolean supports(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException {
|
||||||
// Only supports Local connection
|
// Only supports Local connection
|
||||||
|
@ -69,4 +68,11 @@ public class DefaultLaunchConfigProvider implements ILaunchConfigurationProvider
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean launchDescriptorMatches(ILaunchDescriptor descriptor, ILaunchConfiguration configuration, ILaunchTarget target) throws CoreException {
|
||||||
|
ILaunchConfiguration lc = descriptor.getAdapter(ILaunchConfiguration.class);
|
||||||
|
if (lc == null)
|
||||||
|
return false;
|
||||||
|
return configuration.getName().equals(lc.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||||
/**
|
/**
|
||||||
* The provider of launch configurations of a given type for a given descriptor
|
* The provider of launch configurations of a given type for a given descriptor
|
||||||
* type and a given target type.
|
* type and a given target type.
|
||||||
*
|
*
|
||||||
* It is recommended to extend {@link AbstractLaunchConfigProvider} or one of
|
* It is recommended to extend {@link AbstractLaunchConfigProvider} or one of
|
||||||
* it's subclasses instead of implementing this directly.
|
* it's subclasses instead of implementing this directly.
|
||||||
*/
|
*/
|
||||||
|
@ -26,10 +26,10 @@ public interface ILaunchConfigurationProvider {
|
||||||
/**
|
/**
|
||||||
* Does this config provider provide launch configurations for the
|
* Does this config provider provide launch configurations for the
|
||||||
* combination of descriptor and target.
|
* combination of descriptor and target.
|
||||||
*
|
*
|
||||||
* Note: this is called when filtering targets for a descriptor. Processing
|
* Note: this is called when filtering targets for a descriptor. Processing
|
||||||
* should be minimal.
|
* should be minimal.
|
||||||
*
|
*
|
||||||
* @param descriptor
|
* @param descriptor
|
||||||
* @param target
|
* @param target
|
||||||
* @return true if target is supported, false otherwise.
|
* @return true if target is supported, false otherwise.
|
||||||
|
@ -38,7 +38,7 @@ public interface ILaunchConfigurationProvider {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the launch configuation type for the descriptor and target.
|
* Return the launch configuation type for the descriptor and target.
|
||||||
*
|
*
|
||||||
* @param descriptor
|
* @param descriptor
|
||||||
* @param target
|
* @param target
|
||||||
* launch configuration type or null if not supported
|
* launch configuration type or null if not supported
|
||||||
|
@ -61,11 +61,29 @@ public interface ILaunchConfigurationProvider {
|
||||||
ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target)
|
ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target)
|
||||||
throws CoreException;
|
throws CoreException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if given descriptor is associated with given launch configuration.
|
||||||
|
* I.e. if getLaunchConfiguration(descriptor, target) returns a launch configuration,
|
||||||
|
* calling launchDescriptorMatches(descriptor, configuration, target) should return true.
|
||||||
|
*
|
||||||
|
* This method is used to activate descriptor when launch happens, return false all the time would mean
|
||||||
|
* launch would track launches of this specific descriptor (if they occur outside of launchbar).
|
||||||
|
* @param configuration
|
||||||
|
* launch configuration in question
|
||||||
|
* @param target - target to match, it can be null if launch bar cannot determine target,
|
||||||
|
* in this case it should act as wildcard
|
||||||
|
*
|
||||||
|
* @return launch configuration
|
||||||
|
* @throws CoreException
|
||||||
|
*/
|
||||||
|
boolean launchDescriptorMatches(ILaunchDescriptor descriptor, ILaunchConfiguration configuration, ILaunchTarget target)
|
||||||
|
throws CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A launch configuration has been added. Provider can inspect it and
|
* A launch configuration has been added. Provider can inspect it and
|
||||||
* associate with internal map. Provider should make sure it owns this
|
* associate with internal map. Provider should make sure it owns this
|
||||||
* launch configuration or it can modify it to take over.
|
* launch configuration or it can modify it to take over.
|
||||||
*
|
*
|
||||||
* @return true of provider owns this launch configuration
|
* @return true of provider owns this launch configuration
|
||||||
*/
|
*/
|
||||||
boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException;
|
boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException;
|
||||||
|
@ -76,7 +94,7 @@ public interface ILaunchConfigurationProvider {
|
||||||
* configuration has been removed from file system, so accessing its
|
* configuration has been removed from file system, so accessing its
|
||||||
* attributes won't work. If provider cannot determine if it owns it it
|
* attributes won't work. If provider cannot determine if it owns it it
|
||||||
* should return false.
|
* should return false.
|
||||||
*
|
*
|
||||||
* @param configuration
|
* @param configuration
|
||||||
* @return true if provider owns this launch configuration
|
* @return true if provider owns this launch configuration
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
|
@ -87,7 +105,7 @@ public interface ILaunchConfigurationProvider {
|
||||||
* A launch configuration has been changed. Provider can inspect it to
|
* A launch configuration has been changed. Provider can inspect it to
|
||||||
* re-evaluate its internal map. Provider should make sure it owns this
|
* re-evaluate its internal map. Provider should make sure it owns this
|
||||||
* launch configuration or it can modify it to take over.
|
* launch configuration or it can modify it to take over.
|
||||||
*
|
*
|
||||||
* @return true of provider owns this launch configuration
|
* @return true of provider owns this launch configuration
|
||||||
*/
|
*/
|
||||||
boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException;
|
boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException;
|
||||||
|
@ -95,7 +113,7 @@ public interface ILaunchConfigurationProvider {
|
||||||
/**
|
/**
|
||||||
* A launch descriptor has been removed. Remove any launch configurations
|
* A launch descriptor has been removed. Remove any launch configurations
|
||||||
* that were created for it.
|
* that were created for it.
|
||||||
*
|
*
|
||||||
* @param descriptor
|
* @param descriptor
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
|
@ -104,7 +122,7 @@ public interface ILaunchConfigurationProvider {
|
||||||
/**
|
/**
|
||||||
* A launch target has been removed. Remove any launch configurations that
|
* A launch target has been removed. Remove any launch configurations that
|
||||||
* were created for it.
|
* were created for it.
|
||||||
*
|
*
|
||||||
* @param target
|
* @param target
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -32,8 +32,10 @@ import org.eclipse.core.runtime.jobs.Job;
|
||||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||||
import org.eclipse.debug.core.DebugPlugin;
|
import org.eclipse.debug.core.DebugPlugin;
|
||||||
|
import org.eclipse.debug.core.ILaunch;
|
||||||
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.ILaunchListener;
|
||||||
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.eclipse.launchbar.core.ILaunchBarManager;
|
import org.eclipse.launchbar.core.ILaunchBarManager;
|
||||||
|
@ -44,6 +46,7 @@ import org.eclipse.launchbar.core.ILaunchObjectProvider;
|
||||||
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||||
import org.eclipse.launchbar.core.target.ILaunchTargetListener;
|
import org.eclipse.launchbar.core.target.ILaunchTargetListener;
|
||||||
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
|
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
|
||||||
|
import org.eclipse.launchbar.core.target.launch.ITargetedLaunch;
|
||||||
import org.osgi.service.prefs.BackingStoreException;
|
import org.osgi.service.prefs.BackingStoreException;
|
||||||
import org.osgi.service.prefs.Preferences;
|
import org.osgi.service.prefs.Preferences;
|
||||||
|
|
||||||
|
@ -51,7 +54,6 @@ import org.osgi.service.prefs.Preferences;
|
||||||
* The brains of the launch bar.
|
* The brains of the launch bar.
|
||||||
*/
|
*/
|
||||||
public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListener {
|
public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListener {
|
||||||
|
|
||||||
public interface Listener {
|
public interface Listener {
|
||||||
default void activeLaunchDescriptorChanged() {
|
default void activeLaunchDescriptorChanged() {
|
||||||
}
|
}
|
||||||
|
@ -68,39 +70,29 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
default void launchTargetsChanged() {
|
default void launchTargetsChanged() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final List<Listener> listeners = new LinkedList<>();
|
private final List<Listener> listeners = new LinkedList<>();
|
||||||
|
|
||||||
// The launch object providers
|
// The launch object providers
|
||||||
private final List<ILaunchObjectProvider> objectProviders = new ArrayList<>();
|
private final List<ILaunchObjectProvider> objectProviders = new ArrayList<>();
|
||||||
|
|
||||||
// The descriptor types
|
// The descriptor types
|
||||||
private final Map<String, LaunchDescriptorTypeInfo> descriptorTypes = new HashMap<>();
|
private final Map<String, LaunchDescriptorTypeInfo> descriptorTypes = new HashMap<>();
|
||||||
|
|
||||||
// Descriptor types ordered from highest priority to lowest
|
// Descriptor types ordered from highest priority to lowest
|
||||||
private List<LaunchDescriptorTypeInfo> orderedDescriptorTypes;
|
private List<LaunchDescriptorTypeInfo> orderedDescriptorTypes;
|
||||||
|
|
||||||
// the extended info for loaded descriptor types
|
// the extended info for loaded descriptor types
|
||||||
private final Map<ILaunchDescriptorType, LaunchDescriptorTypeInfo> descriptorTypeInfo = new HashMap<>();
|
private final Map<ILaunchDescriptorType, LaunchDescriptorTypeInfo> descriptorTypeInfo = new HashMap<>();
|
||||||
private final Map<String, List<LaunchConfigProviderInfo>> configProviders = new HashMap<>();
|
private final Map<String, List<LaunchConfigProviderInfo>> configProviders = new HashMap<>();
|
||||||
|
|
||||||
// Descriptors in MRU order, key is desc type id and desc name.
|
// Descriptors in MRU order, key is desc type id and desc name.
|
||||||
private final Map<Pair<String, String>, ILaunchDescriptor> descriptors = new LinkedHashMap<>();
|
private final Map<Pair<String, String>, ILaunchDescriptor> descriptors = new LinkedHashMap<>();
|
||||||
|
|
||||||
// Map of launch objects to launch descriptors
|
// Map of launch objects to launch descriptors
|
||||||
private final Map<Object, ILaunchDescriptor> objectDescriptorMap = new HashMap<>();
|
private final Map<Object, ILaunchDescriptor> objectDescriptorMap = new HashMap<>();
|
||||||
|
|
||||||
private ILaunchTargetManager launchTargetManager;
|
private ILaunchTargetManager launchTargetManager;
|
||||||
|
|
||||||
private ILaunchDescriptor activeLaunchDesc;
|
private ILaunchDescriptor activeLaunchDesc;
|
||||||
private ILaunchMode activeLaunchMode;
|
private ILaunchMode activeLaunchMode;
|
||||||
private ILaunchTarget activeLaunchTarget;
|
private ILaunchTarget activeLaunchTarget;
|
||||||
|
|
||||||
// private static final String PREF_ACTIVE_CONFIG_DESC = "activeConfigDesc";
|
// private static final String PREF_ACTIVE_CONFIG_DESC = "activeConfigDesc";
|
||||||
private static final String PREF_ACTIVE_LAUNCH_MODE = "activeLaunchMode"; //$NON-NLS-1$
|
private static final String PREF_ACTIVE_LAUNCH_MODE = "activeLaunchMode"; //$NON-NLS-1$
|
||||||
private static final String PREF_ACTIVE_LAUNCH_TARGET = "activeLaunchTarget"; //$NON-NLS-1$
|
private static final String PREF_ACTIVE_LAUNCH_TARGET = "activeLaunchTarget"; //$NON-NLS-1$
|
||||||
private static final String PREF_CONFIG_DESC_ORDER = "configDescList"; //$NON-NLS-1$
|
private static final String PREF_CONFIG_DESC_ORDER = "configDescList"; //$NON-NLS-1$
|
||||||
|
private static final String PREF_TRACK_LAUNCHES = "trackLaunches"; //$NON-NLS-1$
|
||||||
boolean initialized = false;
|
boolean initialized = false;
|
||||||
|
|
||||||
public LaunchBarManager() {
|
public LaunchBarManager() {
|
||||||
|
@ -146,17 +138,14 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
// Fetch the desc order before the init messes it up
|
// Fetch the desc order before the init messes it up
|
||||||
IEclipsePreferences store = getPreferenceStore();
|
IEclipsePreferences store = getPreferenceStore();
|
||||||
String configDescIds = store.get(PREF_CONFIG_DESC_ORDER, ""); //$NON-NLS-1$
|
String configDescIds = store.get(PREF_CONFIG_DESC_ORDER, ""); //$NON-NLS-1$
|
||||||
|
|
||||||
// Load up the types
|
// Load up the types
|
||||||
loadExtensions();
|
loadExtensions();
|
||||||
|
|
||||||
// Hook up the existing launch configurations and listen
|
// Hook up the existing launch configurations and listen
|
||||||
ILaunchManager launchManager = getLaunchManager();
|
ILaunchManager launchManager = getLaunchManager();
|
||||||
for (ILaunchConfiguration configuration : launchManager.getLaunchConfigurations()) {
|
for (ILaunchConfiguration configuration : launchManager.getLaunchConfigurations()) {
|
||||||
launchConfigurationAdded(configuration);
|
launchConfigurationAdded(configuration);
|
||||||
}
|
}
|
||||||
launchManager.addLaunchConfigurationListener(this);
|
launchManager.addLaunchConfigurationListener(this);
|
||||||
|
|
||||||
// Reorder the descriptors based on the preference
|
// Reorder the descriptors based on the preference
|
||||||
if (!configDescIds.isEmpty()) {
|
if (!configDescIds.isEmpty()) {
|
||||||
String[] split = configDescIds.split(","); //$NON-NLS-1$
|
String[] split = configDescIds.split(","); //$NON-NLS-1$
|
||||||
|
@ -170,12 +159,51 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
last = desc;
|
last = desc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the active desc, with MRU, it should be the last one
|
// Set the active desc, with MRU, it should be the last one
|
||||||
if (last != null) {
|
if (last != null) {
|
||||||
setActiveLaunchDescriptor(last);
|
setActiveLaunchDescriptor(last);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
launchManager.addLaunchListener(new ILaunchListener() {
|
||||||
|
@Override
|
||||||
|
public void launchRemoved(ILaunch launch) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void launchAdded(ILaunch launch) {
|
||||||
|
if (!getPreferenceStore().getBoolean(PREF_TRACK_LAUNCHES, true))
|
||||||
|
return;
|
||||||
|
ILaunchConfiguration lc = launch.getLaunchConfiguration();
|
||||||
|
String mode = launch.getLaunchMode();
|
||||||
|
ILaunchTarget target = null;
|
||||||
|
if (launch instanceof ITargetedLaunch) {
|
||||||
|
target = ((ITargetedLaunch) launch).getLaunchTarget();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
setActive(lc, mode, target);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
Activator.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void launchChanged(ILaunch launch) {
|
||||||
|
ILaunchConfiguration lc = launch.getLaunchConfiguration();
|
||||||
|
ILaunchTarget target = null;
|
||||||
|
if (launch instanceof ITargetedLaunch) {
|
||||||
|
target = ((ITargetedLaunch) launch).getLaunchTarget();
|
||||||
|
}
|
||||||
|
if (launchDescriptorMatches(activeLaunchDesc, lc, target)) {
|
||||||
|
// active launch delegate may have changed target
|
||||||
|
try {
|
||||||
|
setActiveLaunchTarget(target);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
Activator.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
} finally {
|
} finally {
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
@ -188,7 +216,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
private void loadExtensions() throws CoreException {
|
private void loadExtensions() throws CoreException {
|
||||||
IExtensionPoint point = getExtensionPoint();
|
IExtensionPoint point = getExtensionPoint();
|
||||||
IExtension[] extensions = point.getExtensions();
|
IExtension[] extensions = point.getExtensions();
|
||||||
|
|
||||||
// Load up the types
|
// Load up the types
|
||||||
for (IExtension extension : extensions) {
|
for (IExtension extension : extensions) {
|
||||||
for (IConfigurationElement element : extension.getConfigurationElements()) {
|
for (IConfigurationElement element : extension.getConfigurationElements()) {
|
||||||
|
@ -196,9 +223,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
String elementName = element.getName();
|
String elementName = element.getName();
|
||||||
if (elementName.equals("descriptorType")) { //$NON-NLS-1$
|
if (elementName.equals("descriptorType")) { //$NON-NLS-1$
|
||||||
LaunchDescriptorTypeInfo typeInfo = new LaunchDescriptorTypeInfo(element);
|
LaunchDescriptorTypeInfo typeInfo = new LaunchDescriptorTypeInfo(element);
|
||||||
|
|
||||||
descriptorTypes.put(typeInfo.getId(), typeInfo);
|
descriptorTypes.put(typeInfo.getId(), typeInfo);
|
||||||
|
|
||||||
if (configProviders.get(typeInfo.getId()) == null) {
|
if (configProviders.get(typeInfo.getId()) == null) {
|
||||||
// Make sure we initialize the list
|
// Make sure we initialize the list
|
||||||
configProviders.put(typeInfo.getId(), new ArrayList<LaunchConfigProviderInfo>());
|
configProviders.put(typeInfo.getId(), new ArrayList<LaunchConfigProviderInfo>());
|
||||||
|
@ -217,7 +242,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort things
|
// Sort things
|
||||||
orderedDescriptorTypes = new ArrayList<>(descriptorTypes.values());
|
orderedDescriptorTypes = new ArrayList<>(descriptorTypes.values());
|
||||||
Collections.sort(orderedDescriptorTypes, new Comparator<LaunchDescriptorTypeInfo>() {
|
Collections.sort(orderedDescriptorTypes, new Comparator<LaunchDescriptorTypeInfo>() {
|
||||||
|
@ -234,7 +258,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (List<LaunchConfigProviderInfo> providers : configProviders.values()) {
|
for (List<LaunchConfigProviderInfo> providers : configProviders.values()) {
|
||||||
Collections.sort(providers, new Comparator<LaunchConfigProviderInfo>() {
|
Collections.sort(providers, new Comparator<LaunchConfigProviderInfo>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -250,9 +273,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that all the types are loaded, the object providers which now
|
// Now that all the types are loaded, the object providers which now
|
||||||
// populate the descriptors
|
// populate the descriptors
|
||||||
for (IExtension extension : extensions) {
|
for (IExtension extension : extensions) {
|
||||||
|
@ -282,7 +303,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Pair<String, String>(key.substring(0, i), key.substring(i + 1));
|
return new Pair<String, String>(key.substring(0, i), key.substring(i + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,7 +328,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
if (descriptor == null)
|
if (descriptor == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
for (LaunchConfigProviderInfo providerInfo : configProviders.get(getDescriptorTypeId(descriptor.getType()))) {
|
for (LaunchConfigProviderInfo providerInfo : configProviders.get(getDescriptorTypeId(descriptor.getType()))) {
|
||||||
if (providerInfo.enabled(descriptor) && providerInfo.enabled(target)) {
|
if (providerInfo.enabled(descriptor) && providerInfo.enabled(target)) {
|
||||||
ILaunchConfigurationType type = providerInfo.getProvider().getLaunchConfigurationType(descriptor,
|
ILaunchConfigurationType type = providerInfo.getProvider().getLaunchConfigurationType(descriptor,
|
||||||
|
@ -318,7 +337,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,7 +347,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
if (desc != null) {
|
if (desc != null) {
|
||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (LaunchDescriptorTypeInfo descriptorInfo : orderedDescriptorTypes) {
|
for (LaunchDescriptorTypeInfo descriptorInfo : orderedDescriptorTypes) {
|
||||||
try {
|
try {
|
||||||
if (descriptorInfo.enabled(launchObject)) {
|
if (descriptorInfo.enabled(launchObject)) {
|
||||||
|
@ -343,13 +360,11 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
addDescriptor(launchObject, desc);
|
addDescriptor(launchObject, desc);
|
||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,7 +377,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
if (descriptor.equals(activeLaunchDesc)) {
|
if (descriptor.equals(activeLaunchDesc)) {
|
||||||
setActiveLaunchDescriptor(getLastUsedDescriptor());
|
setActiveLaunchDescriptor(getLastUsedDescriptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (LaunchConfigProviderInfo providerInfo : configProviders
|
for (LaunchConfigProviderInfo providerInfo : configProviders
|
||||||
.get(getDescriptorTypeId(descriptor.getType()))) {
|
.get(getDescriptorTypeId(descriptor.getType()))) {
|
||||||
if (providerInfo.enabled(descriptor)) {
|
if (providerInfo.enabled(descriptor)) {
|
||||||
|
@ -375,14 +389,12 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
@Override
|
@Override
|
||||||
public void launchObjectChanged(Object launchObject) throws CoreException {
|
public void launchObjectChanged(Object launchObject) throws CoreException {
|
||||||
// TODO deal with object renames here, somehow
|
// TODO deal with object renames here, somehow
|
||||||
|
|
||||||
ILaunchDescriptor origDesc = objectDescriptorMap.get(launchObject);
|
ILaunchDescriptor origDesc = objectDescriptorMap.get(launchObject);
|
||||||
if (origDesc == null) {
|
if (origDesc == null) {
|
||||||
// See if anyone wants it now
|
// See if anyone wants it now
|
||||||
launchObjectAdded(launchObject);
|
launchObjectAdded(launchObject);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if descriptor still wants it
|
// check if descriptor still wants it
|
||||||
ILaunchDescriptorType origDescType = origDesc.getType();
|
ILaunchDescriptorType origDescType = origDesc.getType();
|
||||||
try {
|
try {
|
||||||
|
@ -419,6 +431,38 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
return activeLaunchDesc;
|
return activeLaunchDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setActive(ILaunchConfiguration config, String mode, ILaunchTarget target) throws CoreException {
|
||||||
|
ILaunchDescriptor descriptor = getLaunchDescriptor(config, target);
|
||||||
|
if (descriptor == null)
|
||||||
|
return; // not found
|
||||||
|
// we do not call setActiveLaunchTarget because it will cause mode/target switch and cause flickering
|
||||||
|
boolean changeDesc = activeLaunchDesc != descriptor;
|
||||||
|
boolean changeTarget = target != null && activeLaunchTarget != target;
|
||||||
|
if (changeDesc) {
|
||||||
|
doSetActiveLaunchDescriptor(descriptor);
|
||||||
|
// store in persistent storage
|
||||||
|
storeActiveDescriptor(activeLaunchDesc);
|
||||||
|
}
|
||||||
|
if (changeTarget) {
|
||||||
|
activeLaunchTarget = target;
|
||||||
|
storeLaunchTarget(activeLaunchDesc, target);
|
||||||
|
}
|
||||||
|
ILaunchMode[] supportedModes = getLaunchModes();
|
||||||
|
for (ILaunchMode launchMode : supportedModes) {
|
||||||
|
if (launchMode.getIdentifier().equals(mode)) {
|
||||||
|
setActiveLaunchMode(launchMode);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// send delayed notification about descriptor change
|
||||||
|
if (changeDesc) {
|
||||||
|
fireActiveLaunchDescriptorChanged();
|
||||||
|
}
|
||||||
|
if (changeTarget) {
|
||||||
|
fireActiveLaunchTargetChanged(); // notify target listeners
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setActiveLaunchDescriptor(ILaunchDescriptor descriptor) throws CoreException {
|
public void setActiveLaunchDescriptor(ILaunchDescriptor descriptor) throws CoreException {
|
||||||
Activator.trace("set active descriptor " + descriptor); //$NON-NLS-1$
|
Activator.trace("set active descriptor " + descriptor); //$NON-NLS-1$
|
||||||
if (activeLaunchDesc == descriptor) {
|
if (activeLaunchDesc == descriptor) {
|
||||||
|
@ -436,16 +480,9 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
// do not set to null unless no descriptors
|
// do not set to null unless no descriptors
|
||||||
descriptor = getLastUsedDescriptor();
|
descriptor = getLastUsedDescriptor();
|
||||||
}
|
}
|
||||||
activeLaunchDesc = descriptor;
|
doSetActiveLaunchDescriptor(descriptor);
|
||||||
if (descriptor != null) {
|
|
||||||
// keeps most used descriptor last
|
|
||||||
Pair<String, String> id = getDescriptorId(descriptor);
|
|
||||||
descriptors.remove(id);
|
|
||||||
descriptors.put(id, descriptor);
|
|
||||||
}
|
|
||||||
// store in persistent storage
|
// store in persistent storage
|
||||||
storeActiveDescriptor(activeLaunchDesc);
|
storeActiveDescriptor(activeLaunchDesc);
|
||||||
|
|
||||||
// Send notifications
|
// Send notifications
|
||||||
fireActiveLaunchDescriptorChanged();
|
fireActiveLaunchDescriptorChanged();
|
||||||
// Set active target
|
// Set active target
|
||||||
|
@ -454,9 +491,18 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
syncActiveMode();
|
syncActiveMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void doSetActiveLaunchDescriptor(ILaunchDescriptor descriptor) {
|
||||||
|
activeLaunchDesc = descriptor;
|
||||||
|
if (descriptor != null) {
|
||||||
|
// keeps most used descriptor last
|
||||||
|
Pair<String, String> id = getDescriptorId(descriptor);
|
||||||
|
descriptors.remove(id);
|
||||||
|
descriptors.put(id, descriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void storeActiveDescriptor(ILaunchDescriptor descriptor) {
|
private void storeActiveDescriptor(ILaunchDescriptor descriptor) {
|
||||||
Activator.trace("new active config is stored " + descriptor); //$NON-NLS-1$
|
Activator.trace("new active config is stored " + descriptor); //$NON-NLS-1$
|
||||||
|
|
||||||
// Store the desc order, active one is the last one
|
// Store the desc order, active one is the last one
|
||||||
StringBuffer buff = new StringBuffer();
|
StringBuffer buff = new StringBuffer();
|
||||||
// TODO: this can be very long string
|
// TODO: this can be very long string
|
||||||
|
@ -644,14 +690,12 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
public List<ILaunchTarget> getLaunchTargets(ILaunchDescriptor descriptor) {
|
public List<ILaunchTarget> getLaunchTargets(ILaunchDescriptor descriptor) {
|
||||||
if (descriptor == null)
|
if (descriptor == null)
|
||||||
return Arrays.asList(launchTargetManager.getLaunchTargets());
|
return Arrays.asList(launchTargetManager.getLaunchTargets());
|
||||||
|
|
||||||
List<ILaunchTarget> targets = new ArrayList<>();
|
List<ILaunchTarget> targets = new ArrayList<>();
|
||||||
for (ILaunchTarget target : launchTargetManager.getLaunchTargets()) {
|
for (ILaunchTarget target : launchTargetManager.getLaunchTargets()) {
|
||||||
if (supportsTarget(descriptor, target)) {
|
if (supportsTarget(descriptor, target)) {
|
||||||
targets.add(target);
|
targets.add(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return targets;
|
return targets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -727,19 +771,17 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
private ILaunchTarget getDefaultLaunchTarget(ILaunchDescriptor descriptor) {
|
private ILaunchTarget getDefaultLaunchTarget(ILaunchDescriptor descriptor) {
|
||||||
List<ILaunchTarget> targets = getLaunchTargets(descriptor);
|
List<ILaunchTarget> targets = getLaunchTargets(descriptor);
|
||||||
// chances are that better target is most recently added, rather then the oldest
|
// chances are that better target is most recently added, rather then the oldest
|
||||||
return targets.isEmpty() ? ILaunchTarget.NULL_TARGET : targets.get(targets.size()-1);
|
return targets.isEmpty() ? ILaunchTarget.NULL_TARGET : targets.get(targets.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ILaunchConfiguration getActiveLaunchConfiguration() throws CoreException {
|
public ILaunchConfiguration getActiveLaunchConfiguration() throws CoreException {
|
||||||
ILaunchConfiguration configuration = getLaunchConfiguration(activeLaunchDesc, activeLaunchTarget);
|
ILaunchConfiguration configuration = getLaunchConfiguration(activeLaunchDesc, activeLaunchTarget);
|
||||||
|
|
||||||
// This is the only concrete time we have the mapping from launch
|
// This is the only concrete time we have the mapping from launch
|
||||||
// configuration to launch target. Record it in the target manager for
|
// configuration to launch target. Record it in the target manager for
|
||||||
// the launch delegates to use.
|
// the launch delegates to use.
|
||||||
if (configuration != null) {
|
if (configuration != null) {
|
||||||
launchTargetManager.setDefaultLaunchTarget(configuration, activeLaunchTarget);
|
launchTargetManager.setDefaultLaunchTarget(configuration, activeLaunchTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -748,7 +790,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
if (descriptor == null) {
|
if (descriptor == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String descTypeId = getDescriptorTypeId(descriptor.getType());
|
String descTypeId = getDescriptorTypeId(descriptor.getType());
|
||||||
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descTypeId)) {
|
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descTypeId)) {
|
||||||
try {
|
try {
|
||||||
|
@ -767,7 +808,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -809,7 +849,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (LaunchDescriptorTypeInfo descTypeInfo : orderedDescriptorTypes) {
|
for (LaunchDescriptorTypeInfo descTypeInfo : orderedDescriptorTypes) {
|
||||||
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descTypeInfo.getId())) {
|
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descTypeInfo.getId())) {
|
||||||
try {
|
try {
|
||||||
|
@ -900,4 +939,35 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ILaunchDescriptor getLaunchDescriptor(ILaunchConfiguration configuration, ILaunchTarget target) {
|
||||||
|
// shortcut - check active first
|
||||||
|
if (launchDescriptorMatches(activeLaunchDesc, configuration, target)) {
|
||||||
|
return activeLaunchDesc;
|
||||||
|
}
|
||||||
|
for (ILaunchDescriptor desc : getLaunchDescriptors()) { // this should be in MRU, most used first
|
||||||
|
if (launchDescriptorMatches(desc, configuration, target)) {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean launchDescriptorMatches(ILaunchDescriptor desc, ILaunchConfiguration configuration,
|
||||||
|
ILaunchTarget target) {
|
||||||
|
if (desc == null || configuration == null)
|
||||||
|
return false;
|
||||||
|
try {
|
||||||
|
String descriptorTypeId = getDescriptorTypeId(desc.getType());
|
||||||
|
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descriptorTypeId)) {
|
||||||
|
if (providerInfo.enabled(desc) && (target == null || providerInfo.enabled(target))) {
|
||||||
|
if (providerInfo.getProvider().launchDescriptorMatches(desc, configuration, target)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (CoreException e) {
|
||||||
|
Activator.log(e);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue