author | Ed Swartz <ed.swartz@nokia.com> |
Wed, 07 Apr 2010 13:22:43 -0500 | |
changeset 1171 | 651ae39eb566 |
parent 1102 | fc2867001a80 |
child 1172 | d1378138ca79 |
permissions | -rw-r--r-- |
956 | 1 |
package com.nokia.cdt.internal.debug.launch; |
2 |
||
1171
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
3 |
import java.util.ArrayList; |
956 | 4 |
import java.util.List; |
5 |
||
6 |
import org.eclipse.cdt.debug.core.executables.Executable; |
|
994 | 7 |
import org.eclipse.cdt.debug.core.executables.ISourceFileRemapping; |
956 | 8 |
import org.eclipse.core.resources.IFile; |
9 |
import org.eclipse.core.resources.IProject; |
|
10 |
import org.eclipse.core.resources.IResource; |
|
11 |
import org.eclipse.core.runtime.CoreException; |
|
12 |
import org.eclipse.core.runtime.IAdaptable; |
|
13 |
import org.eclipse.core.runtime.IPath; |
|
14 |
import org.eclipse.debug.core.ILaunchConfiguration; |
|
15 |
import org.eclipse.debug.ui.DebugUITools; |
|
1171
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
16 |
import org.eclipse.debug.ui.IDebugModelPresentation; |
956 | 17 |
import org.eclipse.debug.ui.ILaunchShortcut2; |
18 |
import org.eclipse.jface.viewers.ISelection; |
|
19 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
1171
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
20 |
import org.eclipse.jface.window.Window; |
956 | 21 |
import org.eclipse.ui.IEditorInput; |
22 |
import org.eclipse.ui.IEditorPart; |
|
23 |
import org.eclipse.ui.IFileEditorInput; |
|
1171
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
24 |
import org.eclipse.ui.dialogs.ElementListSelectionDialog; |
956 | 25 |
|
26 |
import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin; |
|
1102
fc2867001a80
Refactor executables view support extension from com.nokia.carbide.cpp.edc to com.nokia.cdt.debug.common.
timkelly
parents:
1099
diff
changeset
|
27 |
import com.nokia.cdt.debug.common.internal.executables.SymbianSourceFileRemapping; |
1171
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
28 |
import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils; |
956 | 29 |
|
30 |
public abstract class AbstractSymbianLaunchShortcut implements ILaunchShortcut2 { |
|
31 |
||
32 |
protected abstract void launchProject(IProject project, Executable executable, IPath defaultMMP, String mode); |
|
33 |
||
1171
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
34 |
/** Tell whether this existing configuration matches one the shortcut would create */ |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
35 |
protected abstract boolean isSupportedConfiguration(ILaunchConfiguration config) throws CoreException; |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
36 |
|
956 | 37 |
public void launch(IEditorPart editor, String mode) { |
38 |
// launch an existing config if one exists |
|
39 |
ILaunchConfiguration[] configs = getLaunchConfigurations(editor); |
|
40 |
if (configs.length > 0) { |
|
41 |
// just launch the first one that supports the mode |
|
42 |
for (ILaunchConfiguration config : configs) { |
|
43 |
try { |
|
1171
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
44 |
if (config.supportsMode(mode) && isSupportedConfiguration(config)) { |
956 | 45 |
DebugUITools.launch(configs[0], mode); |
46 |
return; |
|
47 |
} |
|
48 |
} catch (CoreException e) { |
|
49 |
e.printStackTrace(); |
|
50 |
} |
|
51 |
} |
|
52 |
} |
|
53 |
||
54 |
IEditorInput editorInput = editor.getEditorInput(); |
|
55 |
if (editorInput instanceof IFileEditorInput) { |
|
56 |
IFile file = ((IFileEditorInput)editorInput).getFile(); |
|
57 |
if (file != null) { |
|
58 |
launchProject(file.getProject(), null, null, mode); |
|
59 |
} |
|
60 |
} |
|
61 |
} |
|
62 |
||
63 |
public void launch(ISelection selection, String mode) { |
|
64 |
||
65 |
// launch an existing config if one exists |
|
66 |
ILaunchConfiguration[] configs = getLaunchConfigurations(selection); |
|
67 |
if (configs.length > 0) { |
|
1171
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
68 |
// find all the ones that support the mode and shortcut (#11013) |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
69 |
List<ILaunchConfiguration> matches = new ArrayList<ILaunchConfiguration>(); |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
70 |
for (int i = 0; i < configs.length; i++) { |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
71 |
ILaunchConfiguration config = configs[i]; |
956 | 72 |
try { |
1171
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
73 |
if (config.supportsMode(mode) && isSupportedConfiguration(config)) { |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
74 |
matches.add(config); |
956 | 75 |
} |
76 |
} catch (CoreException e) { |
|
77 |
e.printStackTrace(); |
|
78 |
} |
|
79 |
} |
|
1171
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
80 |
// if only one matches, just launch |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
81 |
if (matches.size() > 0) { |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
82 |
if (matches.size() == 1 || WorkbenchUtils.isJUnitRunning()) { |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
83 |
DebugUITools.launch(matches.get(0), mode); |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
84 |
} else { |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
85 |
// else, ask the user |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
86 |
ILaunchConfiguration selected = chooseConfiguration(matches, mode); |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
87 |
if (selected != null) |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
88 |
DebugUITools.launch(selected, mode); |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
89 |
} |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
90 |
return; |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
91 |
} |
956 | 92 |
} |
93 |
||
94 |
IPath defaultMMP = null; |
|
95 |
boolean launched = false; |
|
96 |
Executable executable = null; |
|
97 |
||
98 |
if (selection instanceof IStructuredSelection) { |
|
99 |
Object firstElement = ((IStructuredSelection) selection).getFirstElement(); |
|
100 |
if (firstElement != null && firstElement instanceof Executable) |
|
101 |
{ |
|
102 |
launchProject(((Executable)firstElement).getProject(), (Executable)firstElement, defaultMMP, mode); |
|
103 |
launched = true; |
|
104 |
} |
|
105 |
else |
|
106 |
if (firstElement != null && firstElement instanceof IAdaptable) |
|
107 |
{ |
|
108 |
IFile file = (IFile) ((IAdaptable) firstElement).getAdapter(IFile.class); |
|
109 |
if (file != null) |
|
110 |
{ |
|
111 |
IPath filePath = file.getLocation(); |
|
1171
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
112 |
if ("mmp".equalsIgnoreCase(filePath.getFileExtension())) //$NON-NLS-1$ |
956 | 113 |
{ |
114 |
defaultMMP = filePath; |
|
115 |
} |
|
116 |
else |
|
117 |
{ |
|
994 | 118 |
executable = new Executable(file.getLocation(), file.getProject(), file, |
119 |
new ISourceFileRemapping[] {new SymbianSourceFileRemapping()}); |
|
956 | 120 |
launchProject(file.getProject(), executable, defaultMMP, mode); |
121 |
launched = true; |
|
122 |
} |
|
123 |
} |
|
124 |
} |
|
125 |
} |
|
126 |
||
127 |
if (!launched) |
|
128 |
{ |
|
129 |
List<IProject> projects = CarbideBuilderPlugin.getProjectsFromSelection(selection); |
|
130 |
if (projects.size() > 0) { |
|
131 |
launchProject(projects.get(0), executable, defaultMMP, mode); |
|
132 |
} |
|
133 |
} |
|
134 |
} |
|
1171
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
135 |
|
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
136 |
/** |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
137 |
* Show a selection dialog that allows the user to choose one of the specified |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
138 |
* launch configurations. Return the chosen config, or <code>null</code> if the |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
139 |
* user cancelled the dialog. |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
140 |
*/ |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
141 |
protected ILaunchConfiguration chooseConfiguration(List<ILaunchConfiguration> configList, String mode) { |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
142 |
IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation(); |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
143 |
ElementListSelectionDialog dialog = new ElementListSelectionDialog(WorkbenchUtils.getSafeShell(), labelProvider); |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
144 |
dialog.setElements(configList.toArray()); |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
145 |
dialog.setTitle(Messages.getString("AbstractSymbianLaunchShortcut.ChooseConfigTitle")); //$NON-NLS-1$ |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
146 |
dialog.setMessage(Messages.getString("AbstractSymbianLaunchShortcut.ChooseConfigLabel")); //$NON-NLS-1$ |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
147 |
dialog.setMultipleSelection(false); |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
148 |
int result = dialog.open(); |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
149 |
labelProvider.dispose(); |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
150 |
if (result == Window.OK) { |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
151 |
return (ILaunchConfiguration) dialog.getFirstResult(); |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
152 |
} |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
153 |
return null; |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
154 |
} |
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
155 |
|
956 | 156 |
|
157 |
public ILaunchConfiguration[] getLaunchConfigurations(ISelection selection) { |
|
158 |
IPath defaultMMP = null; |
|
159 |
if (selection instanceof IStructuredSelection) { |
|
160 |
Object firstElement = ((IStructuredSelection) selection).getFirstElement(); |
|
161 |
if (firstElement != null && firstElement instanceof Executable) |
|
162 |
{ |
|
163 |
return LaunchPlugin.getDefault().getLaunchConfigurations(((Executable)firstElement).getProject(), (Executable)firstElement, defaultMMP); |
|
164 |
} |
|
165 |
else |
|
166 |
if (firstElement != null && firstElement instanceof IAdaptable) |
|
167 |
{ |
|
168 |
IFile file = (IFile) ((IAdaptable) firstElement).getAdapter(IFile.class); |
|
169 |
if (file != null) |
|
170 |
{ |
|
171 |
IPath filePath = file.getLocation(); |
|
1171
651ae39eb566
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut and show selection when more than one is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
1102
diff
changeset
|
172 |
if ("mmp".equalsIgnoreCase(filePath.getFileExtension())) //$NON-NLS-1$ |
956 | 173 |
{ |
174 |
defaultMMP = filePath; |
|
175 |
} |
|
994 | 176 |
Executable executable = new Executable(file.getLocation(), file.getProject(), file, |
177 |
new ISourceFileRemapping[] {new SymbianSourceFileRemapping()}); |
|
956 | 178 |
return LaunchPlugin.getDefault().getLaunchConfigurations(file.getProject(), executable, defaultMMP); |
179 |
} |
|
180 |
} |
|
181 |
} |
|
182 |
||
183 |
List<IProject> projects = CarbideBuilderPlugin.getProjectsFromSelection(selection); |
|
184 |
if (projects.size() > 0) { |
|
185 |
return LaunchPlugin.getDefault().getLaunchConfigurations(projects.get(0), null, defaultMMP); |
|
186 |
} |
|
187 |
return null; |
|
188 |
} |
|
189 |
||
190 |
public ILaunchConfiguration[] getLaunchConfigurations(IEditorPart editorpart) { |
|
191 |
IEditorInput editorInput = editorpart.getEditorInput(); |
|
192 |
if (editorInput instanceof IFileEditorInput) { |
|
193 |
IFile file = ((IFileEditorInput)editorInput).getFile(); |
|
194 |
if (file != null) { |
|
195 |
return LaunchPlugin.getDefault().getLaunchConfigurations(file.getProject(), null, null); |
|
196 |
} |
|
197 |
} |
|
198 |
return null; |
|
199 |
} |
|
200 |
||
201 |
public IResource getLaunchableResource(ISelection selection) { |
|
202 |
if (selection instanceof IStructuredSelection) { |
|
203 |
Object firstElement = ((IStructuredSelection) selection).getFirstElement(); |
|
204 |
if (firstElement != null && firstElement instanceof IFile) |
|
205 |
{ |
|
206 |
IFile file = (IFile) firstElement; |
|
207 |
return file.getProject(); |
|
208 |
} |
|
209 |
if (firstElement != null && firstElement instanceof Executable) |
|
210 |
{ |
|
211 |
return ((Executable)firstElement).getProject(); |
|
212 |
} |
|
213 |
} |
|
214 |
List<IProject> projects = CarbideBuilderPlugin.getProjectsFromSelection(selection); |
|
215 |
if (projects.size() > 0) { |
|
216 |
return projects.get(0); |
|
217 |
} |
|
218 |
return null; |
|
219 |
} |
|
220 |
||
221 |
public IResource getLaunchableResource(IEditorPart editorpart) { |
|
222 |
IEditorInput editorInput = editorpart.getEditorInput(); |
|
223 |
if (editorInput instanceof IFileEditorInput) { |
|
224 |
IFile file = ((IFileEditorInput)editorInput).getFile(); |
|
225 |
if (file != null) { |
|
226 |
return file.getProject(); |
|
227 |
} |
|
228 |
} |
|
229 |
return null; |
|
230 |
} |
|
231 |
} |