mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-23 00:03:53 +02:00
launch-bar: prevent event storm on initialization
- prevent events dispatch during initialization of launch bar manager - also fix case when connection is renamed - we don't need to remove it Change-Id: I8ba5938afd21c9b2459563cd9e3385fb9a69f673
This commit is contained in:
parent
baa294b085
commit
013c6fa1fe
1 changed files with 68 additions and 51 deletions
|
@ -124,6 +124,8 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
private static final String PREF_ACTIVE_LAUNCH_TARGET = "activeLaunchTarget";
|
private static final String PREF_ACTIVE_LAUNCH_TARGET = "activeLaunchTarget";
|
||||||
private static final String PREF_CONFIG_DESC_ORDER = "configDescList";
|
private static final String PREF_CONFIG_DESC_ORDER = "configDescList";
|
||||||
|
|
||||||
|
boolean initialized = false;
|
||||||
|
|
||||||
public LaunchBarManager() {
|
public LaunchBarManager() {
|
||||||
this(true);
|
this(true);
|
||||||
}
|
}
|
||||||
|
@ -168,25 +170,22 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
|
|
||||||
// When testing, call this after setting up the mocks.
|
// When testing, call this after setting up the mocks.
|
||||||
void init() throws CoreException {
|
void init() throws CoreException {
|
||||||
|
try {
|
||||||
// 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, "");
|
String configDescIds = store.get(PREF_CONFIG_DESC_ORDER, "");
|
||||||
|
|
||||||
// Load up the types
|
// Load up the types
|
||||||
loadExtensions();
|
loadExtensions();
|
||||||
|
|
||||||
// Add in the default descriptor type
|
// Add in the default descriptor type
|
||||||
LaunchDescriptorTypeInfo defaultInfo = new LaunchDescriptorTypeInfo(DefaultLaunchDescriptorType.ID,
|
LaunchDescriptorTypeInfo defaultInfo = new LaunchDescriptorTypeInfo(DefaultLaunchDescriptorType.ID,
|
||||||
0, defaultDescriptorType);
|
0, defaultDescriptorType);
|
||||||
addDescriptorType(defaultInfo);
|
addDescriptorType(defaultInfo);
|
||||||
|
|
||||||
// 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(",");
|
String[] split = configDescIds.split(",");
|
||||||
|
@ -205,6 +204,13 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
setActiveLaunchDescriptor(last);
|
setActiveLaunchDescriptor(last);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
fireActiveLaunchDescriptorChanged();
|
||||||
|
fireActiveLaunchTargetChanged();
|
||||||
|
fireActiveLaunchModeChanged();
|
||||||
|
fireLaunchTargetsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadExtensions() throws CoreException {
|
private void loadExtensions() throws CoreException {
|
||||||
|
@ -680,6 +686,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireActiveLaunchDescriptorChanged() {
|
private void fireActiveLaunchDescriptorChanged() {
|
||||||
|
if (!initialized) return;
|
||||||
for (Listener listener : listeners) {
|
for (Listener listener : listeners) {
|
||||||
try {
|
try {
|
||||||
listener.activeLaunchDescriptorChanged();
|
listener.activeLaunchDescriptorChanged();
|
||||||
|
@ -737,6 +744,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireActiveLaunchModeChanged() {
|
private void fireActiveLaunchModeChanged() {
|
||||||
|
if (!initialized) return;
|
||||||
for (Listener listener : listeners) {
|
for (Listener listener : listeners) {
|
||||||
try {
|
try {
|
||||||
listener.activeLaunchModeChanged();
|
listener.activeLaunchModeChanged();
|
||||||
|
@ -826,6 +834,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireActiveLaunchTargetChanged() {
|
private void fireActiveLaunchTargetChanged() {
|
||||||
|
if (!initialized) return;
|
||||||
for (Listener listener : listeners) {
|
for (Listener listener : listeners) {
|
||||||
try {
|
try {
|
||||||
listener.activeLaunchTargetChanged();
|
listener.activeLaunchTargetChanged();
|
||||||
|
@ -1027,38 +1036,46 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RemoteConnectionChangeEvent.CONNECTION_REMOVED:
|
case RemoteConnectionChangeEvent.CONNECTION_REMOVED:
|
||||||
case RemoteConnectionChangeEvent.CONNECTION_RENAMED:
|
|
||||||
try {
|
try {
|
||||||
launchTargetRemoved(event.getConnection());
|
launchTargetRemoved(event.getConnection());
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case RemoteConnectionChangeEvent.CONNECTION_RENAMED:
|
||||||
|
fireLaunchTargetsChanged();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fireLaunchTargetsChanged() {
|
||||||
|
if (!initialized) return;
|
||||||
|
for (Listener listener : listeners) {
|
||||||
|
try {
|
||||||
|
listener.launchTargetsChanged();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Activator.log(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void launchTargetAdded(IRemoteConnection target) throws CoreException {
|
private void launchTargetAdded(IRemoteConnection target) throws CoreException {
|
||||||
for (Listener listener : listeners) {
|
if (!initialized)
|
||||||
try {
|
return;
|
||||||
listener.launchTargetsChanged();
|
fireLaunchTargetsChanged();
|
||||||
} catch (Exception e) {
|
// if we added new target we probably want to use it
|
||||||
Activator.log(e);
|
if (activeLaunchDesc != null && supportsTargetType(activeLaunchDesc, target)) {
|
||||||
}
|
|
||||||
}
|
|
||||||
if (activeLaunchDesc != null && activeLaunchTarget == null && supportsTargetType(activeLaunchDesc, target)) {
|
|
||||||
setActiveLaunchTarget(target);
|
setActiveLaunchTarget(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void launchTargetRemoved(IRemoteConnection target) throws CoreException {
|
private void launchTargetRemoved(IRemoteConnection target) throws CoreException {
|
||||||
for (Listener listener : listeners) {
|
if (!initialized)
|
||||||
try {
|
return;
|
||||||
listener.launchTargetsChanged();
|
fireLaunchTargetsChanged();
|
||||||
} catch (Exception e) {
|
|
||||||
Activator.log(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (activeLaunchTarget == target) {
|
if (activeLaunchTarget == target) {
|
||||||
setActiveLaunchTarget(getDefaultLaunchTarget(activeLaunchDesc));
|
setActiveLaunchTarget(getDefaultLaunchTarget(activeLaunchDesc));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue