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

added terminal support

This commit is contained in:
David Inglis 2004-11-16 21:21:58 +00:00
parent b8b99d5287
commit 8cec1f832b
4 changed files with 151 additions and 71 deletions

View file

@ -25,6 +25,7 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
import org.eclipse.cdt.launch.AbstractCLaunchDelegate; import org.eclipse.cdt.launch.AbstractCLaunchDelegate;
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.utils.pty.PTY;
import org.eclipse.cdt.utils.spawner.ProcessFactory; import org.eclipse.cdt.utils.spawner.ProcessFactory;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
@ -119,8 +120,9 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate {
command.add(exePath.toOSString()); command.add(exePath.toOSString());
command.addAll(Arrays.asList(arguments)); command.addAll(Arrays.asList(arguments));
String[] commandArray = (String[]) command.toArray(new String[command.size()]); String[] commandArray = (String[]) command.toArray(new String[command.size()]);
boolean usePty = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL, false);
monitor.worked(5); monitor.worked(5);
Process process = exec(commandArray, getEnvironment(config), wd); Process process = exec(commandArray, getEnvironment(config), wd, usePty);
monitor.worked(3); monitor.worked(3);
DebugPlugin.newProcess(launch, process, renderProcessLabel(commandArray[0])); DebugPlugin.newProcess(launch, process, renderProcessLabel(commandArray[0]));
} }
@ -145,15 +147,18 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate {
* cancelled * cancelled
* @see Runtime * @see Runtime
*/ */
protected Process exec(String[] cmdLine, String[] environ, File workingDirectory) throws CoreException { protected Process exec(String[] cmdLine, String[] environ, File workingDirectory, boolean usePty) throws CoreException {
Process p = null; Process p = null;
try { try {
if (workingDirectory == null) { if (workingDirectory == null) {
p = ProcessFactory.getFactory().exec(cmdLine, environ); p = ProcessFactory.getFactory().exec(cmdLine, environ);
} else {
if (usePty && PTY.isSupported()) {
p = ProcessFactory.getFactory().exec(cmdLine, environ, workingDirectory, new PTY());
} else { } else {
p = ProcessFactory.getFactory().exec(cmdLine, environ, workingDirectory); p = ProcessFactory.getFactory().exec(cmdLine, environ, workingDirectory);
} }
}
} catch (IOException e) { } catch (IOException e) {
if (p != null) { if (p != null) {
p.destroy(); p.destroy();
@ -173,7 +178,7 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate {
if (handler != null) { if (handler != null) {
Object result = handler.handleStatus(status, this); Object result = handler.handleStatus(status, this);
if (result instanceof Boolean && ((Boolean) result).booleanValue()) { if (result instanceof Boolean && ((Boolean) result).booleanValue()) {
p = exec(cmdLine, environ, null); p = exec(cmdLine, environ, null, usePty);
} }
} }
} }

View file

@ -90,6 +90,7 @@ CMainTab.C/C++_Application=C/C++ Application:
CMainTab.Search...=Searc&h... CMainTab.Search...=Searc&h...
CMainTab.Choose_program_to_run=Choose a &program to run: CMainTab.Choose_program_to_run=Choose a &program to run:
CMainTab.Choose_program_to_run_from_NAME=Choose a program to run from {0}: CMainTab.Choose_program_to_run_from_NAME=Choose a program to run from {0}:
CMainTab.UseTerminal=Connect process input && output to a terminal.
CDebuggerTab.Advanced_Options_Dialog_Title=Advanced Options CDebuggerTab.Advanced_Options_Dialog_Title=Advanced Options
CDebuggerTab.Stop_at_main_on_startup=Stop at main() on startup CDebuggerTab.Stop_at_main_on_startup=Stop at main() on startup

View file

@ -26,7 +26,7 @@ public class LocalRunLaunchConfigurationTabGroup extends AbstractLaunchConfigura
*/ */
public void createTabs(ILaunchConfigurationDialog dialog, String mode) { public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
new CMainTab(), new CMainTab(true),
new CArgumentsTab(), new CArgumentsTab(),
new MigratingCEnvironmentTab(), new MigratingCEnvironmentTab(),
new CDebuggerTab(false), new CDebuggerTab(false),

View file

@ -1,13 +1,11 @@
/********************************************************************** /***************************************************************************************************
* Copyright (c) 2002 - 2004 QNX Software Systems and others. * Copyright (c) 2002 - 2004 QNX Software Systems and others. All rights reserved. This program and
* All rights reserved. This program and the accompanying materials * the accompanying materials are made available under the terms of the Common Public License v1.0
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html * http://www.eclipse.org/legal/cpl-v10.html
* *
* Contributors: * Contributors: QNX Software Systems - Initial API and implementation
* QNX Software Systems - Initial API and implementation **************************************************************************************************/
***********************************************************************/
package org.eclipse.cdt.launch.ui; package org.eclipse.cdt.launch.ui;
import java.util.ArrayList; import java.util.ArrayList;
@ -28,6 +26,7 @@ import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
import org.eclipse.cdt.ui.CElementImageDescriptor; import org.eclipse.cdt.ui.CElementImageDescriptor;
import org.eclipse.cdt.ui.CElementLabelProvider; import org.eclipse.cdt.ui.CElementLabelProvider;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
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;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
@ -64,8 +63,8 @@ import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider; import org.eclipse.ui.model.WorkbenchLabelProvider;
/** /**
* A launch configuration tab that displays and edits project and main type name * A launch configuration tab that displays and edits project and main type name launch
* launch configuration attributes. * configuration attributes.
* <p> * <p>
* This class may be instantiated. This class is not intended to be subclassed. * This class may be instantiated. This class is not intended to be subclassed.
* </p> * </p>
@ -85,32 +84,54 @@ public class CMainTab extends CLaunchConfigurationTab {
protected Text fProgText; protected Text fProgText;
protected Button fSearchButton; protected Button fSearchButton;
private final boolean fWantsTerminalOption;
protected Button fTerminalButton;
protected static final String EMPTY_STRING = ""; //$NON-NLS-1$ protected static final String EMPTY_STRING = ""; //$NON-NLS-1$
private String filterPlatform = EMPTY_STRING; private String filterPlatform = EMPTY_STRING;
/* (non-Javadoc)
public CMainTab() {
this(false);
}
public CMainTab(boolean terminalOption) {
fWantsTerminalOption = terminalOption;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite) * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
*/ */
public void createControl(Composite parent) { public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE); Composite comp = new Composite(parent, SWT.NONE);
setControl(comp); setControl(comp);
WorkbenchHelp.setHelp(getControl(), ICDTLaunchHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_MAIN_TAB); WorkbenchHelp.setHelp(getControl(), ICDTLaunchHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_MAIN_TAB);
GridLayout topLayout = new GridLayout(); GridLayout topLayout = new GridLayout();
comp.setLayout(topLayout); comp.setLayout(topLayout);
createVerticalSpacer(comp, 1); createVerticalSpacer(comp, 1);
createProjectGroup(comp, 1);
createExeFileGroup(comp, 1);
createVerticalSpacer(comp, 1);
if (wantsTerminalOption() /*&& ProcessFactory.supportesTerminal()*/) {
createTerminalOption(comp, 1);
}
LaunchUIPlugin.setDialogShell(parent.getShell());
}
Composite projComp = new Composite(comp, SWT.NONE); protected void createProjectGroup(Composite parent, int colSpan) {
Composite projComp = new Composite(parent, SWT.NONE);
GridLayout projLayout = new GridLayout(); GridLayout projLayout = new GridLayout();
projLayout.numColumns = 2; projLayout.numColumns = 2;
projLayout.marginHeight = 0; projLayout.marginHeight = 0;
projLayout.marginWidth = 0; projLayout.marginWidth = 0;
projComp.setLayout(projLayout); projComp.setLayout(projLayout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL); GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = colSpan;
projComp.setLayoutData(gd); projComp.setLayoutData(gd);
fProjLabel = new Label(projComp, SWT.NONE); fProjLabel = new Label(projComp, SWT.NONE);
@ -137,16 +158,17 @@ public class CMainTab extends CLaunchConfigurationTab {
updateLaunchConfigurationDialog(); updateLaunchConfigurationDialog();
} }
}); });
}
createVerticalSpacer(comp, 1); protected void createExeFileGroup(Composite parent, int colSpan) {
Composite mainComp = new Composite(parent, SWT.NONE);
Composite mainComp = new Composite(comp, SWT.NONE);
GridLayout mainLayout = new GridLayout(); GridLayout mainLayout = new GridLayout();
mainLayout.numColumns = 3; mainLayout.numColumns = 3;
mainLayout.marginHeight = 0; mainLayout.marginHeight = 0;
mainLayout.marginWidth = 0; mainLayout.marginWidth = 0;
mainComp.setLayout(mainLayout); mainComp.setLayout(mainLayout);
gd = new GridData(GridData.FILL_HORIZONTAL); GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = colSpan;
mainComp.setLayoutData(gd); mainComp.setLayoutData(gd);
fProgLabel = new Label(mainComp, SWT.NONE); fProgLabel = new Label(mainComp, SWT.NONE);
fProgLabel.setText(LaunchMessages.getString("CMainTab.C/C++_Application")); //$NON-NLS-1$ fProgLabel.setText(LaunchMessages.getString("CMainTab.C/C++_Application")); //$NON-NLS-1$
@ -181,18 +203,54 @@ public class CMainTab extends CLaunchConfigurationTab {
updateLaunchConfigurationDialog(); updateLaunchConfigurationDialog();
} }
}); });
LaunchUIPlugin.setDialogShell(parent.getShell());
} }
/* (non-Javadoc) protected boolean wantsTerminalOption() {
return fWantsTerminalOption;
}
protected void createTerminalOption(Composite parent, int colSpan) {
Composite mainComp = new Composite(parent, SWT.NONE);
GridLayout mainLayout = new GridLayout();
mainLayout.numColumns = 1;
mainLayout.marginHeight = 0;
mainLayout.marginWidth = 0;
mainComp.setLayout(mainLayout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = colSpan;
mainComp.setLayoutData(gd);
fTerminalButton = createCheckButton(mainComp, LaunchMessages.getString("CMainTab.UseTerminal")); //$NON-NLS-1$
fTerminalButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
updateLaunchConfigurationDialog();
}
});
fTerminalButton.setEnabled(PTY.isSupported());
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration) * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
*/ */
public void initializeFrom(ILaunchConfiguration config) { public void initializeFrom(ILaunchConfiguration config) {
filterPlatform = getPlatform(config); filterPlatform = getPlatform(config);
updateProjectFromConfig(config); updateProjectFromConfig(config);
updateProgramFromConfig(config); updateProgramFromConfig(config);
}
protected void updateTerminalFromConfig(ILaunchConfiguration config) {
if (fTerminalButton != null) {
boolean useTerminal = true;
try {
useTerminal = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL, true);
} catch (CoreException e) {
LaunchUIPlugin.log(e);
}
fTerminalButton.setSelection(useTerminal);
}
} }
protected void updateProjectFromConfig(ILaunchConfiguration config) { protected void updateProjectFromConfig(ILaunchConfiguration config) {
@ -215,12 +273,17 @@ public class CMainTab extends CLaunchConfigurationTab {
fProgText.setText(programName); fProgText.setText(programName);
} }
/* (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) {
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, fProjText.getText()); config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, fProjText.getText());
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, fProgText.getText()); config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, fProgText.getText());
if (fTerminalButton != null) {
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL, fTerminalButton.getSelection());
}
} }
/** /**
@ -299,9 +362,9 @@ public class CMainTab extends CLaunchConfigurationTab {
} }
/** /**
* Show a dialog that lets the user select a project. This in turn provides * Show a dialog that lets the user select a project. This in turn provides context for the main
* context for the main type, allowing the user to key a main type name, or * type, allowing the user to key a main type name, or constraining the search for main types to
* constraining the search for main types to the specified project. * the specified project.
*/ */
protected void handleBinaryBrowseButtonSelected() { protected void handleBinaryBrowseButtonSelected() {
final ICProject cproject = getCProject(); final ICProject cproject = getCProject();
@ -325,22 +388,22 @@ public class CMainTab extends CLaunchConfigurationTab {
public IStatus validate(Object[] selection) { public IStatus validate(Object[] selection) {
if (selection.length == 0 || !(selection[0] instanceof IFile)) { if (selection.length == 0 || !(selection[0] instanceof IFile)) {
return new Status(IStatus.ERROR, LaunchUIPlugin.getUniqueIdentifier(), 1, return new Status(IStatus.ERROR, LaunchUIPlugin.getUniqueIdentifier(), 1, LaunchMessages
LaunchMessages.getString("CMainTab.Selection_must_be_file"), null); //$NON-NLS-1$ .getString("CMainTab.Selection_must_be_file"), null); //$NON-NLS-1$
} }
try { try {
ICElement celement = cproject.findElement(((IFile) selection[0]).getProjectRelativePath()); ICElement celement = cproject.findElement(((IFile) selection[0]).getProjectRelativePath());
if (celement == null if (celement == null
|| (celement.getElementType() != ICElement.C_BINARY && celement.getElementType() != ICElement.C_ARCHIVE)) { || (celement.getElementType() != ICElement.C_BINARY && celement.getElementType() != ICElement.C_ARCHIVE)) {
return new Status(IStatus.ERROR, LaunchUIPlugin.getUniqueIdentifier(), 1, return new Status(IStatus.ERROR, LaunchUIPlugin.getUniqueIdentifier(), 1, LaunchMessages
LaunchMessages.getString("CMainTab.Selection_must_be_binary_file"), null); //$NON-NLS-1$ .getString("CMainTab.Selection_must_be_binary_file"), null); //$NON-NLS-1$
} }
return new Status(IStatus.OK, LaunchUIPlugin.getUniqueIdentifier(), IStatus.OK, return new Status(IStatus.OK, LaunchUIPlugin.getUniqueIdentifier(), IStatus.OK, celement.getResource()
celement.getResource().getName(), null); .getName(), null);
} catch (Exception ex) { } catch (Exception ex) {
return new Status(IStatus.ERROR, LaunchUIPlugin.PLUGIN_ID, 1, return new Status(IStatus.ERROR, LaunchUIPlugin.PLUGIN_ID, 1, LaunchMessages
LaunchMessages.getString("CMainTab.Selection_must_be_binary_file"), null); //$NON-NLS-1$ .getString("CMainTab.Selection_must_be_binary_file"), null); //$NON-NLS-1$
} }
} }
}); });
@ -388,9 +451,9 @@ public class CMainTab extends CLaunchConfigurationTab {
} }
/** /**
* Show a dialog that lets the user select a project. This in turn provides * Show a dialog that lets the user select a project. This in turn provides context for the main
* context for the main type, allowing the user to key a main type name, or * type, allowing the user to key a main type name, or constraining the search for main types to
* constraining the search for main types to the specified project. * the specified project.
*/ */
protected void handleProjectButtonSelected() { protected void handleProjectButtonSelected() {
ICProject project = chooseCProject(); ICProject project = chooseCProject();
@ -403,8 +466,8 @@ public class CMainTab extends CLaunchConfigurationTab {
} }
/** /**
* Realize a C Project selection dialog and return the first selected * Realize a C Project selection dialog and return the first selected project, or null if there
* project, or null if there was none. * was none.
*/ */
protected ICProject chooseCProject() { protected ICProject chooseCProject() {
try { try {
@ -432,7 +495,6 @@ public class CMainTab extends CLaunchConfigurationTab {
/** /**
* Return an array a ICProject whose platform match that of the runtime env. * Return an array a ICProject whose platform match that of the runtime env.
*/ */
protected ICProject[] getCProjects() throws CModelException { protected ICProject[] getCProjects() throws CModelException {
ICProject cproject[] = CoreModel.getDefault().getCModel().getCProjects(); ICProject cproject[] = CoreModel.getDefault().getCModel().getCProjects();
ArrayList list = new ArrayList(cproject.length); ArrayList list = new ArrayList(cproject.length);
@ -457,9 +519,10 @@ public class CMainTab extends CLaunchConfigurationTab {
} }
return (ICProject[]) list.toArray(new ICProject[list.size()]); return (ICProject[]) list.toArray(new ICProject[list.size()]);
} }
/** /**
* Return the ICProject corresponding to the project name in the project * Return the ICProject corresponding to the project name in the project name text field, or
* name text field, or null if the text does not match a project name. * null if the text does not match a project name.
*/ */
protected ICProject getCProject() { protected ICProject getCProject() {
String projectName = fProjText.getText().trim(); String projectName = fProjText.getText().trim();
@ -469,7 +532,9 @@ public class CMainTab extends CLaunchConfigurationTab {
return CoreModel.getDefault().getCModel().getCProject(projectName); return CoreModel.getDefault().getCModel().getCProject(projectName);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration) * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
*/ */
public boolean isValid(ILaunchConfiguration config) { public boolean isValid(ILaunchConfiguration config) {
@ -508,7 +573,9 @@ public class CMainTab extends CLaunchConfigurationTab {
return true; return true;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
*/ */
public void setDefaults(ILaunchConfigurationWorkingCopy config) { public void setDefaults(ILaunchConfigurationWorkingCopy config) {
@ -528,11 +595,13 @@ public class CMainTab extends CLaunchConfigurationTab {
initializeCProject(cElement, config); initializeCProject(cElement, config);
initializeProgramName(cElement, config); initializeProgramName(cElement, config);
} }
if (wantsTerminalOption()) {
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL, true);
}
} }
/** /**
* Set the program name attributes on the working copy based on the * Set the program name attributes on the working copy based on the ICElement
* ICElement
*/ */
protected void initializeProgramName(ICElement cElement, ILaunchConfigurationWorkingCopy config) { protected void initializeProgramName(ICElement cElement, ILaunchConfigurationWorkingCopy config) {
IBinary binary = null; IBinary binary = null;
@ -560,25 +629,30 @@ public class CMainTab extends CLaunchConfigurationTab {
} }
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName() * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
*/ */
public String getName() { public String getName() {
return LaunchMessages.getString("CMainTab.Main"); //$NON-NLS-1$ return LaunchMessages.getString("CMainTab.Main"); //$NON-NLS-1$
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage() * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
*/ */
public Image getImage() { public Image getImage() {
return LaunchImages.get(LaunchImages.IMG_VIEW_MAIN_TAB); return LaunchImages.get(LaunchImages.IMG_VIEW_MAIN_TAB);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#updateLaunchConfigurationDialog() * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#updateLaunchConfigurationDialog()
*/ */
protected void updateLaunchConfigurationDialog() { protected void updateLaunchConfigurationDialog() {
super.updateLaunchConfigurationDialog(); super.updateLaunchConfigurationDialog();
} }
} }