mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
LaunchBar - use unique descriptor id, not the name
Change-Id: I90674ab2e8d72a351be2f717c839e9305bdf2cbe Signed-off-by: Alena Laskavaia <elaskavaia.cdt@gmail.com> Reviewed-on: https://git.eclipse.org/r/30366 Reviewed-by: Doug Schaefer <dschaefer@qnx.com> Tested-by: Doug Schaefer <dschaefer@qnx.com>
This commit is contained in:
parent
30b00414b0
commit
cd81c09a4f
3 changed files with 47 additions and 10 deletions
|
@ -13,7 +13,6 @@ package org.eclipse.cdt.launchbar.core;
|
|||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
|
||||
public class DefaultLaunchDescriptor implements ILaunchDescriptor {
|
||||
|
||||
private final ILaunchDescriptorType type;
|
||||
private final ILaunchConfiguration config;
|
||||
|
||||
|
@ -36,4 +35,26 @@ public class DefaultLaunchDescriptor implements ILaunchDescriptor {
|
|||
return config;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return config.getName() + "." + type.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 17 + getId().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (!(obj instanceof DefaultLaunchDescriptor))
|
||||
return false;
|
||||
DefaultLaunchDescriptor other = (DefaultLaunchDescriptor) obj;
|
||||
if (!getId().equals(other.getId()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,13 @@ public interface ILaunchDescriptor {
|
|||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Unique id of the descriptor (globally)
|
||||
*
|
||||
* @return the non null string representing id of the launch descriptor
|
||||
*/
|
||||
String getId();
|
||||
|
||||
/**
|
||||
* The type of launch descriptor.
|
||||
*
|
||||
|
|
|
@ -139,7 +139,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
|
||||
// Load up the active from the preferences before loading the descriptors
|
||||
IEclipsePreferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
|
||||
String activeConfigDescName = store.get(PREF_ACTIVE_CONFIG_DESC, null);
|
||||
String activeConfigDescId = store.get(PREF_ACTIVE_CONFIG_DESC, null);
|
||||
|
||||
for (ILaunchDescriptorType descriptorType : descriptorTypes) {
|
||||
descriptorType.init(this);
|
||||
|
@ -167,12 +167,12 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
launchManager.addLaunchConfigurationListener(this);
|
||||
|
||||
// Now that all the descriptors are loaded, set the one
|
||||
if (activeConfigDescName == null && !descriptors.isEmpty()) {
|
||||
activeConfigDescName = descriptors.values().iterator().next().getName();
|
||||
if (activeConfigDescId == null && !descriptors.isEmpty()) {
|
||||
activeConfigDescId = getId(descriptors.values().iterator().next());
|
||||
}
|
||||
|
||||
if (activeConfigDescName != null) {
|
||||
ILaunchDescriptor configDesc = descriptors.get(activeConfigDescName);
|
||||
if (activeConfigDescId != null) {
|
||||
ILaunchDescriptor configDesc = descriptors.get(activeConfigDescId);
|
||||
if (configDesc != null) {
|
||||
setActiveLaunchDescriptor(configDesc);
|
||||
}
|
||||
|
@ -189,8 +189,13 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
try {
|
||||
if (descriptorType.ownsLaunchObject(element)) {
|
||||
desc = descriptorType.getDescriptor(element);
|
||||
if (desc != null) {
|
||||
descriptors.put(desc.getName(), desc);
|
||||
if (desc != null) { // own the object but do not create descriptor to ignore it
|
||||
String id = getId(desc);
|
||||
ILaunchDescriptor old = descriptors.get(id);
|
||||
if (old != null && !desc.equals(old))
|
||||
throw new IllegalStateException(
|
||||
"Name of descriptor must be unique within same type (or descriptors with same name must be equal)");
|
||||
descriptors.put(id, desc);
|
||||
objectDescriptorMap.put(element, desc);
|
||||
setActiveLaunchDescriptor(desc);
|
||||
return desc;
|
||||
|
@ -204,11 +209,15 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
return null;
|
||||
}
|
||||
|
||||
private String getId(ILaunchDescriptor desc) {
|
||||
return desc.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void launchObjectRemoved(Object element) throws CoreException {
|
||||
ILaunchDescriptor desc = objectDescriptorMap.get(element);
|
||||
if (desc != null) {
|
||||
descriptors.remove(desc.getName());
|
||||
descriptors.remove(getId(desc));
|
||||
objectDescriptorMap.remove(element);
|
||||
if (desc.equals(activeLaunchDesc)) {
|
||||
// Roll back to the last one and make sure we don't come back
|
||||
|
@ -245,7 +254,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
|
||||
IEclipsePreferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
|
||||
if (activeLaunchDesc != null) {
|
||||
store.put(PREF_ACTIVE_CONFIG_DESC, activeLaunchDesc.getName());
|
||||
store.put(PREF_ACTIVE_CONFIG_DESC, getId(activeLaunchDesc));
|
||||
} else {
|
||||
store.remove(PREF_ACTIVE_CONFIG_DESC);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue