1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 06:02:11 +02:00

Have CAbstractMainTab share the common portions of CDI CMainTab and DSF CMainTab.

This commit is contained in:
Ken Ryall 2010-03-09 05:26:19 +00:00
parent 06c10e1f7e
commit 86224bcfa0
3 changed files with 645 additions and 842 deletions

View file

@ -11,16 +11,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.dsf.gdb.internal.ui.launching; package org.eclipse.cdt.dsf.gdb.internal.ui.launching;
import java.io.IOException;
import java.util.ArrayList;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
@ -28,6 +19,7 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin; import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin;
import org.eclipse.cdt.dsf.gdb.launching.LaunchMessages; import org.eclipse.cdt.dsf.gdb.launching.LaunchMessages;
import org.eclipse.cdt.launch.ui.CAbstractMainTab;
import org.eclipse.cdt.ui.CElementLabelProvider; import org.eclipse.cdt.ui.CElementLabelProvider;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
@ -43,7 +35,6 @@ import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.window.Window; import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
@ -53,11 +44,8 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
import org.eclipse.ui.dialogs.TwoPaneElementSelector; import org.eclipse.ui.dialogs.TwoPaneElementSelector;
/** /**
@ -68,7 +56,7 @@ import org.eclipse.ui.dialogs.TwoPaneElementSelector;
* </p> * </p>
*/ */
public class CMainTab extends CLaunchConfigurationTab { public class CMainTab extends CAbstractMainTab {
/** /**
* Tab identifier used for ordering of tabs added using the * Tab identifier used for ordering of tabs added using the
@ -79,41 +67,22 @@ public class CMainTab extends CLaunchConfigurationTab {
*/ */
public static final String TAB_ID = "org.eclipse.cdt.dsf.gdb.launch.mainTab"; //$NON-NLS-1$ public static final String TAB_ID = "org.eclipse.cdt.dsf.gdb.launch.mainTab"; //$NON-NLS-1$
// Project UI widgets
protected Label fProjLabel;
protected Text fProjText;
protected Button fProjButton;
// Main class UI widgets
protected Label fProgLabel;
protected Text fProgText;
protected Button fSearchButton;
// Core file UI widgets
/** @since 2.0 */
protected Label fCoreLabel;
/** @since 2.0 */
protected Text fCoreText;
/** @since 2.0 */
protected Button fCoreButton;
private final boolean fDontCheckProgram; private final boolean fDontCheckProgram;
private final boolean fSpecifyCoreFile; private final boolean fSpecifyCoreFile;
private final boolean fIncludeBuildSettings;
protected static final String EMPTY_STRING = ""; //$NON-NLS-1$
private String filterPlatform = EMPTY_STRING;
public static final int DONT_CHECK_PROGRAM = 2; public static final int DONT_CHECK_PROGRAM = 2;
public static final int SPECIFY_CORE_FILE = 4; public static final int SPECIFY_CORE_FILE = 4;
public static final int INCLUDE_BUILD_SETTINGS = 8;
public CMainTab() { public CMainTab() {
this(0); this(INCLUDE_BUILD_SETTINGS);
} }
public CMainTab(int flags) { public CMainTab(int flags) {
fDontCheckProgram = (flags & DONT_CHECK_PROGRAM) != 0; fDontCheckProgram = (flags & DONT_CHECK_PROGRAM) != 0;
fSpecifyCoreFile = (flags & SPECIFY_CORE_FILE) != 0; fSpecifyCoreFile = (flags & SPECIFY_CORE_FILE) != 0;
fIncludeBuildSettings = (flags & INCLUDE_BUILD_SETTINGS) != 0;
} }
/* /*
@ -137,48 +106,13 @@ public class CMainTab extends CLaunchConfigurationTab {
if (fSpecifyCoreFile) { if (fSpecifyCoreFile) {
createCoreFileGroup(comp, 1); createCoreFileGroup(comp, 1);
} }
if (fIncludeBuildSettings){
createBuildOptionGroup(comp, 1);
}
GdbUIPlugin.setDialogShell(parent.getShell()); GdbUIPlugin.setDialogShell(parent.getShell());
} }
protected void createProjectGroup(Composite parent, int colSpan) {
Composite projComp = new Composite(parent, SWT.NONE);
GridLayout projLayout = new GridLayout();
projLayout.numColumns = 2;
projLayout.marginHeight = 0;
projLayout.marginWidth = 0;
projComp.setLayout(projLayout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = colSpan;
projComp.setLayoutData(gd);
fProjLabel = new Label(projComp, SWT.NONE);
fProjLabel.setText(LaunchMessages.getString("CMainTab.&ProjectColon")); //$NON-NLS-1$
gd = new GridData();
gd.horizontalSpan = 2;
fProjLabel.setLayoutData(gd);
fProjText = new Text(projComp, SWT.SINGLE | SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL);
fProjText.setLayoutData(gd);
fProjText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent evt) {
updateLaunchConfigurationDialog();
}
});
fProjButton = createPushButton(projComp, LaunchMessages.getString("Launch.common.Browse_1"), null); //$NON-NLS-1$
fProjButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent evt) {
handleProjectButtonSelected();
updateLaunchConfigurationDialog();
}
});
}
protected void createExeFileGroup(Composite parent, int colSpan) { protected void createExeFileGroup(Composite parent, int colSpan) {
Composite mainComp = new Composite(parent, SWT.NONE); Composite mainComp = new Composite(parent, SWT.NONE);
GridLayout mainLayout = new GridLayout(); GridLayout mainLayout = new GridLayout();
@ -225,45 +159,6 @@ public class CMainTab extends CLaunchConfigurationTab {
} }
}); });
} }
/** @since 2.0 */
protected void createCoreFileGroup(Composite parent, int colSpan) {
Composite coreComp = new Composite(parent, SWT.NONE);
GridLayout coreLayout = new GridLayout();
coreLayout.numColumns = 3;
coreLayout.marginHeight = 0;
coreLayout.marginWidth = 0;
coreComp.setLayout(coreLayout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = colSpan;
coreComp.setLayoutData(gd);
fCoreLabel = new Label(coreComp, SWT.NONE);
fCoreLabel.setText(LaunchMessages.getString("CMainTab.CoreFile_path")); //$NON-NLS-1$
gd = new GridData();
gd.horizontalSpan = 3;
fCoreLabel.setLayoutData(gd);
fCoreText = new Text(coreComp, SWT.SINGLE | SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL);
fCoreText.setLayoutData(gd);
fCoreText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent evt) {
updateLaunchConfigurationDialog();
}
});
Button browseForCoreButton;
browseForCoreButton = createPushButton(coreComp, LaunchMessages.getString("Launch.common.Browse_2"), null); //$NON-NLS-1$
browseForCoreButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent evt) {
String text = handleBrowseButtonSelected();
if (text != null) {
fCoreText.setText(text);
}
updateLaunchConfigurationDialog();
}
});
}
/* /*
* (non-Javadoc) * (non-Javadoc)
@ -275,26 +170,7 @@ public class CMainTab extends CLaunchConfigurationTab {
updateProjectFromConfig(config); updateProjectFromConfig(config);
updateProgramFromConfig(config); updateProgramFromConfig(config);
updateCoreFromConfig(config); updateCoreFromConfig(config);
} updateBuildOptionFromConfig(config);
protected void updateProjectFromConfig(ILaunchConfiguration config) {
String projectName = EMPTY_STRING;
try {
projectName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, EMPTY_STRING);
} catch (CoreException ce) {
GdbUIPlugin.log(ce);
}
fProjText.setText(projectName);
}
protected void updateProgramFromConfig(ILaunchConfiguration config) {
String programName = EMPTY_STRING;
try {
programName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, EMPTY_STRING);
} catch (CoreException ce) {
GdbUIPlugin.log(ce);
}
fProgText.setText(programName);
} }
/** @since 2.0 */ /** @since 2.0 */
@ -315,22 +191,13 @@ public class CMainTab extends CLaunchConfigurationTab {
* *
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
*/ */
@Override
public void performApply(ILaunchConfigurationWorkingCopy config) { public void performApply(ILaunchConfigurationWorkingCopy config) {
super.performApply(config);
ICProject cProject = this.getCProject(); ICProject cProject = this.getCProject();
if (cProject != null && cProject.exists()) if (cProject != null && cProject.exists())
{ {
config.setMappedResources(new IResource[] { cProject.getProject() }); config.setMappedResources(new IResource[] { cProject.getProject() });
try { // Only initialize the build config ID once.
if (config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, "").length() == 0)//$NON-NLS-1$
{
ICProjectDescription projDes = CCorePlugin.getDefault().getProjectDescription(cProject.getProject());
if (projDes != null)
{
String buildConfigID = projDes.getActiveConfiguration().getId();
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, buildConfigID);
}
}
} catch (CoreException e) { e.printStackTrace(); }
} else { } else {
config.setMappedResources(null); config.setMappedResources(null);
} }
@ -345,6 +212,7 @@ public class CMainTab extends CLaunchConfigurationTab {
/** /**
* Show a dialog that lists all main types * Show a dialog that lists all main types
*/ */
@Override
protected void handleSearchButtonSelected() { protected void handleSearchButtonSelected() {
if (getCProject() == null) { if (getCProject() == null) {
@ -415,135 +283,6 @@ public class CMainTab extends CLaunchConfigurationTab {
} }
/**
* Show a dialog that lets the user select a file.
*/
protected String handleBrowseButtonSelected() {
FileDialog fileDialog = new FileDialog(getShell(), SWT.NONE);
fileDialog.setFileName(fProgText.getText());
return fileDialog.open();
}
/**
* Iterate through and suck up all of the executable files that we can find.
*/
protected IBinary[] getBinaryFiles(final ICProject cproject) {
final Display display;
if (cproject == null || !cproject.exists()) {
return null;
}
if (getShell() == null) {
display = GdbUIPlugin.getShell().getDisplay();
} else {
display = getShell().getDisplay();
}
final Object[] ret = new Object[1];
BusyIndicator.showWhile(display, new Runnable() {
public void run() {
try {
ret[0] = cproject.getBinaryContainer().getBinaries();
} catch (CModelException e) {
GdbUIPlugin.errorDialog("Launch UI internal error", e); //$NON-NLS-1$
}
}
});
return (IBinary[])ret[0];
}
/**
* Show a dialog that lets the user select a project. This in turn provides context for the main
* type, allowing the user to key a main type name, or constraining the search for main types to
* the specified project.
*/
protected void handleProjectButtonSelected() {
String currentProjectName = fProjText.getText();
ICProject project = chooseCProject();
if (project == null) {
return;
}
String projectName = project.getElementName();
fProjText.setText(projectName);
if (currentProjectName.length() == 0)
{
// New project selected for the first time, set the program name default too.
IBinary[] bins = getBinaryFiles(project);
if (bins != null && bins.length == 1) {
fProgText.setText(bins[0].getResource().getProjectRelativePath().toOSString());
}
}
}
/**
* Realize a C Project selection dialog and return the first selected project, or null if there
* was none.
*/
protected ICProject chooseCProject() {
try {
ICProject[] projects = getCProjects();
ILabelProvider labelProvider = new CElementLabelProvider();
ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider);
dialog.setTitle(LaunchMessages.getString("CMainTab.Project_Selection")); //$NON-NLS-1$
dialog.setMessage(LaunchMessages.getString("CMainTab.Choose_project_to_constrain_search_for_program")); //$NON-NLS-1$
dialog.setElements(projects);
ICProject cProject = getCProject();
if (cProject != null) {
dialog.setInitialSelections(new Object[]{cProject});
}
if (dialog.open() == Window.OK) {
return (ICProject)dialog.getFirstResult();
}
} catch (CModelException e) {
GdbUIPlugin.errorDialog("Launch UI internal error", e); //$NON-NLS-1$
}
return null;
}
/**
* Return an array a ICProject whose platform match that of the runtime env.
*/
protected ICProject[] getCProjects() throws CModelException {
ICProject cproject[] = CoreModel.getDefault().getCModel().getCProjects();
ArrayList<ICProject> list = new ArrayList<ICProject>(cproject.length);
for (int i = 0; i < cproject.length; i++) {
ICDescriptor cdesciptor = null;
try {
cdesciptor = CCorePlugin.getDefault().getCProjectDescription((IProject)cproject[i].getResource(), false);
if (cdesciptor != null) {
String projectPlatform = cdesciptor.getPlatform();
if (filterPlatform.equals("*") //$NON-NLS-1$
|| projectPlatform.equals("*") //$NON-NLS-1$
|| filterPlatform.equalsIgnoreCase(projectPlatform) == true) {
list.add(cproject[i]);
}
} else {
list.add(cproject[i]);
}
} catch (CoreException e) {
list.add(cproject[i]);
}
}
return list.toArray(new ICProject[list.size()]);
}
/**
* Return the ICProject corresponding to the project name in the project name text field, or
* null if the text does not match a project name.
*/
protected ICProject getCProject() {
String projectName = fProjText.getText().trim();
if (projectName.length() < 1) {
return null;
}
return CoreModel.getDefault().getCModel().getCProject(projectName);
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -625,34 +364,6 @@ public class CMainTab extends CLaunchConfigurationTab {
return true; return true;
} }
/**
* @param project
* @param exePath
* @return
* @throws CoreException
*/
protected boolean isBinary(IProject project, IPath exePath) throws CoreException {
ICExtensionReference[] parserRef = CCorePlugin.getDefault().getBinaryParserExtensions(project);
for (int i = 0; i < parserRef.length; i++) {
try {
IBinaryParser parser = (IBinaryParser)parserRef[i].createExtension();
IBinaryObject exe = (IBinaryObject)parser.getBinary(exePath);
if (exe != null) {
return true;
}
} catch (ClassCastException e) {
} catch (IOException e) {
}
}
IBinaryParser parser = CCorePlugin.getDefault().getDefaultBinaryParser();
try {
IBinaryObject exe = (IBinaryObject)parser.getBinary(exePath);
return exe != null;
} catch (ClassCastException e) {
} catch (IOException e) {
}
return false;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -666,6 +377,7 @@ public class CMainTab extends CLaunchConfigurationTab {
// corresponding text boxes) // corresponding text boxes)
// plus getContext will use this to base context from if set. // plus getContext will use this to base context from if set.
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, EMPTY_STRING); config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, EMPTY_STRING);
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, EMPTY_STRING);
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_COREFILE_PATH, EMPTY_STRING); config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_COREFILE_PATH, EMPTY_STRING);
ICElement cElement = null; ICElement cElement = null;
@ -763,13 +475,4 @@ public class CMainTab extends CLaunchConfigurationTab {
return LaunchImages.get(LaunchImages.IMG_VIEW_MAIN_TAB); return LaunchImages.get(LaunchImages.IMG_VIEW_MAIN_TAB);
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#updateLaunchConfigurationDialog()
*/
@Override
protected void updateLaunchConfigurationDialog() {
super.updateLaunchConfigurationDialog();
}
} }

View file

@ -0,0 +1,540 @@
package org.eclipse.cdt.launch.ui;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.launch.LaunchUtils;
import org.eclipse.cdt.launch.internal.ui.LaunchMessages;
import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
import org.eclipse.cdt.ui.CElementLabelProvider;
import org.eclipse.cdt.ui.newui.CDTPropertyManager;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
import org.eclipse.ui.dialogs.PreferencesUtil;
/**
* @since 6.1
*/
public abstract class CAbstractMainTab extends CLaunchConfigurationTab {
protected static final String EMPTY_STRING = ""; //$NON-NLS-1$
protected String filterPlatform = EMPTY_STRING;
/**
* @since 6.0
*/
protected Combo fBuildConfigCombo;
/** @since 6.1 */
protected Button fDisableBuildButton;
/** @since 6.1 */
protected Button fEnableBuildButton;
/** @since 6.1 */
protected Button fWorkspaceSettingsButton;
/** @since 6.1 */
protected Link fWorkpsaceSettingsLink;
protected final Map<IPath, Boolean> fBinaryExeCache = new HashMap<IPath, Boolean>();
protected Label fProjLabel;
protected Text fProjText;
protected Button fProjButton;
protected Label fProgLabel;
protected Text fProgText;
protected Button fSearchButton;
// Core file UI widgets
/** @since 2.0 */
protected Label fCoreLabel;
/** @since 2.0 */
protected Text fCoreText;
/** @since 2.0 */
protected Button fCoreButton;
/**
* Name of most recently checked program; avoid constantly checking binary.
* See bug 277663.
*/
protected String fPreviouslyCheckedProgram;
/**
* Validity result of most recently checked program; avoid constantly
* checking binary. See bug 277663. N/A if fPreviouslyCheckedProgram = null;
*/
protected boolean fPreviouslyCheckedProgramIsValid;
/**
* Validity error message of most recently checked program; avoid constantly
* checking binary. See bug 277663. N/A if fPreviouslyCheckedProgram = null.
*/
protected String fPreviouslyCheckedProgramErrorMsg;
public CAbstractMainTab() {
super();
}
abstract protected void handleSearchButtonSelected();
/**
* @since 6.0
*/
protected void createProjectGroup(Composite parent, int colSpan) {
Composite projComp = new Composite(parent, SWT.NONE);
GridLayout projLayout = new GridLayout();
projLayout.numColumns = 2;
projLayout.marginHeight = 0;
projLayout.marginWidth = 0;
projComp.setLayout(projLayout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = colSpan;
projComp.setLayoutData(gd);
fProjLabel = new Label(projComp, SWT.NONE);
fProjLabel.setText(LaunchMessages.getString("CMainTab.&ProjectColon")); //$NON-NLS-1$
gd = new GridData();
gd.horizontalSpan = 2;
fProjLabel.setLayoutData(gd);
fProjText = new Text(projComp, SWT.SINGLE | SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL);
fProjText.setLayoutData(gd);
fProjText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent evt) {
// if project changes, invalidate program name cache
fPreviouslyCheckedProgram = null;
updateBuildConfigCombo(""); //$NON-NLS-1$
updateLaunchConfigurationDialog();
}
});
fProjButton = createPushButton(projComp, LaunchMessages.getString("Launch.common.Browse_1"), null); //$NON-NLS-1$
fProjButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent evt) {
handleProjectButtonSelected();
updateLaunchConfigurationDialog();
}
});
}
/**
* Return the ICProject corresponding to the project name in the project name text field, or
* null if the text does not match a project name.
*/
protected ICProject getCProject() {
String projectName = fProjText.getText().trim();
if (projectName.length() < 1) {
return null;
}
return CoreModel.getDefault().getCModel().getCProject(projectName);
}
/**
* Show a dialog that lets the user select a project. This in turn provides context for the main
* type, allowing the user to key a main type name, or constraining the search for main types to
* the specified project.
*/
protected void handleProjectButtonSelected() {
String currentProjectName = fProjText.getText();
ICProject project = chooseCProject();
if (project == null) {
return;
}
String projectName = project.getElementName();
fProjText.setText(projectName);
if (currentProjectName.length() == 0)
{
// New project selected for the first time, set the program name default too.
IBinary[] bins = getBinaryFiles(project);
if (bins != null && bins.length == 1) {
fProgText.setText(bins[0].getResource().getProjectRelativePath().toOSString());
}
}
}
/**
* Return an array a ICProject whose platform match that of the runtime env.
*/
protected ICProject[] getCProjects() throws CModelException {
ICProject cproject[] = CoreModel.getDefault().getCModel().getCProjects();
ArrayList<ICProject> list = new ArrayList<ICProject>(cproject.length);
for (int i = 0; i < cproject.length; i++) {
ICDescriptor cdesciptor = null;
try {
cdesciptor = CCorePlugin.getDefault().getCProjectDescription((IProject)cproject[i].getResource(), false);
if (cdesciptor != null) {
String projectPlatform = cdesciptor.getPlatform();
if (filterPlatform.equals("*") //$NON-NLS-1$
|| projectPlatform.equals("*") //$NON-NLS-1$
|| filterPlatform.equalsIgnoreCase(projectPlatform) == true) {
list.add(cproject[i]);
}
} else {
list.add(cproject[i]);
}
} catch (CoreException e) {
list.add(cproject[i]);
}
}
return list.toArray(new ICProject[list.size()]);
}
/**
* Realize a C Project selection dialog and return the first selected project, or null if there
* was none.
*/
protected ICProject chooseCProject() {
try {
ICProject[] projects = getCProjects();
ILabelProvider labelProvider = new CElementLabelProvider();
ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider);
dialog.setTitle(LaunchMessages.getString("CMainTab.Project_Selection")); //$NON-NLS-1$
dialog.setMessage(LaunchMessages.getString("CMainTab.Choose_project_to_constrain_search_for_program")); //$NON-NLS-1$
dialog.setElements(projects);
ICProject cProject = getCProject();
if (cProject != null) {
dialog.setInitialSelections(new Object[]{cProject});
}
if (dialog.open() == Window.OK) {
return (ICProject)dialog.getFirstResult();
}
} catch (CModelException e) {
LaunchUIPlugin.errorDialog("Launch UI internal error", e); //$NON-NLS-1$
}
return null;
}
/**
* @since 6.0
*/
protected void updateBuildConfigCombo(String selectedConfigID) {
if (fBuildConfigCombo != null)
{
fBuildConfigCombo.removeAll();
fBuildConfigCombo.add(LaunchMessages.getString("CMainTab.Use_Active")); //$NON-NLS-1$
fBuildConfigCombo.setData("0", ""); //$NON-NLS-1$ //$NON-NLS-2$
fBuildConfigCombo.select(0);
ICProject cproject = getCProject();
if (cproject != null){
ICProjectDescription projDes = CDTPropertyManager.getProjectDescription(cproject.getProject());
if (projDes != null)
{
int selIndex = 0;
ICConfigurationDescription[] configurations = projDes.getConfigurations();
ICConfigurationDescription selectedConfig = projDes.getConfigurationById(selectedConfigID);
for (int i = 0; i < configurations.length; i++) {
String configName = configurations[i].getName();
fBuildConfigCombo.add(configName);
fBuildConfigCombo.setData(Integer.toString(i + 1), configurations[i].getId());
if (selectedConfig != null && selectedConfigID.equals(configurations[i].getId()))
selIndex = i + 1;
}
fBuildConfigCombo.select(selIndex);
}
}
}
}
/**
* @since 6.0
*/
protected void createBuildConfigCombo(Composite parent, int colspan) {
Composite comboComp = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
comboComp.setLayout(layout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = colspan;
comboComp.setLayoutData(gd);
Label dlabel = new Label(comboComp, SWT.NONE);
dlabel.setText(LaunchMessages.getString("CMainTab.Build_Config")); //$NON-NLS-1$
fBuildConfigCombo = new Combo(comboComp, SWT.READ_ONLY | SWT.DROP_DOWN);
fBuildConfigCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fBuildConfigCombo.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
updateLaunchConfigurationDialog();
}
public void widgetDefaultSelected(SelectionEvent e) {
updateLaunchConfigurationDialog();
}
});
}
/** @since 6.1 */
protected void createBuildOptionGroup(final Composite parent, int colSpan) {
Group buildGroup = new Group(parent, SWT.NONE);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = colSpan;
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
gridLayout.marginHeight = 5;
gridLayout.marginWidth = 5;
gridLayout.makeColumnsEqualWidth= true;
buildGroup.setLayoutData(gridData);
buildGroup.setLayout(gridLayout);
buildGroup.setText(LaunchMessages.getString("CMainTab.Build_options")); //$NON-NLS-1$
createBuildConfigCombo(buildGroup, 2);
fEnableBuildButton = new Button(buildGroup, SWT.RADIO);
fEnableBuildButton.setText(LaunchMessages.getString("CMainTab.Enable_build_button_label")); //$NON-NLS-1$
fEnableBuildButton.setToolTipText(LaunchMessages.getString("CMainTab.Enable_build_button_tooltip")); //$NON-NLS-1$
fEnableBuildButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
updateLaunchConfigurationDialog();
}
});
fDisableBuildButton = new Button(buildGroup, SWT.RADIO);
fDisableBuildButton.setText(LaunchMessages.getString("CMainTab.Disable_build_button_label")); //$NON-NLS-1$
fDisableBuildButton.setToolTipText(LaunchMessages.getString("CMainTab.Disable_build_button_tooltip")); //$NON-NLS-1$
fDisableBuildButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
updateLaunchConfigurationDialog();
}
});
fWorkspaceSettingsButton = new Button(buildGroup, SWT.RADIO);
fWorkspaceSettingsButton.setText(LaunchMessages.getString("CMainTab.Workspace_settings_button_label")); //$NON-NLS-1$
fWorkspaceSettingsButton.setToolTipText(LaunchMessages.getString("CMainTab.Workspace_settings_button_tooltip")); //$NON-NLS-1$
fWorkspaceSettingsButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
updateLaunchConfigurationDialog();
}
});
fWorkpsaceSettingsLink = new Link(buildGroup, SWT.NONE); //$NON-NLS-1$
fWorkpsaceSettingsLink.setText(LaunchMessages.getString("CMainTab.Workspace_settings_link_label")); //$NON-NLS-1$
fWorkpsaceSettingsLink.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
PreferencesUtil.createPreferenceDialogOn(
parent.getShell(),
LaunchMessages.getString("CMainTab.Workspace_settings_page_id"), //$NON-NLS-1$
null,
null).open();
}
});
}
/** @since 6.1 */
protected void updateBuildOptionFromConfig(ILaunchConfiguration config) {
int buildBeforeLaunchValue = ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING;
try {
buildBeforeLaunchValue = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH, buildBeforeLaunchValue);
} catch (CoreException e) {
LaunchUIPlugin.log(e);
}
if (fDisableBuildButton != null)
fDisableBuildButton.setSelection(buildBeforeLaunchValue == ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_DISABLED);
if (fEnableBuildButton != null)
fEnableBuildButton.setSelection(buildBeforeLaunchValue == ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_ENABLED);
if (fWorkspaceSettingsButton != null)
fWorkspaceSettingsButton.setSelection(buildBeforeLaunchValue == ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING);
}
/**
* Show a dialog that lets the user select a file.
*
* @since 6.0
*/
protected String handleBrowseButtonSelected() {
FileDialog fileDialog = new FileDialog(getShell(), SWT.NONE);
fileDialog.setFileName(fProgText.getText());
return fileDialog.open();
}
/** @since 2.0 */
protected void createCoreFileGroup(Composite parent, int colSpan) {
Composite coreComp = new Composite(parent, SWT.NONE);
GridLayout coreLayout = new GridLayout();
coreLayout.numColumns = 3;
coreLayout.marginHeight = 0;
coreLayout.marginWidth = 0;
coreComp.setLayout(coreLayout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = colSpan;
coreComp.setLayoutData(gd);
fCoreLabel = new Label(coreComp, SWT.NONE);
fCoreLabel.setText(LaunchMessages.getString("CMainTab.CoreFile_path")); //$NON-NLS-1$
gd = new GridData();
gd.horizontalSpan = 3;
fCoreLabel.setLayoutData(gd);
fCoreText = new Text(coreComp, SWT.SINGLE | SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL);
fCoreText.setLayoutData(gd);
fCoreText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent evt) {
updateLaunchConfigurationDialog();
}
});
Button browseForCoreButton;
browseForCoreButton = createPushButton(coreComp, LaunchMessages.getString("Launch.common.Browse_2"), null); //$NON-NLS-1$
browseForCoreButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent evt) {
String text = handleBrowseButtonSelected();
if (text != null) {
fCoreText.setText(text);
}
updateLaunchConfigurationDialog();
}
});
}
/**
* @param project
* @param exePath
* @return
* @throws CoreException
*/
protected boolean isBinary(IProject project, IPath exePath) throws CoreException {
try {
Boolean binValue = fBinaryExeCache.get(exePath);
if (binValue == null)
{
IBinaryObject exe = LaunchUtils.getBinary(project, exePath);
binValue = exe != null;
fBinaryExeCache.put(exePath, binValue);
}
return binValue;
} catch (ClassCastException e) {
}
return false;
}
/**
* Iterate through and suck up all of the executable files that we can find.
*/
protected IBinary[] getBinaryFiles(final ICProject cproject) {
final Display display;
if (cproject == null || !cproject.exists()) {
return null;
}
if (getShell() == null) {
display = LaunchUIPlugin.getShell().getDisplay();
} else {
display = getShell().getDisplay();
}
final Object[] ret = new Object[1];
BusyIndicator.showWhile(display, new Runnable() {
public void run() {
try {
ret[0] = cproject.getBinaryContainer().getBinaries();
} catch (CModelException e) {
LaunchUIPlugin.errorDialog("Launch UI internal error", e); //$NON-NLS-1$
}
}
});
return (IBinary[])ret[0];
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
*/
public void performApply(ILaunchConfigurationWorkingCopy config) {
if (fBuildConfigCombo != null) {
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, (String)fBuildConfigCombo.getData(Integer.toString(fBuildConfigCombo.getSelectionIndex())));
}
if (fDisableBuildButton != null) {
int buildBeforeLaunchValue = ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING;
if (fDisableBuildButton.getSelection()) {
buildBeforeLaunchValue = ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_DISABLED;
} else if (fEnableBuildButton.getSelection()) {
buildBeforeLaunchValue = ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_ENABLED;
}
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH, buildBeforeLaunchValue);
}
}
protected void updateProjectFromConfig(ILaunchConfiguration config) {
String projectName = EMPTY_STRING;
String configName = EMPTY_STRING;
try {
projectName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, EMPTY_STRING);
configName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, EMPTY_STRING);
} catch (CoreException ce) {
LaunchUIPlugin.log(ce);
}
fProjText.setText(projectName);
updateBuildConfigCombo(configName);
}
protected void updateProgramFromConfig(ILaunchConfiguration config) {
if (fProgText != null)
{
String programName = EMPTY_STRING;
try {
programName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, EMPTY_STRING);
} catch (CoreException ce) {
LaunchUIPlugin.log(ce);
}
fProgText.setText(programName);
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#updateLaunchConfigurationDialog()
*/
@Override
protected void updateLaunchConfigurationDialog() {
super.updateLaunchConfigurationDialog();
}
}

View file

@ -12,29 +12,18 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.launch.ui; package org.eclipse.cdt.launch.ui;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.launch.LaunchUtils;
import org.eclipse.cdt.launch.internal.ui.LaunchImages; import org.eclipse.cdt.launch.internal.ui.LaunchImages;
import org.eclipse.cdt.launch.internal.ui.LaunchMessages; import org.eclipse.cdt.launch.internal.ui.LaunchMessages;
import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin; import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
import org.eclipse.cdt.ui.CElementLabelProvider; import org.eclipse.cdt.ui.CElementLabelProvider;
import org.eclipse.cdt.ui.newui.CDTPropertyManager;
import org.eclipse.cdt.utils.pty.PTY; import org.eclipse.cdt.utils.pty.PTY;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
@ -52,26 +41,18 @@ import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.window.Window; import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
import org.eclipse.ui.dialogs.PreferencesUtil;
import org.eclipse.ui.dialogs.TwoPaneElementSelector; import org.eclipse.ui.dialogs.TwoPaneElementSelector;
/** /**
@ -84,7 +65,7 @@ import org.eclipse.ui.dialogs.TwoPaneElementSelector;
* @since 2.0 * @since 2.0
*/ */
public class CMainTab extends CLaunchConfigurationTab { public class CMainTab extends CAbstractMainTab {
/** /**
* Tab identifier used for ordering of tabs added using the * Tab identifier used for ordering of tabs added using the
@ -95,16 +76,6 @@ public class CMainTab extends CLaunchConfigurationTab {
*/ */
public static final String TAB_ID = "org.eclipse.cdt.cdi.launch.mainTab"; //$NON-NLS-1$ public static final String TAB_ID = "org.eclipse.cdt.cdi.launch.mainTab"; //$NON-NLS-1$
// Project UI widgets
protected Label fProjLabel;
protected Text fProjText;
protected Button fProjButton;
// Main class UI widgets
protected Label fProgLabel;
protected Text fProgText;
protected Button fSearchButton;
// Core file UI widgets // Core file UI widgets
/** @since 6.0 */ /** @since 6.0 */
protected Label fCoreLabel; protected Label fCoreLabel;
@ -113,56 +84,17 @@ public class CMainTab extends CLaunchConfigurationTab {
/** @since 6.0 */ /** @since 6.0 */
protected Button fCoreButton; protected Button fCoreButton;
/**
* @since 6.0
*/
protected Combo fBuildConfigCombo;
// Build option UI widgets
/** @since 6.1 */
protected Button fDisableBuildButton;
/** @since 6.1 */
protected Button fEnableBuildButton;
/** @since 6.1 */
protected Button fWorkspaceSettingsButton;
/** @since 6.1 */
protected Link fWorkpsaceSettingsLink;
private final boolean fWantsTerminalOption; private final boolean fWantsTerminalOption;
protected Button fTerminalButton; protected Button fTerminalButton;
private final boolean dontCheckProgram; private final boolean dontCheckProgram;
private final boolean fSpecifyCoreFile; private final boolean fSpecifyCoreFile;
protected static final String EMPTY_STRING = ""; //$NON-NLS-1$
private String filterPlatform = EMPTY_STRING;
public static final int WANTS_TERMINAL = 1; public static final int WANTS_TERMINAL = 1;
public static final int DONT_CHECK_PROGRAM = 2; public static final int DONT_CHECK_PROGRAM = 2;
/** @since 6.0 */ /** @since 6.0 */
public static final int SPECIFY_CORE_FILE = 4; public static final int SPECIFY_CORE_FILE = 4;
private final Map<IPath, Boolean> fBinaryExeCache = new HashMap<IPath, Boolean>();
/**
* Name of most recently checked program; avoid constantly checking binary.
* See bug 277663.
*/
private String fPreviouslyCheckedProgram;
/**
* Validity result of most recently checked program; avoid constantly
* checking binary. See bug 277663. N/A if fPreviouslyCheckedProgram = null;
*/
private boolean fPreviouslyCheckedProgramIsValid;
/**
* Validity error message of most recently checked program; avoid constantly
* checking binary. See bug 277663. N/A if fPreviouslyCheckedProgram = null.
*/
private String fPreviouslyCheckedProgramErrorMsg;
public CMainTab() { public CMainTab() {
this(WANTS_TERMINAL); this(WANTS_TERMINAL);
} }
@ -205,252 +137,6 @@ public class CMainTab extends CLaunchConfigurationTab {
LaunchUIPlugin.setDialogShell(parent.getShell()); LaunchUIPlugin.setDialogShell(parent.getShell());
} }
/**
* @since 6.0
*/
protected void createProjectGroup(Composite parent, int colSpan) {
Composite projComp = new Composite(parent, SWT.NONE);
GridLayout projLayout = new GridLayout();
projLayout.numColumns = 2;
projLayout.marginHeight = 0;
projLayout.marginWidth = 0;
projComp.setLayout(projLayout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = colSpan;
projComp.setLayoutData(gd);
fProjLabel = new Label(projComp, SWT.NONE);
fProjLabel.setText(LaunchMessages.getString("CMainTab.&ProjectColon")); //$NON-NLS-1$
gd = new GridData();
gd.horizontalSpan = 2;
fProjLabel.setLayoutData(gd);
fProjText = new Text(projComp, SWT.SINGLE | SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL);
fProjText.setLayoutData(gd);
fProjText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent evt) {
// if project changes, invalidate program name cache
fPreviouslyCheckedProgram = null;
updateBuildConfigCombo(EMPTY_STRING);
updateLaunchConfigurationDialog();
}
});
fProjButton = createPushButton(projComp, LaunchMessages.getString("Launch.common.Browse_1"), null); //$NON-NLS-1$
fProjButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent evt) {
handleProjectButtonSelected();
updateLaunchConfigurationDialog();
}
});
}
/**
* @since 6.0
*/
protected void updateBuildConfigCombo(String selectedConfigID) {
if (fBuildConfigCombo != null)
{
fBuildConfigCombo.removeAll();
fBuildConfigCombo.add(LaunchMessages.getString("CMainTab.Use_Active")); //$NON-NLS-1$
fBuildConfigCombo.setData("0", EMPTY_STRING); //$NON-NLS-1$
fBuildConfigCombo.select(0);
ICProject cproject = getCProject();
if (cproject != null){
ICProjectDescription projDes = CDTPropertyManager.getProjectDescription(cproject.getProject());
if (projDes != null)
{
int selIndex = 0;
ICConfigurationDescription[] configurations = projDes.getConfigurations();
ICConfigurationDescription selectedConfig = projDes.getConfigurationById(selectedConfigID);
for (int i = 0; i < configurations.length; i++) {
String configName = configurations[i].getName();
fBuildConfigCombo.add(configName);
fBuildConfigCombo.setData(Integer.toString(i + 1), configurations[i].getId());
if (selectedConfig != null && selectedConfigID.equals(configurations[i].getId()))
selIndex = i + 1;
}
fBuildConfigCombo.select(selIndex);
}
}
}
}
/**
* @since 6.0
*/
protected void createBuildConfigCombo(Composite parent, int colspan) {
Composite comboComp = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
comboComp.setLayout(layout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = colspan;
comboComp.setLayoutData(gd);
Label dlabel = new Label(comboComp, SWT.NONE);
dlabel.setText(LaunchMessages.getString("CMainTab.Build_Config")); //$NON-NLS-1$
fBuildConfigCombo = new Combo(comboComp, SWT.READ_ONLY | SWT.DROP_DOWN);
fBuildConfigCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fBuildConfigCombo.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
updateLaunchConfigurationDialog();
}
public void widgetDefaultSelected(SelectionEvent e) {
updateLaunchConfigurationDialog();
}
});
}
protected void createExeFileGroup(Composite parent, int colSpan) {
Composite mainComp = new Composite(parent, SWT.NONE);
GridLayout mainLayout = new GridLayout();
mainLayout.numColumns = 3;
mainLayout.marginHeight = 0;
mainLayout.marginWidth = 0;
mainComp.setLayout(mainLayout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = colSpan;
mainComp.setLayoutData(gd);
fProgLabel = new Label(mainComp, SWT.NONE);
fProgLabel.setText(LaunchMessages.getString("CMainTab.C/C++_Application")); //$NON-NLS-1$
gd = new GridData();
gd.horizontalSpan = 3;
fProgLabel.setLayoutData(gd);
fProgText = new Text(mainComp, SWT.SINGLE | SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL);
fProgText.setLayoutData(gd);
fProgText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent evt) {
updateLaunchConfigurationDialog();
}
});
fSearchButton = createPushButton(mainComp, LaunchMessages.getString("CMainTab.Search..."), null); //$NON-NLS-1$
fSearchButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent evt) {
handleSearchButtonSelected();
updateLaunchConfigurationDialog();
}
});
Button fBrowseForBinaryButton;
fBrowseForBinaryButton = createPushButton(mainComp, LaunchMessages.getString("Launch.common.Browse_2"), null); //$NON-NLS-1$
fBrowseForBinaryButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent evt) {
handleBinaryBrowseButtonSelected();
updateLaunchConfigurationDialog();
}
});
}
/** @since 6.1 */
protected void createBuildOptionGroup(final Composite parent, int colSpan) {
Group buildGroup = new Group(parent, SWT.NONE);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = colSpan;
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
gridLayout.marginHeight = 5;
gridLayout.marginWidth = 5;
gridLayout.makeColumnsEqualWidth= true;
buildGroup.setLayoutData(gridData);
buildGroup.setLayout(gridLayout);
buildGroup.setText(LaunchMessages.getString("CMainTab.Build_options")); //$NON-NLS-1$
createBuildConfigCombo(buildGroup, 2);
fEnableBuildButton = new Button(buildGroup, SWT.RADIO);
fEnableBuildButton.setText(LaunchMessages.getString("CMainTab.Enable_build_button_label")); //$NON-NLS-1$
fEnableBuildButton.setToolTipText(LaunchMessages.getString("CMainTab.Enable_build_button_tooltip")); //$NON-NLS-1$
fEnableBuildButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
updateLaunchConfigurationDialog();
}
});
fDisableBuildButton = new Button(buildGroup, SWT.RADIO);
fDisableBuildButton.setText(LaunchMessages.getString("CMainTab.Disable_build_button_label")); //$NON-NLS-1$
fDisableBuildButton.setToolTipText(LaunchMessages.getString("CMainTab.Disable_build_button_tooltip")); //$NON-NLS-1$
fDisableBuildButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
updateLaunchConfigurationDialog();
}
});
fWorkspaceSettingsButton = new Button(buildGroup, SWT.RADIO);
fWorkspaceSettingsButton.setText(LaunchMessages.getString("CMainTab.Workspace_settings_button_label")); //$NON-NLS-1$
fWorkspaceSettingsButton.setToolTipText(LaunchMessages.getString("CMainTab.Workspace_settings_button_tooltip")); //$NON-NLS-1$
fWorkspaceSettingsButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
updateLaunchConfigurationDialog();
}
});
fWorkpsaceSettingsLink = new Link(buildGroup, SWT.NONE); //$NON-NLS-1$
fWorkpsaceSettingsLink.setText(LaunchMessages.getString("CMainTab.Workspace_settings_link_label")); //$NON-NLS-1$
fWorkpsaceSettingsLink.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
PreferencesUtil.createPreferenceDialogOn(
parent.getShell(),
LaunchMessages.getString("CMainTab.Workspace_settings_page_id"), //$NON-NLS-1$
null,
null).open();
}
});
}
/** @since 6.0 */
protected void createCoreFileGroup(Composite parent, int colSpan) {
Composite coreComp = new Composite(parent, SWT.NONE);
GridLayout coreLayout = new GridLayout();
coreLayout.numColumns = 3;
coreLayout.marginHeight = 0;
coreLayout.marginWidth = 0;
coreComp.setLayout(coreLayout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = colSpan;
coreComp.setLayoutData(gd);
fCoreLabel = new Label(coreComp, SWT.NONE);
fCoreLabel.setText(LaunchMessages.getString("CMainTab.CoreFile_path")); //$NON-NLS-1$
gd = new GridData();
gd.horizontalSpan = 3;
fCoreLabel.setLayoutData(gd);
fCoreText = new Text(coreComp, SWT.SINGLE | SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL);
fCoreText.setLayoutData(gd);
fCoreText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent evt) {
updateLaunchConfigurationDialog();
}
});
Button browseForCoreButton;
browseForCoreButton = createPushButton(coreComp, LaunchMessages.getString("Launch.common.Browse_2"), null); //$NON-NLS-1$
browseForCoreButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent evt) {
String text = handleBrowseButtonSelected();
if (text != null) {
fCoreText.setText(text);
}
updateLaunchConfigurationDialog();
}
});
}
protected boolean wantsTerminalOption() { protected boolean wantsTerminalOption() {
return fWantsTerminalOption; return fWantsTerminalOption;
} }
@ -503,32 +189,6 @@ public class CMainTab extends CLaunchConfigurationTab {
} }
} }
protected void updateProjectFromConfig(ILaunchConfiguration config) {
String projectName = EMPTY_STRING;
String configName = EMPTY_STRING;
try {
projectName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, EMPTY_STRING);
configName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, EMPTY_STRING);
} catch (CoreException ce) {
LaunchUIPlugin.log(ce);
}
fProjText.setText(projectName);
updateBuildConfigCombo(configName);
}
protected void updateProgramFromConfig(ILaunchConfiguration config) {
if (fProgText != null)
{
String programName = EMPTY_STRING;
try {
programName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, EMPTY_STRING);
} catch (CoreException ce) {
LaunchUIPlugin.log(ce);
}
fProgText.setText(programName);
}
}
/** @since 6.0 */ /** @since 6.0 */
protected void updateCoreFromConfig(ILaunchConfiguration config) { protected void updateCoreFromConfig(ILaunchConfiguration config) {
if (fCoreText != null) { if (fCoreText != null) {
@ -542,29 +202,13 @@ public class CMainTab extends CLaunchConfigurationTab {
} }
} }
/** @since 6.1 */
protected void updateBuildOptionFromConfig(ILaunchConfiguration config) {
int buildBeforeLaunchValue = ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING;
try {
buildBeforeLaunchValue = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH, buildBeforeLaunchValue);
} catch (CoreException e) {
LaunchUIPlugin.log(e);
}
if (fDisableBuildButton != null)
fDisableBuildButton.setSelection(buildBeforeLaunchValue == ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_DISABLED);
if (fEnableBuildButton != null)
fEnableBuildButton.setSelection(buildBeforeLaunchValue == ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_ENABLED);
if (fWorkspaceSettingsButton != null)
fWorkspaceSettingsButton.setSelection(buildBeforeLaunchValue == ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING);
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
*/ */
public void performApply(ILaunchConfigurationWorkingCopy config) { public void performApply(ILaunchConfigurationWorkingCopy config) {
super.performApply(config);
ICProject cProject = this.getCProject(); ICProject cProject = this.getCProject();
if (cProject != null && cProject.exists()) if (cProject != null && cProject.exists())
{ {
@ -577,9 +221,6 @@ public class CMainTab extends CLaunchConfigurationTab {
config.setMappedResources(null); config.setMappedResources(null);
} }
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, fProjText.getText()); config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, fProjText.getText());
if (fBuildConfigCombo != null) {
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, (String)fBuildConfigCombo.getData(Integer.toString(fBuildConfigCombo.getSelectionIndex())));
}
if (fProgText != null) { if (fProgText != null) {
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, fProgText.getText()); config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, fProgText.getText());
} }
@ -590,15 +231,6 @@ public class CMainTab extends CLaunchConfigurationTab {
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL, fTerminalButton.getSelection()); config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL, fTerminalButton.getSelection());
} }
if (fDisableBuildButton != null) {
int buildBeforeLaunchValue = ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING;
if (fDisableBuildButton.getSelection()) {
buildBeforeLaunchValue = ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_DISABLED;
} else if (fEnableBuildButton.getSelection()) {
buildBeforeLaunchValue = ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_ENABLED;
}
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH, buildBeforeLaunchValue);
}
} }
/** /**
@ -674,6 +306,95 @@ public class CMainTab extends CLaunchConfigurationTab {
} }
/**
* @since 6.0
*/
protected void createProjectGroup(Composite parent, int colSpan) {
Composite projComp = new Composite(parent, SWT.NONE);
GridLayout projLayout = new GridLayout();
projLayout.numColumns = 2;
projLayout.marginHeight = 0;
projLayout.marginWidth = 0;
projComp.setLayout(projLayout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = colSpan;
projComp.setLayoutData(gd);
fProjLabel = new Label(projComp, SWT.NONE);
fProjLabel.setText(LaunchMessages.getString("CMainTab.&ProjectColon")); //$NON-NLS-1$
gd = new GridData();
gd.horizontalSpan = 2;
fProjLabel.setLayoutData(gd);
fProjText = new Text(projComp, SWT.SINGLE | SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL);
fProjText.setLayoutData(gd);
fProjText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent evt) {
// if project changes, invalidate program name cache
fPreviouslyCheckedProgram = null;
updateBuildConfigCombo(""); //$NON-NLS-1$
updateLaunchConfigurationDialog();
}
});
fProjButton = createPushButton(projComp, LaunchMessages.getString("Launch.common.Browse_1"), null); //$NON-NLS-1$
fProjButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent evt) {
handleProjectButtonSelected();
updateLaunchConfigurationDialog();
}
});
}
protected void createExeFileGroup(Composite parent, int colSpan) {
Composite mainComp = new Composite(parent, SWT.NONE);
GridLayout mainLayout = new GridLayout();
mainLayout.numColumns = 3;
mainLayout.marginHeight = 0;
mainLayout.marginWidth = 0;
mainComp.setLayout(mainLayout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = colSpan;
mainComp.setLayoutData(gd);
fProgLabel = new Label(mainComp, SWT.NONE);
fProgLabel.setText(LaunchMessages.getString("CMainTab.C/C++_Application")); //$NON-NLS-1$
gd = new GridData();
gd.horizontalSpan = 3;
fProgLabel.setLayoutData(gd);
fProgText = new Text(mainComp, SWT.SINGLE | SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL);
fProgText.setLayoutData(gd);
fProgText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent evt) {
updateLaunchConfigurationDialog();
}
});
fSearchButton = createPushButton(mainComp, LaunchMessages.getString("CMainTab.Search..."), null); //$NON-NLS-1$
fSearchButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent evt) {
handleSearchButtonSelected();
updateLaunchConfigurationDialog();
}
});
Button fBrowseForBinaryButton;
fBrowseForBinaryButton = createPushButton(mainComp, LaunchMessages.getString("Launch.common.Browse_2"), null); //$NON-NLS-1$
fBrowseForBinaryButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent evt) {
handleBinaryBrowseButtonSelected();
updateLaunchConfigurationDialog();
}
});
}
/** /**
* Show a dialog that lets the user select a project. This in turn provides context for the main * Show a dialog that lets the user select a project. This in turn provides context for the main
* type, allowing the user to key a main type name, or constraining the search for main types to * type, allowing the user to key a main type name, or constraining the search for main types to
@ -694,137 +415,6 @@ public class CMainTab extends CLaunchConfigurationTab {
} }
} }
/**
* Show a dialog that lets the user select a file.
*
* @since 6.0
*/
protected String handleBrowseButtonSelected() {
FileDialog fileDialog = new FileDialog(getShell(), SWT.NONE);
fileDialog.setFileName(fProgText.getText());
return fileDialog.open();
}
/**
* Iterate through and suck up all of the executable files that we can find.
*/
protected IBinary[] getBinaryFiles(final ICProject cproject) {
final Display display;
if (cproject == null || !cproject.exists()) {
return null;
}
if (getShell() == null) {
display = LaunchUIPlugin.getShell().getDisplay();
} else {
display = getShell().getDisplay();
}
final Object[] ret = new Object[1];
BusyIndicator.showWhile(display, new Runnable() {
public void run() {
try {
ret[0] = cproject.getBinaryContainer().getBinaries();
} catch (CModelException e) {
LaunchUIPlugin.errorDialog("Launch UI internal error", e); //$NON-NLS-1$
}
}
});
return (IBinary[])ret[0];
}
/**
* Show a dialog that lets the user select a project. This in turn provides context for the main
* type, allowing the user to key a main type name, or constraining the search for main types to
* the specified project.
*/
protected void handleProjectButtonSelected() {
String currentProjectName = fProjText.getText();
ICProject project = chooseCProject();
if (project == null) {
return;
}
String projectName = project.getElementName();
fProjText.setText(projectName);
if (currentProjectName.length() == 0)
{
// New project selected for the first time, set the program name default too.
IBinary[] bins = getBinaryFiles(project);
if (bins != null && bins.length == 1) {
fProgText.setText(bins[0].getResource().getProjectRelativePath().toOSString());
}
}
}
/**
* Realize a C Project selection dialog and return the first selected project, or null if there
* was none.
*/
protected ICProject chooseCProject() {
try {
ICProject[] projects = getCProjects();
ILabelProvider labelProvider = new CElementLabelProvider();
ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider);
dialog.setTitle(LaunchMessages.getString("CMainTab.Project_Selection")); //$NON-NLS-1$
dialog.setMessage(LaunchMessages.getString("CMainTab.Choose_project_to_constrain_search_for_program")); //$NON-NLS-1$
dialog.setElements(projects);
ICProject cProject = getCProject();
if (cProject != null) {
dialog.setInitialSelections(new Object[]{cProject});
}
if (dialog.open() == Window.OK) {
return (ICProject)dialog.getFirstResult();
}
} catch (CModelException e) {
LaunchUIPlugin.errorDialog("Launch UI internal error", e); //$NON-NLS-1$
}
return null;
}
/**
* Return an array a ICProject whose platform match that of the runtime env.
*/
protected ICProject[] getCProjects() throws CModelException {
ICProject cproject[] = CoreModel.getDefault().getCModel().getCProjects();
List<ICProject> list = new ArrayList<ICProject>(cproject.length);
for (int i = 0; i < cproject.length; i++) {
ICDescriptor cdesciptor = null;
try {
cdesciptor = CCorePlugin.getDefault().getCProjectDescription((IProject)cproject[i].getResource(), false);
if (cdesciptor != null) {
String projectPlatform = cdesciptor.getPlatform();
if (filterPlatform.equals("*") //$NON-NLS-1$
|| projectPlatform.equals("*") //$NON-NLS-1$
|| filterPlatform.equalsIgnoreCase(projectPlatform) == true) {
list.add(cproject[i]);
}
} else {
list.add(cproject[i]);
}
} catch (CoreException e) {
list.add(cproject[i]);
}
}
return list.toArray(new ICProject[list.size()]);
}
/**
* Return the ICProject corresponding to the project name in the project name text field, or
* null if the text does not match a project name.
*/
protected ICProject getCProject() {
String projectName = fProjText.getText().trim();
if (projectName.length() < 1) {
return null;
}
return CoreModel.getDefault().getCModel().getCProject(projectName);
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -937,26 +527,6 @@ public class CMainTab extends CLaunchConfigurationTab {
return true; return true;
} }
/**
* @param project
* @param exePath
* @return
* @throws CoreException
*/
protected boolean isBinary(IProject project, IPath exePath) throws CoreException {
try {
Boolean binValue = fBinaryExeCache.get(exePath);
if (binValue == null)
{
IBinaryObject exe = LaunchUtils.getBinary(project, exePath);
binValue = exe != null;
fBinaryExeCache.put(exePath, binValue);
}
return binValue;
} catch (ClassCastException e) {
}
return false;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -1073,7 +643,6 @@ public class CMainTab extends CLaunchConfigurationTab {
return TAB_ID; return TAB_ID;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -1093,13 +662,4 @@ public class CMainTab extends CLaunchConfigurationTab {
return LaunchImages.get(LaunchImages.IMG_VIEW_MAIN_TAB); return LaunchImages.get(LaunchImages.IMG_VIEW_MAIN_TAB);
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#updateLaunchConfigurationDialog()
*/
@Override
protected void updateLaunchConfigurationDialog() {
super.updateLaunchConfigurationDialog();
}
} }