|
13 | 13 | *******************************************************************************/ |
14 | 14 | package org.eclipse.debug.internal.ui.launchConfigurations; |
15 | 15 |
|
16 | | -import java.util.Collection; |
17 | | -import java.util.HashSet; |
18 | | - |
19 | 16 | import org.eclipse.core.runtime.CoreException; |
20 | 17 | import org.eclipse.debug.core.ILaunchConfiguration; |
21 | 18 | import org.eclipse.debug.core.ILaunchConfigurationType; |
@@ -104,34 +101,37 @@ protected void performAction() { |
104 | 101 | */ |
105 | 102 | @Override |
106 | 103 | protected boolean updateSelection(IStructuredSelection selection) { |
107 | | - // Enable action only if launch configuration(s) of the same type |
108 | | - // is(are) selected and the launch configuration type allows prototypes |
109 | | - Collection<ILaunchConfigurationType> launchConfigurationTypes = new HashSet<>(); |
| 104 | + if (selection.isEmpty()) { |
| 105 | + return false; |
| 106 | + } |
| 107 | + ILaunchConfigurationType type = null; |
110 | 108 | for (Object object : selection.toList()) { |
111 | | - if (object instanceof ILaunchConfiguration) { |
112 | | - if (((ILaunchConfiguration) object).isPrototype()) { |
| 109 | + if (!(object instanceof ILaunchConfiguration launchConfig)) { |
| 110 | + return false; |
| 111 | + } |
| 112 | + |
| 113 | + if (launchConfig.isPrototype()) { |
| 114 | + return false; |
| 115 | + } |
| 116 | + |
| 117 | + ILaunchConfigurationType currentType; |
| 118 | + try { |
| 119 | + currentType = launchConfig.getType(); |
| 120 | + if (currentType.getPrototypes().length == 0) { |
113 | 121 | return false; |
114 | | - } else { |
115 | | - ILaunchConfigurationType type = null; |
116 | | - try { |
117 | | - type = ((ILaunchConfiguration) object).getType(); |
118 | | - } catch (CoreException e) { |
119 | | - DebugUIPlugin.log(e.getStatus()); |
120 | | - } |
121 | | - if (type != null) { |
122 | | - launchConfigurationTypes.add(type); |
123 | | - } else { |
124 | | - return false; |
125 | | - } |
126 | 122 | } |
127 | | - } else { |
| 123 | + } catch (CoreException e) { |
| 124 | + DebugUIPlugin.log(e.getStatus()); |
| 125 | + return false; |
| 126 | + } |
| 127 | + |
| 128 | + if (type == null) { |
| 129 | + type = currentType; |
| 130 | + } else if (!type.equals(currentType)) { |
128 | 131 | return false; |
129 | 132 | } |
130 | 133 | } |
131 | | - if (launchConfigurationTypes.size() == 1) { |
132 | | - return launchConfigurationTypes.iterator().next().supportsPrototypes(); |
133 | | - } |
134 | | - return false; |
| 134 | + return true; |
135 | 135 | } |
136 | 136 |
|
137 | 137 | @Override |
|
0 commit comments