blob: 71d79f61ce4c2c9733a8d695a26ac969f939230e [file] [log] [blame]
package org.eclipse.cdt.launch.ui;
/*
* (c) Copyright QNX Software System 2002.
* All Rights Reserved.
*/
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.launch.internal.ui.LaunchImages;
import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
import org.eclipse.cdt.launch.internal.ui.WorkingDirectoryBlock;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.help.WorkbenchHelp;
/**
* A launch configuration tab that displays and edits program arguments,
* and working directory launch configuration attributes.
* <p>
* This class may be instantiated. This class is not intended to be subclassed.
* </p>
*/
public class CArgumentsTab extends CLaunchConfigurationTab {
// Program arguments UI widgets
protected Label fPrgmArgumentsLabel;
protected Text fPrgmArgumentsText;
// Working directory
protected WorkingDirectoryBlock fWorkingDirectoryBlock = new WorkingDirectoryBlock();
/**
* @see ILaunchConfigurationTab#createControl(Composite)
*/
public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
setControl(comp);
WorkbenchHelp.setHelp(getControl(), ICDTLaunchHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_ARGUMNETS_TAB);
GridLayout topLayout = new GridLayout();
comp.setLayout(topLayout);
GridData gd;
createVerticalSpacer(comp, 1);
fPrgmArgumentsLabel = new Label(comp, SWT.NONE);
fPrgmArgumentsLabel.setText("C/C++ Program Arguments:");
fPrgmArgumentsText = new Text(comp, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.heightHint = 40;
fPrgmArgumentsText.setLayoutData(gd);
fPrgmArgumentsText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent evt) {
updateLaunchConfigurationDialog();
}
});
createVerticalSpacer(comp, 1);
fWorkingDirectoryBlock.createControl(comp);
}
/**
* @see ILaunchConfigurationTab#dispose()
*/
public void dispose() {
}
/**
* @see ILaunchConfigurationTab#isValid(ILaunchConfiguration)
*/
public boolean isValid(ILaunchConfiguration config) {
return fWorkingDirectoryBlock.isValid(config);
}
/**
* Defaults are empty.
*
* @see ILaunchConfigurationTab#setDefaults(ILaunchConfigurationWorkingCopy)
*/
public void setDefaults(ILaunchConfigurationWorkingCopy config) {
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String) null);
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null);
}
/**
* @see ILaunchConfigurationTab#initializeFrom(ILaunchConfiguration)
*/
public void initializeFrom(ILaunchConfiguration configuration) {
try {
fPrgmArgumentsText.setText(configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, "")); //$NON-NLS-1$
fWorkingDirectoryBlock.initializeFrom(configuration);
}
catch (CoreException e) {
setErrorMessage("Exception occurred reading configuration " + e.getStatus().getMessage());
LaunchUIPlugin.log(e);
}
}
/**
* @see ILaunchConfigurationTab#performApply(ILaunchConfigurationWorkingCopy)
*/
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
configuration.setAttribute(
ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
getAttributeValueFrom(fPrgmArgumentsText));
fWorkingDirectoryBlock.performApply(configuration);
}
/**
* Retuns the string in the text widget, or <code>null</code> if empty.
*
* @return text or <code>null</code>
*/
protected String getAttributeValueFrom(Text text) {
String content = text.getText().trim();
if (content.length() > 0) {
return content;
}
return null;
}
/**
* @see ILaunchConfigurationTab#getName()
*/
public String getName() {
return "Arguments";
}
/**
* @see ILaunchConfigurationTab#setLaunchConfigurationDialog(ILaunchConfigurationDialog)
*/
public void setLaunchConfigurationDialog(ILaunchConfigurationDialog dialog) {
super.setLaunchConfigurationDialog(dialog);
fWorkingDirectoryBlock.setLaunchConfigurationDialog(dialog);
}
/**
* @see ILaunchConfigurationTab#getErrorMessage()
*/
public String getErrorMessage() {
String m = super.getErrorMessage();
if (m == null) {
return fWorkingDirectoryBlock.getErrorMessage();
}
return m;
}
/**
* @see ILaunchConfigurationTab#getMessage()
*/
public String getMessage() {
String m = super.getMessage();
if (m == null) {
return fWorkingDirectoryBlock.getMessage();
}
return m;
}
/**
* @see ILaunchConfigurationTab#getImage()
*/
public Image getImage() {
return LaunchImages.get(LaunchImages.IMG_VIEW_ARGUMENTS_TAB);
}
/**
* @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#updateLaunchConfigurationDialog()
*/
protected void updateLaunchConfigurationDialog() {
super.updateLaunchConfigurationDialog();
}
}