Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 74480 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/debug/internal/ui/contextlaunching/ProfileContextLaunchingAction.java (-36 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.internal.ui.contextlaunching;
12
13
import org.eclipse.debug.core.ILaunchManager;
14
15
/**
16
 * Specialization of <code>ContextLaunchingAction</code> for profile mode
17
 * 
18
 * @see ContextLaunchingAction
19
 * @see ILaunchManager
20
 * @see RunContextLaunchingAction
21
 * @see DebugContextLaunchingAction
22
 * 
23
 * @since 3.3
24
 * EXPERIMENTAL
25
 * CONTEXTLAUNCHING
26
 */
27
public class ProfileContextLaunchingAction extends ContextLaunchingAction {
28
29
	/**
30
	 * Constructor
31
	 */
32
	public ProfileContextLaunchingAction() {
33
		super(ILaunchManager.PROFILE_MODE);
34
	}
35
36
}
(-)ui/org/eclipse/debug/internal/ui/contextlaunching/ContextLaunchingAction.java (-76 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.internal.ui.contextlaunching;
12
13
import org.eclipse.jface.action.IAction;
14
import org.eclipse.jface.viewers.ISelection;
15
import org.eclipse.swt.widgets.Event;
16
import org.eclipse.ui.IActionDelegate2;
17
18
/**
19
 * A universal context launching action for popup menus. 
20
 * This action gets its immediate context from what was right-clicked
21
 * on to present the action.
22
 * 
23
 * @see ContextRunner
24
 * @see IActionDelegate2
25
 * @see RunContextLaunchingAction
26
 * @see DebugContextLaunchingAction
27
 * @see ProfileContextLaunchingAction
28
 * 
29
 * @since 3.3
30
 * EXPERIMENTAL
31
 * CONTEXTLAUNCHING
32
 */
33
public class ContextLaunchingAction implements IActionDelegate2 {
34
35
	/**
36
	 * the mode the action is created on
37
	 */
38
	private String fMode = null;
39
	
40
	/**
41
	 * Constructor
42
	 * @param mode
43
	 */
44
	public ContextLaunchingAction(String mode) {
45
		fMode = mode;
46
	}
47
48
	/**
49
	 * @see org.eclipse.ui.IActionDelegate2#dispose()
50
	 */
51
	public void dispose() {}
52
53
	/**
54
	 * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
55
	 */
56
	public void init(IAction action) {}
57
58
	/**
59
	 * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
60
	 */
61
	public void runWithEvent(IAction action, Event event) {
62
		ContextRunner.getDefault().launch(fMode);
63
	}
64
	
65
	/**
66
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
67
	 */
68
	public void run(IAction action) {
69
		//not called
70
	}
71
72
	/**
73
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
74
	 */
75
	public void selectionChanged(IAction action, ISelection selection) {}
76
}
(-)ui/org/eclipse/debug/internal/ui/contextlaunching/ContextMessages.java (-8 / +6 lines)
Lines 10-26 Link Here
10
 */
10
 */
11
public class ContextMessages extends NLS {
11
public class ContextMessages extends NLS {
12
	private static final String BUNDLE_NAME = "org.eclipse.debug.internal.ui.contextlaunching.ContextMessages"; //$NON-NLS-1$
12
	private static final String BUNDLE_NAME = "org.eclipse.debug.internal.ui.contextlaunching.ContextMessages"; //$NON-NLS-1$
13
	
14
	public static String ContextRunner_0;
13
	public static String ContextRunner_0;
15
	public static String ContextRunner_1;
14
	public static String ContextRunner_10;
16
	public static String ContextRunner_2;
15
	public static String ContextRunner_11;
17
	public static String ContextRunner_3;
16
	public static String ContextRunner_12;
18
	public static String ContextRunner_4;
19
	public static String ContextRunner_5;
20
	public static String ContextRunner_6;
21
22
	public static String ContextRunner_7;
17
	public static String ContextRunner_7;
18
	public static String ContextRunner_8;
19
	public static String ContextRunner_9;
23
	public static String OpenLaunchDialogAction_0;
20
	public static String OpenLaunchDialogAction_0;
21
	public static String OpenLaunchDialogAction_1;
24
	static {
22
	static {
25
		// initialize resource bundle
23
		// initialize resource bundle
26
		NLS.initializeMessages(BUNDLE_NAME, ContextMessages.class);
24
		NLS.initializeMessages(BUNDLE_NAME, ContextMessages.class);
(-)ui/org/eclipse/debug/internal/ui/contextlaunching/ContextLaunchingToolbarAction.java (-82 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.internal.ui.contextlaunching;
12
13
import org.eclipse.debug.internal.ui.DebugUIPlugin;
14
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension;
15
import org.eclipse.jface.action.Action;
16
import org.eclipse.jface.action.IAction;
17
import org.eclipse.jface.viewers.ISelection;
18
import org.eclipse.swt.widgets.Event;
19
import org.eclipse.ui.IWorkbenchWindow;
20
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
21
22
/**
23
 * A wrapper class for a context launching toolbar action
24
 * 
25
 * @see ContextRunner
26
 * @see ContextLaunchingAction
27
 * @see Action
28
 * @see IWorkbenchWindowActionDelegate
29
 * 
30
 *  @since 3.3
31
 *  EXPERIMENTAL
32
 *  CONTEXTLAUNCHING
33
 */
34
public class ContextLaunchingToolbarAction extends Action implements IWorkbenchWindowActionDelegate {
35
36
	/**
37
	 * The mode this action applies to
38
	 */
39
	private String fMode = null;
40
	
41
	/**
42
	 * Constructor
43
	 * @param id
44
	 */
45
	public ContextLaunchingToolbarAction(String id) {
46
		LaunchGroupExtension extension = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(id);
47
		if (extension != null) {
48
			fMode = extension.getMode();
49
			setText(extension.getLabel());
50
			setImageDescriptor(extension.getImageDescriptor());
51
		}
52
	}
53
54
	/**
55
	 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
56
	 */
57
	public void dispose() {}
58
59
	/**
60
	 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
61
	 */
62
	public void init(IWorkbenchWindow window) {}
63
	
64
	/**
65
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
66
	 */
67
	public void selectionChanged(IAction action, ISelection selection) {}
68
69
	/**
70
	 * @see org.eclipse.jface.action.Action#runWithEvent(org.eclipse.swt.widgets.Event)
71
	 */
72
	public void runWithEvent(Event event) {
73
		ContextRunner.getDefault().launch(fMode);
74
	}
75
76
	/**
77
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
78
	 */
79
	public void run(IAction action) {
80
		//do nothing
81
	}
82
}
(-)ui/org/eclipse/debug/internal/ui/contextlaunching/ContextMessages.properties (-7 / +7 lines)
Lines 1-9 Link Here
1
ContextRunner_0=Unable To Launch
1
ContextRunner_0=Unable To Launch
2
ContextRunner_1=There is no way to launch the currently selected context, would you like to {0} the last thing you launched?
3
ContextRunner_2=&Always perform this action
4
ContextRunner_3=Not Runnable
5
ContextRunner_4={0} is not runnable, would you like to check its'' parent project for a way to run it?
6
ContextRunner_5=Cannot Launch
7
ContextRunner_6=Neither the selected resource or its' associated project are launchable.
8
ContextRunner_7=The current context cannot be launched, and there are no recent launches.
2
ContextRunner_7=The current context cannot be launched, and there are no recent launches.
9
OpenLaunchDialogAction_0=Open {0} Dialog
3
ContextRunner_8=&Select a configuration to launch:
4
ContextRunner_9=Select Configuration
5
ContextRunner_10=Would you like to try and launch the parent project [{0}] of {1}?
6
ContextRunner_11=Launch Parent Project?
7
ContextRunner_12=&Always launch project if resource is not launchable
8
OpenLaunchDialogAction_0=Open {0} Dialog...
9
OpenLaunchDialogAction_1=&Open {0} Dialog...
(-)ui/org/eclipse/debug/internal/ui/contextlaunching/ContextRunner.java (-267 / +184 lines)
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;
14
import java.util.Iterator;
13
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;
16
import org.eclipse.core.resources.IProject;
21
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.IAdaptable;
19
import org.eclipse.core.runtime.IAdaptable;
24
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;
30
import org.eclipse.debug.internal.ui.DebugUIPlugin;
21
import org.eclipse.debug.internal.ui.DebugUIPlugin;
22
import org.eclipse.debug.internal.ui.DefaultLabelProvider;
31
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
23
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
24
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
32
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchHistory;
25
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchHistory;
33
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension;
26
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension;
34
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutSelectionDialog;
27
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutSelectionDialog;
Lines 38-54 Link Here
38
import org.eclipse.jface.dialogs.MessageDialog;
31
import org.eclipse.jface.dialogs.MessageDialog;
39
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
32
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;
45
import org.eclipse.ui.dialogs.ListDialog;
52
46
53
import com.ibm.icu.text.MessageFormat;
47
import com.ibm.icu.text.MessageFormat;
54
48
Lines 59-72 Link Here
59
 * @see ContextLaunchingAction
53
 * @see ContextLaunchingAction
60
 * @see ContextLaunchingToolbarAction
54
 * @see ContextLaunchingToolbarAction
61
 * @see ILaunchListener
55
 * @see ILaunchListener
62
 * @see org.eclipse.debug.core.ILaunchManager
63
 * 
56
 * 
64
 *  @since 3.3
57
 *  @since 3.3
65
 *  EXPERIMENTAL
58
 *  EXPERIMENTAL
66
 *  CONTEXTLAUNCHING
59
 *  CONTEXTLAUNCHING
67
 */
60
 */
68
public class ContextRunner implements ILaunchListener {
61
public final class ContextRunner {
69
	
62
	
63
	/**
64
	 * The singleton instance of the context runner
65
	 */
70
	private static ContextRunner fgInstance = null;
66
	private static ContextRunner fgInstance = null;
71
	
67
	
72
	/**
68
	/**
Lines 79-92 Link Here
79
		}
75
		}
80
		return fgInstance;
76
		return fgInstance;
81
	}
77
	}
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
	
78
	
91
	/**
79
	/**
92
	 * Performs the context launching given the object context and the mode to launch in.
80
	 * Performs the context launching given the object context and the mode to launch in.
Lines 94-178 Link Here
94
	 */
82
	 */
95
	public void launch(String mode) {
83
	public void launch(String mode) {
96
		try {
84
		try {
85
			//1. resolve resource
97
			Object context = getCurrentContext();
86
			Object context = getCurrentContext();
98
			ILaunchConfiguration config = isSharedConfig(context);
87
			ILaunchConfiguration config = null;
99
			if(config != null) { 
88
			if(context != null) {
100
				DebugUITools.launch(config, mode);
89
				if(context instanceof IAdaptable) {
101
				return;
90
					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) {
91
					if(resource != null) {
120
						fBackingResource = resource;
92
						selectAndLaunch(resource, mode);
121
						config = getLaunchManager().getDefaultConfiguration(resource);
93
						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
					}
137
				}
138
			}
139
			else {
140
				handleUnknownContext(mode);
141
			}
142
		}
143
		catch(CoreException ce) {DebugUIPlugin.log(ce);}
144
	}
145
	
146
	/**
147
	 * Handles the case where the context is unknown: Meaning that nothing can be launched.
148
	 * @param mode the mode
149
	 */
150
	protected void handleUnknownContext(String mode) {
151
		ILaunchConfiguration config = getLastLaunch(mode);
152
		if(config == null) {
153
			MessageDialog.openInformation(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_0, ContextMessages.ContextRunner_7);
154
		}
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
					}
94
					}
170
				}
95
				}
171
			}
96
			}
172
			else if(MessageDialogWithToggle.ALWAYS.equals(prompt)) {
97
			//2. launch last if no resource
98
			config = getLastLaunch(mode);
99
			if(config != null) {
173
				DebugUITools.launch(config, mode);
100
				DebugUITools.launch(config, mode);
101
				return;
174
			}
102
			}
103
			
175
		}
104
		}
105
		catch(CoreException ce) {DebugUIPlugin.log(ce);}
176
	}
106
	}
177
	
107
	
178
	/**
108
	/**
Lines 192-213 Link Here
192
	}
122
	}
193
	
123
	
194
	/**
124
	/**
195
	 * This method return if the editor input is from a shared java launch configuration file or not
125
	 * Returns the <code>ILaunchGroup</code> that corresponds to the specified mode
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
209
	 * @param mode the mode to find the launch group
126
	 * @param mode the mode to find the launch group
210
	 * @return the launch group that corresponds to the specified mode
127
	 * @return the <code>ILaunchGroup</code> that corresponds to the specified mode, or <code>null</code>
211
	 */
128
	 */
212
	protected ILaunchGroup resolveLaunchGroup(String mode) {
129
	protected ILaunchGroup resolveLaunchGroup(String mode) {
213
		//TODO might not return the group we want
130
		//TODO might not return the group we want
Lines 221-338 Link Here
221
	}
138
	}
222
	
139
	
223
	/**
140
	/**
224
	 * Returns the shared config from the selected resource or <code>null</code> if the selected resources is not a shared config
141
	 * Returns if the parent project should be checked automatically
225
	 * @param receiver
142
	 * @return true if the parent project should checked automatically, false otherwise
226
	 * @return the shared config from the selected resource or <code>null</code> if the selected resources is not a shared config
143
	 */
227
	 */
144
	protected boolean shouldCheckParent() {
228
	public ILaunchConfiguration isSharedConfig(Object receiver) {
145
		return DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_LAUNCH_PARENT_PROJECT);
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
	}
146
	}
244
	
147
	
245
	/**
148
	/**
246
	 * Prompts the user to select a way of launching the current resource, where a 'way'
149
	 * 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
150
	 * 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
249
	 * @param resource
151
	 * @param resource
152
	 * @param mode
250
	 * @return if the context was launched in the given mode or not
153
	 * @return if the context was launched in the given mode or not
251
	 * @throws CoreException
154
	 * @throws CoreException
252
	 */
155
	 */
253
	protected boolean selectAndLaunch(IResource resource, String mode) throws CoreException {
156
	protected boolean selectAndLaunch(IResource resource, String mode) throws CoreException {
254
		boolean launched = false;
157
		List configs = getLaunchConfigurationManager().getApplicableLaunchConfigurations(resource);
255
		if(launchDefault(resource, mode)) {
158
		int csize = configs.size();
256
			return true;
159
		if(csize == 1) {
257
		}
160
			DebugUITools.launch((ILaunchConfiguration) configs.get(0), mode);
258
		List exts = getLaunchShortcuts(resource);
259
		if(exts.size() == 1) {
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;
161
			return true;
264
		}
162
		}
265
		else if(exts.size() < 1) {
163
		if(csize < 1) {
266
			//prompt to try the parent containers
164
			List exts = getLaunchConfigurationManager().getLaunchShortcuts(resource);
267
			String prompt = DebugUIPlugin.getDefault().getPreferenceStore().getString(IInternalDebugUIConstants.PREF_ALWAYS_RUN_PROJECT_CONFIGURATION);
165
			int esize = exts.size();
268
			if(MessageDialogWithToggle.ALWAYS.equals(prompt)) {
166
			if(esize == 1) {
269
				//go ahead and check
167
				LaunchShortcutExtension ext = (LaunchShortcutExtension) exts.get(0);
270
				selectAndLaunch(resource.getProject(), mode);
168
				ext.launch(new StructuredSelection(resource), mode);
271
			}
169
				return true;
272
			else if(MessageDialogWithToggle.PROMPT.equals(prompt)) {
170
			}
273
				MessageDialogWithToggle mdwt = MessageDialogWithToggle.openYesNoQuestion(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_3,
171
			if(esize > 1) {
274
						MessageFormat.format(ContextMessages.ContextRunner_4, new String[] {fBackingResource.getName()}),
172
				return showShortcutSelectionDialog(resource, mode);
275
						ContextMessages.ContextRunner_2, false, null, null);
173
			}
276
				int ret = mdwt.getReturnCode();
174
			if(esize < 1) {
277
				boolean checked = mdwt.getToggleState();
175
				IProject project = resource.getProject();
278
				if(ret == IDialogConstants.YES_ID) {
176
				if(project != null && !project.equals(resource)) {
279
					if(checked) {
177
					if(!shouldCheckParent()) {
280
						DebugUIPlugin.getDefault().getPreferenceStore().putValue(IInternalDebugUIConstants.PREF_ALWAYS_RUN_PROJECT_CONFIGURATION, MessageDialogWithToggle.ALWAYS);
178
						String msg = MessageFormat.format(ContextMessages.ContextRunner_10, new String[] {project.getName(), resource.getName()});
179
						MessageDialogWithToggle mdwt = new MessageDialogWithToggle(DebugUIPlugin.getShell(), 
180
								ContextMessages.ContextRunner_11, 
181
								null, 
182
								msg,
183
								MessageDialog.QUESTION, 
184
								new String[] {IDialogConstants.YES_LABEL, IDialogConstants.CANCEL_LABEL},
185
								0, 
186
								ContextMessages.ContextRunner_12,
187
								false);
188
						if(mdwt.open() == IDialogConstants.YES_ID) {
189
							DebugUIPlugin.getDefault().getPreferenceStore().setValue(IInternalDebugUIConstants.PREF_LAUNCH_PARENT_PROJECT, mdwt.getToggleState());
190
							selectAndLaunch(project, mode);
191
						}
281
					}
192
					}
282
					selectAndLaunch(resource.getProject(), mode);
193
					else {
194
						selectAndLaunch(project, mode);
195
					}
196
				}
197
				else {
198
					MessageDialog.openInformation(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_0, ContextMessages.ContextRunner_7);
283
				}
199
				}
284
			}
200
			}
285
			return false;
286
		}
201
		}
287
		else {
202
		else if(csize > 1){
288
			boolean project = resource instanceof IProject;
203
			ILaunchConfiguration config = getMRUConfiguration(configs, mode);
289
			if(exts.isEmpty()) {
204
			if(config != null) {
290
				MessageDialog.openError(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_5, ContextMessages.ContextRunner_6);
205
				DebugUITools.launch(config, mode);
291
			}
206
			}
292
			else {
207
			else {
293
				LaunchShortcutSelectionDialog dialog = new LaunchShortcutSelectionDialog(resource, mode, !project, project);
208
				return showConfigurationSelectionDialog(configs, mode);
294
				if (dialog.open() == Window.OK) {
209
			}
295
					Object[] result = dialog.getResult();
210
		}
296
					if(result.length > 0) {
211
		return false;
297
						fMakeProjectDefault = dialog.makeProjectDefault();
212
	}
298
						fMakeResourceDefault = dialog.makeDefault();
213
	
299
						if(fMakeProjectDefault || fMakeResourceDefault) {
214
	/**
300
							getLaunchManager().addLaunchListener(this);
215
	 * Launches the first occurance of any one of the configurations in the provided list, if they are found in the launch history
301
						}
216
	 * for the corresponding launch group
302
						LaunchShortcutExtension method = (LaunchShortcutExtension) result[0];
217
	 * @param configurations
303
						if(method != null) {
218
	 * @param mode
304
							method.launch(new StructuredSelection(resource), mode);
219
	 * @return the associated launch configuration from the MRU listing or <code>null</code> if there isn't one
305
						}
220
	 */
306
					}
221
	protected ILaunchConfiguration getMRUConfiguration(List configurations, String mode) {
222
		ILaunchGroup group = resolveLaunchGroup(mode);
223
		if(group != null) {
224
			LaunchHistory history = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchHistory(group.getIdentifier());
225
			ILaunchConfiguration config = null;
226
			for(Iterator iter = configurations.iterator(); iter.hasNext();) {
227
				config = (ILaunchConfiguration) iter.next();
228
				if(history.contains(config)) {
229
					return config;
307
				}
230
				}
308
			}
231
			}
309
		}
232
		}
310
		return launched;
233
		return null;
311
	}
234
	}
312
	
235
	
313
	/**
236
	/**
314
	 * Creates a listing of the launch shortcut extensions that are applicable to the underlying resource
237
	 * Presents the user with a dialog to pick the launch configuration to launch
315
	 * @param resource the underlying resource
238
	 * @param configurations the listing of applicable configurations to present
316
	 * @return a listing of applicable launch shortcuts
239
	 * @param mode the mode
317
	 * @throws CoreException
240
	 * @return true if something was launched, false otherwise
241
	 */
242
	protected boolean showConfigurationSelectionDialog(List configurations, String mode) {
243
		ListDialog lsd = new ListDialog(DebugUIPlugin.getShell());
244
		lsd.setContentProvider(new ArrayContentProvider());
245
		lsd.setLabelProvider(new DefaultLabelProvider());
246
		lsd.setMessage(ContextMessages.ContextRunner_8);
247
		lsd.setTitle(ContextMessages.ContextRunner_9);
248
		lsd.setInput(configurations);
249
		if(lsd.open() == IDialogConstants.OK_ID) {
250
			ILaunchConfiguration config = (ILaunchConfiguration) lsd.getResult()[0];
251
			DebugUITools.launch(config, mode);
252
			return true;
253
		}
254
		return false;
255
	}
256
	
257
	/**
258
	 * Presents a selection dialog to the user to pick a launch shortcut
259
	 * @param resource the resource context
260
	 * @param mode the mode
261
	 * @return true if something was launched, false otherwise
318
	 */
262
	 */
319
	public List getLaunchShortcuts(IResource resource) throws CoreException {
263
	protected boolean showShortcutSelectionDialog(IResource resource, String mode) {
320
		List list = new ArrayList(); 
264
		LaunchShortcutSelectionDialog dialog = new LaunchShortcutSelectionDialog(resource, mode);
321
		List sc = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchShortcuts();
265
		if (dialog.open() == Window.OK) {
322
		List ctxt = new ArrayList();
266
			Object[] result = dialog.getResult();
323
		ctxt.add(resource);
267
			if(result.length > 0) {
324
		IEvaluationContext context = new EvaluationContext(null, ctxt);
268
				LaunchShortcutExtension method = (LaunchShortcutExtension) result[0];
325
		context.addVariable("selection", ctxt); //$NON-NLS-1$
269
				if(method != null) {
326
		LaunchShortcutExtension ext = null;
270
					method.launch(new StructuredSelection(resource), mode);
327
		for(Iterator iter = sc.iterator(); iter.hasNext();) {
271
					return true;
328
			ext = (LaunchShortcutExtension) iter.next();
329
			if(ext.evalEnablementExpression(context, ext.getContextualLaunchEnablementExpression())) {
330
				if(!list.contains(ext)) {
331
					list.add(ext);
332
				}
272
				}
333
			}
273
			}
334
		}
274
		}
335
		return list;
275
		return false;
336
	}
276
	}
337
	
277
	
338
	/**
278
	/**
Lines 342-347 Link Here
342
	 * <li>IEditorInput</li>
282
	 * <li>IEditorInput</li>
343
	 * <li>Object where <i>object</i> is the first element in the selection obtained from the 
283
	 * <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>
284
	 * selection provider of the currently selected workbench part</li>
285
	 * <li><code>null</code>, if the current context is unknown</li>
345
	 * </ol>
286
	 * </ol>
346
	 * @return the currently selected context to consider for launching, or <code>null</code>.
287
	 * @return the currently selected context to consider for launching, or <code>null</code>.
347
	 *
288
	 *
Lines 373-492 Link Here
373
							else if(sel instanceof ITextSelection) {
314
							else if(sel instanceof ITextSelection) {
374
								return part;
315
								return part;
375
							}
316
							}
376
							return sel;
377
						}
317
						}
378
						else {
318
						else {
379
							//default to returning the part, which can be further queried for adapters
380
							return part;
319
							return part;
381
						}
320
						}
382
					}
321
					}
383
				}
322
				}
384
			}
323
			}
385
			
386
		}
324
		}
387
		return null;
325
		return null;
388
	}
326
	}
389
	
327
	
390
	/**
328
	/**
391
	 * Returns the name of the currently selected context, or the empty string.
329
	 * Returns the associated launch configuration name of the currently selected context, or the empty string.
392
	 * This method can return null in the event the contributor of the selected context returns <code>null</code>
330
	 * @param mode the mode for the label request
393
	 * as the resource name.
331
	 * @return the associated launch configuration name of the currently selected context or the empty string. 
394
	 * @return the name of the currently selected context or the empty string. 
395
	 */
332
	 */
396
	public String getContextName() {
333
	public String getContextName(String mode) {
397
		Object o = getCurrentContext();
334
		Object o = getCurrentContext();
398
		ILaunchConfiguration config = isSharedConfig(o);
335
		ILaunchConfiguration config = getLaunchConfigurationManager().isSharedConfig(o);
399
		if(config != null) {
336
		if(config != null) {
400
			return config.getName();
337
			return config.getName();
401
		}
338
		}
402
		else {
339
		else {
403
			config = isSharedConfigEditorInput(o);
340
			if(o instanceof IAdaptable) {
404
			if(config != null) {
341
				Object a = ((IAdaptable)o).getAdapter(IResource.class);
405
				return config.getName();
342
				if(a != null) {
406
			}
343
					IResource res = (IResource) a;
407
			else {
344
					String lbl = resolveConfigName(res, mode);
408
				if(o instanceof IAdaptable) {
345
					if(!"".equals(lbl)) { //$NON-NLS-1$
409
					IAdaptable adapt = (IAdaptable) o;
346
						return lbl;
410
					Object a = adapt.getAdapter(ILaunchConfiguration.class);
411
					if(a != null) {
412
						return ((ILaunchConfiguration) a).getName();
413
					}
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
					}
347
					}
421
				}
348
				}
422
			}
349
			}
350
			config = getLastLaunch(mode);
351
			if(config != null) {
352
				return config.getName();
353
			}
423
		}
354
		}
424
		return ""; //$NON-NLS-1$
355
		return ""; //$NON-NLS-1$
425
	}
356
	}
426
	
357
	
427
	/**
358
	/**
428
	 * Returns if context launching is enabled
359
	 * Returns the name of the <code>ILaunchConfiguration</code> that corresponds to the specified <code>IResource</code>
429
	 * @return if context launching is enabled
360
	 * @param resource the resource
430
	 */
361
	 * @param mode the mode
431
	public static boolean isContextLaunchEnabled() {
362
	 * @return the name of the associated launch configuration, or the empty string if none
432
		return DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH);
433
	}
434
	
435
	/**
436
	 * Returns the launch manager
437
	 * @return the launch manager
438
	 */
439
	protected LaunchManager getLaunchManager() {
440
		return (LaunchManager) DebugPlugin.getDefault().getLaunchManager();
441
	}
442
	
443
	/**
444
	 * @see org.eclipse.debug.core.ILaunchListener#launchAdded(org.eclipse.debug.core.ILaunch)
445
	 */
363
	 */
446
	public void launchAdded(ILaunch launch) {
364
	protected String resolveConfigName(IResource resource, String mode) {
447
		if(fBackingResource != null) {
365
		if(resource != null) {
448
			try {
366
			try {
449
				if(fMakeResourceDefault) {
367
				ILaunchConfiguration config = null;
450
					getLaunchManager().setDefaultConfiguration(fBackingResource, launch.getLaunchConfiguration());
368
				List configs = getLaunchConfigurationManager().getApplicableLaunchConfigurations(resource);
369
				if(configs.size() == 1) {
370
					config = (ILaunchConfiguration) configs.get(0);
371
				}
372
				else if(configs.size() > 1){
373
					config = getMRUConfiguration(configs, mode);
374
					if(config == null) {
375
						return "..."; //$NON-NLS-1$
376
					}
377
				}
378
				else {
379
					//no configs
380
					List shortcuts = getLaunchConfigurationManager().getLaunchShortcuts(resource);
381
					if(shortcuts.size() > 0) {
382
						return "..."; //$NON-NLS-1$
383
					}
451
				}
384
				}
452
				if(fMakeProjectDefault) {
385
				if(config != null) {
453
					getLaunchManager().setDefaultConfiguration(fBackingResource.getProject(), launch.getLaunchConfiguration());
386
					return config.getName();
454
				}
387
				}
455
				getLaunchManager().removeLaunchListener(this);
456
				fMakeProjectDefault = false;
457
				fMakeResourceDefault = false;
458
			}
388
			}
459
			catch(CoreException ce) {DebugUIPlugin.log(ce);}
389
			catch (CoreException ce) {DebugUIPlugin.log(ce);}
460
		}
390
		}
391
		return ""; //$NON-NLS-1$
461
	}
392
	}
462
393
	
463
	/**
394
	/**
464
	 * Handles launching the default launch configuration for the specified resource, if there is no default
395
	 * Returns if context launching is enabled
465
	 * this method delegates to the <code>handleUnknownContext</code> method to figure out what to do
396
	 * @return if context launching is enabled
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
	 */
397
	 */
471
	protected boolean launchDefault(IResource res, String mode) throws CoreException {
398
	public boolean isContextLaunchEnabled() {
472
		ILaunchConfiguration config = getLaunchManager().getDefaultConfiguration(res);
399
		return DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH);
473
		if(config != null && config.exists()) {
474
			DebugUITools.launch(config, mode);
475
			return true;
476
		}
477
		else {
478
			return false;
479
		}
480
	}
400
	}
481
	
401
	
482
	/**
402
	/**
483
	 * @see org.eclipse.debug.core.ILaunchListener#launchChanged(org.eclipse.debug.core.ILaunch)
403
	 * Returns the launch configuration manager
484
	 */
404
	 * @return the launch configuration manager
485
	public void launchChanged(ILaunch launch) {}
486
487
	/**
488
	 * @see org.eclipse.debug.core.ILaunchListener#launchRemoved(org.eclipse.debug.core.ILaunch)
489
	 */
405
	 */
490
	public void launchRemoved(ILaunch launch) {}
406
	protected LaunchConfigurationManager getLaunchConfigurationManager() {
491
	
407
		return DebugUIPlugin.getDefault().getLaunchConfigurationManager();
408
	}
492
}
409
}
(-)ui/org/eclipse/debug/internal/ui/contextlaunching/RunContextLaunchingAction.java (-36 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.internal.ui.contextlaunching;
12
13
import org.eclipse.debug.core.ILaunchManager;
14
15
/**
16
 * Specialization of <code>ContextLaunchingAction</code> for run mode
17
 * 
18
 * @see ContextLaunchingAction
19
 * @see ILaunchManager
20
 * @see DebugContextLaunchingAction
21
 * @see ProfileContextLaunchingAction
22
 * 
23
 * @since 3.3
24
 * EXPERIMENTAL
25
 * CONTEXTLAUNCHING
26
 */
27
public class RunContextLaunchingAction extends ContextLaunchingAction {
28
29
	/**
30
	 * Constructor
31
	 */
32
	public RunContextLaunchingAction() {
33
		super(ILaunchManager.RUN_MODE);
34
	}
35
36
}
(-)ui/org/eclipse/debug/internal/ui/contextlaunching/DebugContextLaunchingAction.java (-35 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.internal.ui.contextlaunching;
12
13
import org.eclipse.debug.core.ILaunchManager;
14
15
/**
16
 * Specialization of <code>ContextLaunchingAction</code> for debug mode
17
 * 
18
 * @see ContextLaunchingAction
19
 * @see ILaunchManager
20
 * @see RunContextLaunchingAction
21
 * @see ProfileContextLaunchingAction
22
 * 
23
 * @since 3.3
24
 * EXPERIMENTAL
25
 * CONTEXTLAUNCHING
26
 */
27
public class DebugContextLaunchingAction extends ContextLaunchingAction {
28
	
29
	/**
30
	 * Constructor
31
	 */
32
	public DebugContextLaunchingAction() {
33
		super(ILaunchManager.DEBUG_MODE);
34
	}
35
}
(-)ui/org/eclipse/debug/internal/ui/actions/ActionMessages.properties (+2 lines)
Lines 127-132 Link Here
127
ModifyWatchpointAction_0=Error
127
ModifyWatchpointAction_0=Error
128
ModifyWatchpointAction_1=Failed to modify watchpoint
128
ModifyWatchpointAction_1=Failed to modify watchpoint
129
LaunchShortcutsAction_1=(none applicable)
129
LaunchShortcutsAction_1=(none applicable)
130
LaunchConfigurationAction_0=&{0} {1}
130
FindDialog_1=&Specify an element to select (? = any character, * = any String):
131
FindDialog_1=&Specify an element to select (? = any character, * = any String):
131
FindDialog_3=Find
132
FindDialog_3=Find
132
FindAction_0=&Find...
133
FindAction_0=&Find...
Lines 165-167 Link Here
165
ConfigureColumnsAction_0=Select &Columns...
166
ConfigureColumnsAction_0=Select &Columns...
166
ConfigureColumnsAction_1=Select the &columns to display:
167
ConfigureColumnsAction_1=Select the &columns to display:
167
ConfigureColumnsAction_2=Select Columns
168
ConfigureColumnsAction_2=Select Columns
169
ContextualLaunchAction_0={0} (default)
(-)ui/org/eclipse/debug/internal/ui/actions/ActionMessages.java (+4 lines)
Lines 38-43 Link Here
38
    public static String ConfigureColumnsAction_0;
38
    public static String ConfigureColumnsAction_0;
39
	public static String ConfigureColumnsAction_1;
39
	public static String ConfigureColumnsAction_1;
40
	public static String ConfigureColumnsAction_2;
40
	public static String ConfigureColumnsAction_2;
41
42
	public static String ContextualLaunchAction_0;
41
    
43
    
42
    public static String CopyToClipboardActionDelegate_Problem_Copying_to_Clipboard_1;
44
    public static String CopyToClipboardActionDelegate_Problem_Copying_to_Clipboard_1;
43
    public static String CopyToClipboardActionDelegate_There_was_a_problem_when_accessing_the_system_clipboard__Retry__2;
45
    public static String CopyToClipboardActionDelegate_There_was_a_problem_when_accessing_the_system_clipboard__Retry__2;
Lines 56-61 Link Here
56
    public static String EnableBreakpointAction_Enabling_breakpoints_3;
58
    public static String EnableBreakpointAction_Enabling_breakpoints_3;
57
    public static String EnableBreakpointAction_Exceptions_occurred_enabling_the_breakpoint_s___4;
59
    public static String EnableBreakpointAction_Exceptions_occurred_enabling_the_breakpoint_s___4;
58
60
61
	public static String LaunchConfigurationAction_0;
62
59
    public static String OpenBreakpointMarkerAction__Go_to_File_1;
63
    public static String OpenBreakpointMarkerAction__Go_to_File_1;
60
    public static String OpenBreakpointMarkerAction_Exceptions_occurred_attempting_to_open_the_editor_for_the_breakpoint_resource_2;
64
    public static String OpenBreakpointMarkerAction_Exceptions_occurred_attempting_to_open_the_editor_for_the_breakpoint_resource_2;
61
    public static String OpenBreakpointMarkerAction_Go_to_Breakpoint_1;
65
    public static String OpenBreakpointMarkerAction_Go_to_Breakpoint_1;
(-)ui/org/eclipse/debug/internal/ui/actions/LaunchShortcutAction.java (-2 lines)
Lines 45-52 Link Here
45
		updateEnablement();
45
		updateEnablement();
46
	}
46
	}
47
	
47
	
48
	
49
50
	/**
48
	/**
51
	 * Runs with either the active editor or workbench selection.
49
	 * Runs with either the active editor or workbench selection.
52
	 * 
50
	 * 
(-)ui/org/eclipse/debug/internal/ui/actions/LaunchablePropertyTester.java (-18 / +19 lines)
Lines 17-23 Link Here
17
import org.eclipse.core.runtime.Platform;
17
import org.eclipse.core.runtime.Platform;
18
import org.eclipse.debug.internal.ui.DebugUIPlugin;
18
import org.eclipse.debug.internal.ui.DebugUIPlugin;
19
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
19
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
20
import org.eclipse.debug.internal.ui.contextlaunching.ContextRunner;
20
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
21
import org.eclipse.debug.ui.actions.ILaunchable;
21
import org.eclipse.debug.ui.actions.ILaunchable;
22
22
23
/**
23
/**
Lines 34-62 Link Here
34
					return Platform.getAdapterManager().hasAdapter(receiver, ILaunchable.class.getName());
34
					return Platform.getAdapterManager().hasAdapter(receiver, ILaunchable.class.getName());
35
				}
35
				}
36
		}
36
		}
37
		if("resource".equals(property)) { //$NON-NLS-1$
38
			IResource res = getResource(receiver);
39
			if(res != null) {
40
				return res.isAccessible();
41
			}
42
		}
43
		if("contextlaunch".equals(property)) { //$NON-NLS-1$
37
		if("contextlaunch".equals(property)) { //$NON-NLS-1$
44
			return DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH);
38
			if(DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH)) {
45
		}
39
				try {
46
		if("contextlaunchable".equals(property)) { //$NON-NLS-1$
40
					IResource res = getResource(receiver);
47
			try {
41
					if(res != null) {
48
				IResource res = getResource(receiver);
42
						return res.isAccessible() && getLaunchConfiguraitonManager().getLaunchShortcuts(getResource(receiver)).size() > 0 && getLaunchConfiguraitonManager().isSharedConfig(receiver) == null;
49
				if(res != null) {
43
					}
50
					return ContextRunner.getDefault().getLaunchShortcuts(getResource(receiver)).size() > 0 && ContextRunner.getDefault().isSharedConfig(receiver) == null;
44
					return false;
51
				}
45
				} 
52
				return false;
46
				catch (CoreException e) {return false;}
53
			} 
47
			}
54
			catch (CoreException e) {return false;}
55
		}
48
		}
56
		return false;
49
		return false;
57
	}
50
	}
58
51
59
	/**
52
	/**
53
	 * Returns the launch configuration manager
54
	 * @return the launch configuration manager
55
	 */
56
	protected LaunchConfigurationManager getLaunchConfiguraitonManager() {
57
		return DebugUIPlugin.getDefault().getLaunchConfigurationManager();
58
	}
59
	
60
	/**
60
	 * Returns the resource this property page is open on.
61
	 * Returns the resource this property page is open on.
61
	 * 
62
	 * 
62
	 * @return resource
63
	 * @return resource
(-)ui/org/eclipse/debug/internal/ui/actions/SharedLaunchConfigAction.java (-55 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.internal.ui.actions;
12
13
import org.eclipse.debug.core.ILaunchConfiguration;
14
import org.eclipse.debug.ui.DebugUITools;
15
import org.eclipse.jface.action.Action;
16
import org.eclipse.jface.resource.ImageDescriptor;
17
18
/**
19
 * This class provides an action warpper for adding shared launch configuration actions to the context menu
20
 * of the Run->... menu item
21
 * 
22
 * @since 3.3
23
 */
24
public class SharedLaunchConfigAction extends Action {
25
26
	private ILaunchConfiguration fConfig;
27
	private String fMode;
28
	
29
	/**
30
	 * Consturtor
31
	 * @param text the text for the action
32
	 * @param image the image for the action
33
	 */
34
	public SharedLaunchConfigAction(ILaunchConfiguration config, String mode, ImageDescriptor image) {
35
		super(config.getName(), image);
36
		fConfig = config;
37
		fMode = mode;
38
	}
39
	
40
	/**
41
	 * Allows access to the launch configuration associated with the action
42
	 * @return the associated launch configuration
43
	 */
44
	public ILaunchConfiguration getLaunchConfiguration() {
45
		return fConfig;
46
	}
47
48
	/* (non-Javadoc)
49
	 * @see org.eclipse.jface.action.Action#run()
50
	 */
51
	public void run() {
52
		DebugUITools.launch(fConfig, fMode);
53
	}
54
55
}
(-)ui/org/eclipse/debug/internal/ui/preferences/RunDebugPropertiesPage.java (-82 / +47 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.debug.internal.ui.preferences;
11
package org.eclipse.debug.internal.ui.preferences;
12
12
13
import java.util.ArrayList;
14
import java.util.Arrays;
13
import java.util.Arrays;
15
import java.util.Collections;
14
import java.util.Collections;
16
import java.util.Comparator;
15
import java.util.Comparator;
Lines 22-28 Link Here
22
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.IResource;
23
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.IAdaptable;
23
import org.eclipse.core.runtime.IAdaptable;
25
import org.eclipse.core.runtime.IPath;
26
import org.eclipse.debug.core.DebugPlugin;
24
import org.eclipse.debug.core.DebugPlugin;
27
import org.eclipse.debug.core.ILaunchConfiguration;
25
import org.eclipse.debug.core.ILaunchConfiguration;
28
import org.eclipse.debug.core.ILaunchConfigurationType;
26
import org.eclipse.debug.core.ILaunchConfigurationType;
Lines 33-40 Link Here
33
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
31
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
34
import org.eclipse.debug.internal.ui.SWTUtil;
32
import org.eclipse.debug.internal.ui.SWTUtil;
35
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationComparator;
33
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationComparator;
36
import org.eclipse.debug.ui.DebugUITools;
37
import org.eclipse.debug.ui.IDebugUIConstants;
34
import org.eclipse.debug.ui.IDebugUIConstants;
35
import org.eclipse.jface.dialogs.IDialogConstants;
38
import org.eclipse.jface.viewers.ArrayContentProvider;
36
import org.eclipse.jface.viewers.ArrayContentProvider;
39
import org.eclipse.jface.viewers.CheckStateChangedEvent;
37
import org.eclipse.jface.viewers.CheckStateChangedEvent;
40
import org.eclipse.jface.viewers.CheckboxTableViewer;
38
import org.eclipse.jface.viewers.CheckboxTableViewer;
Lines 84-89 Link Here
84
	private Set fOriginalCandidates;
82
	private Set fOriginalCandidates;
85
	
83
	
86
	/**
84
	/**
85
	 * Holds configurations that need to be saved when the page closes
86
	 */
87
	private Set fChangedConfigurations = new HashSet();
88
	
89
	/**
87
	 * List of the applicable launch config types for the backing resource
90
	 * List of the applicable launch config types for the backing resource
88
	 */
91
	 */
89
	private List fTypeCandidates = null;
92
	private List fTypeCandidates = null;
Lines 207-212 Link Here
207
	}
210
	}
208
211
209
	/**
212
	/**
213
	 * @see org.eclipse.jface.dialogs.DialogPage#dispose()
214
	 */
215
	public void dispose() {
216
		if(fOriginalCandidates != null) {
217
			fOriginalCandidates.clear();
218
			fOriginalCandidates = null;
219
		}
220
		if(fChangedConfigurations != null) {
221
			fChangedConfigurations.clear();
222
			fChangedConfigurations = null;
223
		}
224
		super.dispose();
225
	}
226
227
	/**
210
	 * Returns the viewer displaying possible default configurations.
228
	 * Returns the viewer displaying possible default configurations.
211
	 * 
229
	 * 
212
	 * @return viewer
230
	 * @return viewer
Lines 253-324 Link Here
253
	protected Set collectConfigCandidates(IResource resource) {
271
	protected Set collectConfigCandidates(IResource resource) {
254
		if(fOriginalCandidates == null) {
272
		if(fOriginalCandidates == null) {
255
			fOriginalCandidates = new HashSet();
273
			fOriginalCandidates = new HashSet();
256
			IPath resourcePath = resource.getFullPath();
257
			try {
274
			try {
258
				List types = collectTypeCandidates();
275
				List configs = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getApplicableLaunchConfigurations(resource);
259
				List configs = new ArrayList();
276
				for(Iterator iter = configs.iterator(); iter.hasNext();) {
260
				ILaunchConfiguration[] configurations = getLaunchManager().getLaunchConfigurations();
277
					fOriginalCandidates.add(((ILaunchConfiguration)iter.next()).getWorkingCopy());
261
				for(int i = 0; i < configurations.length; i++) {
262
					if(types.contains(configurations[i].getType())) {
263
						if(configurations[i].isMigrationCandidate()) {
264
							configurations[i].migrate();
265
						}
266
						configs.add(configurations[i]);
267
					}
268
				}
269
				ILaunchConfiguration configuration = null;
270
				IResource[] resources = null;
271
				for (Iterator iter = configs.iterator(); iter.hasNext();) {
272
					configuration = (ILaunchConfiguration) iter.next();
273
					if(acceptConfiguration(configuration)) { 
274
						if(configuration.contentsEqual(getLaunchManager().getDefaultConfiguration(resource))) {
275
							fOriginalCandidates.add(configuration.getWorkingCopy());
276
						}
277
						else {
278
							resources = configuration.getMappedResources();
279
							if (resources != null) {
280
								for (int j = 0; j < resources.length; j++) {
281
									if (resource.equals(resources[j]) || resourcePath.isPrefixOf(resources[j].getFullPath())) {
282
										fOriginalCandidates.add(configuration.getWorkingCopy());
283
										break;
284
									}
285
								}
286
							}
287
							else {
288
								//in the event the config has no mapping
289
								fOriginalCandidates.add(configuration.getWorkingCopy());
290
							}
291
						}
292
					}
293
				}
278
				}
294
			} catch (CoreException e) {
295
				fOriginalCandidates.clear();
296
				DebugPlugin.log(e);
297
			}
279
			}
280
			catch(CoreException ce) {DebugUIPlugin.log(ce);}
298
		}
281
		}
299
		return fOriginalCandidates;
282
		return fOriginalCandidates;
300
	}
283
	}
301
	
284
	
302
	/**
285
	
303
	 * Returns if the specified configuration should be considered as a potential candidate
304
	 * @param config
305
	 * @return if the specified configuration should be considered as a potential candidate
306
	 * @throws CoreException
307
	 */
308
	private boolean acceptConfiguration(ILaunchConfiguration config) throws CoreException {
309
		if(config != null && !DebugUITools.isPrivate(config)) {
310
			if(!"org.eclipse.ui.externaltools".equals(config.getType().getCategory())) { //$NON-NLS-1$
311
				return true;
312
			}
313
			else {
314
				IResource[] res = config.getMappedResources();
315
				if(res != null) {
316
					return true;
317
				}
318
			}
319
		}
320
		return false;
321
	}
322
	
286
	
323
	/**
287
	/**
324
	 * Returns the resource this property page is open on.
288
	 * Returns the resource this property page is open on.
Lines 365-379 Link Here
365
			}
329
			}
366
		}
330
		}
367
	//add
331
	//add
368
		iter = fOriginalCandidates.iterator();
332
		iter = fChangedConfigurations.iterator();
369
		while (iter.hasNext()) {
333
		while (iter.hasNext()) {
370
			ILaunchConfigurationWorkingCopy currentConfig = (ILaunchConfigurationWorkingCopy) iter.next();
334
			ILaunchConfigurationWorkingCopy currentConfig = (ILaunchConfigurationWorkingCopy) iter.next();
371
			if (currentConfig.isDirty()){
335
			try{
372
				try{
336
				currentConfig.doSave();
373
					currentConfig.doSave();
337
			} catch (CoreException e) {
374
				} catch (CoreException e) {
338
				DebugPlugin.logMessage("Problem saving changes to configuration " + currentConfig.getName(), e); //$NON-NLS-1$
375
					DebugPlugin.logMessage("Problem saving changes to configuration " + currentConfig.getName(), e); //$NON-NLS-1$
376
				}
377
			}
339
			}
378
		}
340
		}
379
		
341
		
Lines 397-408 Link Here
397
	private Set getConfigurationNames() {
359
	private Set getConfigurationNames() {
398
		Set names = new HashSet();
360
		Set names = new HashSet();
399
		Iterator iter = fOriginalCandidates.iterator();
361
		Iterator iter = fOriginalCandidates.iterator();
400
		Object o = null;
401
		while (iter.hasNext()) {
362
		while (iter.hasNext()) {
402
			o = iter.next();
363
			names.add(((ILaunchConfiguration)iter.next()).getName());
403
			if(o instanceof ILaunchConfiguration) {
364
		}
404
				names.add(((ILaunchConfiguration)o).getName());
365
		iter = fChangedConfigurations.iterator();
405
			}
366
		while (iter.hasNext()) {
367
			names.add(((ILaunchConfiguration)iter.next()).getName());
406
		}
368
		}
407
		return names;
369
		return names;
408
	}
370
	}
Lines 426-433 Link Here
426
			ILaunchConfigurationWorkingCopy copy = configuration.copy(
388
			ILaunchConfigurationWorkingCopy copy = configuration.copy(
427
					((LaunchManager)DebugPlugin.getDefault().getLaunchManager()).generateUniqueLaunchConfigurationNameFrom(configuration.getName(), getConfigurationNames()));
389
					((LaunchManager)DebugPlugin.getDefault().getLaunchManager()).generateUniqueLaunchConfigurationNameFrom(configuration.getName(), getConfigurationNames()));
428
			copy.setAttributes(configuration.getAttributes());
390
			copy.setAttributes(configuration.getAttributes());
429
			fOriginalCandidates.add(copy);
391
			fChangedConfigurations.add(copy);
430
			fViewer.refresh();
392
			fViewer.add(copy);
431
			fViewer.setSelection(new StructuredSelection(copy));
393
			fViewer.setSelection(new StructuredSelection(copy));
432
		} catch (CoreException e) {
394
		} catch (CoreException e) {
433
			setErrorMessage(e.getMessage());
395
			setErrorMessage(e.getMessage());
Lines 444-452 Link Here
444
		ILaunchConfiguration[] configurations = getSelectedConfigurations();
406
		ILaunchConfiguration[] configurations = getSelectedConfigurations();
445
		for (int i = 0; i < configurations.length; i++) {
407
		for (int i = 0; i < configurations.length; i++) {
446
			fDeletedConfigurations.add(configurations[i]);
408
			fDeletedConfigurations.add(configurations[i]);
447
			fOriginalCandidates.remove(configurations[i]);
409
			fChangedConfigurations.remove(configurations[i]);
410
			fViewer.remove(configurations[i]);
448
		}
411
		}
449
		fViewer.refresh();
450
		if (indices[0] < table.getItemCount()) {
412
		if (indices[0] < table.getItemCount()) {
451
			fViewer.setSelection(new StructuredSelection(table.getItem(indices[0]).getData()));
413
			fViewer.setSelection(new StructuredSelection(table.getItem(indices[0]).getData()));
452
		} else if (table.getItemCount() > 0) {
414
		} else if (table.getItemCount() > 0) {
Lines 458-465 Link Here
458
	 * Edit the selection
420
	 * Edit the selection
459
	 */
421
	 */
460
	private void handleEdit() {
422
	private void handleEdit() {
461
		edit(getSelectedConfigurations()[0]);
423
		ILaunchConfigurationWorkingCopy config = getSelectedConfigurations()[0]; 
462
		fViewer.refresh();
424
		if(edit(config) == IDialogConstants.OK_ID) {
425
			fChangedConfigurations.add(config);
426
			fViewer.refresh();
427
		}
463
	}
428
	}
464
429
465
	/**
430
	/**
Lines 493-500 Link Here
493
							((LaunchManager)DebugPlugin.getDefault().getLaunchManager()).
458
							((LaunchManager)DebugPlugin.getDefault().getLaunchManager()).
494
							generateUniqueLaunchConfigurationNameFrom("New_configuration", getConfigurationNames())); //$NON-NLS-1$
459
							generateUniqueLaunchConfigurationNameFrom("New_configuration", getConfigurationNames())); //$NON-NLS-1$
495
					if (edit(wc) == Window.OK) {
460
					if (edit(wc) == Window.OK) {
496
						fOriginalCandidates.add(wc);
461
						fChangedConfigurations.add(wc);
497
						fViewer.refresh();
462
						fViewer.add(wc);
498
						fViewer.setSelection(new StructuredSelection(wc));
463
						fViewer.setSelection(new StructuredSelection(wc));
499
					}
464
					}
500
				} catch (CoreException e) {
465
				} catch (CoreException e) {
(-)ui/org/eclipse/debug/internal/ui/preferences/ContextLaunchingPreferencePage.java (-12 / +3 lines)
Lines 17-27 Link Here
17
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
17
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
18
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
18
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
19
import org.eclipse.debug.internal.ui.SWTUtil;
19
import org.eclipse.debug.internal.ui.SWTUtil;
20
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
21
import org.eclipse.jface.preference.BooleanFieldEditor;
20
import org.eclipse.jface.preference.BooleanFieldEditor;
22
import org.eclipse.jface.preference.FieldEditor;
21
import org.eclipse.jface.preference.FieldEditor;
23
import org.eclipse.jface.preference.PreferencePage;
22
import org.eclipse.jface.preference.PreferencePage;
24
import org.eclipse.jface.preference.RadioGroupFieldEditor;
25
import org.eclipse.swt.layout.GridData;
23
import org.eclipse.swt.layout.GridData;
26
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Control;
25
import org.eclipse.swt.widgets.Control;
Lines 69-85 Link Here
69
	//use contextual launch
67
	//use contextual launch
70
		FieldEditor edit = new BooleanFieldEditor(IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH, DebugPreferencesMessages.ContextualLaunchPreferencePage_1, comp);	
68
		FieldEditor edit = new BooleanFieldEditor(IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH, DebugPreferencesMessages.ContextualLaunchPreferencePage_1, comp);	
71
		fFieldEditors.add(edit);
69
		fFieldEditors.add(edit);
72
			
70
		
73
		edit = new RadioGroupFieldEditor(IInternalDebugUIConstants.PREF_ALWAYS_RUN_LAST_LAUNCH, DebugPreferencesMessages.ContextLaunchingPreferencePage_0, 3, 
71
		edit = new BooleanFieldEditor(IInternalDebugUIConstants.PREF_LAUNCH_PARENT_PROJECT, DebugPreferencesMessages.ContextLaunchingPreferencePage_0, comp);
74
				new String[][] {{DebugPreferencesMessages.LaunchingPreferencePage_3, MessageDialogWithToggle.ALWAYS}, 
75
				 {DebugPreferencesMessages.LaunchingPreferencePage_5, MessageDialogWithToggle.PROMPT}},
76
				 comp, true);	
77
		fFieldEditors.add(edit);
78
		edit = new RadioGroupFieldEditor(IInternalDebugUIConstants.PREF_ALWAYS_RUN_PROJECT_CONFIGURATION, DebugPreferencesMessages.ContextLaunchingPreferencePage_1, 3, 
79
				new String[][] {{DebugPreferencesMessages.LaunchingPreferencePage_7, MessageDialogWithToggle.ALWAYS}, 
80
				 {DebugPreferencesMessages.LaunchingPreferencePage_9, MessageDialogWithToggle.PROMPT}},
81
				 comp, true);	
82
		fFieldEditors.add(edit);
72
		fFieldEditors.add(edit);
73
		
83
	//init the field editors
74
	//init the field editors
84
		FieldEditor editor;
75
		FieldEditor editor;
85
		for(int i = 0; i < fFieldEditors.size(); i++) {
76
		for(int i = 0; i < fFieldEditors.size(); i++) {
(-)ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.properties (-2 / +1 lines)
Lines 18-25 Link Here
18
ConsolePreferencePage_Wrap_text_1=Fixed &width console
18
ConsolePreferencePage_Wrap_text_1=Fixed &width console
19
ContextualLaunchPreferencePage_0=This page is used to edit contextual launching options (EXPERIMENTAL).
19
ContextualLaunchPreferencePage_0=This page is used to edit contextual launching options (EXPERIMENTAL).
20
ContextualLaunchPreferencePage_1=&Enable contextual launching.
20
ContextualLaunchPreferencePage_1=&Enable contextual launching.
21
ContextLaunchingPreferencePage_0=Launch previous when no context available
21
ContextLaunchingPreferencePage_0=Always launch &related project if context is not launchable
22
ContextLaunchingPreferencePage_1=Launch project of un-runnable context
23
ConsolePreferencePage_Console_width=&Maximum character width:
22
ConsolePreferencePage_Console_width=&Maximum character width:
24
ConsolePreferencePage_Limit_console_output_1=&Limit console output
23
ConsolePreferencePage_Limit_console_output_1=&Limit console output
25
ConsolePreferencePage_Console_buffer_size__characters___2=Console &buffer size (characters):
24
ConsolePreferencePage_Console_buffer_size__characters___2=Console &buffer size (characters):
(-)ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java (-93 / +133 lines)
Lines 34-40 Link Here
34
34
35
import org.eclipse.core.expressions.EvaluationContext;
35
import org.eclipse.core.expressions.EvaluationContext;
36
import org.eclipse.core.expressions.IEvaluationContext;
36
import org.eclipse.core.expressions.IEvaluationContext;
37
import org.eclipse.core.resources.IProject;
37
import org.eclipse.core.resources.IFile;
38
import org.eclipse.core.resources.IResource;
38
import org.eclipse.core.resources.IResource;
39
import org.eclipse.core.resources.ISaveContext;
39
import org.eclipse.core.resources.ISaveContext;
40
import org.eclipse.core.resources.ISaveParticipant;
40
import org.eclipse.core.resources.ISaveParticipant;
Lines 43-52 Link Here
43
import org.eclipse.core.runtime.IConfigurationElement;
43
import org.eclipse.core.runtime.IConfigurationElement;
44
import org.eclipse.core.runtime.IExtensionPoint;
44
import org.eclipse.core.runtime.IExtensionPoint;
45
import org.eclipse.core.runtime.IPath;
45
import org.eclipse.core.runtime.IPath;
46
import org.eclipse.core.runtime.IStatus;
47
import org.eclipse.core.runtime.Platform;
46
import org.eclipse.core.runtime.Platform;
48
import org.eclipse.core.runtime.Status;
49
import org.eclipse.core.runtime.preferences.InstanceScope;
50
import org.eclipse.debug.core.DebugException;
47
import org.eclipse.debug.core.DebugException;
51
import org.eclipse.debug.core.DebugPlugin;
48
import org.eclipse.debug.core.DebugPlugin;
52
import org.eclipse.debug.core.ILaunch;
49
import org.eclipse.debug.core.ILaunch;
Lines 63-68 Link Here
63
import org.eclipse.debug.internal.ui.DebugUIPlugin;
60
import org.eclipse.debug.internal.ui.DebugUIPlugin;
64
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
61
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
65
import org.eclipse.debug.internal.ui.ILaunchHistoryChangedListener;
62
import org.eclipse.debug.internal.ui.ILaunchHistoryChangedListener;
63
import org.eclipse.debug.ui.DebugUITools;
66
import org.eclipse.debug.ui.IDebugUIConstants;
64
import org.eclipse.debug.ui.IDebugUIConstants;
67
import org.eclipse.debug.ui.ILaunchConfigurationTab;
65
import org.eclipse.debug.ui.ILaunchConfigurationTab;
68
import org.eclipse.debug.ui.ILaunchGroup;
66
import org.eclipse.debug.ui.ILaunchGroup;
Lines 70-80 Link Here
70
import org.eclipse.swt.SWT;
68
import org.eclipse.swt.SWT;
71
import org.eclipse.swt.graphics.Image;
69
import org.eclipse.swt.graphics.Image;
72
import org.eclipse.swt.widgets.Display;
70
import org.eclipse.swt.widgets.Display;
71
import org.eclipse.ui.IFileEditorInput;
73
import org.eclipse.ui.PlatformUI;
72
import org.eclipse.ui.PlatformUI;
74
import org.eclipse.ui.activities.IWorkbenchActivitySupport;
73
import org.eclipse.ui.activities.IWorkbenchActivitySupport;
75
import org.eclipse.ui.activities.WorkbenchActivityHelper;
74
import org.eclipse.ui.activities.WorkbenchActivityHelper;
76
import org.osgi.service.prefs.BackingStoreException;
77
import org.osgi.service.prefs.Preferences;
78
import org.w3c.dom.Document;
75
import org.w3c.dom.Document;
79
import org.w3c.dom.Element;
76
import org.w3c.dom.Element;
80
import org.w3c.dom.Node;
77
import org.w3c.dom.Node;
Lines 600-612 Link Here
600
	}
597
	}
601
598
602
	/**
599
	/**
600
	 * Creates a listing of the launch shortcut extensions that are applicable to the underlying resource
601
	 * @param resource the underlying resource
602
	 * @return a listing of applicable launch shortcuts or an empty list, never <code>null</code>
603
	 * @throws CoreException
604
	 * @since 3.3
605
	 */
606
	public List getLaunchShortcuts(IResource resource) throws CoreException {
607
		List list = new ArrayList(); 
608
		List sc = getLaunchShortcuts();
609
		List ctxt = new ArrayList();
610
		ctxt.add(resource);
611
		IEvaluationContext context = new EvaluationContext(null, ctxt);
612
		context.addVariable("selection", ctxt); //$NON-NLS-1$
613
		LaunchShortcutExtension ext = null;
614
		for(Iterator iter = sc.iterator(); iter.hasNext();) {
615
			ext = (LaunchShortcutExtension) iter.next();
616
			if(ext.evalEnablementExpression(context, ext.getContextualLaunchEnablementExpression()) && !WorkbenchActivityHelper.filterItem(ext)) {
617
				if(!list.contains(ext)) {
618
					list.add(ext);
619
				}
620
			}
621
		}
622
		return list;
623
	}
624
	
625
	/**
603
	 * Returns a listing of all of the <code>ILaunchConfigurationType</code>s that apply to the currently
626
	 * Returns a listing of all of the <code>ILaunchConfigurationType</code>s that apply to the currently
604
	 * specified <code>IResource</code>.
627
	 * specified <code>IResource</code>.
605
	 * 
628
	 * 
606
	 * @param resource the resource context
629
	 * @param resource the resource context
607
	 * @return a listing of applicable <code>ILaunchConfigurationType</code>s, or an empty list, never <code>null</code>
630
	 * @return a listing of applicable <code>ILaunchConfigurationType</code>s, or an empty list, never <code>null</code>
608
	 * @since 3.3
631
	 * @since 3.3
609
	 * EXPERIMENTAL
610
	 * CONTEXTLAUNCHING
632
	 * CONTEXTLAUNCHING
611
	 */
633
	 */
612
	public List getApplicableConfigurationTypes(IResource resource) {
634
	public List getApplicableConfigurationTypes(IResource resource) {
Lines 617-622 Link Here
617
			List list = new ArrayList();
639
			List list = new ArrayList();
618
			list.add(resource);
640
			list.add(resource);
619
			IEvaluationContext context = new EvaluationContext(null, list);
641
			IEvaluationContext context = new EvaluationContext(null, list);
642
			context.setAllowPluginActivation(true);
620
			context.addVariable("selection", list); //$NON-NLS-1$
643
			context.addVariable("selection", list); //$NON-NLS-1$
621
			HashSet set = new HashSet();
644
			HashSet set = new HashSet();
622
			for(Iterator iter = exts.iterator(); iter.hasNext();) {
645
			for(Iterator iter = exts.iterator(); iter.hasNext();) {
Lines 641-667 Link Here
641
	}
664
	}
642
	
665
	
643
	/**
666
	/**
644
	 * Returns a listing of all applicable <code>LaunchShortcutExtension</code>s for the given
667
	 * Returns a list of the <code>ILaunchConfiguration</code>s that apply to the specified <code>IResource</code>
645
	 * launch configuration type id.
668
	 * @param resource the resource
646
	 * @param typeid the id of the launch configuration
669
	 * @return a listing of applicable <code>ILaunchConfiguration</code>s for the specified <code>IResource</code> or an empty 
647
	 * @return a listing of <code>LaunchShortcutExtension</code>s that are associated with the specified launch configuration
670
	 * list if none, never <code>null</code>
648
	 * type id or an empty list, never <code>null</code>
649
	 * 
650
	 * @since 3.3
671
	 * @since 3.3
651
	 */
672
	 */
652
	public List getApplicableLaunchShortcuts(String typeid) {
673
	public List getApplicableLaunchConfigurations(IResource resource) {
653
		List list = new ArrayList();
674
		ArrayList list = new ArrayList();
654
		LaunchShortcutExtension ext = null;
675
		IPath resourcePath = resource.getFullPath();
655
		for(int i = 0; i < fLaunchShortcuts.size(); i++) {
676
		try {
656
			ext = (LaunchShortcutExtension) fLaunchShortcuts.get(i);
677
			List types = getApplicableConfigurationTypes(resource);
657
			if(ext.getAssociatedConfigurationTypes().contains(typeid)) {
678
			List configs = new ArrayList();
658
				list.add(ext);
679
			ILaunchConfiguration[] configurations = getLaunchManager().getLaunchConfigurations();
680
			for(int i = 0; i < configurations.length; i++) {
681
				if(types.contains(configurations[i].getType())) {
682
					if(configurations[i].isMigrationCandidate()) {
683
						configurations[i].migrate();
684
					}
685
					configs.add(configurations[i]);
686
				}
659
			}
687
			}
688
			ILaunchConfiguration configuration = null;
689
			IResource[] resources = null;
690
			for (Iterator iter = configs.iterator(); iter.hasNext();) {
691
				configuration = (ILaunchConfiguration) iter.next();
692
				if(acceptConfiguration(configuration)) { 
693
					if(configuration.contentsEqual(getLaunchManager().getDefaultConfiguration(resource))) {
694
						list.add(configuration);
695
					}
696
					else {
697
						resources = configuration.getMappedResources();
698
						if (resources != null) {
699
							for (int j = 0; j < resources.length; j++) {
700
								if (resource.equals(resources[j]) || resourcePath.isPrefixOf(resources[j].getFullPath())) {
701
									list.add(configuration);
702
									break;
703
								}
704
							}
705
						}
706
						else {
707
							//in the event the config has no mapping
708
							list.add(configuration);
709
						}
710
					}
711
				}
712
			}
713
		} catch (CoreException e) {
714
			list.clear();
715
			DebugPlugin.log(e);
660
		}
716
		}
661
		return list;
717
		return list;
662
	}
718
	}
663
	
719
	
664
	/**
720
	/**
721
	 * Returns if the specified configuration should be considered as a potential candidate
722
	 * @param config
723
	 * @return if the specified configuration should be considered as a potential candidate
724
	 * @throws CoreException
725
	 */
726
	private boolean acceptConfiguration(ILaunchConfiguration config) throws CoreException {
727
		if(config != null && !DebugUITools.isPrivate(config)) {
728
			if(!"org.eclipse.ui.externaltools".equals(config.getType().getCategory())) { //$NON-NLS-1$
729
				return true;
730
			}
731
			else {
732
				IResource[] res = config.getMappedResources();
733
				if(res != null) {
734
					return true;
735
				}
736
			}
737
		}
738
		return false;
739
	}
740
	
741
	/**
665
	 * Returns all launch shortcuts for the given category
742
	 * Returns all launch shortcuts for the given category
666
	 *
743
	 *
667
	 * @return all launch shortcuts
744
	 * @return all launch shortcuts
Lines 738-746 Link Here
738
	 * or <code>null</code>
815
	 * or <code>null</code>
739
	 * 
816
	 * 
740
	 * @since 3.3
817
	 * @since 3.3
741
	 * 
742
	 * EXPERIMENTAL
743
	 * CONTEXTLAUNCHING
744
	 */
818
	 */
745
	public LaunchShortcutExtension getLaunchShortcut(String id) {
819
	public LaunchShortcutExtension getLaunchShortcut(String id) {
746
		loadLaunchShortcuts();
820
		loadLaunchShortcuts();
Lines 755-760 Link Here
755
	}
829
	}
756
	
830
	
757
	/**
831
	/**
832
	 * Returns the shared config from the selected resource or <code>null</code> if the selected resources is not a shared config
833
	 * @param receiver the object to test if it is a shared launch configuration
834
	 * @return the shared config from the selected resource or <code>null</code> if the selected resources is not a shared config
835
	 * @since 3.3
836
	 */
837
	public ILaunchConfiguration isSharedConfig(Object receiver) {
838
		if(receiver instanceof IFile) {
839
			IFile file = (IFile) receiver;
840
			String ext = file.getFileExtension();
841
			if(ext == null) {
842
				return null;
843
			}
844
			if(ext.equals("launch")) { //$NON-NLS-1$
845
				ILaunchConfiguration config = DebugPlugin.getDefault().getLaunchManager().getLaunchConfiguration(file);
846
				if(config != null && config.exists()) {
847
					return config;
848
				}
849
			}
850
		}
851
		else if(receiver instanceof IFileEditorInput) {
852
			IFileEditorInput input = (IFileEditorInput) receiver;
853
			return isSharedConfig(input.getFile());
854
		}
855
		return null;
856
	}
857
	
858
	/**
758
	 * Returns the image used to display an error in the given tab
859
	 * Returns the image used to display an error in the given tab
759
	 */
860
	 */
760
	public Image getErrorTabImage(ILaunchConfigurationTab tab) {
861
	public Image getErrorTabImage(ILaunchConfigurationTab tab) {
Lines 815-820 Link Here
815
	}	
916
	}	
816
	
917
	
817
	/**
918
	/**
919
	 * Returns the singleton instance of the launch manager
920
	 * @return the singleton instance of the launch manager
921
	 * @since 3.3
922
	 */
923
	private LaunchManager getLaunchManager() {
924
		return (LaunchManager) DebugPlugin.getDefault().getLaunchManager();
925
	}
926
	
927
	/**
818
	 * Restore launch history
928
	 * Restore launch history
819
	 */
929
	 */
820
	private void loadLaunchHistories() {
930
	private void loadLaunchHistories() {
Lines 835-910 Link Here
835
	}
945
	}
836
	
946
	
837
	/**
947
	/**
838
	 * This method allows a default launch shortcut to be specified for the given resource. This sets
839
	 * a default way of <i>how</i> something should be launched, not what specific <code>ILaunchConfiguration</code>
840
	 * will do the launching. Passing in <code>null</code> for a shortcut will remove the attribute.
841
	 * 
842
	 * @see {@link ILaunchManager#setDefaultConfiguration(IResource, ILaunchConfiguration)}
843
	 * @param resource the resource to map the specified launch shortcut to
844
	 * @param shortcut the shortcut to map
845
	 * 
846
	 * @since 3.3
847
	 * 
848
	 * EXPERIMENTAL
849
	 * CONTEXTLAUNCHING
850
	 */
851
	public void setDefaultLaunchShortcut(IResource resource, LaunchShortcutExtension shortcut) throws CoreException {
852
		IProject project = resource.getProject();
853
		if (project == null) {
854
			throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(),
855
					DebugPlugin.INTERNAL_ERROR, "Illegal argument: can only set default launch shortcut on and within projects.", null)); //$NON-NLS-1$ (internal error)
856
		}
857
		Preferences node = getInstanceNode(resource);
858
		if(shortcut != null) {
859
			node.put(IConfigurationElementConstants.DEFAULT_LAUNCH_SHORTCUT, shortcut.getId());
860
		}
861
		else {
862
			node.remove(IConfigurationElementConstants.DEFAULT_LAUNCH_SHORTCUT);
863
		}
864
		try {
865
			node.flush();
866
		} 
867
		catch (BackingStoreException e) {DebugUIPlugin.log(e);}
868
	}
869
	
870
	/**
871
	 * This method allows access to the default <code>LaunchShortcutExtension</code> for
872
	 * the specified <code>IResource</code>.
873
	 * 
874
	 * @see {@link ILaunchManager#getDefaultConfiguration(IResource)}
875
	 * @param resource the resource
876
	 * @return the corresponding <code>LaunchShortcutExtension</code> for the given <code>IResource</code>,
877
	 * or <code>null</code> if there is not one.
878
	 * 
879
	 * @since 3.3
880
	 * 
881
	 * EXPERIMENTAL
882
	 * CONTEXTLAUNCHING
883
	 */
884
	public LaunchShortcutExtension getDefaultLaunchShortcut(IResource resource) {
885
		IProject project = resource.getProject();
886
		if (project != null) {
887
			Preferences node = getInstanceNode(resource);
888
			String id = node.get(IConfigurationElementConstants.DEFAULT_LAUNCH_SHORTCUT, null);
889
			if(id != null) {
890
				return getLaunchShortcut(id);
891
			}
892
		}
893
		return null;
894
	}
895
	
896
	/**
897
	 * Returns the node for instance project preferences
898
	 * @param resource the resource to get the node for
899
	 * @return the instance node for debug UI
900
	 */
901
	private org.osgi.service.prefs.Preferences getInstanceNode(IResource resource) {
902
		org.osgi.service.prefs.Preferences node = Platform.getPreferencesService().getRootNode();
903
		node = node.node(InstanceScope.SCOPE).node(DebugUIPlugin.getUniqueIdentifier());
904
		return node.node(resource.getFullPath().makeRelative().toString());
905
	}
906
	
907
	/**
908
	 * Returns the default launch group for the given mode.
948
	 * Returns the default launch group for the given mode.
909
	 * 
949
	 * 
910
	 * @param mode
950
	 * @param mode
(-)ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchHistory.java (+11 lines)
Lines 73-78 Link Here
73
	}
73
	}
74
	
74
	
75
	/**
75
	/**
76
	 * Returns if either the history listing or the favorites listing contain the specified <code>ILaunchConfiguration</code>
77
	 * @param config the config to look for
78
	 * @return true if one of the listing contains the specified config, false otherwise
79
	 * @since 3.3
80
	 * CONTEXTLAUNCHING
81
	 */
82
	public boolean contains(ILaunchConfiguration config) {
83
		return fHistory.contains(config) || fFavorites.contains(config);
84
	}
85
	
86
	/**
76
	 * Adds the given configuration to this history
87
	 * Adds the given configuration to this history
77
	 * 
88
	 * 
78
	 * @param configuration
89
	 * @param configuration
(-)ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchShortcutSelectionDialog.java (-50 / +2 lines)
Lines 20-36 Link Here
20
import org.eclipse.debug.internal.ui.DebugUIPlugin;
20
import org.eclipse.debug.internal.ui.DebugUIPlugin;
21
import org.eclipse.debug.internal.ui.DefaultLabelProvider;
21
import org.eclipse.debug.internal.ui.DefaultLabelProvider;
22
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
22
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
23
import org.eclipse.debug.internal.ui.SWTUtil;
24
import org.eclipse.debug.internal.ui.contextlaunching.ContextRunner;
25
import org.eclipse.debug.ui.IDebugUIConstants;
23
import org.eclipse.debug.ui.IDebugUIConstants;
26
import org.eclipse.jface.dialogs.IDialogSettings;
24
import org.eclipse.jface.dialogs.IDialogSettings;
27
import org.eclipse.jface.viewers.ArrayContentProvider;
25
import org.eclipse.jface.viewers.ArrayContentProvider;
28
import org.eclipse.jface.viewers.ISelectionChangedListener;
26
import org.eclipse.jface.viewers.ISelectionChangedListener;
29
import org.eclipse.jface.viewers.SelectionChangedEvent;
27
import org.eclipse.jface.viewers.SelectionChangedEvent;
30
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.SWT;
31
import org.eclipse.swt.events.SelectionEvent;
32
import org.eclipse.swt.events.SelectionListener;
33
import org.eclipse.swt.widgets.Button;
34
import org.eclipse.swt.widgets.Composite;
29
import org.eclipse.swt.widgets.Composite;
35
import org.eclipse.swt.widgets.Control;
30
import org.eclipse.swt.widgets.Control;
36
import org.eclipse.ui.PlatformUI;
31
import org.eclipse.ui.PlatformUI;
Lines 57-66 Link Here
57
	 */
52
	 */
58
	private String fMode = null;
53
	private String fMode = null;
59
	private IResource fResource = null;
54
	private IResource fResource = null;
60
	private boolean fChecked = false;
61
	private boolean fProject = false;
62
	private boolean fShowProject = false;
63
	private boolean fShowResource = false;
64
	
55
	
65
	/**
56
	/**
66
	 * Constructor
57
	 * Constructor
Lines 68-80 Link Here
68
	 * @param resource
59
	 * @param resource
69
	 * @param mode
60
	 * @param mode
70
	 */
61
	 */
71
	public LaunchShortcutSelectionDialog(IResource resource, String mode, boolean showresource, boolean showproject) {
62
	public LaunchShortcutSelectionDialog(IResource resource, String mode) {
72
		super(DebugUIPlugin.getShell());
63
		super(DebugUIPlugin.getShell());
73
		setShellStyle(getShellStyle() | SWT.RESIZE);
64
		setShellStyle(getShellStyle() | SWT.RESIZE);
74
		fResource = resource;
65
		fResource = resource;
75
		fMode = mode;
66
		fMode = mode;
76
		fShowProject = showproject;
77
		fShowResource = showresource;
78
		ILaunchMode lmode = DebugPlugin.getDefault().getLaunchManager().getLaunchMode(fMode);
67
		ILaunchMode lmode = DebugPlugin.getDefault().getLaunchManager().getLaunchMode(fMode);
79
		String modename = fMode;
68
		String modename = fMode;
80
		if (lmode != null) {
69
		if (lmode != null) {
Lines 127-173 Link Here
127
	protected Control createDialogArea(Composite container) {
116
	protected Control createDialogArea(Composite container) {
128
		Composite comp = (Composite) super.createDialogArea(container);
117
		Composite comp = (Composite) super.createDialogArea(container);
129
		try {
118
		try {
130
			List input = new ArrayList(ContextRunner.getDefault().getLaunchShortcuts(fResource));
119
			List input = new ArrayList(DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchShortcuts(fResource));
131
			Button butt = null;
132
			if(!input.isEmpty()) {
133
				if(fShowResource) {
134
					butt = SWTUtil.createCheckButton(comp, MessageFormat.format(LaunchConfigurationsMessages.LaunchShortcutSelectionDialog_2, new String[] {fResource.getName()}), null, fChecked);
135
					butt.addSelectionListener(new SelectionListener() {
136
						public void widgetDefaultSelected(SelectionEvent e) {}
137
						public void widgetSelected(SelectionEvent e) {
138
							fChecked = ((Button)e.getSource()).getSelection();
139
						}
140
					});
141
				}
142
				if(fShowProject) {
143
					butt = SWTUtil.createCheckButton(comp, MessageFormat.format(LaunchConfigurationsMessages.LaunchShortcutSelectionDialog_3, new String[] {fResource.getProject().getName()}), null, false);
144
					butt.addSelectionListener(new SelectionListener() {
145
						public void widgetDefaultSelected(SelectionEvent e) {}
146
						public void widgetSelected(SelectionEvent e) {
147
							fProject = ((Button)e.getSource()).getSelection();
148
						}
149
					});
150
				}
151
			}
152
			getTableViewer().setInput(input);
120
			getTableViewer().setInput(input);
153
		}
121
		}
154
		catch(CoreException ce) {DebugUIPlugin.log(ce);}
122
		catch(CoreException ce) {DebugUIPlugin.log(ce);}
155
		return comp;
123
		return comp;
156
	}
124
	}
157
 
158
	/**
159
	 * Returns if the launched config from the selected shortcut should be made the default for the underlying resource
160
	 * @return if the launched config should be made the default
161
	 */
162
	public boolean makeDefault() {
163
		return fChecked;
164
	}
165
	
166
	/**
167
	 * Returns if the launched config from the selected shortcut should be made the default for the underlying resources' associated project
168
	 * @return if the launched config from the selected shortcut should be made the default for the underlying resources' associated project
169
	 */
170
	public boolean makeProjectDefault() {
171
		return fProject;
172
	}
173
}
125
}
(-)ui/org/eclipse/debug/ui/actions/ContextualLaunchAction.java (-39 / +44 lines)
Lines 20-34 Link Here
20
import org.eclipse.core.expressions.EvaluationContext;
20
import org.eclipse.core.expressions.EvaluationContext;
21
import org.eclipse.core.expressions.Expression;
21
import org.eclipse.core.expressions.Expression;
22
import org.eclipse.core.expressions.IEvaluationContext;
22
import org.eclipse.core.expressions.IEvaluationContext;
23
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.resources.IResource;
24
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.IAdaptable;
25
import org.eclipse.debug.core.DebugPlugin;
26
import org.eclipse.debug.core.DebugPlugin;
26
import org.eclipse.debug.core.ILaunchConfiguration;
27
import org.eclipse.debug.core.ILaunchConfiguration;
27
import org.eclipse.debug.core.ILaunchManager;
28
import org.eclipse.debug.core.ILaunchManager;
28
import org.eclipse.debug.internal.ui.DebugUIPlugin;
29
import org.eclipse.debug.internal.ui.DebugUIPlugin;
30
import org.eclipse.debug.internal.ui.actions.ActionMessages;
31
import org.eclipse.debug.internal.ui.actions.LaunchConfigurationAction;
29
import org.eclipse.debug.internal.ui.actions.LaunchShortcutAction;
32
import org.eclipse.debug.internal.ui.actions.LaunchShortcutAction;
30
import org.eclipse.debug.internal.ui.actions.SharedLaunchConfigAction;
31
import org.eclipse.debug.internal.ui.contextlaunching.ContextRunner;
32
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
33
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
33
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension;
34
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension;
34
import org.eclipse.debug.ui.DebugUITools;
35
import org.eclipse.debug.ui.DebugUITools;
Lines 44-55 Link Here
44
import org.eclipse.swt.widgets.Control;
45
import org.eclipse.swt.widgets.Control;
45
import org.eclipse.swt.widgets.Menu;
46
import org.eclipse.swt.widgets.Menu;
46
import org.eclipse.swt.widgets.MenuItem;
47
import org.eclipse.swt.widgets.MenuItem;
47
import org.eclipse.ui.IFileEditorInput;
48
import org.eclipse.ui.IObjectActionDelegate;
48
import org.eclipse.ui.IObjectActionDelegate;
49
import org.eclipse.ui.IWorkbenchPart;
49
import org.eclipse.ui.IWorkbenchPart;
50
import org.eclipse.ui.PlatformUI;
50
import org.eclipse.ui.PlatformUI;
51
import org.eclipse.ui.activities.WorkbenchActivityHelper;
51
import org.eclipse.ui.activities.WorkbenchActivityHelper;
52
52
53
import com.ibm.icu.text.MessageFormat;
54
53
/**
55
/**
54
 * An action delegate that builds a context menu with applicable launch shortcuts
56
 * An action delegate that builds a context menu with applicable launch shortcuts
55
 * for a specific launch mode.
57
 * for a specific launch mode.
Lines 130-141 Link Here
130
		menu.addMenuListener(new MenuAdapter() {
132
		menu.addMenuListener(new MenuAdapter() {
131
			public void menuShown(MenuEvent e) {
133
			public void menuShown(MenuEvent e) {
132
				if (fFillMenu) {
134
				if (fFillMenu) {
133
					Menu m = (Menu)e.widget;
135
					try {
134
					MenuItem[] items = m.getItems();
136
						Menu m = (Menu)e.widget;
135
					for (int i=0; i < items.length; i++) {
137
						MenuItem[] items = m.getItems();
136
						items[i].dispose();
138
						for (int i=0; i < items.length; i++) {
139
							items[i].dispose();
140
						}
141
						fillMenu(m);
137
					}
142
					}
138
					fillMenu(m);
143
					catch(CoreException ce) {}
139
					fFillMenu = false;
144
					fFillMenu = false;
140
				}
145
				}
141
			}
146
			}
Lines 179-224 Link Here
179
	}
184
	}
180
	
185
	
181
	/**
186
	/**
182
	 * Prepares a SharedLaunchConfigAction and adds it to the current menu
187
	 * Returns the resource this menu is open on.
183
	 * @param file the file to get the launch configuration from
188
	 * 
184
	 * @param image the image for the action
189
	 * @return resource
185
	 * @param menu the menu to add the new action to.
186
	 * @since 3.3
187
	 */
190
	 */
188
	private void prepareSharedConfigAction(IFile file, Menu menu) {
191
	protected IResource getResource(Object element) {
189
		ILaunchConfiguration config = getLaunchManager().getLaunchConfiguration(file);
192
		IResource resource = null;
190
		try {
193
		if (element instanceof IResource) {
191
            if(config != null && config.exists() && config.supportsMode(fMode)) {
194
			resource = (IResource) element;
192
            	IAction action = new SharedLaunchConfigAction(config, fMode, DebugUITools.getDefaultImageDescriptor(config));
195
		} else if (element instanceof IAdaptable) {
193
                ActionContributionItem item= new ActionContributionItem(action);
196
			resource = (IResource) ((IAdaptable)element).getAdapter(IResource.class);
194
                item.fill(menu, -1);
197
		}
195
            }
198
		return resource;
196
        } catch (CoreException e) {
197
        }
198
	}
199
	}
199
	
200
	
200
    /**
201
    /**
201
     * Fills the menu with applicable launch shortcuts
202
     * Fills the menu with applicable launch shortcuts
202
     * @param menu The menu to fill
203
     * @param menu The menu to fill
203
     */
204
     */
204
	protected void fillMenu(Menu menu) {
205
	protected void fillMenu(Menu menu) throws CoreException {
205
		if (fSelection == null) {
206
		if (fSelection == null) {
206
			return;
207
			return;
207
		}
208
		}
208
		IEvaluationContext context = createContext();
209
		IEvaluationContext context = createContext();
209
		//add in any selected shared configs before the rest of the items to launch as
210
		//feature fix for 
211
		//CONTEXTLAUNCHING
210
		//CONTEXTLAUNCHING
212
		if(!fSelection.isEmpty()) {
211
		Object obj = fSelection.getFirstElement();
213
			Object obj = fSelection.getFirstElement();
212
		int accelerator = 1;
214
			if(ContextRunner.getDefault().isSharedConfig(obj) != null) {
213
		ILaunchConfiguration config = getLaunchManager().getDefaultConfiguration(getResource(obj));
215
				prepareSharedConfigAction((IFile)obj, menu);
214
		if(config != null && config.exists() && config.supportsMode(fMode)) {
216
				new MenuItem(menu, SWT.SEPARATOR);
215
        	IAction action = new LaunchConfigurationAction(config, fMode, MessageFormat.format(ActionMessages.ContextualLaunchAction_0, new String[] {config.getName()}), DebugUITools.getDefaultImageDescriptor(config), accelerator++);
217
			} 
216
            ActionContributionItem item = new ActionContributionItem(action);
218
			else if(ContextRunner.getDefault().isSharedConfigEditorInput(obj) != null) {
217
            item.fill(menu, -1);
219
				prepareSharedConfigAction(((IFileEditorInput) obj).getFile(), menu);
218
            new MenuItem(menu, SWT.SEPARATOR);
220
				new MenuItem(menu, SWT.SEPARATOR);
219
		}
221
			}
220
		config = getLaunchConfigurationManager().isSharedConfig(obj);
221
        if(config != null && config.exists() && config.supportsMode(fMode)) {
222
        	IAction action = new LaunchConfigurationAction(config, fMode, config.getName(), DebugUITools.getDefaultImageDescriptor(config), accelerator++);
223
            ActionContributionItem item = new ActionContributionItem(action);
224
            item.fill(menu, -1);
225
            new MenuItem(menu, SWT.SEPARATOR);
222
		}
226
		}
223
		List allShortCuts = getLaunchConfigurationManager().getLaunchShortcuts();
227
		List allShortCuts = getLaunchConfigurationManager().getLaunchShortcuts();
224
		Iterator iter = allShortCuts.iterator();
228
		Iterator iter = allShortCuts.iterator();
Lines 233-239 Link Here
233
			catch (CoreException e) {DebugUIPlugin.log(e);}
237
			catch (CoreException e) {DebugUIPlugin.log(e);}
234
		}
238
		}
235
		iter = filteredShortCuts.iterator();
239
		iter = filteredShortCuts.iterator();
236
		int accelerator = 1;
240
		
237
		List categories = new ArrayList();
241
		List categories = new ArrayList();
238
		while (iter.hasNext()) {
242
		while (iter.hasNext()) {
239
			LaunchShortcutExtension ext = (LaunchShortcutExtension) iter.next();
243
			LaunchShortcutExtension ext = (LaunchShortcutExtension) iter.next();
Lines 299-305 Link Here
299
		ArrayList result = new ArrayList();
303
		ArrayList result = new ArrayList();
300
		Iterator iter = fSelection.iterator();
304
		Iterator iter = fSelection.iterator();
301
		while (iter.hasNext()) {
305
		while (iter.hasNext()) {
302
			result.add(iter.next());
306
			Object next = iter.next();
307
			result.add(next);
303
		}
308
		}
304
		return result;
309
		return result;
305
	}
310
	}
(-)ui/org/eclipse/debug/ui/actions/AbstractLaunchHistoryAction.java (-3 / +3 lines)
Lines 186-193 Link Here
186
		String launchName= configuration.getName();
186
		String launchName= configuration.getName();
187
		String label = null;
187
		String label = null;
188
		//CONTEXTLAUNCHING
188
		//CONTEXTLAUNCHING
189
		if(ContextRunner.isContextLaunchEnabled() && !getLaunchGroupIdentifier().equals("org.eclipse.ui.externaltools.launchGroup")) { //$NON-NLS-1$
189
		if(ContextRunner.getDefault().isContextLaunchEnabled() && !getLaunchGroupIdentifier().equals("org.eclipse.ui.externaltools.launchGroup")) { //$NON-NLS-1$
190
			launchName = ContextRunner.getDefault().getContextName();
190
			launchName = ContextRunner.getDefault().getContextName(getMode());
191
		}
191
		}
192
		String mode = getMode();
192
		String mode = getMode();
193
		if (mode.equals(ILaunchManager.RUN_MODE)) {
193
		if (mode.equals(ILaunchManager.RUN_MODE)) {
Lines 342-348 Link Here
342
		if (fAction == null) {
342
		if (fAction == null) {
343
			initialize(action);
343
			initialize(action);
344
		} 
344
		} 
345
		if(ContextRunner.isContextLaunchEnabled()) {
345
		if(ContextRunner.getDefault().isContextLaunchEnabled()) {
346
			updateTooltip();
346
			updateTooltip();
347
		}
347
		}
348
	}
348
	}
(-)ui/org/eclipse/debug/ui/actions/OpenLaunchDialogAction.java (-15 / +9 lines)
Lines 18-30 Link Here
18
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
18
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
19
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
19
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
20
import org.eclipse.debug.internal.ui.contextlaunching.ContextMessages;
20
import org.eclipse.debug.internal.ui.contextlaunching.ContextMessages;
21
import org.eclipse.debug.internal.ui.contextlaunching.ContextRunner;
22
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension;
21
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension;
23
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchHistory;
22
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchHistory;
24
import org.eclipse.debug.ui.DebugUITools;
23
import org.eclipse.debug.ui.DebugUITools;
25
import org.eclipse.jface.action.Action;
24
import org.eclipse.jface.action.Action;
26
import org.eclipse.jface.action.IAction;
25
import org.eclipse.jface.action.IAction;
27
import org.eclipse.jface.util.IPropertyChangeListener;
28
import org.eclipse.jface.util.PropertyChangeEvent;
26
import org.eclipse.jface.util.PropertyChangeEvent;
29
import org.eclipse.jface.viewers.ISelection;
27
import org.eclipse.jface.viewers.ISelection;
30
import org.eclipse.jface.viewers.IStructuredSelection;
28
import org.eclipse.jface.viewers.IStructuredSelection;
Lines 46-52 Link Here
46
 * </p>
44
 * </p>
47
 * @since 2.1
45
 * @since 2.1
48
 */
46
 */
49
public class OpenLaunchDialogAction extends Action implements IPropertyChangeListener, IActionDelegate2, IWorkbenchWindowActionDelegate {
47
public class OpenLaunchDialogAction extends Action implements IActionDelegate2, IWorkbenchWindowActionDelegate {
50
48
51
	/**
49
	/**
52
	 * Launch group identifier
50
	 * Launch group identifier
Lines 102-117 Link Here
102
	/**
100
	/**
103
	 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
101
	 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
104
	 */
102
	 */
105
	public void dispose() {
103
	public void dispose() {}
106
		DebugUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this);
107
	}
108
104
109
	/* (non-Javadoc)
105
	/* (non-Javadoc)
110
	 * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
106
	 * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
111
	 */
107
	 */
112
	public void init(IAction action) {
108
	public void init(IAction action) {
113
		fBackingAction = action;
109
		fBackingAction = action;
114
		DebugUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this);
115
		PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.OPEN_LAUNCH_CONFIGURATION_ACTION);
110
		PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.OPEN_LAUNCH_CONFIGURATION_ACTION);
116
		updateActionState();
111
		updateActionState();
117
	}
112
	}
Lines 125-140 Link Here
125
		LaunchGroupExtension extension = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(fIdentifier);
120
		LaunchGroupExtension extension = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(fIdentifier);
126
		if(fBackingAction == null) {
121
		if(fBackingAction == null) {
127
			//there is no backing action, like a toolbar action delegate
122
			//there is no backing action, like a toolbar action delegate
128
			if(ContextRunner.isContextLaunchEnabled() && !"org.eclipse.ui.externaltools.launchGroup".equals(fIdentifier)) { //$NON-NLS-1$
123
			setText(MessageFormat.format(ContextMessages.OpenLaunchDialogAction_0, new String[] {extension.getLabel()}));
129
				setText(MessageFormat.format(ContextMessages.OpenLaunchDialogAction_0, new String[] {extension.getLabel()}));
124
			setImageDescriptor(extension.getImageDescriptor());
130
				setImageDescriptor(null);
131
			}
132
			else {
133
				setText(extension.getLabel() + "..."); //$NON-NLS-1$
134
				setImageDescriptor(extension.getImageDescriptor());
135
			}
136
			setEnabled(existsConfigTypesForMode());
125
			setEnabled(existsConfigTypesForMode());
137
		}
126
		}
127
		else {
128
			fBackingAction.setText(MessageFormat.format(ContextMessages.OpenLaunchDialogAction_1, new String[] {DebugUIPlugin.removeAccelerators(extension.getLabel())}));
129
			fBackingAction.setImageDescriptor(extension.getImageDescriptor());
130
			fBackingAction.setEnabled(existsConfigTypesForMode());
131
		}
138
	}
132
	}
139
	
133
	
140
	/**
134
	/**
(-)ui/org/eclipse/debug/ui/actions/LaunchShortcutsAction.java (-4 / +44 lines)
Lines 20-34 Link Here
20
import org.eclipse.core.expressions.EvaluationContext;
20
import org.eclipse.core.expressions.EvaluationContext;
21
import org.eclipse.core.expressions.Expression;
21
import org.eclipse.core.expressions.Expression;
22
import org.eclipse.core.expressions.IEvaluationContext;
22
import org.eclipse.core.expressions.IEvaluationContext;
23
import org.eclipse.core.resources.IResource;
23
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.IAdaptable;
24
import org.eclipse.debug.core.DebugPlugin;
26
import org.eclipse.debug.core.DebugPlugin;
27
import org.eclipse.debug.core.ILaunchConfiguration;
25
import org.eclipse.debug.core.ILaunchConfigurationType;
28
import org.eclipse.debug.core.ILaunchConfigurationType;
26
import org.eclipse.debug.core.ILaunchMode;
29
import org.eclipse.debug.core.ILaunchMode;
27
import org.eclipse.debug.internal.ui.DebugUIPlugin;
30
import org.eclipse.debug.internal.ui.DebugUIPlugin;
28
import org.eclipse.debug.internal.ui.actions.ActionMessages;
31
import org.eclipse.debug.internal.ui.actions.ActionMessages;
32
import org.eclipse.debug.internal.ui.actions.LaunchConfigurationAction;
29
import org.eclipse.debug.internal.ui.actions.LaunchShortcutAction;
33
import org.eclipse.debug.internal.ui.actions.LaunchShortcutAction;
34
import org.eclipse.debug.internal.ui.contextlaunching.ContextRunner;
30
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
35
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
31
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension;
36
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension;
37
import org.eclipse.debug.ui.DebugUITools;
32
import org.eclipse.debug.ui.ILaunchGroup;
38
import org.eclipse.debug.ui.ILaunchGroup;
33
import org.eclipse.jface.action.Action;
39
import org.eclipse.jface.action.Action;
34
import org.eclipse.jface.action.ActionContributionItem;
40
import org.eclipse.jface.action.ActionContributionItem;
Lines 37-42 Link Here
37
import org.eclipse.jface.viewers.ISelection;
43
import org.eclipse.jface.viewers.ISelection;
38
import org.eclipse.jface.viewers.ISelectionProvider;
44
import org.eclipse.jface.viewers.ISelectionProvider;
39
import org.eclipse.jface.viewers.IStructuredSelection;
45
import org.eclipse.jface.viewers.IStructuredSelection;
46
import org.eclipse.swt.SWT;
40
import org.eclipse.swt.events.MenuAdapter;
47
import org.eclipse.swt.events.MenuAdapter;
41
import org.eclipse.swt.events.MenuEvent;
48
import org.eclipse.swt.events.MenuEvent;
42
import org.eclipse.swt.widgets.Control;
49
import org.eclipse.swt.widgets.Control;
Lines 51-56 Link Here
51
import org.eclipse.ui.PlatformUI;
58
import org.eclipse.ui.PlatformUI;
52
import org.eclipse.ui.activities.WorkbenchActivityHelper;
59
import org.eclipse.ui.activities.WorkbenchActivityHelper;
53
60
61
import com.ibm.icu.text.MessageFormat;
62
54
/**
63
/**
55
 * A cascading sub-menu that shows all launch shortcuts pertinent to a
64
 * A cascading sub-menu that shows all launch shortcuts pertinent to a
56
 * selection. This action is similar to <code>ContextualLaunchAction</code>
65
 * selection. This action is similar to <code>ContextualLaunchAction</code>
Lines 168-181 Link Here
168
	}	
177
	}	
169
	
178
	
170
	/**
179
	/**
180
	 * Returns the resource this menu is open on.
181
	 * 
182
	 * @return resource
183
	 */
184
	protected IResource getResource(Object element) {
185
		IResource resource = null;
186
		if (element instanceof IResource) {
187
			resource = (IResource) element;
188
		} else if (element instanceof IAdaptable) {
189
			resource = (IResource) ((IAdaptable)element).getAdapter(IResource.class);
190
		}
191
		return resource;
192
	}
193
	
194
	/**
171
	 * Fills the flyout menu 
195
	 * Fills the flyout menu 
172
	 */
196
	 */
173
	private void fillMenu() {
197
	private void fillMenu() {
198
		try {
199
			Object selection = ContextRunner.getDefault().getCurrentContext();
200
			int accelerator = 1;
201
			ILaunchConfiguration config = DebugPlugin.getDefault().getLaunchManager().getDefaultConfiguration(getResource(selection));
202
			if(config != null && config.exists() && config.supportsMode(getMode())) {
203
	        	IAction action = new LaunchConfigurationAction(config, getMode(), MessageFormat.format(ActionMessages.ContextualLaunchAction_0, new String[] {config.getName()}), DebugUITools.getDefaultImageDescriptor(config), accelerator++);
204
	            ActionContributionItem item = new ActionContributionItem(action);
205
	            item.fill(fCreatedMenu, -1);
206
	            new MenuItem(fCreatedMenu, SWT.SEPARATOR);
207
			}
208
			config = getLaunchConfigurationManager().isSharedConfig(selection);
209
	        if(config != null && config.exists() && config.supportsMode(getMode())) {
210
	        	IAction action = new LaunchConfigurationAction(config, getMode(), config.getName(), DebugUITools.getDefaultImageDescriptor(config), accelerator++);
211
	            ActionContributionItem item = new ActionContributionItem(action);
212
	            item.fill(fCreatedMenu, -1);
213
	            new MenuItem(fCreatedMenu, SWT.SEPARATOR);
214
			}
215
		}
216
		catch(CoreException ce) {DebugUIPlugin.log(ce);}
174
		IEvaluationContext context = createContext();
217
		IEvaluationContext context = createContext();
175
		// gather all shortcuts and run their filters so that we only run the
218
		List allShortCuts = getLaunchConfigurationManager().getLaunchShortcuts(fGroup.getCategory());
176
		// filters one time for each shortcut. Running filters can be expensive.
177
		// Also, only *LOADED* plug-ins get their filters run.
178
		List /* <LaunchShortcutExtension> */ allShortCuts = getLaunchConfigurationManager().getLaunchShortcuts(fGroup.getCategory());
179
		Iterator iter = allShortCuts.iterator();
219
		Iterator iter = allShortCuts.iterator();
180
		List filteredShortCuts = new ArrayList(10);
220
		List filteredShortCuts = new ArrayList(10);
181
		while (iter.hasNext()) {
221
		while (iter.hasNext()) {
(-)ui/org/eclipse/debug/ui/actions/AbstractLaunchToolbarAction.java (-13 / +2 lines)
Lines 13-19 Link Here
13
13
14
import org.eclipse.debug.core.ILaunchConfiguration;
14
import org.eclipse.debug.core.ILaunchConfiguration;
15
import org.eclipse.debug.internal.ui.DebugUIPlugin;
15
import org.eclipse.debug.internal.ui.DebugUIPlugin;
16
import org.eclipse.debug.internal.ui.contextlaunching.ContextLaunchingToolbarAction;
17
import org.eclipse.debug.internal.ui.contextlaunching.ContextRunner;
16
import org.eclipse.debug.internal.ui.contextlaunching.ContextRunner;
18
import org.eclipse.debug.internal.ui.launchConfigurations.OrganizeFavoritesAction;
17
import org.eclipse.debug.internal.ui.launchConfigurations.OrganizeFavoritesAction;
19
import org.eclipse.debug.ui.DebugUITools;
18
import org.eclipse.debug.ui.DebugUITools;
Lines 51-70 Link Here
51
	 */
50
	 */
52
	protected void fillMenu(Menu menu) {
51
	protected void fillMenu(Menu menu) {
53
		super.fillMenu(menu);
52
		super.fillMenu(menu);
54
55
		// Separator between history and common actions
53
		// Separator between history and common actions
56
		if (menu.getItemCount() > 0) {
54
		if (menu.getItemCount() > 0) {
57
			addSeparator(menu);
55
			addSeparator(menu);
58
		}
56
		}
59
		//CONTEXTLAUNCHING
57
		addToMenu(menu, new LaunchShortcutsAction(getLaunchGroupIdentifier()), -1);
60
		if(!getLaunchGroupIdentifier().equals("org.eclipse.ui.externaltools.launchGroup")) { //$NON-NLS-1$
61
			if(ContextRunner.isContextLaunchEnabled()) {
62
				addToMenu(menu, new ContextLaunchingToolbarAction(getLaunchGroupIdentifier()), -1);
63
			}
64
			else {
65
				addToMenu(menu, new LaunchShortcutsAction(getLaunchGroupIdentifier()), -1);
66
			}
67
		}
68
		addToMenu(menu, getOpenDialogAction(), -1);
58
		addToMenu(menu, getOpenDialogAction(), -1);
69
		addToMenu(menu, new OrganizeFavoritesAction(getLaunchGroupIdentifier()), -1);
59
		addToMenu(menu, new OrganizeFavoritesAction(getLaunchGroupIdentifier()), -1);
70
	}
60
	}
Lines 83-90 Link Here
83
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
73
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
84
	 */
74
	 */
85
	public void run(IAction action) {
75
	public void run(IAction action) {
86
	//CONTEXTLAUNCHING
76
		if(ContextRunner.getDefault().isContextLaunchEnabled()) {
87
		if(ContextRunner.isContextLaunchEnabled() && !getLaunchGroupIdentifier().equals("org.eclipse.ui.externaltools.launchGroup")) { //$NON-NLS-1$
88
			ContextRunner.getDefault().launch(getMode());
77
			ContextRunner.getDefault().launch(getMode());
89
		}
78
		}
90
		else {
79
		else {
(-)ui/org/eclipse/debug/internal/ui/DebugUIPreferenceInitializer.java (-2 / +1 lines)
Lines 51-58 Link Here
51
		
51
		
52
	//contextual launching preference page
52
	//contextual launching preference page
53
		prefs.setDefault(IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH, false);
53
		prefs.setDefault(IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH, false);
54
		prefs.setDefault(IInternalDebugUIConstants.PREF_ALWAYS_RUN_LAST_LAUNCH, MessageDialogWithToggle.PROMPT);
54
		prefs.setDefault(IInternalDebugUIConstants.PREF_LAUNCH_PARENT_PROJECT, false);
55
		prefs.setDefault(IInternalDebugUIConstants.PREF_ALWAYS_RUN_PROJECT_CONFIGURATION, MessageDialogWithToggle.PROMPT);
56
		
55
		
57
		//View Management preference page
56
		//View Management preference page
58
		prefs.setDefault(IDebugUIConstants.PREF_MANAGE_VIEW_PERSPECTIVES, IDebugUIConstants.ID_DEBUG_PERSPECTIVE);
57
		prefs.setDefault(IDebugUIConstants.PREF_MANAGE_VIEW_PERSPECTIVES, IDebugUIConstants.ID_DEBUG_PERSPECTIVE);
(-)ui/org/eclipse/debug/internal/ui/IInternalDebugUIConstants.java (-14 / +5 lines)
Lines 208-232 Link Here
208
     * @since 3.3
208
     * @since 3.3
209
     * CONTEXTLAUNCHING
209
     * CONTEXTLAUNCHING
210
     */ 
210
     */ 
211
    public static final String PREF_USE_CONTEXTUAL_LAUNCH= IDebugUIConstants.PLUGIN_ID + ".UseContextualLaunch"; //$NON-NLS-1$
211
    public static final String PREF_USE_CONTEXTUAL_LAUNCH = IDebugUIConstants.PLUGIN_ID + ".UseContextualLaunch"; //$NON-NLS-1$
212
    
212
    
213
    /**
213
    /**
214
     * always/never/prompt preference indicating the action for the event when there is no context to launch during context launching 
214
     * Boolean preference indicating if we should always consider the parent project when
215
     * a selected context is not runnable
215
     * 
216
     * 
216
     * @since 3.3
217
     *  @since 3.3
217
     *  
218
     *  CONTEXTLAUNCHING
218
     *  CONTEXTLAUNCHING
219
     */
219
     */
220
    public static final String PREF_ALWAYS_RUN_LAST_LAUNCH = IDebugUIConstants.PLUGIN_ID + ".AlwaysRunLastLaunch"; //$NON-NLS-1$
220
    public static final String PREF_LAUNCH_PARENT_PROJECT = IDebugUIConstants.PLUGIN_ID + ".LaunchParentProject"; //$NON-NLS-1$
221
    
222
    /**
223
     * always/never/prompt preference indicating the action to take when an un-runnable file is the context
224
     * 
225
     * @since 3.3
226
     * 
227
     * CONTEXTLAUNCHING
228
     */
229
    public static final String PREF_ALWAYS_RUN_PROJECT_CONFIGURATION = IDebugUIConstants.PLUGIN_ID + ".ALwaysRunProjectConfiguration"; //$NON-NLS-1$
230
    
221
    
231
    /**
222
    /**
232
     * String preference controlling whether editors are saved before launching.
223
     * String preference controlling whether editors are saved before launching.
(-)plugin.xml (-93 / +3 lines)
Lines 883-894 Link Here
883
               id="org.eclipse.debug.ui.contextualLaunch.profile.submenu">
883
               id="org.eclipse.debug.ui.contextualLaunch.profile.submenu">
884
        </action>    
884
        </action>    
885
        <enablement>
885
        <enablement>
886
          <and>
886
          <test property="org.eclipse.debug.ui.launchable" value="profile"/>
887
          	<test property="org.eclipse.debug.ui.launchable" value="profile"/>
888
          	<not>
889
          		<test property="org.eclipse.debug.ui.contextlaunch" />
890
          	</not>
891
          </and>
892
        </enablement>        
887
        </enablement>        
893
      </objectContribution>
888
      </objectContribution>
894
      <objectContribution
889
      <objectContribution
Lines 903-914 Link Here
903
               id="org.eclipse.debug.ui.contextualLaunch.debug.submenu">
898
               id="org.eclipse.debug.ui.contextualLaunch.debug.submenu">
904
         </action>
899
         </action>
905
         <enablement>
900
         <enablement>
906
          <and>
901
         	<test property="org.eclipse.debug.ui.launchable" value="debug"/>
907
          	<test property="org.eclipse.debug.ui.launchable" value="debug"/>
908
          	<not>
909
          		<test property="org.eclipse.debug.ui.contextlaunch" />
910
          	</not>
911
          </and>
912
         </enablement>     
902
         </enablement>     
913
       </objectContribution>    
903
       </objectContribution>    
914
       <objectContribution
904
       <objectContribution
Lines 923-1005 Link Here
923
               id="org.eclipse.debug.ui.contextualLaunch.run.submenu">
913
               id="org.eclipse.debug.ui.contextualLaunch.run.submenu">
924
         </action>                  
914
         </action>                  
925
         <enablement>
915
         <enablement>
926
          <and>
927
          	<test property="org.eclipse.debug.ui.launchable" value="run"/>
916
          	<test property="org.eclipse.debug.ui.launchable" value="run"/>
928
          	<not>
929
          		<test property="org.eclipse.debug.ui.contextlaunch" />
930
          	</not>
931
          </and>
932
         </enablement>
917
         </enablement>
933
      </objectContribution>
918
      </objectContribution>
934
       <objectContribution
935
             id="org.eclipse.debug.ui.contextlaunch.debugas"
936
             objectClass="org.eclipse.core.runtime.IAdaptable">
937
          <action
938
                class="org.eclipse.debug.internal.ui.contextlaunching.DebugContextLaunchingAction"
939
                enablesFor="1"
940
                icon="icons/full/etool16/debug_exc.gif"
941
                id="org.eclipse.debug.ui.contextlaunch.debugas"
942
                label="%ContextLaunchingDebugMenu.name"
943
                menubarPath="additions"
944
                tooltip="%ContextLaunchingDebugMenu.tooltip">
945
          </action>
946
          <enablement>
947
          <and>
948
            <test
949
                  property="org.eclipse.debug.ui.resource"
950
                  />
951
          	<test
952
                 property="org.eclipse.debug.ui.contextlaunch"
953
                 />
954
          	<test property="org.eclipse.debug.ui.launchable" value="debug"/>
955
          </and>
956
         </enablement>
957
       </objectContribution>
958
       <objectContribution
959
             id="org.eclipse.debug.ui.contextlaunch.profileas"
960
             objectClass="org.eclipse.core.runtime.IAdaptable">
961
          <action
962
                class="org.eclipse.debug.internal.ui.contextlaunching.ProfileContextLaunchingAction"
963
                enablesFor="1"
964
                icon="icons/full/etool16/profile_exc.gif"
965
                id="org.eclipse.debug.ui.contextlaunch.profileas"
966
                label="%ContextLaunchingProfileMenu.name"
967
                menubarPath="additions"
968
                tooltip="%ContextLaunchingProfileMenu.tooltip">
969
          </action>
970
          <enablement>
971
          <and>
972
            <test
973
                  property="org.eclipse.debug.ui.resource"
974
                  />
975
          	<test property="org.eclipse.debug.ui.contextlaunch" />
976
          	<test property="org.eclipse.debug.ui.launchable" value="profile"/>
977
          </and>
978
         </enablement> 
979
       </objectContribution>
980
   <!-- console additions -->
919
   <!-- console additions -->
981
      <objectContribution
982
            id="org.eclipse.debug.ui.contextlaunch.runas"
983
            objectClass="org.eclipse.core.runtime.IAdaptable">
984
         <action
985
               class="org.eclipse.debug.internal.ui.contextlaunching.RunContextLaunchingAction"
986
               enablesFor="1"
987
               icon="icons/full/etool16/run_exc.gif"
988
               id="org.eclipse.debug.ui.contextlaunch.runas"
989
               label="%ContextLaunchingRunMenu.name"
990
               menubarPath="additions"
991
               tooltip="%ContextLaunchingRunMenu.tooltip">
992
         </action>
993
         <enablement>
994
          <and>
995
          	<test property="org.eclipse.debug.ui.contextlaunch" />
996
          	<test
997
                 property="org.eclipse.debug.ui.resource"
998
                 />
999
          	<test property="org.eclipse.debug.ui.launchable" value="run"/>
1000
          </and>
1001
         </enablement> 
1002
      </objectContribution>
1003
      <viewerContribution
920
      <viewerContribution
1004
             targetID="org.eclipse.debug.ui.ProcessConsoleType.#ContextMenu"
921
             targetID="org.eclipse.debug.ui.ProcessConsoleType.#ContextMenu"
1005
             id="org.eclipse.debug.ui.processConsoleContextMenu">
922
             id="org.eclipse.debug.ui.processConsoleContextMenu">
Lines 1499-1511 Link Here
1499
               <test
1416
               <test
1500
                     property="org.eclipse.debug.ui.contextlaunch"
1417
                     property="org.eclipse.debug.ui.contextlaunch"
1501
                     />
1418
                     />
1502
               <test
1503
                     property="org.eclipse.debug.ui.contextlaunchable"
1504
                     >
1505
               </test>
1506
               <test
1507
                     property="org.eclipse.debug.ui.resource">
1508
               </test>
1509
            </and>
1419
            </and>
1510
         </enabledWhen>
1420
         </enabledWhen>
1511
      </page>
1421
      </page>
Lines 2147-2153 Link Here
2147
      </propertyTester>
2057
      </propertyTester>
2148
	  <propertyTester
2058
	  <propertyTester
2149
			namespace="org.eclipse.debug.ui"
2059
			namespace="org.eclipse.debug.ui"
2150
			properties="launchable, resource, contextlaunch, contextlaunchable"
2060
			properties="launchable, contextlaunch"
2151
			type="java.lang.Object"
2061
			type="java.lang.Object"
2152
			class="org.eclipse.debug.internal.ui.actions.LaunchablePropertyTester"
2062
			class="org.eclipse.debug.internal.ui.actions.LaunchablePropertyTester"
2153
			id="org.eclipse.debug.ui.propertyTesters.launchable">		
2063
			id="org.eclipse.debug.ui.propertyTesters.launchable">		
(-)ui/org/eclipse/debug/internal/ui/views/variables/details/DetailPaneManager.java (-1 / +1 lines)
Lines 195-201 Link Here
195
		 * @return an evaluatable expression or <code>null</code>
195
		 * @return an evaluatable expression or <code>null</code>
196
		 */
196
		 */
197
		private Expression getEnablementExpression(){
197
		private Expression getEnablementExpression(){
198
			// all of this stuff is optional, so...tedius testing is required
198
			// all of this stuff is optional, so...tedious testing is required
199
			if (fEnablementExpression == null) {
199
			if (fEnablementExpression == null) {
200
				try{
200
				try{
201
					IConfigurationElement[] elements = fConfigElement.getChildren(ExpressionTagNames.ENABLEMENT);
201
					IConfigurationElement[] elements = fConfigElement.getChildren(ExpressionTagNames.ENABLEMENT);
(-)ui/org/eclipse/debug/internal/ui/actions/LaunchConfigurationAction.java (+57 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.internal.ui.actions;
12
13
import org.eclipse.debug.core.ILaunchConfiguration;
14
import org.eclipse.debug.ui.DebugUITools;
15
import org.eclipse.jface.action.Action;
16
import org.eclipse.jface.resource.ImageDescriptor;
17
18
import com.ibm.icu.text.MessageFormat;
19
20
/**
21
 * This class provides an action wrapper for adding launch configuration actions to the context menu
22
 * of the Run->... menu item
23
 * 
24
 * @since 3.3
25
 */
26
public class LaunchConfigurationAction extends Action {
27
28
	private ILaunchConfiguration fConfig;
29
	private String fMode;
30
	
31
	/**
32
	 * Constructor
33
	 * @param text the text for the action
34
	 * @param image the image for the action
35
	 */
36
	public LaunchConfigurationAction(ILaunchConfiguration config, String mode, String text, ImageDescriptor image, int accelerator) {
37
		super(MessageFormat.format(ActionMessages.LaunchConfigurationAction_0, new String[] {Integer.toString(accelerator), text}), image);
38
		fConfig = config;
39
		fMode = mode;
40
	}
41
	
42
	/**
43
	 * Allows access to the launch configuration associated with the action
44
	 * @return the associated launch configuration
45
	 */
46
	public ILaunchConfiguration getLaunchConfiguration() {
47
		return fConfig;
48
	}
49
50
	/* (non-Javadoc)
51
	 * @see org.eclipse.jface.action.Action#run()
52
	 */
53
	public void run() {
54
		DebugUITools.launch(fConfig, fMode);
55
	}
56
57
}
(-)tests/org/eclipse/jdt/debug/tests/launching/LaunchShortcutTests.java (-28 / +23 lines)
Lines 10-21 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.debug.tests.launching;
11
package org.eclipse.jdt.debug.tests.launching;
12
12
13
import org.eclipse.core.resources.IProject;
13
import java.util.ArrayList;
14
import org.eclipse.core.runtime.CoreException;
14
import java.util.List;
15
15
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
16
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
16
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension;
17
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension;
17
import org.eclipse.jdt.core.IJavaProject;
18
import org.eclipse.jdt.debug.tests.AbstractDebugTest;
18
import org.eclipse.jdt.debug.tests.AbstractDebugTest;
19
import org.eclipse.ui.activities.WorkbenchActivityHelper;
19
20
20
/**
21
/**
21
 * Tests the capabilities of launch shortcuts from the <code>LaunchShortcuts</code> extension point
22
 * Tests the capabilities of launch shortcuts from the <code>LaunchShortcuts</code> extension point
Lines 95-128 Link Here
95
	 * For this test there should be a minimum of two shortcuts found.
96
	 * For this test there should be a minimum of two shortcuts found.
96
	 */
97
	 */
97
	public void testGetApplicableLaunchShortcuts() {
98
	public void testGetApplicableLaunchShortcuts() {
98
		LaunchConfigurationManager lcm = getLaunchConfigurationManager();
99
		assertTrue("there should be 2 or more shortcuts", getApplicableLaunchShortcuts("org.eclipse.jdt.launching.localJavaApplication").size() >= 2);
99
		assertNotNull("launch configuration manager cannot be null", lcm);
100
		assertTrue("there should be 2 or more shortcuts", lcm.getApplicableLaunchShortcuts("org.eclipse.jdt.launching.localJavaApplication").size() >= 2);
101
	}
100
	}
102
	
101
	
103
	/**
102
	/**
104
	 * test that a default launch shortcut can be set, persisted and retrieved
103
	 * Returns a listing of all applicable <code>LaunchShortcutExtension</code>s for the given
105
	 */
104
	 * launch configuration type id.
106
	public void testSetDefaultLaunchShortcut() {
105
	 * @param typeid the id of the launch configuration
107
		LaunchConfigurationManager lcm = getLaunchConfigurationManager();
106
	 * @return a listing of <code>LaunchShortcutExtension</code>s that are associated with the specified launch configuration
108
		assertNotNull("the launch configuration manager should not be null", lcm);
107
	 * type id or an empty list, never <code>null</code>
109
		LaunchShortcutExtension ext = getJavaApplicationLaunchShortcut();
108
	 * 
110
		assertNotNull("the java launch shortcut should not be null", ext);
109
	 * @since 3.3
111
		IJavaProject jproject = getJavaProject();
110
	 */
112
		assertNotNull("the java project should not be null", jproject);
111
	public List getApplicableLaunchShortcuts(String typeid) {
113
		IProject project = jproject.getProject();
112
		List list = new ArrayList();
114
		assertNotNull("the project should not be null", project);
113
		LaunchShortcutExtension ext = null;
115
		try {
114
		List shortcuts = getLaunchConfigurationManager().getLaunchShortcuts();
116
			assertNull("there should be no default launch shortcut for the test project", lcm.getDefaultLaunchShortcut(project));
115
		for(int i = 0; i < shortcuts.size(); i++) {
117
			lcm.setDefaultLaunchShortcut(project, ext);
116
			ext = (LaunchShortcutExtension) shortcuts.get(i);
118
			ext = lcm.getDefaultLaunchShortcut(project);
117
			if(ext.getAssociatedConfigurationTypes().contains(typeid) && !WorkbenchActivityHelper.filterItem(ext)) {
119
			assertNotNull("the default launch shortcut should be the java app shortcut", ext);
118
				list.add(ext);
120
			lcm.setDefaultLaunchShortcut(project, null);
119
			}
121
			ext = lcm.getDefaultLaunchShortcut(project);
122
			assertNull("there should be no default launch shortcut for the test project", ext);
123
		} 
124
		catch (CoreException e) {
125
			fail();
126
		}
120
		}
121
		return list;
127
	}
122
	}
128
}
123
}
(-)tests/org/eclipse/jdt/debug/tests/performance/PerfContextualLaunchMenu.java (-1 / +5 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.debug.tests.performance;
11
package org.eclipse.jdt.debug.tests.performance;
12
12
13
import org.eclipse.core.runtime.CoreException;
13
import org.eclipse.debug.core.ILaunchManager;
14
import org.eclipse.debug.core.ILaunchManager;
14
import org.eclipse.debug.internal.ui.DebugUIPlugin;
15
import org.eclipse.debug.internal.ui.DebugUIPlugin;
15
import org.eclipse.debug.ui.actions.ContextualLaunchAction;
16
import org.eclipse.debug.ui.actions.ContextualLaunchAction;
Lines 90-96 Link Here
90
        }
91
        }
91
        
92
        
92
        void showMenu(Menu menu) {
93
        void showMenu(Menu menu) {
93
            fillMenu(menu);
94
        	try {
95
        		fillMenu(menu);
96
        	}
97
        	catch(CoreException ce)  {}
94
        }
98
        }
95
    }
99
    }
96
}
100
}
(-)core/org/eclipse/debug/internal/core/LaunchManager.java (-13 / +15 lines)
Lines 2415-2434 Link Here
2415
	 * CONTEXTLAUNCHING
2415
	 * CONTEXTLAUNCHING
2416
	 */
2416
	 */
2417
	public ILaunchConfiguration getDefaultConfiguration(IResource resource) throws CoreException {
2417
	public ILaunchConfiguration getDefaultConfiguration(IResource resource) throws CoreException {
2418
		IProject project = resource.getProject();
2418
		if(resource != null) {
2419
		if (project != null) {
2419
			IProject project = resource.getProject();
2420
			org.osgi.service.prefs.Preferences projectNode = getProjectNode(resource);
2420
			if (project != null) {
2421
			String configValue = projectNode.get(DEFAULT_CONFIGURATION, null);
2421
				org.osgi.service.prefs.Preferences projectNode = getProjectNode(resource);
2422
			if (configValue != null) {
2422
				String configValue = projectNode.get(DEFAULT_CONFIGURATION, null);
2423
				// shared config
2424
				IFile file = project.getFile(Path.fromPortableString(configValue));
2425
				return getLaunchConfiguration(file);
2426
			} else {
2427
				org.osgi.service.prefs.Preferences instanceNode = getInstanceNode(resource);
2428
				configValue = instanceNode.get(DEFAULT_CONFIGURATION, null);
2429
				if (configValue != null) {
2423
				if (configValue != null) {
2430
					// local config
2424
					// shared config
2431
					return getLaunchConfiguration(configValue);
2425
					IFile file = project.getFile(Path.fromPortableString(configValue));
2426
					return getLaunchConfiguration(file);
2427
				} else {
2428
					org.osgi.service.prefs.Preferences instanceNode = getInstanceNode(resource);
2429
					configValue = instanceNode.get(DEFAULT_CONFIGURATION, null);
2430
					if (configValue != null) {
2431
						// local config
2432
						return getLaunchConfiguration(configValue);
2433
					}
2432
				}
2434
				}
2433
			}
2435
			}
2434
		}
2436
		}
(-)core/org/eclipse/debug/internal/core/LaunchConfigurationWorkingCopy.java (-2 / +7 lines)
Lines 176-183 Link Here
176
		if (getParent() != null) {
176
		if (getParent() != null) {
177
			// save to parent working copy
177
			// save to parent working copy
178
			LaunchConfigurationWorkingCopy wc = (LaunchConfigurationWorkingCopy) getParent();
178
			LaunchConfigurationWorkingCopy wc = (LaunchConfigurationWorkingCopy) getParent();
179
			wc.setName(getName());
179
			if(fRenamed) {
180
			wc.copyFrom(this);
180
				wc.rename(getName());
181
			}
182
			else {
183
				wc.setName(getName());
184
			}
185
			wc.setAttributes(getInfo().getAttributes());
181
			return wc;
186
			return wc;
182
		}
187
		}
183
		else {
188
		else {

Return to bug 74480