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;
|
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||||
|
|
||||||
public class DefaultLaunchDescriptor implements ILaunchDescriptor {
|
public class DefaultLaunchDescriptor implements ILaunchDescriptor {
|
||||||
|
|
||||||
private final ILaunchDescriptorType type;
|
private final ILaunchDescriptorType type;
|
||||||
private final ILaunchConfiguration config;
|
private final ILaunchConfiguration config;
|
||||||
|
|
||||||
|
@ -36,4 +35,26 @@ public class DefaultLaunchDescriptor implements ILaunchDescriptor {
|
||||||
return config;
|
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();
|
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.
|
* 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
|
// Load up the active from the preferences before loading the descriptors
|
||||||
IEclipsePreferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
|
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) {
|
for (ILaunchDescriptorType descriptorType : descriptorTypes) {
|
||||||
descriptorType.init(this);
|
descriptorType.init(this);
|
||||||
|
@ -167,12 +167,12 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
||||||
launchManager.addLaunchConfigurationListener(this);
|
launchManager.addLaunchConfigurationListener(this);
|
||||||
|
|
||||||
// Now that all the descriptors are loaded, set the one
|
// Now that all the descriptors are loaded, set the one
|
||||||
if (activeConfigDescName == null && !descriptors.isEmpty()) {
|
if (activeConfigDescId == null && !descriptors.isEmpty()) {
|
||||||
activeConfigDescName = descriptors.values().iterator().next().getName();
|
activeConfigDescId = getId(descriptors.values().iterator().next());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activeConfigDescName != null) {
|
if (activeConfigDescId != null) {
|
||||||
ILaunchDescriptor configDesc = descriptors.get(activeConfigDescName);
|
ILaunchDescriptor configDesc = descriptors.get(activeConfigDescId);
|
||||||
if (configDesc != null) {
|
if (configDesc != null) {
|
||||||
setActiveLaunchDescriptor(configDesc);
|
setActiveLaunchDescriptor(configDesc);
|
||||||
}
|
}
|
||||||
|
@ -189,8 +189,13 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
||||||
try {
|
try {
|
||||||
if (descriptorType.ownsLaunchObject(element)) {
|
if (descriptorType.ownsLaunchObject(element)) {
|
||||||
desc = descriptorType.getDescriptor(element);
|
desc = descriptorType.getDescriptor(element);
|
||||||
if (desc != null) {
|
if (desc != null) { // own the object but do not create descriptor to ignore it
|
||||||
descriptors.put(desc.getName(), desc);
|
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);
|
objectDescriptorMap.put(element, desc);
|
||||||
setActiveLaunchDescriptor(desc);
|
setActiveLaunchDescriptor(desc);
|
||||||
return desc;
|
return desc;
|
||||||
|
@ -204,11 +209,15 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getId(ILaunchDescriptor desc) {
|
||||||
|
return desc.getId();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void launchObjectRemoved(Object element) throws CoreException {
|
public void launchObjectRemoved(Object element) throws CoreException {
|
||||||
ILaunchDescriptor desc = objectDescriptorMap.get(element);
|
ILaunchDescriptor desc = objectDescriptorMap.get(element);
|
||||||
if (desc != null) {
|
if (desc != null) {
|
||||||
descriptors.remove(desc.getName());
|
descriptors.remove(getId(desc));
|
||||||
objectDescriptorMap.remove(element);
|
objectDescriptorMap.remove(element);
|
||||||
if (desc.equals(activeLaunchDesc)) {
|
if (desc.equals(activeLaunchDesc)) {
|
||||||
// Roll back to the last one and make sure we don't come back
|
// 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);
|
IEclipsePreferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
|
||||||
if (activeLaunchDesc != null) {
|
if (activeLaunchDesc != null) {
|
||||||
store.put(PREF_ACTIVE_CONFIG_DESC, activeLaunchDesc.getName());
|
store.put(PREF_ACTIVE_CONFIG_DESC, getId(activeLaunchDesc));
|
||||||
} else {
|
} else {
|
||||||
store.remove(PREF_ACTIVE_CONFIG_DESC);
|
store.remove(PREF_ACTIVE_CONFIG_DESC);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue