37
|
1 |
/*******************************************************************************
|
|
2 |
* Copyright (c) 2005, 2009 QNX Software Systems 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 |
* QNX Software Systems - initial API and implementation
|
|
10 |
* Ken Ryall (Nokia) - bug 178731
|
|
11 |
* IBM Corporation
|
|
12 |
*******************************************************************************/
|
|
13 |
package org.eclipse.cdt.launch.ui;
|
|
14 |
|
|
15 |
import java.util.ArrayList;
|
|
16 |
import java.util.HashMap;
|
|
17 |
import java.util.HashSet;
|
|
18 |
import java.util.List;
|
|
19 |
import java.util.Map;
|
|
20 |
|
|
21 |
import org.eclipse.cdt.core.CCorePlugin;
|
|
22 |
import org.eclipse.cdt.core.ICDescriptor;
|
|
23 |
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
|
|
24 |
import org.eclipse.cdt.core.model.CModelException;
|
|
25 |
import org.eclipse.cdt.core.model.CoreModel;
|
|
26 |
import org.eclipse.cdt.core.model.IBinary;
|
|
27 |
import org.eclipse.cdt.core.model.ICElement;
|
|
28 |
import org.eclipse.cdt.core.model.ICProject;
|
|
29 |
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
|
30 |
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
|
31 |
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
|
|
32 |
import org.eclipse.cdt.launch.LaunchUtils;
|
|
33 |
import org.eclipse.cdt.launch.internal.ui.LaunchImages;
|
|
34 |
import org.eclipse.cdt.launch.internal.ui.LaunchMessages;
|
|
35 |
import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
|
|
36 |
import org.eclipse.cdt.ui.CElementLabelProvider;
|
|
37 |
import org.eclipse.cdt.ui.newui.CDTPropertyManager;
|
|
38 |
import org.eclipse.cdt.utils.pty.PTY;
|
|
39 |
import org.eclipse.core.resources.IFile;
|
|
40 |
import org.eclipse.core.resources.IProject;
|
|
41 |
import org.eclipse.core.resources.IResource;
|
|
42 |
import org.eclipse.core.resources.ResourcesPlugin;
|
|
43 |
import org.eclipse.core.runtime.CoreException;
|
|
44 |
import org.eclipse.core.runtime.IPath;
|
|
45 |
import org.eclipse.core.runtime.Path;
|
|
46 |
import org.eclipse.debug.core.ILaunchConfiguration;
|
|
47 |
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
|
48 |
import org.eclipse.debug.core.ILaunchDelegate;
|
|
49 |
import org.eclipse.debug.ui.DebugUITools;
|
|
50 |
import org.eclipse.debug.ui.IDebugUIConstants;
|
|
51 |
import org.eclipse.jface.dialogs.MessageDialog;
|
|
52 |
import org.eclipse.jface.viewers.ILabelProvider;
|
|
53 |
import org.eclipse.jface.window.Window;
|
|
54 |
import org.eclipse.swt.SWT;
|
|
55 |
import org.eclipse.swt.custom.BusyIndicator;
|
|
56 |
import org.eclipse.swt.events.ModifyEvent;
|
|
57 |
import org.eclipse.swt.events.ModifyListener;
|
|
58 |
import org.eclipse.swt.events.SelectionAdapter;
|
|
59 |
import org.eclipse.swt.events.SelectionEvent;
|
|
60 |
import org.eclipse.swt.events.SelectionListener;
|
|
61 |
import org.eclipse.swt.graphics.Image;
|
|
62 |
import org.eclipse.swt.layout.GridData;
|
|
63 |
import org.eclipse.swt.layout.GridLayout;
|
|
64 |
import org.eclipse.swt.widgets.Button;
|
|
65 |
import org.eclipse.swt.widgets.Combo;
|
|
66 |
import org.eclipse.swt.widgets.Composite;
|
|
67 |
import org.eclipse.swt.widgets.Display;
|
|
68 |
import org.eclipse.swt.widgets.FileDialog;
|
54
|
69 |
import org.eclipse.swt.widgets.Group;
|
37
|
70 |
import org.eclipse.swt.widgets.Label;
|
54
|
71 |
import org.eclipse.swt.widgets.Link;
|
37
|
72 |
import org.eclipse.swt.widgets.Text;
|
|
73 |
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
|
54
|
74 |
import org.eclipse.ui.dialogs.PreferencesUtil;
|
37
|
75 |
import org.eclipse.ui.dialogs.TwoPaneElementSelector;
|
|
76 |
|
|
77 |
/**
|
|
78 |
* A launch configuration tab that displays and edits project and main type name launch
|
|
79 |
* configuration attributes.
|
|
80 |
* <p>
|
|
81 |
* This class may be instantiated. This class is not intended to be subclassed.
|
|
82 |
* </p>
|
|
83 |
*
|
|
84 |
* @since 2.0
|
|
85 |
*/
|
|
86 |
|
|
87 |
public class CMainTab extends CLaunchConfigurationTab {
|
|
88 |
|
|
89 |
/**
|
|
90 |
* Tab identifier used for ordering of tabs added using the
|
|
91 |
* <code>org.eclipse.debug.ui.launchConfigurationTabs</code>
|
|
92 |
* extension point.
|
|
93 |
*
|
|
94 |
* @since 6.0
|
|
95 |
*/
|
|
96 |
public static final String TAB_ID = "org.eclipse.cdt.cdi.launch.mainTab"; //$NON-NLS-1$
|
|
97 |
|
|
98 |
// Project UI widgets
|
|
99 |
protected Label fProjLabel;
|
|
100 |
protected Text fProjText;
|
|
101 |
protected Button fProjButton;
|
|
102 |
|
|
103 |
// Main class UI widgets
|
|
104 |
protected Label fProgLabel;
|
|
105 |
protected Text fProgText;
|
|
106 |
protected Button fSearchButton;
|
|
107 |
|
|
108 |
// Core file UI widgets
|
|
109 |
/** @since 6.0 */
|
|
110 |
protected Label fCoreLabel;
|
|
111 |
/** @since 6.0 */
|
|
112 |
protected Text fCoreText;
|
|
113 |
/** @since 6.0 */
|
|
114 |
protected Button fCoreButton;
|
|
115 |
|
|
116 |
/**
|
|
117 |
* @since 6.0
|
|
118 |
*/
|
|
119 |
protected Combo fBuildConfigCombo;
|
54
|
120 |
// Build option UI widgets
|
62
|
121 |
/** @since 6.1 */
|
54
|
122 |
protected Button fDisableBuildButton;
|
62
|
123 |
/** @since 6.1 */
|
54
|
124 |
protected Button fEnableBuildButton;
|
62
|
125 |
/** @since 6.1 */
|
54
|
126 |
protected Button fWorkspaceSettingsButton;
|
62
|
127 |
/** @since 6.1 */
|
54
|
128 |
protected Link fWorkpsaceSettingsLink;
|
37
|
129 |
|
|
130 |
private final boolean fWantsTerminalOption;
|
|
131 |
protected Button fTerminalButton;
|
|
132 |
|
|
133 |
private final boolean dontCheckProgram;
|
|
134 |
private final boolean fSpecifyCoreFile;
|
|
135 |
|
|
136 |
protected static final String EMPTY_STRING = ""; //$NON-NLS-1$
|
|
137 |
|
|
138 |
private String filterPlatform = EMPTY_STRING;
|
|
139 |
|
|
140 |
public static final int WANTS_TERMINAL = 1;
|
|
141 |
public static final int DONT_CHECK_PROGRAM = 2;
|
|
142 |
/** @since 6.0 */
|
|
143 |
public static final int SPECIFY_CORE_FILE = 4;
|
|
144 |
|
|
145 |
private final Map<IPath, Boolean> fBinaryExeCache = new HashMap<IPath, Boolean>();
|
|
146 |
|
|
147 |
|
|
148 |
public CMainTab() {
|
|
149 |
this(WANTS_TERMINAL);
|
|
150 |
}
|
|
151 |
|
|
152 |
public CMainTab(boolean terminalOption) {
|
|
153 |
this(terminalOption ? WANTS_TERMINAL : 0);
|
|
154 |
}
|
|
155 |
|
|
156 |
public CMainTab(int flags) {
|
|
157 |
fWantsTerminalOption = (flags & WANTS_TERMINAL) != 0;
|
|
158 |
dontCheckProgram = (flags & DONT_CHECK_PROGRAM) != 0;
|
|
159 |
fSpecifyCoreFile = (flags & SPECIFY_CORE_FILE) != 0;
|
|
160 |
}
|
|
161 |
|
|
162 |
/*
|
|
163 |
* (non-Javadoc)
|
|
164 |
*
|
|
165 |
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
|
|
166 |
*/
|
|
167 |
public void createControl(Composite parent) {
|
|
168 |
Composite comp = new Composite(parent, SWT.NONE);
|
|
169 |
setControl(comp);
|
|
170 |
|
|
171 |
LaunchUIPlugin.getDefault().getWorkbench().getHelpSystem().setHelp(getControl(), ICDTLaunchHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_MAIN_TAB);
|
|
172 |
|
|
173 |
GridLayout topLayout = new GridLayout();
|
|
174 |
comp.setLayout(topLayout);
|
|
175 |
|
|
176 |
createVerticalSpacer(comp, 1);
|
62
|
177 |
createExeFileGroup(comp, 1);
|
37
|
178 |
createProjectGroup(comp, 1);
|
54
|
179 |
createBuildOptionGroup(comp, 1);
|
37
|
180 |
createVerticalSpacer(comp, 1);
|
|
181 |
if (fSpecifyCoreFile) {
|
|
182 |
createCoreFileGroup(comp, 1);
|
|
183 |
}
|
|
184 |
if (wantsTerminalOption() /* && ProcessFactory.supportesTerminal() */) {
|
|
185 |
createTerminalOption(comp, 1);
|
|
186 |
}
|
|
187 |
LaunchUIPlugin.setDialogShell(parent.getShell());
|
|
188 |
}
|
|
189 |
|
|
190 |
/**
|
|
191 |
* @since 6.0
|
|
192 |
*/
|
|
193 |
protected void createProjectGroup(Composite parent, int colSpan) {
|
|
194 |
Composite projComp = new Composite(parent, SWT.NONE);
|
|
195 |
GridLayout projLayout = new GridLayout();
|
|
196 |
projLayout.numColumns = 2;
|
|
197 |
projLayout.marginHeight = 0;
|
|
198 |
projLayout.marginWidth = 0;
|
|
199 |
projComp.setLayout(projLayout);
|
|
200 |
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
|
|
201 |
gd.horizontalSpan = colSpan;
|
|
202 |
projComp.setLayoutData(gd);
|
|
203 |
|
|
204 |
fProjLabel = new Label(projComp, SWT.NONE);
|
|
205 |
fProjLabel.setText(LaunchMessages.getString("CMainTab.&ProjectColon")); //$NON-NLS-1$
|
|
206 |
gd = new GridData();
|
|
207 |
gd.horizontalSpan = 2;
|
|
208 |
fProjLabel.setLayoutData(gd);
|
|
209 |
|
|
210 |
fProjText = new Text(projComp, SWT.SINGLE | SWT.BORDER);
|
|
211 |
gd = new GridData(GridData.FILL_HORIZONTAL);
|
|
212 |
fProjText.setLayoutData(gd);
|
|
213 |
fProjText.addModifyListener(new ModifyListener() {
|
|
214 |
|
|
215 |
public void modifyText(ModifyEvent evt) {
|
|
216 |
updateBuildConfigCombo(EMPTY_STRING);
|
|
217 |
updateLaunchConfigurationDialog();
|
|
218 |
}
|
|
219 |
});
|
|
220 |
|
|
221 |
fProjButton = createPushButton(projComp, LaunchMessages.getString("Launch.common.Browse_1"), null); //$NON-NLS-1$
|
|
222 |
fProjButton.addSelectionListener(new SelectionAdapter() {
|
|
223 |
|
|
224 |
@Override
|
|
225 |
public void widgetSelected(SelectionEvent evt) {
|
|
226 |
handleProjectButtonSelected();
|
|
227 |
updateLaunchConfigurationDialog();
|
|
228 |
}
|
|
229 |
});
|
|
230 |
}
|
|
231 |
|
|
232 |
/**
|
|
233 |
* @since 6.0
|
|
234 |
*/
|
|
235 |
protected void updateBuildConfigCombo(String selectedConfigID) {
|
|
236 |
if (fBuildConfigCombo != null)
|
|
237 |
{
|
|
238 |
fBuildConfigCombo.removeAll();
|
|
239 |
fBuildConfigCombo.add(LaunchMessages.getString("CMainTab.Use_Active")); //$NON-NLS-1$
|
|
240 |
fBuildConfigCombo.setData("0", EMPTY_STRING); //$NON-NLS-1$
|
|
241 |
fBuildConfigCombo.select(0);
|
|
242 |
ICProject cproject = getCProject();
|
|
243 |
if (cproject != null){
|
|
244 |
|
|
245 |
ICProjectDescription projDes = CDTPropertyManager.getProjectDescription(cproject.getProject());
|
|
246 |
if (projDes != null)
|
|
247 |
{
|
|
248 |
int selIndex = 0;
|
|
249 |
ICConfigurationDescription[] configurations = projDes.getConfigurations();
|
|
250 |
ICConfigurationDescription selectedConfig = projDes.getConfigurationById(selectedConfigID);
|
|
251 |
for (int i = 0; i < configurations.length; i++) {
|
|
252 |
String configName = configurations[i].getName();
|
|
253 |
fBuildConfigCombo.add(configName);
|
|
254 |
fBuildConfigCombo.setData(Integer.toString(i + 1), configurations[i].getId());
|
|
255 |
if (selectedConfig != null && selectedConfigID.equals(configurations[i].getId()))
|
|
256 |
selIndex = i + 1;
|
|
257 |
}
|
|
258 |
fBuildConfigCombo.select(selIndex);
|
|
259 |
}
|
|
260 |
|
|
261 |
}
|
|
262 |
|
|
263 |
}
|
|
264 |
}
|
|
265 |
|
|
266 |
/**
|
|
267 |
* @since 6.0
|
|
268 |
*/
|
|
269 |
protected void createBuildConfigCombo(Composite parent, int colspan) {
|
|
270 |
Composite comboComp = new Composite(parent, SWT.NONE);
|
|
271 |
GridLayout layout = new GridLayout(2, false);
|
|
272 |
comboComp.setLayout(layout);
|
|
273 |
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
|
|
274 |
gd.horizontalSpan = colspan;
|
|
275 |
comboComp.setLayoutData(gd);
|
|
276 |
Label dlabel = new Label(comboComp, SWT.NONE);
|
|
277 |
dlabel.setText(LaunchMessages.getString("CMainTab.Build_Config")); //$NON-NLS-1$
|
|
278 |
fBuildConfigCombo = new Combo(comboComp, SWT.READ_ONLY | SWT.DROP_DOWN);
|
|
279 |
fBuildConfigCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
|
280 |
fBuildConfigCombo.addSelectionListener(new SelectionListener() {
|
|
281 |
public void widgetSelected(SelectionEvent e) {
|
|
282 |
updateLaunchConfigurationDialog();
|
|
283 |
}
|
|
284 |
|
|
285 |
public void widgetDefaultSelected(SelectionEvent e) {
|
|
286 |
updateLaunchConfigurationDialog();
|
|
287 |
}
|
|
288 |
});
|
|
289 |
}
|
|
290 |
|
|
291 |
protected void createExeFileGroup(Composite parent, int colSpan) {
|
|
292 |
Composite mainComp = new Composite(parent, SWT.NONE);
|
|
293 |
GridLayout mainLayout = new GridLayout();
|
|
294 |
mainLayout.numColumns = 3;
|
|
295 |
mainLayout.marginHeight = 0;
|
|
296 |
mainLayout.marginWidth = 0;
|
|
297 |
mainComp.setLayout(mainLayout);
|
|
298 |
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
|
|
299 |
gd.horizontalSpan = colSpan;
|
|
300 |
mainComp.setLayoutData(gd);
|
|
301 |
fProgLabel = new Label(mainComp, SWT.NONE);
|
|
302 |
fProgLabel.setText(LaunchMessages.getString("CMainTab.C/C++_Application")); //$NON-NLS-1$
|
|
303 |
gd = new GridData();
|
|
304 |
gd.horizontalSpan = 3;
|
|
305 |
fProgLabel.setLayoutData(gd);
|
|
306 |
fProgText = new Text(mainComp, SWT.SINGLE | SWT.BORDER);
|
|
307 |
gd = new GridData(GridData.FILL_HORIZONTAL);
|
|
308 |
fProgText.setLayoutData(gd);
|
|
309 |
fProgText.addModifyListener(new ModifyListener() {
|
|
310 |
public void modifyText(ModifyEvent evt) {
|
|
311 |
updateLaunchConfigurationDialog();
|
|
312 |
}
|
|
313 |
});
|
|
314 |
|
|
315 |
fSearchButton = createPushButton(mainComp, LaunchMessages.getString("CMainTab.Search..."), null); //$NON-NLS-1$
|
|
316 |
fSearchButton.addSelectionListener(new SelectionAdapter() {
|
|
317 |
@Override
|
|
318 |
public void widgetSelected(SelectionEvent evt) {
|
|
319 |
handleSearchButtonSelected();
|
|
320 |
updateLaunchConfigurationDialog();
|
|
321 |
}
|
|
322 |
});
|
|
323 |
|
|
324 |
Button fBrowseForBinaryButton;
|
|
325 |
fBrowseForBinaryButton = createPushButton(mainComp, LaunchMessages.getString("Launch.common.Browse_2"), null); //$NON-NLS-1$
|
|
326 |
fBrowseForBinaryButton.addSelectionListener(new SelectionAdapter() {
|
|
327 |
@Override
|
|
328 |
public void widgetSelected(SelectionEvent evt) {
|
|
329 |
handleBinaryBrowseButtonSelected();
|
|
330 |
updateLaunchConfigurationDialog();
|
|
331 |
}
|
|
332 |
});
|
|
333 |
}
|
|
334 |
|
62
|
335 |
/** @since 6.1 */
|
54
|
336 |
protected void createBuildOptionGroup(final Composite parent, int colSpan) {
|
|
337 |
Group buildGroup = new Group(parent, SWT.NONE);
|
|
338 |
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
|
|
339 |
gridData.horizontalSpan = colSpan;
|
|
340 |
GridLayout gridLayout = new GridLayout();
|
|
341 |
gridLayout.numColumns = 2;
|
|
342 |
gridLayout.marginHeight = 5;
|
|
343 |
gridLayout.marginWidth = 5;
|
|
344 |
gridLayout.makeColumnsEqualWidth= true;
|
|
345 |
buildGroup.setLayoutData(gridData);
|
|
346 |
buildGroup.setLayout(gridLayout);
|
62
|
347 |
buildGroup.setText(LaunchMessages.getString("CMainTab.Build_options")); //$NON-NLS-1$
|
|
348 |
|
|
349 |
createBuildConfigCombo(buildGroup, 2);
|
|
350 |
|
71
|
351 |
fEnableBuildButton = new Button(buildGroup, SWT.RADIO);
|
|
352 |
fEnableBuildButton.setText(LaunchMessages.getString("CMainTab.Enable_build_button_label")); //$NON-NLS-1$
|
|
353 |
fEnableBuildButton.setToolTipText(LaunchMessages.getString("CMainTab.Enable_build_button_tooltip")); //$NON-NLS-1$
|
|
354 |
fEnableBuildButton.addSelectionListener(new SelectionAdapter() {
|
|
355 |
|
|
356 |
public void widgetSelected(SelectionEvent evt) {
|
|
357 |
updateLaunchConfigurationDialog();
|
|
358 |
}
|
|
359 |
});
|
|
360 |
|
|
361 |
fDisableBuildButton = new Button(buildGroup, SWT.RADIO);
|
|
362 |
fDisableBuildButton.setText(LaunchMessages.getString("CMainTab.Disable_build_button_label")); //$NON-NLS-1$
|
120
|
363 |
fDisableBuildButton.setToolTipText(LaunchMessages.getString("CMainTab.Disable_build_button_tooltip")); //$NON-NLS-1$
|
71
|
364 |
fDisableBuildButton.addSelectionListener(new SelectionAdapter() {
|
|
365 |
|
|
366 |
public void widgetSelected(SelectionEvent evt) {
|
|
367 |
updateLaunchConfigurationDialog();
|
|
368 |
}
|
|
369 |
});
|
|
370 |
|
62
|
371 |
fWorkspaceSettingsButton = new Button(buildGroup, SWT.RADIO);
|
|
372 |
fWorkspaceSettingsButton.setText(LaunchMessages.getString("CMainTab.Workspace_settings_button_label")); //$NON-NLS-1$
|
|
373 |
fWorkspaceSettingsButton.setToolTipText(LaunchMessages.getString("CMainTab.Workspace_settings_button_tooltip")); //$NON-NLS-1$
|
|
374 |
fWorkspaceSettingsButton.addSelectionListener(new SelectionAdapter() {
|
|
375 |
|
|
376 |
public void widgetSelected(SelectionEvent evt) {
|
|
377 |
updateLaunchConfigurationDialog();
|
|
378 |
}
|
|
379 |
});
|
|
380 |
|
|
381 |
fWorkpsaceSettingsLink = new Link(buildGroup, SWT.NONE); //$NON-NLS-1$
|
|
382 |
fWorkpsaceSettingsLink.setText(LaunchMessages.getString("CMainTab.Workspace_settings_link_label")); //$NON-NLS-1$
|
|
383 |
fWorkpsaceSettingsLink.addSelectionListener(new SelectionAdapter() {
|
|
384 |
public void widgetSelected(SelectionEvent e) {
|
|
385 |
PreferencesUtil.createPreferenceDialogOn(
|
|
386 |
parent.getShell(),
|
|
387 |
LaunchMessages.getString("CMainTab.Workspace_settings_page_id"), //$NON-NLS-1$
|
|
388 |
null,
|
|
389 |
null).open();
|
|
390 |
}
|
|
391 |
});
|
54
|
392 |
|
|
393 |
}
|
37
|
394 |
/** @since 6.0 */
|
|
395 |
protected void createCoreFileGroup(Composite parent, int colSpan) {
|
|
396 |
Composite coreComp = new Composite(parent, SWT.NONE);
|
|
397 |
GridLayout coreLayout = new GridLayout();
|
|
398 |
coreLayout.numColumns = 3;
|
|
399 |
coreLayout.marginHeight = 0;
|
|
400 |
coreLayout.marginWidth = 0;
|
|
401 |
coreComp.setLayout(coreLayout);
|
|
402 |
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
|
|
403 |
gd.horizontalSpan = colSpan;
|
|
404 |
coreComp.setLayoutData(gd);
|
|
405 |
fCoreLabel = new Label(coreComp, SWT.NONE);
|
|
406 |
fCoreLabel.setText(LaunchMessages.getString("CMainTab.CoreFile_path")); //$NON-NLS-1$
|
|
407 |
gd = new GridData();
|
|
408 |
gd.horizontalSpan = 3;
|
|
409 |
fCoreLabel.setLayoutData(gd);
|
|
410 |
fCoreText = new Text(coreComp, SWT.SINGLE | SWT.BORDER);
|
|
411 |
gd = new GridData(GridData.FILL_HORIZONTAL);
|
|
412 |
fCoreText.setLayoutData(gd);
|
|
413 |
fCoreText.addModifyListener(new ModifyListener() {
|
|
414 |
public void modifyText(ModifyEvent evt) {
|
|
415 |
updateLaunchConfigurationDialog();
|
|
416 |
}
|
|
417 |
});
|
|
418 |
|
|
419 |
Button browseForCoreButton;
|
|
420 |
browseForCoreButton = createPushButton(coreComp, LaunchMessages.getString("Launch.common.Browse_2"), null); //$NON-NLS-1$
|
|
421 |
browseForCoreButton.addSelectionListener(new SelectionAdapter() {
|
|
422 |
@Override
|
|
423 |
public void widgetSelected(SelectionEvent evt) {
|
|
424 |
String text = handleBrowseButtonSelected();
|
|
425 |
if (text != null) {
|
|
426 |
fCoreText.setText(text);
|
|
427 |
}
|
|
428 |
updateLaunchConfigurationDialog();
|
|
429 |
}
|
|
430 |
});
|
|
431 |
}
|
|
432 |
|
|
433 |
protected boolean wantsTerminalOption() {
|
|
434 |
return fWantsTerminalOption;
|
|
435 |
}
|
|
436 |
|
|
437 |
protected void createTerminalOption(Composite parent, int colSpan) {
|
|
438 |
Composite mainComp = new Composite(parent, SWT.NONE);
|
|
439 |
GridLayout mainLayout = new GridLayout();
|
|
440 |
mainLayout.numColumns = 1;
|
|
441 |
mainLayout.marginHeight = 0;
|
|
442 |
mainLayout.marginWidth = 0;
|
|
443 |
mainComp.setLayout(mainLayout);
|
|
444 |
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
|
|
445 |
gd.horizontalSpan = colSpan;
|
|
446 |
mainComp.setLayoutData(gd);
|
|
447 |
|
|
448 |
fTerminalButton = createCheckButton(mainComp, LaunchMessages.getString("CMainTab.UseTerminal")); //$NON-NLS-1$
|
|
449 |
fTerminalButton.addSelectionListener(new SelectionAdapter() {
|
|
450 |
|
|
451 |
@Override
|
|
452 |
public void widgetSelected(SelectionEvent evt) {
|
|
453 |
updateLaunchConfigurationDialog();
|
|
454 |
}
|
|
455 |
});
|
|
456 |
fTerminalButton.setEnabled(PTY.isSupported());
|
|
457 |
}
|
|
458 |
|
|
459 |
/*
|
|
460 |
* (non-Javadoc)
|
|
461 |
*
|
|
462 |
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
|
|
463 |
*/
|
|
464 |
public void initializeFrom(ILaunchConfiguration config) {
|
|
465 |
filterPlatform = getPlatform(config);
|
|
466 |
updateProjectFromConfig(config);
|
|
467 |
updateProgramFromConfig(config);
|
|
468 |
updateCoreFromConfig(config);
|
54
|
469 |
updateBuildOptionFromConfig(config);
|
37
|
470 |
updateTerminalFromConfig(config);
|
|
471 |
}
|
|
472 |
|
|
473 |
protected void updateTerminalFromConfig(ILaunchConfiguration config) {
|
|
474 |
if (fTerminalButton != null) {
|
|
475 |
boolean useTerminal = true;
|
|
476 |
try {
|
|
477 |
useTerminal = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL, ICDTLaunchConfigurationConstants.USE_TERMINAL_DEFAULT);
|
|
478 |
} catch (CoreException e) {
|
|
479 |
LaunchUIPlugin.log(e);
|
|
480 |
}
|
|
481 |
fTerminalButton.setSelection(useTerminal);
|
|
482 |
}
|
|
483 |
}
|
|
484 |
|
|
485 |
protected void updateProjectFromConfig(ILaunchConfiguration config) {
|
|
486 |
String projectName = EMPTY_STRING;
|
|
487 |
String configName = EMPTY_STRING;
|
|
488 |
try {
|
|
489 |
projectName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, EMPTY_STRING);
|
|
490 |
configName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, EMPTY_STRING);
|
|
491 |
} catch (CoreException ce) {
|
|
492 |
LaunchUIPlugin.log(ce);
|
|
493 |
}
|
|
494 |
fProjText.setText(projectName);
|
|
495 |
updateBuildConfigCombo(configName);
|
|
496 |
}
|
|
497 |
|
|
498 |
protected void updateProgramFromConfig(ILaunchConfiguration config) {
|
54
|
499 |
if (fProgText != null)
|
|
500 |
{
|
|
501 |
String programName = EMPTY_STRING;
|
|
502 |
try {
|
|
503 |
programName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, EMPTY_STRING);
|
|
504 |
} catch (CoreException ce) {
|
|
505 |
LaunchUIPlugin.log(ce);
|
|
506 |
}
|
|
507 |
fProgText.setText(programName);
|
37
|
508 |
}
|
|
509 |
}
|
|
510 |
|
|
511 |
/** @since 6.0 */
|
|
512 |
protected void updateCoreFromConfig(ILaunchConfiguration config) {
|
|
513 |
if (fCoreText != null) {
|
|
514 |
String coreName = EMPTY_STRING;
|
|
515 |
try {
|
|
516 |
coreName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_COREFILE_PATH, EMPTY_STRING);
|
|
517 |
} catch (CoreException ce) {
|
|
518 |
LaunchUIPlugin.log(ce);
|
|
519 |
}
|
62
|
520 |
fCoreText.setText(coreName);
|
37
|
521 |
}
|
|
522 |
}
|
54
|
523 |
|
62
|
524 |
/** @since 6.1 */
|
54
|
525 |
protected void updateBuildOptionFromConfig(ILaunchConfiguration config) {
|
|
526 |
int buildBeforeLaunchValue = ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING;
|
|
527 |
try {
|
|
528 |
buildBeforeLaunchValue = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH, buildBeforeLaunchValue);
|
|
529 |
} catch (CoreException e) {
|
|
530 |
LaunchUIPlugin.log(e);
|
|
531 |
}
|
|
532 |
|
|
533 |
fDisableBuildButton.setSelection(buildBeforeLaunchValue == ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_DISABLED);
|
|
534 |
fEnableBuildButton.setSelection(buildBeforeLaunchValue == ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_ENABLED);
|
|
535 |
fWorkspaceSettingsButton.setSelection(buildBeforeLaunchValue == ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING);
|
|
536 |
}
|
|
537 |
|
37
|
538 |
/*
|
|
539 |
* (non-Javadoc)
|
|
540 |
*
|
|
541 |
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
|
|
542 |
*/
|
|
543 |
public void performApply(ILaunchConfigurationWorkingCopy config) {
|
|
544 |
ICProject cProject = this.getCProject();
|
|
545 |
if (cProject != null && cProject.exists())
|
|
546 |
{
|
|
547 |
config.setMappedResources(new IResource[] { cProject.getProject() });
|
|
548 |
}
|
|
549 |
else
|
|
550 |
{
|
|
551 |
// the user typed in a non-existent project name. Ensure that
|
|
552 |
// won't be suppressed from the dialog. This matches JDT behaviour
|
|
553 |
config.setMappedResources(null);
|
|
554 |
}
|
|
555 |
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, fProjText.getText());
|
54
|
556 |
if (fBuildConfigCombo != null) {
|
|
557 |
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, (String)fBuildConfigCombo.getData(Integer.toString(fBuildConfigCombo.getSelectionIndex())));
|
|
558 |
}
|
|
559 |
if (fProgText != null) {
|
|
560 |
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, fProgText.getText());
|
|
561 |
}
|
37
|
562 |
if (fCoreText != null) {
|
|
563 |
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_COREFILE_PATH, fCoreText.getText());
|
|
564 |
}
|
|
565 |
if (fTerminalButton != null) {
|
|
566 |
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL, fTerminalButton.getSelection());
|
|
567 |
}
|
54
|
568 |
|
|
569 |
if (fDisableBuildButton != null) {
|
|
570 |
int buildBeforeLaunchValue = ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING;
|
|
571 |
if (fDisableBuildButton.getSelection()) {
|
|
572 |
buildBeforeLaunchValue = ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_DISABLED;
|
|
573 |
} else if (fEnableBuildButton.getSelection()) {
|
|
574 |
buildBeforeLaunchValue = ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_ENABLED;
|
|
575 |
}
|
|
576 |
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH, buildBeforeLaunchValue);
|
|
577 |
}
|
37
|
578 |
}
|
|
579 |
|
|
580 |
/**
|
|
581 |
* Show a dialog that lists all main types
|
|
582 |
*/
|
|
583 |
protected void handleSearchButtonSelected() {
|
|
584 |
|
|
585 |
if (getCProject() == null) {
|
|
586 |
MessageDialog.openInformation(getShell(), LaunchMessages.getString("CMainTab.Project_required"), //$NON-NLS-1$
|
|
587 |
LaunchMessages.getString("CMainTab.Enter_project_before_searching_for_program")); //$NON-NLS-1$
|
|
588 |
return;
|
|
589 |
}
|
|
590 |
|
|
591 |
ILabelProvider programLabelProvider = new CElementLabelProvider() {
|
|
592 |
|
|
593 |
@Override
|
|
594 |
public String getText(Object element) {
|
|
595 |
if (element instanceof IBinary) {
|
|
596 |
IBinary bin = (IBinary)element;
|
|
597 |
StringBuffer name = new StringBuffer();
|
|
598 |
name.append(bin.getPath().lastSegment());
|
|
599 |
return name.toString();
|
|
600 |
}
|
|
601 |
return super.getText(element);
|
|
602 |
}
|
|
603 |
|
|
604 |
@Override
|
|
605 |
public Image getImage(Object element) {
|
|
606 |
if (! (element instanceof ICElement)) {
|
|
607 |
return super.getImage(element);
|
|
608 |
}
|
|
609 |
ICElement celement = (ICElement)element;
|
|
610 |
|
|
611 |
if (celement.getElementType() == ICElement.C_BINARY) {
|
|
612 |
IBinary belement = (IBinary)celement;
|
|
613 |
if (belement.isExecutable()) {
|
|
614 |
return DebugUITools.getImage(IDebugUIConstants.IMG_ACT_RUN);
|
|
615 |
}
|
|
616 |
}
|
|
617 |
|
|
618 |
return super.getImage(element);
|
|
619 |
}
|
|
620 |
};
|
|
621 |
|
|
622 |
ILabelProvider qualifierLabelProvider = new CElementLabelProvider() {
|
|
623 |
|
|
624 |
@Override
|
|
625 |
public String getText(Object element) {
|
|
626 |
if (element instanceof IBinary) {
|
|
627 |
IBinary bin = (IBinary)element;
|
|
628 |
StringBuffer name = new StringBuffer();
|
|
629 |
name.append(bin.getCPU() + (bin.isLittleEndian() ? "le" : "be")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
630 |
name.append(" - "); //$NON-NLS-1$
|
|
631 |
name.append(bin.getPath().toString());
|
|
632 |
return name.toString();
|
|
633 |
}
|
|
634 |
return super.getText(element);
|
|
635 |
}
|
|
636 |
};
|
|
637 |
|
|
638 |
TwoPaneElementSelector dialog = new TwoPaneElementSelector(getShell(), programLabelProvider, qualifierLabelProvider);
|
|
639 |
dialog.setElements(getBinaryFiles(getCProject()));
|
|
640 |
dialog.setMessage(LaunchMessages.getString("CMainTab.Choose_program_to_run")); //$NON-NLS-1$
|
|
641 |
dialog.setTitle(LaunchMessages.getString("CMainTab.Program_Selection")); //$NON-NLS-1$
|
|
642 |
dialog.setUpperListLabel(LaunchMessages.getString("Launch.common.BinariesColon")); //$NON-NLS-1$
|
|
643 |
dialog.setLowerListLabel(LaunchMessages.getString("Launch.common.QualifierColon")); //$NON-NLS-1$
|
|
644 |
dialog.setMultipleSelection(false);
|
|
645 |
// dialog.set
|
|
646 |
if (dialog.open() == Window.OK) {
|
|
647 |
IBinary binary = (IBinary)dialog.getFirstResult();
|
|
648 |
fProgText.setText(binary.getResource().getProjectRelativePath().toString());
|
|
649 |
}
|
|
650 |
|
|
651 |
}
|
|
652 |
|
|
653 |
/**
|
|
654 |
* Show a dialog that lets the user select a project. This in turn provides context for the main
|
|
655 |
* type, allowing the user to key a main type name, or constraining the search for main types to
|
|
656 |
* the specified project.
|
|
657 |
*/
|
|
658 |
protected void handleBinaryBrowseButtonSelected() {
|
|
659 |
final ICProject cproject = getCProject();
|
|
660 |
if (cproject == null) {
|
|
661 |
MessageDialog.openInformation(getShell(), LaunchMessages.getString("CMainTab.Project_required"), //$NON-NLS-1$
|
|
662 |
LaunchMessages.getString("CMainTab.Enter_project_before_browsing_for_program")); //$NON-NLS-1$
|
|
663 |
return;
|
|
664 |
}
|
|
665 |
FileDialog fileDialog = new FileDialog(getShell(), SWT.NONE);
|
|
666 |
fileDialog.setFileName(fProgText.getText());
|
|
667 |
String text= fileDialog.open();
|
|
668 |
if (text != null) {
|
|
669 |
fProgText.setText(text);
|
|
670 |
}
|
|
671 |
}
|
|
672 |
|
|
673 |
/**
|
|
674 |
* Show a dialog that lets the user select a file.
|
|
675 |
*
|
|
676 |
* @since 6.0
|
|
677 |
*/
|
|
678 |
protected String handleBrowseButtonSelected() {
|
|
679 |
FileDialog fileDialog = new FileDialog(getShell(), SWT.NONE);
|
|
680 |
fileDialog.setFileName(fProgText.getText());
|
|
681 |
return fileDialog.open();
|
|
682 |
}
|
|
683 |
|
|
684 |
/**
|
|
685 |
* Iterate through and suck up all of the executable files that we can find.
|
|
686 |
*/
|
|
687 |
protected IBinary[] getBinaryFiles(final ICProject cproject) {
|
|
688 |
final Display display;
|
|
689 |
if (cproject == null || !cproject.exists()) {
|
|
690 |
return null;
|
|
691 |
}
|
|
692 |
if (getShell() == null) {
|
|
693 |
display = LaunchUIPlugin.getShell().getDisplay();
|
|
694 |
} else {
|
|
695 |
display = getShell().getDisplay();
|
|
696 |
}
|
|
697 |
final Object[] ret = new Object[1];
|
|
698 |
BusyIndicator.showWhile(display, new Runnable() {
|
|
699 |
|
|
700 |
public void run() {
|
|
701 |
try {
|
|
702 |
ret[0] = cproject.getBinaryContainer().getBinaries();
|
|
703 |
} catch (CModelException e) {
|
|
704 |
LaunchUIPlugin.errorDialog("Launch UI internal error", e); //$NON-NLS-1$
|
|
705 |
}
|
|
706 |
}
|
|
707 |
});
|
|
708 |
|
|
709 |
return (IBinary[])ret[0];
|
|
710 |
}
|
|
711 |
|
|
712 |
/**
|
|
713 |
* Show a dialog that lets the user select a project. This in turn provides context for the main
|
|
714 |
* type, allowing the user to key a main type name, or constraining the search for main types to
|
|
715 |
* the specified project.
|
|
716 |
*/
|
|
717 |
protected void handleProjectButtonSelected() {
|
|
718 |
ICProject project = chooseCProject();
|
|
719 |
if (project == null) {
|
|
720 |
return;
|
|
721 |
}
|
|
722 |
|
|
723 |
String projectName = project.getElementName();
|
|
724 |
fProjText.setText(projectName);
|
|
725 |
}
|
|
726 |
|
|
727 |
/**
|
|
728 |
* Realize a C Project selection dialog and return the first selected project, or null if there
|
|
729 |
* was none.
|
|
730 |
*/
|
|
731 |
protected ICProject chooseCProject() {
|
|
732 |
try {
|
|
733 |
ICProject[] projects = getCProjects();
|
|
734 |
|
|
735 |
ILabelProvider labelProvider = new CElementLabelProvider();
|
|
736 |
ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider);
|
|
737 |
dialog.setTitle(LaunchMessages.getString("CMainTab.Project_Selection")); //$NON-NLS-1$
|
|
738 |
dialog.setMessage(LaunchMessages.getString("CMainTab.Choose_project_to_constrain_search_for_program")); //$NON-NLS-1$
|
|
739 |
dialog.setElements(projects);
|
|
740 |
|
|
741 |
ICProject cProject = getCProject();
|
|
742 |
if (cProject != null) {
|
|
743 |
dialog.setInitialSelections(new Object[]{cProject});
|
|
744 |
}
|
|
745 |
if (dialog.open() == Window.OK) {
|
|
746 |
return (ICProject)dialog.getFirstResult();
|
|
747 |
}
|
|
748 |
} catch (CModelException e) {
|
|
749 |
LaunchUIPlugin.errorDialog("Launch UI internal error", e); //$NON-NLS-1$
|
|
750 |
}
|
|
751 |
return null;
|
|
752 |
}
|
|
753 |
|
|
754 |
/**
|
|
755 |
* Return an array a ICProject whose platform match that of the runtime env.
|
|
756 |
*/
|
|
757 |
protected ICProject[] getCProjects() throws CModelException {
|
|
758 |
ICProject cproject[] = CoreModel.getDefault().getCModel().getCProjects();
|
|
759 |
List<ICProject> list = new ArrayList<ICProject>(cproject.length);
|
|
760 |
|
|
761 |
for (int i = 0; i < cproject.length; i++) {
|
|
762 |
ICDescriptor cdesciptor = null;
|
|
763 |
try {
|
|
764 |
cdesciptor = CCorePlugin.getDefault().getCProjectDescription((IProject)cproject[i].getResource(), false);
|
|
765 |
if (cdesciptor != null) {
|
|
766 |
String projectPlatform = cdesciptor.getPlatform();
|
|
767 |
if (filterPlatform.equals("*") //$NON-NLS-1$
|
|
768 |
|| projectPlatform.equals("*") //$NON-NLS-1$
|
|
769 |
|| filterPlatform.equalsIgnoreCase(projectPlatform) == true) {
|
|
770 |
list.add(cproject[i]);
|
|
771 |
}
|
|
772 |
} else {
|
|
773 |
list.add(cproject[i]);
|
|
774 |
}
|
|
775 |
} catch (CoreException e) {
|
|
776 |
list.add(cproject[i]);
|
|
777 |
}
|
|
778 |
}
|
|
779 |
return list.toArray(new ICProject[list.size()]);
|
|
780 |
}
|
|
781 |
|
|
782 |
/**
|
|
783 |
* Return the ICProject corresponding to the project name in the project name text field, or
|
|
784 |
* null if the text does not match a project name.
|
|
785 |
*/
|
|
786 |
protected ICProject getCProject() {
|
|
787 |
String projectName = fProjText.getText().trim();
|
|
788 |
if (projectName.length() < 1) {
|
|
789 |
return null;
|
|
790 |
}
|
|
791 |
return CoreModel.getDefault().getCModel().getCProject(projectName);
|
|
792 |
}
|
|
793 |
|
|
794 |
/*
|
|
795 |
* (non-Javadoc)
|
|
796 |
*
|
|
797 |
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
|
|
798 |
*/
|
|
799 |
@Override
|
|
800 |
public boolean isValid(ILaunchConfiguration config) {
|
|
801 |
|
|
802 |
setErrorMessage(null);
|
|
803 |
setMessage(null);
|
|
804 |
|
|
805 |
if (!dontCheckProgram) {
|
|
806 |
|
|
807 |
String name = fProjText.getText().trim();
|
|
808 |
if (name.length() == 0) {
|
|
809 |
setErrorMessage(LaunchMessages.getString("CMainTab.Project_not_specified")); //$NON-NLS-1$
|
|
810 |
return false;
|
|
811 |
}
|
|
812 |
if (!ResourcesPlugin.getWorkspace().getRoot().getProject(name).exists()) {
|
|
813 |
setErrorMessage(LaunchMessages.getString("Launch.common.Project_does_not_exist")); //$NON-NLS-1$
|
|
814 |
return false;
|
|
815 |
}
|
|
816 |
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
|
|
817 |
if (!project.isOpen()) {
|
|
818 |
setErrorMessage(LaunchMessages.getString("CMainTab.Project_must_be_opened")); //$NON-NLS-1$
|
|
819 |
return false;
|
|
820 |
}
|
|
821 |
|
|
822 |
name = fProgText.getText().trim();
|
|
823 |
if (name.length() == 0) {
|
|
824 |
setErrorMessage(LaunchMessages.getString("CMainTab.Program_not_specified")); //$NON-NLS-1$
|
|
825 |
return false;
|
|
826 |
}
|
|
827 |
if (name.equals(".") || name.equals("..")) { //$NON-NLS-1$ //$NON-NLS-2$
|
|
828 |
setErrorMessage(LaunchMessages.getString("CMainTab.Program_does_not_exist")); //$NON-NLS-1$
|
|
829 |
return false;
|
|
830 |
}
|
|
831 |
IPath exePath = new Path(name);
|
|
832 |
if (!exePath.isAbsolute()) {
|
|
833 |
IPath location = project.getLocation();
|
|
834 |
if (location == null) {
|
|
835 |
setErrorMessage(LaunchMessages.getString("CMainTab.Program_does_not_exist")); //$NON-NLS-1$
|
|
836 |
return false;
|
|
837 |
}
|
|
838 |
|
|
839 |
exePath = location.append(name);
|
|
840 |
if (!exePath.toFile().exists()) {
|
|
841 |
// Try the old way, which is required to support linked resources.
|
|
842 |
IFile projFile = null;
|
|
843 |
try {
|
|
844 |
projFile = project.getFile(name);
|
|
845 |
}
|
|
846 |
catch (IllegalArgumentException exc) {} // thrown if relative path that resolves to a root file ("..\somefile")
|
|
847 |
if (projFile == null || !projFile.exists()) {
|
|
848 |
setErrorMessage(LaunchMessages.getString("CMainTab.Program_does_not_exist")); //$NON-NLS-1$
|
|
849 |
return false;
|
|
850 |
}
|
|
851 |
else {
|
|
852 |
exePath = projFile.getLocation();
|
|
853 |
}
|
|
854 |
}
|
|
855 |
}
|
|
856 |
if (!exePath.toFile().exists()) {
|
|
857 |
setErrorMessage(LaunchMessages.getString("CMainTab.Program_does_not_exist")); //$NON-NLS-1$
|
|
858 |
return false;
|
|
859 |
}
|
|
860 |
try {
|
|
861 |
if (!isBinary(project, exePath)) {
|
|
862 |
setErrorMessage(LaunchMessages.getString("CMainTab.Program_is_not_a_recongnized_executable")); //$NON-NLS-1$
|
|
863 |
return false;
|
|
864 |
}
|
|
865 |
} catch (CoreException e) {
|
|
866 |
LaunchUIPlugin.log(e);
|
|
867 |
setErrorMessage(e.getLocalizedMessage());
|
|
868 |
return false;
|
|
869 |
}
|
|
870 |
}
|
|
871 |
|
|
872 |
if (fCoreText != null) {
|
|
873 |
String coreName = fCoreText.getText().trim();
|
|
874 |
// We accept an empty string. This should trigger a prompt to the user
|
|
875 |
// This allows to re-use the launch, with a different core file.
|
|
876 |
if (!coreName.equals(EMPTY_STRING)) {
|
|
877 |
if (coreName.equals(".") || coreName.equals("..")) { //$NON-NLS-1$ //$NON-NLS-2$
|
|
878 |
setErrorMessage(LaunchMessages.getString("CMainTab.Core_does_not_exist")); //$NON-NLS-1$
|
|
879 |
return false;
|
|
880 |
}
|
|
881 |
IPath corePath = new Path(coreName);
|
|
882 |
if (!corePath.toFile().exists()) {
|
|
883 |
setErrorMessage(LaunchMessages.getString("CMainTab.Core_does_not_exist")); //$NON-NLS-1$
|
|
884 |
return false;
|
|
885 |
}
|
|
886 |
}
|
|
887 |
}
|
|
888 |
|
|
889 |
return true;
|
|
890 |
}
|
|
891 |
|
|
892 |
/**
|
|
893 |
* @param project
|
|
894 |
* @param exePath
|
|
895 |
* @return
|
|
896 |
* @throws CoreException
|
|
897 |
*/
|
|
898 |
protected boolean isBinary(IProject project, IPath exePath) throws CoreException {
|
|
899 |
try {
|
|
900 |
Boolean binValue = fBinaryExeCache.get(exePath);
|
|
901 |
if (binValue == null)
|
|
902 |
{
|
|
903 |
IBinaryObject exe = LaunchUtils.getBinary(project, exePath);
|
|
904 |
binValue = exe != null;
|
|
905 |
fBinaryExeCache.put(exePath, binValue);
|
|
906 |
}
|
|
907 |
return binValue;
|
|
908 |
} catch (ClassCastException e) {
|
|
909 |
}
|
|
910 |
return false;
|
|
911 |
}
|
|
912 |
/*
|
|
913 |
* (non-Javadoc)
|
|
914 |
*
|
|
915 |
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
|
|
916 |
*/
|
|
917 |
public void setDefaults(ILaunchConfigurationWorkingCopy config) {
|
|
918 |
|
|
919 |
// Workaround for bug 262840: select the standard CDT launcher by default.
|
|
920 |
HashSet<String> set = new HashSet<String>();
|
|
921 |
set.add(getLaunchConfigurationDialog().getMode());
|
|
922 |
try {
|
|
923 |
ILaunchDelegate preferredDelegate = config.getPreferredDelegate(set);
|
|
924 |
if (preferredDelegate == null) {
|
|
925 |
if (config.getType().getIdentifier().equals(ICDTLaunchConfigurationConstants.ID_LAUNCH_C_APP)) {
|
|
926 |
config.setPreferredLaunchDelegate(set, "org.eclipse.cdt.cdi.launch.localCLaunch");
|
|
927 |
} else if (config.getType().getIdentifier().equals(ICDTLaunchConfigurationConstants.ID_LAUNCH_C_ATTACH)) {
|
|
928 |
config.setPreferredLaunchDelegate(set, "org.eclipse.cdt.cdi.launch.localCAttachLaunch");
|
|
929 |
} else if (config.getType().getIdentifier().equals(ICDTLaunchConfigurationConstants.ID_LAUNCH_C_POST_MORTEM)) {
|
|
930 |
config.setPreferredLaunchDelegate(set, "org.eclipse.cdt.cdi.launch.coreFileCLaunch");
|
|
931 |
}
|
|
932 |
}
|
|
933 |
} catch (CoreException e) {}
|
|
934 |
|
|
935 |
// We set empty attributes for project & program so that when one config
|
|
936 |
// is
|
|
937 |
// compared to another, the existence of empty attributes doesn't cause
|
|
938 |
// an
|
|
939 |
// incorrect result (the performApply() method can result in empty
|
|
940 |
// values
|
|
941 |
// for these attributes being set on a config if there is nothing in the
|
|
942 |
// corresponding text boxes)
|
|
943 |
// plus getContext will use this to base context from if set.
|
|
944 |
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, EMPTY_STRING);
|
|
945 |
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, EMPTY_STRING);
|
|
946 |
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_COREFILE_PATH, EMPTY_STRING);
|
|
947 |
|
|
948 |
ICElement cElement = null;
|
|
949 |
cElement = getContext(config, getPlatform(config));
|
|
950 |
if (cElement != null) {
|
|
951 |
initializeCProject(cElement, config);
|
|
952 |
initializeProgramName(cElement, config);
|
|
953 |
} else {
|
|
954 |
// don't want to remember the interim value from before
|
|
955 |
config.setMappedResources(null);
|
|
956 |
}
|
|
957 |
if (wantsTerminalOption()) {
|
|
958 |
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL, ICDTLaunchConfigurationConstants.USE_TERMINAL_DEFAULT);
|
|
959 |
}
|
|
960 |
}
|
|
961 |
|
|
962 |
/**
|
|
963 |
* Set the program name attributes on the working copy based on the ICElement
|
|
964 |
*/
|
|
965 |
protected void initializeProgramName(ICElement cElement, ILaunchConfigurationWorkingCopy config) {
|
|
966 |
|
|
967 |
boolean renamed = false;
|
|
968 |
|
|
969 |
if (!(cElement instanceof IBinary))
|
|
970 |
{
|
|
971 |
cElement = cElement.getCProject();
|
|
972 |
}
|
|
973 |
|
|
974 |
if (cElement instanceof ICProject) {
|
|
975 |
|
|
976 |
IProject project = cElement.getCProject().getProject();
|
|
977 |
String name = project.getName();
|
|
978 |
ICProjectDescription projDes = CCorePlugin.getDefault().getProjectDescription(project);
|
|
979 |
if (projDes != null) {
|
|
980 |
String buildConfigName = projDes.getActiveConfiguration().getName();
|
|
981 |
//bug 234951
|
|
982 |
name = LaunchMessages.getFormattedString("CMainTab.Configuration_name", new String[]{name, buildConfigName}); //$NON-NLS-1$
|
|
983 |
}
|
|
984 |
name = getLaunchConfigurationDialog().generateName(name);
|
|
985 |
config.rename(name);
|
|
986 |
renamed = true;
|
|
987 |
}
|
|
988 |
|
|
989 |
IBinary binary = null;
|
|
990 |
if (cElement instanceof ICProject) {
|
|
991 |
IBinary[] bins = getBinaryFiles((ICProject)cElement);
|
|
992 |
if (bins != null && bins.length == 1) {
|
|
993 |
binary = bins[0];
|
|
994 |
}
|
|
995 |
} else if (cElement instanceof IBinary) {
|
|
996 |
binary = (IBinary)cElement;
|
|
997 |
}
|
|
998 |
|
|
999 |
if (binary != null) {
|
|
1000 |
String path;
|
|
1001 |
path = binary.getResource().getProjectRelativePath().toOSString();
|
|
1002 |
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, path);
|
|
1003 |
if (!renamed)
|
|
1004 |
{
|
|
1005 |
String name = binary.getElementName();
|
|
1006 |
int index = name.lastIndexOf('.');
|
|
1007 |
if (index > 0) {
|
|
1008 |
name = name.substring(0, index);
|
|
1009 |
}
|
|
1010 |
name = getLaunchConfigurationDialog().generateName(name);
|
|
1011 |
config.rename(name);
|
|
1012 |
renamed = true;
|
|
1013 |
}
|
|
1014 |
}
|
|
1015 |
|
|
1016 |
if (!renamed)
|
|
1017 |
{
|
|
1018 |
String name = getLaunchConfigurationDialog().generateName(cElement.getCProject().getElementName());
|
|
1019 |
config.rename(name);
|
|
1020 |
}
|
|
1021 |
}
|
|
1022 |
|
|
1023 |
@Override
|
|
1024 |
public String getId() {
|
|
1025 |
return TAB_ID;
|
|
1026 |
}
|
|
1027 |
|
|
1028 |
|
|
1029 |
/*
|
|
1030 |
* (non-Javadoc)
|
|
1031 |
*
|
|
1032 |
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
|
|
1033 |
*/
|
|
1034 |
public String getName() {
|
|
1035 |
return LaunchMessages.getString("CMainTab.Main"); //$NON-NLS-1$
|
|
1036 |
}
|
|
1037 |
|
|
1038 |
/*
|
|
1039 |
* (non-Javadoc)
|
|
1040 |
*
|
|
1041 |
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
|
|
1042 |
*/
|
|
1043 |
@Override
|
|
1044 |
public Image getImage() {
|
|
1045 |
return LaunchImages.get(LaunchImages.IMG_VIEW_MAIN_TAB);
|
|
1046 |
}
|
|
1047 |
|
|
1048 |
/*
|
|
1049 |
* (non-Javadoc)
|
|
1050 |
*
|
|
1051 |
* @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#updateLaunchConfigurationDialog()
|
|
1052 |
*/
|
|
1053 |
@Override
|
|
1054 |
protected void updateLaunchConfigurationDialog() {
|
|
1055 |
super.updateLaunchConfigurationDialog();
|
|
1056 |
}
|
|
1057 |
}
|