1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 06:32:10 +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.internal.ui.LaunchMessages;
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.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@ -119,8 +120,9 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate {
command.add(exePath.toOSString());
command.addAll(Arrays.asList(arguments));
String[] commandArray = (String[]) command.toArray(new String[command.size()]);
boolean usePty = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL, false);
monitor.worked(5);
Process process = exec(commandArray, getEnvironment(config), wd);
Process process = exec(commandArray, getEnvironment(config), wd, usePty);
monitor.worked(3);
DebugPlugin.newProcess(launch, process, renderProcessLabel(commandArray[0]));
}
@ -145,15 +147,18 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate {
* cancelled
* @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;
try {
if (workingDirectory == null) {
p = ProcessFactory.getFactory().exec(cmdLine, environ);
} else {
if (usePty && PTY.isSupported()) {
p = ProcessFactory.getFactory().exec(cmdLine, environ, workingDirectory, new PTY());
} else {
p = ProcessFactory.getFactory().exec(cmdLine, environ, workingDirectory);
}
}
} catch (IOException e) {
if (p != null) {
p.destroy();
@ -173,7 +178,7 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate {
if (handler != null) {
Object result = handler.handleStatus(status, this);
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.Choose_program_to_run=Choose a &program to run:
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.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) {
ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
new CMainTab(),
new CMainTab(true),
new CArgumentsTab(),
new MigratingCEnvironmentTab(),
new CDebuggerTab(false),

View file

@ -1,13 +1,11 @@
/**********************************************************************
* Copyright (c) 2002 - 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
/***************************************************************************************************
* Copyright (c) 2002 - 2004 QNX Software Systems and others. All rights reserved. This program and
* the accompanying materials are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
* Contributors: QNX Software Systems - Initial API and implementation
**************************************************************************************************/
package org.eclipse.cdt.launch.ui;
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.CElementLabelProvider;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.utils.pty.PTY;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@ -64,8 +63,8 @@ import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;
/**
* A launch configuration tab that displays and edits project and main type name
* launch configuration attributes.
* A launch configuration tab that displays and edits project and main type name launch
* configuration attributes.
* <p>
* This class may be instantiated. This class is not intended to be subclassed.
* </p>
@ -85,32 +84,54 @@ public class CMainTab extends CLaunchConfigurationTab {
protected Text fProgText;
protected Button fSearchButton;
private final boolean fWantsTerminalOption;
protected Button fTerminalButton;
protected static final String EMPTY_STRING = ""; //$NON-NLS-1$
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)
*/
public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
setControl(comp);
WorkbenchHelp.setHelp(getControl(), ICDTLaunchHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_MAIN_TAB);
GridLayout topLayout = new GridLayout();
comp.setLayout(topLayout);
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();
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);
@ -137,16 +158,17 @@ public class CMainTab extends CLaunchConfigurationTab {
updateLaunchConfigurationDialog();
}
});
}
createVerticalSpacer(comp, 1);
Composite mainComp = new Composite(comp, SWT.NONE);
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);
gd = new GridData(GridData.FILL_HORIZONTAL);
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$
@ -181,18 +203,54 @@ public class CMainTab extends CLaunchConfigurationTab {
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)
*/
public void initializeFrom(ILaunchConfiguration config) {
filterPlatform = getPlatform(config);
updateProjectFromConfig(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) {
@ -215,12 +273,17 @@ public class CMainTab extends CLaunchConfigurationTab {
fProgText.setText(programName);
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
*/
public void performApply(ILaunchConfigurationWorkingCopy config) {
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, fProjText.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
* 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.
* 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 handleBinaryBrowseButtonSelected() {
final ICProject cproject = getCProject();
@ -325,22 +388,22 @@ public class CMainTab extends CLaunchConfigurationTab {
public IStatus validate(Object[] selection) {
if (selection.length == 0 || !(selection[0] instanceof IFile)) {
return new Status(IStatus.ERROR, LaunchUIPlugin.getUniqueIdentifier(), 1,
LaunchMessages.getString("CMainTab.Selection_must_be_file"), null); //$NON-NLS-1$
return new Status(IStatus.ERROR, LaunchUIPlugin.getUniqueIdentifier(), 1, LaunchMessages
.getString("CMainTab.Selection_must_be_file"), null); //$NON-NLS-1$
}
try {
ICElement celement = cproject.findElement(((IFile) selection[0]).getProjectRelativePath());
if (celement == null
|| (celement.getElementType() != ICElement.C_BINARY && celement.getElementType() != ICElement.C_ARCHIVE)) {
return new Status(IStatus.ERROR, LaunchUIPlugin.getUniqueIdentifier(), 1,
LaunchMessages.getString("CMainTab.Selection_must_be_binary_file"), null); //$NON-NLS-1$
return new Status(IStatus.ERROR, LaunchUIPlugin.getUniqueIdentifier(), 1, LaunchMessages
.getString("CMainTab.Selection_must_be_binary_file"), null); //$NON-NLS-1$
}
return new Status(IStatus.OK, LaunchUIPlugin.getUniqueIdentifier(), IStatus.OK,
celement.getResource().getName(), null);
return new Status(IStatus.OK, LaunchUIPlugin.getUniqueIdentifier(), IStatus.OK, celement.getResource()
.getName(), null);
} catch (Exception ex) {
return new Status(IStatus.ERROR, LaunchUIPlugin.PLUGIN_ID, 1,
LaunchMessages.getString("CMainTab.Selection_must_be_binary_file"), null); //$NON-NLS-1$
return new Status(IStatus.ERROR, LaunchUIPlugin.PLUGIN_ID, 1, LaunchMessages
.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
* 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.
* 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() {
ICProject project = chooseCProject();
@ -403,8 +466,8 @@ public class CMainTab extends CLaunchConfigurationTab {
}
/**
* Realize a C Project selection dialog and return the first selected
* project, or null if there was none.
* Realize a C Project selection dialog and return the first selected project, or null if there
* was none.
*/
protected ICProject chooseCProject() {
try {
@ -432,7 +495,6 @@ public class CMainTab extends CLaunchConfigurationTab {
/**
* 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 list = new ArrayList(cproject.length);
@ -457,9 +519,10 @@ public class CMainTab extends CLaunchConfigurationTab {
}
return (ICProject[]) 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.
* 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();
@ -469,7 +532,9 @@ public class CMainTab extends CLaunchConfigurationTab {
return CoreModel.getDefault().getCModel().getCProject(projectName);
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
*/
public boolean isValid(ILaunchConfiguration config) {
@ -508,7 +573,9 @@ public class CMainTab extends CLaunchConfigurationTab {
return true;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
*/
public void setDefaults(ILaunchConfigurationWorkingCopy config) {
@ -528,11 +595,13 @@ public class CMainTab extends CLaunchConfigurationTab {
initializeCProject(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
* ICElement
* Set the program name attributes on the working copy based on the ICElement
*/
protected void initializeProgramName(ICElement cElement, ILaunchConfigurationWorkingCopy config) {
IBinary binary = null;
@ -560,25 +629,30 @@ public class CMainTab extends CLaunchConfigurationTab {
}
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
*/
public String getName() {
return LaunchMessages.getString("CMainTab.Main"); //$NON-NLS-1$
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
*/
public Image getImage() {
return LaunchImages.get(LaunchImages.IMG_VIEW_MAIN_TAB);
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#updateLaunchConfigurationDialog()
*/
protected void updateLaunchConfigurationDialog() {
super.updateLaunchConfigurationDialog();
}
}