|
Lines 10-34
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.debug.internal.ui.contextlaunching; |
11 |
package org.eclipse.debug.internal.ui.contextlaunching; |
| 12 |
|
12 |
|
| 13 |
import java.util.ArrayList; |
13 |
import java.util.HashSet; |
| 14 |
import java.util.Iterator; |
|
|
| 15 |
import java.util.List; |
14 |
import java.util.List; |
| 16 |
|
15 |
|
| 17 |
import org.eclipse.core.expressions.EvaluationContext; |
|
|
| 18 |
import org.eclipse.core.expressions.IEvaluationContext; |
| 19 |
import org.eclipse.core.resources.IFile; |
| 20 |
import org.eclipse.core.resources.IProject; |
| 21 |
import org.eclipse.core.resources.IResource; |
16 |
import org.eclipse.core.resources.IResource; |
| 22 |
import org.eclipse.core.runtime.CoreException; |
17 |
import org.eclipse.core.runtime.CoreException; |
| 23 |
import org.eclipse.core.runtime.IAdaptable; |
18 |
import org.eclipse.core.runtime.IAdaptable; |
| 24 |
import org.eclipse.debug.core.DebugPlugin; |
19 |
import org.eclipse.debug.core.DebugPlugin; |
| 25 |
import org.eclipse.debug.core.ILaunch; |
|
|
| 26 |
import org.eclipse.debug.core.ILaunchConfiguration; |
20 |
import org.eclipse.debug.core.ILaunchConfiguration; |
| 27 |
import org.eclipse.debug.core.ILaunchListener; |
|
|
| 28 |
import org.eclipse.debug.core.ILaunchMode; |
| 29 |
import org.eclipse.debug.internal.core.LaunchManager; |
21 |
import org.eclipse.debug.internal.core.LaunchManager; |
| 30 |
import org.eclipse.debug.internal.ui.DebugUIPlugin; |
22 |
import org.eclipse.debug.internal.ui.DebugUIPlugin; |
|
|
23 |
import org.eclipse.debug.internal.ui.DefaultLabelProvider; |
| 31 |
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; |
24 |
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; |
|
|
25 |
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager; |
| 32 |
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchHistory; |
26 |
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchHistory; |
| 33 |
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension; |
27 |
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension; |
| 34 |
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutSelectionDialog; |
28 |
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutSelectionDialog; |
|
Lines 36-56
Link Here
|
| 36 |
import org.eclipse.debug.ui.ILaunchGroup; |
30 |
import org.eclipse.debug.ui.ILaunchGroup; |
| 37 |
import org.eclipse.jface.dialogs.IDialogConstants; |
31 |
import org.eclipse.jface.dialogs.IDialogConstants; |
| 38 |
import org.eclipse.jface.dialogs.MessageDialog; |
32 |
import org.eclipse.jface.dialogs.MessageDialog; |
| 39 |
import org.eclipse.jface.dialogs.MessageDialogWithToggle; |
|
|
| 40 |
import org.eclipse.jface.text.ITextSelection; |
33 |
import org.eclipse.jface.text.ITextSelection; |
|
|
34 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
| 41 |
import org.eclipse.jface.viewers.ISelection; |
35 |
import org.eclipse.jface.viewers.ISelection; |
| 42 |
import org.eclipse.jface.viewers.ISelectionProvider; |
36 |
import org.eclipse.jface.viewers.ISelectionProvider; |
| 43 |
import org.eclipse.jface.viewers.IStructuredSelection; |
37 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 44 |
import org.eclipse.jface.viewers.StructuredSelection; |
38 |
import org.eclipse.jface.viewers.StructuredSelection; |
| 45 |
import org.eclipse.jface.window.Window; |
39 |
import org.eclipse.jface.window.Window; |
| 46 |
import org.eclipse.ui.IEditorPart; |
40 |
import org.eclipse.ui.IEditorPart; |
| 47 |
import org.eclipse.ui.IFileEditorInput; |
|
|
| 48 |
import org.eclipse.ui.IWorkbenchPage; |
41 |
import org.eclipse.ui.IWorkbenchPage; |
| 49 |
import org.eclipse.ui.IWorkbenchPart; |
42 |
import org.eclipse.ui.IWorkbenchPart; |
| 50 |
import org.eclipse.ui.IWorkbenchPartSite; |
43 |
import org.eclipse.ui.IWorkbenchPartSite; |
| 51 |
import org.eclipse.ui.IWorkbenchWindow; |
44 |
import org.eclipse.ui.IWorkbenchWindow; |
| 52 |
|
45 |
import org.eclipse.ui.dialogs.ListDialog; |
| 53 |
import com.ibm.icu.text.MessageFormat; |
|
|
| 54 |
|
46 |
|
| 55 |
/** |
47 |
/** |
| 56 |
* Static runner for context launching to provide the base capability of context |
48 |
* Static runner for context launching to provide the base capability of context |
|
Lines 65-72
Link Here
|
| 65 |
* EXPERIMENTAL |
57 |
* EXPERIMENTAL |
| 66 |
* CONTEXTLAUNCHING |
58 |
* CONTEXTLAUNCHING |
| 67 |
*/ |
59 |
*/ |
| 68 |
public class ContextRunner implements ILaunchListener { |
60 |
public final class ContextRunner { |
| 69 |
|
61 |
|
|
|
62 |
/** |
| 63 |
* The singleton instance of the context runner |
| 64 |
*/ |
| 70 |
private static ContextRunner fgInstance = null; |
65 |
private static ContextRunner fgInstance = null; |
| 71 |
|
66 |
|
| 72 |
/** |
67 |
/** |
|
Lines 79-92
Link Here
|
| 79 |
} |
74 |
} |
| 80 |
return fgInstance; |
75 |
return fgInstance; |
| 81 |
} |
76 |
} |
| 82 |
|
|
|
| 83 |
/** |
| 84 |
* The underlying resource that is derived from the object context of the |
| 85 |
* run(Object, String) method |
| 86 |
*/ |
| 87 |
private IResource fBackingResource = null; |
| 88 |
private boolean fMakeResourceDefault = false; |
| 89 |
private boolean fMakeProjectDefault = false; |
| 90 |
|
77 |
|
| 91 |
/** |
78 |
/** |
| 92 |
* Performs the context launching given the object context and the mode to launch in. |
79 |
* Performs the context launching given the object context and the mode to launch in. |
|
Lines 94-144
Link Here
|
| 94 |
*/ |
81 |
*/ |
| 95 |
public void launch(String mode) { |
82 |
public void launch(String mode) { |
| 96 |
try { |
83 |
try { |
|
|
84 |
//1. resolve resource |
| 97 |
Object context = getCurrentContext(); |
85 |
Object context = getCurrentContext(); |
| 98 |
ILaunchConfiguration config = isSharedConfig(context); |
86 |
ILaunchConfiguration config = null; |
| 99 |
if(config != null) { |
87 |
if(context != null) { |
| 100 |
DebugUITools.launch(config, mode); |
88 |
if(context instanceof IAdaptable) { |
| 101 |
return; |
89 |
IResource resource = (IResource) ((IAdaptable)context).getAdapter(IResource.class); |
| 102 |
} |
|
|
| 103 |
config = isSharedConfigEditorInput(context); |
| 104 |
if(config != null) { |
| 105 |
DebugUITools.launch(config, mode); |
| 106 |
return; |
| 107 |
} |
| 108 |
if(context instanceof IAdaptable) { |
| 109 |
IAdaptable adapt = (IAdaptable) context; |
| 110 |
//try to get the ILaunchConfiguration adapter first |
| 111 |
config = (ILaunchConfiguration) adapt.getAdapter(ILaunchConfiguration.class); |
| 112 |
if(config != null) { |
| 113 |
DebugUITools.launch(config, mode); |
| 114 |
return; |
| 115 |
} |
| 116 |
else { |
| 117 |
//try to get the resource adapter from the context |
| 118 |
IResource resource = (IResource) adapt.getAdapter(IResource.class); |
| 119 |
if(resource != null) { |
90 |
if(resource != null) { |
| 120 |
fBackingResource = resource; |
91 |
selectAndLaunch(resource, mode); |
| 121 |
config = getLaunchManager().getDefaultConfiguration(resource); |
92 |
return; |
| 122 |
if(config != null && config.exists()) { |
|
|
| 123 |
//the default config is available |
| 124 |
DebugUITools.launch(config, mode); |
| 125 |
return; |
| 126 |
} |
| 127 |
else { |
| 128 |
//there is no default config |
| 129 |
getLaunchManager().setDefaultConfiguration(resource, null); |
| 130 |
selectAndLaunch(fBackingResource, mode); |
| 131 |
return; |
| 132 |
} |
| 133 |
} |
| 134 |
else { |
| 135 |
handleUnknownContext(mode); |
| 136 |
} |
93 |
} |
| 137 |
} |
94 |
} |
| 138 |
} |
95 |
} |
| 139 |
else { |
96 |
//2. launch last if no resource |
| 140 |
handleUnknownContext(mode); |
97 |
config = getLastLaunch(mode); |
|
|
98 |
if(config != null) { |
| 99 |
DebugUITools.launch(config, mode); |
| 100 |
return; |
| 141 |
} |
101 |
} |
|
|
102 |
|
| 142 |
} |
103 |
} |
| 143 |
catch(CoreException ce) {DebugUIPlugin.log(ce);} |
104 |
catch(CoreException ce) {DebugUIPlugin.log(ce);} |
| 144 |
} |
105 |
} |
|
Lines 152-178
Link Here
|
| 152 |
if(config == null) { |
113 |
if(config == null) { |
| 153 |
MessageDialog.openInformation(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_0, ContextMessages.ContextRunner_7); |
114 |
MessageDialog.openInformation(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_0, ContextMessages.ContextRunner_7); |
| 154 |
} |
115 |
} |
| 155 |
else { |
|
|
| 156 |
String prompt = DebugUIPlugin.getDefault().getPreferenceStore().getString(IInternalDebugUIConstants.PREF_ALWAYS_RUN_LAST_LAUNCH); |
| 157 |
if(MessageDialogWithToggle.PROMPT.equals(prompt)) { |
| 158 |
ILaunchMode lmode = getLaunchManager().getLaunchMode(mode); |
| 159 |
MessageDialogWithToggle mdwt = MessageDialogWithToggle.openYesNoQuestion(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_0, |
| 160 |
MessageFormat.format(ContextMessages.ContextRunner_1, new String[] {DebugUIPlugin.removeAccelerators(lmode.getLabel().toLowerCase())}), ContextMessages.ContextRunner_2, |
| 161 |
false, null, null); |
| 162 |
int ret = mdwt.getReturnCode(); |
| 163 |
boolean checked = mdwt.getToggleState(); |
| 164 |
if(ret == IDialogConstants.YES_ID) { |
| 165 |
//get launch history for the given mode and do it |
| 166 |
DebugUITools.launch(config, mode); |
| 167 |
if(checked) { |
| 168 |
DebugUIPlugin.getDefault().getPreferenceStore().putValue(IInternalDebugUIConstants.PREF_ALWAYS_RUN_LAST_LAUNCH, MessageDialogWithToggle.ALWAYS); |
| 169 |
} |
| 170 |
} |
| 171 |
} |
| 172 |
else if(MessageDialogWithToggle.ALWAYS.equals(prompt)) { |
| 173 |
DebugUITools.launch(config, mode); |
| 174 |
} |
| 175 |
} |
| 176 |
} |
116 |
} |
| 177 |
|
117 |
|
| 178 |
/** |
118 |
/** |
|
Lines 192-210
Link Here
|
| 192 |
} |
132 |
} |
| 193 |
|
133 |
|
| 194 |
/** |
134 |
/** |
| 195 |
* This method return if the editor input is from a shared java launch configuration file or not |
|
|
| 196 |
* @param receiver the editor input to examine |
| 197 |
* @return true if the editor input is from a shared launch configuration file, false otherwise. |
| 198 |
*/ |
| 199 |
public ILaunchConfiguration isSharedConfigEditorInput(Object receiver) { |
| 200 |
if(receiver instanceof IFileEditorInput) { |
| 201 |
IFileEditorInput input = (IFileEditorInput) receiver; |
| 202 |
return isSharedConfig(input.getFile()); |
| 203 |
} |
| 204 |
return null; |
| 205 |
} |
| 206 |
|
| 207 |
/** |
| 208 |
* Returns the launch group that corresponds to the specified mode |
135 |
* Returns the launch group that corresponds to the specified mode |
| 209 |
* @param mode the mode to find the launch group |
136 |
* @param mode the mode to find the launch group |
| 210 |
* @return the launch group that corresponds to the specified mode |
137 |
* @return the launch group that corresponds to the specified mode |
|
Lines 221-248
Link Here
|
| 221 |
} |
148 |
} |
| 222 |
|
149 |
|
| 223 |
/** |
150 |
/** |
| 224 |
* Returns the shared config from the selected resource or <code>null</code> if the selected resources is not a shared config |
|
|
| 225 |
* @param receiver |
| 226 |
* @return the shared config from the selected resource or <code>null</code> if the selected resources is not a shared config |
| 227 |
*/ |
| 228 |
public ILaunchConfiguration isSharedConfig(Object receiver) { |
| 229 |
if(receiver instanceof IFile) { |
| 230 |
IFile file = (IFile) receiver; |
| 231 |
String ext = file.getFileExtension(); |
| 232 |
if(ext == null) { |
| 233 |
return null; |
| 234 |
} |
| 235 |
if(ext.equals("launch")) { //$NON-NLS-1$ |
| 236 |
ILaunchConfiguration config = DebugPlugin.getDefault().getLaunchManager().getLaunchConfiguration(file); |
| 237 |
if(config != null && config.exists()) { |
| 238 |
return config; |
| 239 |
} |
| 240 |
} |
| 241 |
} |
| 242 |
return null; |
| 243 |
} |
| 244 |
|
| 245 |
/** |
| 246 |
* Prompts the user to select a way of launching the current resource, where a 'way' |
151 |
* Prompts the user to select a way of launching the current resource, where a 'way' |
| 247 |
* is defined as a launch shortcut, and returns if a launch took place |
152 |
* is defined as a launch shortcut, and returns if a launch took place |
| 248 |
* @param adapt the adaptable type the specified resource was derived from |
153 |
* @param adapt the adaptable type the specified resource was derived from |
|
Lines 251-338
Link Here
|
| 251 |
* @throws CoreException |
156 |
* @throws CoreException |
| 252 |
*/ |
157 |
*/ |
| 253 |
protected boolean selectAndLaunch(IResource resource, String mode) throws CoreException { |
158 |
protected boolean selectAndLaunch(IResource resource, String mode) throws CoreException { |
| 254 |
boolean launched = false; |
159 |
List configs = getLaunchConfigurationManager().getApplicableLaunchConfigurations(resource); |
| 255 |
if(launchDefault(resource, mode)) { |
160 |
int csize = configs.size(); |
| 256 |
return true; |
161 |
List exts = getLaunchConfigurationManager().getLaunchShortcuts(resource); |
| 257 |
} |
162 |
int esize = exts.size(); |
| 258 |
List exts = getLaunchShortcuts(resource); |
163 |
if(csize == 1) { |
| 259 |
if(exts.size() == 1) { |
164 |
DebugUITools.launch((ILaunchConfiguration) configs.get(0), mode); |
| 260 |
//just launch it and set it as the default |
|
|
| 261 |
LaunchShortcutExtension ext = (LaunchShortcutExtension) exts.get(0); |
| 262 |
ext.launch(new StructuredSelection(resource), mode); |
| 263 |
return true; |
165 |
return true; |
| 264 |
} |
166 |
} |
| 265 |
else if(exts.size() < 1) { |
167 |
if(csize < 1) { |
| 266 |
//prompt to try the parent containers |
168 |
if(esize == 1) { |
| 267 |
String prompt = DebugUIPlugin.getDefault().getPreferenceStore().getString(IInternalDebugUIConstants.PREF_ALWAYS_RUN_PROJECT_CONFIGURATION); |
169 |
LaunchShortcutExtension ext = (LaunchShortcutExtension) exts.get(0); |
| 268 |
if(MessageDialogWithToggle.ALWAYS.equals(prompt)) { |
170 |
ext.launch(new StructuredSelection(resource), mode); |
| 269 |
//go ahead and check |
171 |
return true; |
| 270 |
selectAndLaunch(resource.getProject(), mode); |
|
|
| 271 |
} |
| 272 |
else if(MessageDialogWithToggle.PROMPT.equals(prompt)) { |
| 273 |
MessageDialogWithToggle mdwt = MessageDialogWithToggle.openYesNoQuestion(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_3, |
| 274 |
MessageFormat.format(ContextMessages.ContextRunner_4, new String[] {fBackingResource.getName()}), |
| 275 |
ContextMessages.ContextRunner_2, false, null, null); |
| 276 |
int ret = mdwt.getReturnCode(); |
| 277 |
boolean checked = mdwt.getToggleState(); |
| 278 |
if(ret == IDialogConstants.YES_ID) { |
| 279 |
if(checked) { |
| 280 |
DebugUIPlugin.getDefault().getPreferenceStore().putValue(IInternalDebugUIConstants.PREF_ALWAYS_RUN_PROJECT_CONFIGURATION, MessageDialogWithToggle.ALWAYS); |
| 281 |
} |
| 282 |
selectAndLaunch(resource.getProject(), mode); |
| 283 |
} |
| 284 |
} |
172 |
} |
| 285 |
return false; |
173 |
if(esize > 1) { |
| 286 |
} |
174 |
return showShortcutSelectionDialog(resource, mode); |
| 287 |
else { |
175 |
} |
| 288 |
boolean project = resource instanceof IProject; |
176 |
if(esize < 1) { |
| 289 |
if(exts.isEmpty()) { |
177 |
//TODO check project?? should we prompt? |
| 290 |
MessageDialog.openError(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_5, ContextMessages.ContextRunner_6); |
178 |
MessageDialog.openError(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_5, ContextMessages.ContextRunner_6); |
| 291 |
} |
179 |
} |
| 292 |
else { |
180 |
} |
| 293 |
LaunchShortcutSelectionDialog dialog = new LaunchShortcutSelectionDialog(resource, mode, !project, project); |
181 |
else if(csize > 1){ |
| 294 |
if (dialog.open() == Window.OK) { |
182 |
if(!launchMRU(configs, mode)) { |
| 295 |
Object[] result = dialog.getResult(); |
183 |
return showConfigurationSelectionDialog(configs, mode); |
| 296 |
if(result.length > 0) { |
184 |
} |
| 297 |
fMakeProjectDefault = dialog.makeProjectDefault(); |
185 |
} |
| 298 |
fMakeResourceDefault = dialog.makeDefault(); |
186 |
return false; |
| 299 |
if(fMakeProjectDefault || fMakeResourceDefault) { |
187 |
} |
| 300 |
getLaunchManager().addLaunchListener(this); |
188 |
|
| 301 |
} |
189 |
/** |
| 302 |
LaunchShortcutExtension method = (LaunchShortcutExtension) result[0]; |
190 |
* Launches the first occurance of any one of the configurations in the provided list, if they are found in the launch history |
| 303 |
if(method != null) { |
191 |
* for the corresponding launch group |
| 304 |
method.launch(new StructuredSelection(resource), mode); |
192 |
* @param configurations |
| 305 |
} |
193 |
* @param mode |
| 306 |
} |
194 |
* @return true if something launched, false otherwise |
|
|
195 |
*/ |
| 196 |
protected boolean launchMRU(List configurations, String mode) { |
| 197 |
ILaunchGroup group = resolveLaunchGroup(mode); |
| 198 |
if(group != null) { |
| 199 |
LaunchHistory history = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchHistory(group.getIdentifier()); |
| 200 |
HashSet set = new HashSet(configurations); |
| 201 |
ILaunchConfiguration[] configarray = history.getHistory(); |
| 202 |
for(int i = 0; i < configarray.length; i++) { |
| 203 |
if(set.contains(configarray[i])) { |
| 204 |
DebugUITools.launch(configarray[i], mode); |
| 205 |
return true; |
| 307 |
} |
206 |
} |
| 308 |
} |
207 |
} |
| 309 |
} |
208 |
} |
| 310 |
return launched; |
209 |
return false; |
| 311 |
} |
210 |
} |
| 312 |
|
211 |
|
| 313 |
/** |
212 |
/** |
| 314 |
* Creates a listing of the launch shortcut extensions that are applicable to the underlying resource |
213 |
* Presents the user with a dialog to pick the launch configuration to launch |
| 315 |
* @param resource the underlying resource |
214 |
* @param configurations the listing of applicable configurations to present |
| 316 |
* @return a listing of applicable launch shortcuts |
215 |
* @param mode the mode |
| 317 |
* @throws CoreException |
216 |
* @return true if something was launched, false otherwise |
|
|
217 |
*/ |
| 218 |
protected boolean showConfigurationSelectionDialog(List configurations, String mode) { |
| 219 |
ListDialog lsd = new ListDialog(DebugUIPlugin.getShell()); |
| 220 |
lsd.setContentProvider(new ArrayContentProvider()); |
| 221 |
lsd.setLabelProvider(new DefaultLabelProvider()); |
| 222 |
lsd.setMessage(ContextMessages.ContextRunner_8); |
| 223 |
lsd.setTitle(ContextMessages.ContextRunner_9); |
| 224 |
lsd.setInput(configurations); |
| 225 |
if(lsd.open() == IDialogConstants.OK_ID) { |
| 226 |
ILaunchConfiguration config = (ILaunchConfiguration) lsd.getResult()[0]; |
| 227 |
DebugUITools.launch(config, mode); |
| 228 |
return true; |
| 229 |
} |
| 230 |
return false; |
| 231 |
} |
| 232 |
|
| 233 |
/** |
| 234 |
* Presents a selection dialog to the user to pick a launch shortcut |
| 235 |
* @param resource the resource context |
| 236 |
* @param mode the mode |
| 237 |
* @return true if something was launched, false otherwise |
| 318 |
*/ |
238 |
*/ |
| 319 |
public List getLaunchShortcuts(IResource resource) throws CoreException { |
239 |
protected boolean showShortcutSelectionDialog(IResource resource, String mode) { |
| 320 |
List list = new ArrayList(); |
240 |
LaunchShortcutSelectionDialog dialog = new LaunchShortcutSelectionDialog(resource, mode); |
| 321 |
List sc = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchShortcuts(); |
241 |
if (dialog.open() == Window.OK) { |
| 322 |
List ctxt = new ArrayList(); |
242 |
Object[] result = dialog.getResult(); |
| 323 |
ctxt.add(resource); |
243 |
if(result.length > 0) { |
| 324 |
IEvaluationContext context = new EvaluationContext(null, ctxt); |
244 |
LaunchShortcutExtension method = (LaunchShortcutExtension) result[0]; |
| 325 |
context.addVariable("selection", ctxt); //$NON-NLS-1$ |
245 |
if(method != null) { |
| 326 |
LaunchShortcutExtension ext = null; |
246 |
method.launch(new StructuredSelection(resource), mode); |
| 327 |
for(Iterator iter = sc.iterator(); iter.hasNext();) { |
247 |
return true; |
| 328 |
ext = (LaunchShortcutExtension) iter.next(); |
|
|
| 329 |
if(ext.evalEnablementExpression(context, ext.getContextualLaunchEnablementExpression())) { |
| 330 |
if(!list.contains(ext)) { |
| 331 |
list.add(ext); |
| 332 |
} |
248 |
} |
| 333 |
} |
249 |
} |
| 334 |
} |
250 |
} |
| 335 |
return list; |
251 |
return false; |
| 336 |
} |
252 |
} |
| 337 |
|
253 |
|
| 338 |
/** |
254 |
/** |
|
Lines 342-347
Link Here
|
| 342 |
* <li>IEditorInput</li> |
258 |
* <li>IEditorInput</li> |
| 343 |
* <li>Object where <i>object</i> is the first element in the selection obtained from the |
259 |
* <li>Object where <i>object</i> is the first element in the selection obtained from the |
| 344 |
* selection provider of the currently selected workbench part</li> |
260 |
* selection provider of the currently selected workbench part</li> |
|
|
261 |
* <li><code>null</code>, if the current context is unknown</li> |
| 345 |
* </ol> |
262 |
* </ol> |
| 346 |
* @return the currently selected context to consider for launching, or <code>null</code>. |
263 |
* @return the currently selected context to consider for launching, or <code>null</code>. |
| 347 |
* |
264 |
* |
|
Lines 373-382
Link Here
|
| 373 |
else if(sel instanceof ITextSelection) { |
290 |
else if(sel instanceof ITextSelection) { |
| 374 |
return part; |
291 |
return part; |
| 375 |
} |
292 |
} |
| 376 |
return sel; |
|
|
| 377 |
} |
293 |
} |
| 378 |
else { |
294 |
else { |
| 379 |
//default to returning the part, which can be further queried for adapters |
|
|
| 380 |
return part; |
295 |
return part; |
| 381 |
} |
296 |
} |
| 382 |
} |
297 |
} |
|
Lines 395-422
Link Here
|
| 395 |
*/ |
310 |
*/ |
| 396 |
public String getContextName() { |
311 |
public String getContextName() { |
| 397 |
Object o = getCurrentContext(); |
312 |
Object o = getCurrentContext(); |
| 398 |
ILaunchConfiguration config = isSharedConfig(o); |
313 |
ILaunchConfiguration config = getLaunchConfigurationManager().isSharedConfig(o); |
| 399 |
if(config != null) { |
314 |
if(config != null) { |
| 400 |
return config.getName(); |
315 |
return config.getName(); |
| 401 |
} |
316 |
} |
| 402 |
else { |
317 |
else { |
| 403 |
config = isSharedConfigEditorInput(o); |
318 |
if(o instanceof IAdaptable) { |
| 404 |
if(config != null) { |
319 |
IAdaptable adapt = (IAdaptable) o; |
| 405 |
return config.getName(); |
320 |
Object a = adapt.getAdapter(ILaunchConfiguration.class); |
| 406 |
} |
321 |
if(a != null) { |
| 407 |
else { |
322 |
return ((ILaunchConfiguration) a).getName(); |
| 408 |
if(o instanceof IAdaptable) { |
323 |
} |
| 409 |
IAdaptable adapt = (IAdaptable) o; |
324 |
else { |
| 410 |
Object a = adapt.getAdapter(ILaunchConfiguration.class); |
325 |
a = adapt.getAdapter(IResource.class); |
| 411 |
if(a != null) { |
326 |
if(a != null) { |
| 412 |
return ((ILaunchConfiguration) a).getName(); |
327 |
IResource res = (IResource) a; |
| 413 |
} |
328 |
return (res.isAccessible() ? res.getName() : ""); //$NON-NLS-1$ |
| 414 |
else { |
|
|
| 415 |
a = adapt.getAdapter(IResource.class); |
| 416 |
if(a != null) { |
| 417 |
IResource res = (IResource) a; |
| 418 |
return (res.isAccessible() ? res.getName() : ""); //$NON-NLS-1$ |
| 419 |
} |
| 420 |
} |
329 |
} |
| 421 |
} |
330 |
} |
| 422 |
} |
331 |
} |
|
Lines 428-434
Link Here
|
| 428 |
* Returns if context launching is enabled |
337 |
* Returns if context launching is enabled |
| 429 |
* @return if context launching is enabled |
338 |
* @return if context launching is enabled |
| 430 |
*/ |
339 |
*/ |
| 431 |
public static boolean isContextLaunchEnabled() { |
340 |
public boolean isContextLaunchEnabled() { |
| 432 |
return DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH); |
341 |
return DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH); |
| 433 |
} |
342 |
} |
| 434 |
|
343 |
|
|
Lines 441-492
Link Here
|
| 441 |
} |
350 |
} |
| 442 |
|
351 |
|
| 443 |
/** |
352 |
/** |
| 444 |
* @see org.eclipse.debug.core.ILaunchListener#launchAdded(org.eclipse.debug.core.ILaunch) |
353 |
* Returns the launch configuration manager |
| 445 |
*/ |
354 |
* @return the launch configuration manager |
| 446 |
public void launchAdded(ILaunch launch) { |
|
|
| 447 |
if(fBackingResource != null) { |
| 448 |
try { |
| 449 |
if(fMakeResourceDefault) { |
| 450 |
getLaunchManager().setDefaultConfiguration(fBackingResource, launch.getLaunchConfiguration()); |
| 451 |
} |
| 452 |
if(fMakeProjectDefault) { |
| 453 |
getLaunchManager().setDefaultConfiguration(fBackingResource.getProject(), launch.getLaunchConfiguration()); |
| 454 |
} |
| 455 |
getLaunchManager().removeLaunchListener(this); |
| 456 |
fMakeProjectDefault = false; |
| 457 |
fMakeResourceDefault = false; |
| 458 |
} |
| 459 |
catch(CoreException ce) {DebugUIPlugin.log(ce);} |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
/** |
| 464 |
* Handles launching the default launch configuration for the specified resource, if there is no default |
| 465 |
* this method delegates to the <code>handleUnknownContext</code> method to figure out what to do |
| 466 |
* @param res the resource to find the default configuration for |
| 467 |
* @param mode the mode to launch it in |
| 468 |
* @return true if the method launched something false otherwise |
| 469 |
* @throws CoreException |
| 470 |
*/ |
355 |
*/ |
| 471 |
protected boolean launchDefault(IResource res, String mode) throws CoreException { |
356 |
protected LaunchConfigurationManager getLaunchConfigurationManager() { |
| 472 |
ILaunchConfiguration config = getLaunchManager().getDefaultConfiguration(res); |
357 |
return DebugUIPlugin.getDefault().getLaunchConfigurationManager(); |
| 473 |
if(config != null && config.exists()) { |
|
|
| 474 |
DebugUITools.launch(config, mode); |
| 475 |
return true; |
| 476 |
} |
| 477 |
else { |
| 478 |
return false; |
| 479 |
} |
| 480 |
} |
358 |
} |
| 481 |
|
|
|
| 482 |
/** |
| 483 |
* @see org.eclipse.debug.core.ILaunchListener#launchChanged(org.eclipse.debug.core.ILaunch) |
| 484 |
*/ |
| 485 |
public void launchChanged(ILaunch launch) {} |
| 486 |
|
| 487 |
/** |
| 488 |
* @see org.eclipse.debug.core.ILaunchListener#launchRemoved(org.eclipse.debug.core.ILaunch) |
| 489 |
*/ |
| 490 |
public void launchRemoved(ILaunch launch) {} |
| 491 |
|
| 492 |
} |
359 |
} |