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

added variable support to launching

This commit is contained in:
David Inglis 2004-10-22 14:42:59 +00:00
parent 51f2da0305
commit 2e47a2377b
10 changed files with 463 additions and 474 deletions

View file

@ -1,3 +1,16 @@
2004-10-22 David Inglis
Added variables support to arguments, environment and working directory.
* plugin.xml
* src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java
* src/org/eclipse/cdt/launch/internal/LocalRunLaunchDelegate.java
* src/org/eclipse/cdt/launch/internal/ui/LaunchMessages.properties
* src/org/eclipse/cdt/launch/internal/ui/LocalRunLaunchConfigurationTabGroup.java
* src/org/eclipse/cdt/launch/internal/ui/WorkingDirectoryBlock.java
* src/org/eclipse/cdt/launch/ui/CArgumentsTab.java
* src/org/eclipse/cdt/launch/ui/CDebuggerTab.java
* src/org/eclipse/cdt/launch/internal/ui/MigratingCEnvironmentTab.java
2004-10-18 Alain Magloire 2004-10-18 Alain Magloire
Adjust to changes in CDI Adjust to changes in CDI
* src/org/eclipse/cdt/launch/internal/LocalRunLaunchDelegate.java * src/org/eclipse/cdt/launch/internal/LocalRunLaunchDelegate.java

View file

@ -25,6 +25,7 @@
<import plugin="org.eclipse.cdt.debug.ui"/> <import plugin="org.eclipse.cdt.debug.ui"/>
<import plugin="org.eclipse.core.boot"/> <import plugin="org.eclipse.core.boot"/>
<import plugin="org.eclipse.core.runtime"/> <import plugin="org.eclipse.core.runtime"/>
<import plugin="org.eclipse.core.variables"/>
</requires> </requires>

View file

@ -16,13 +16,11 @@ import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.Enumeration;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Map.Entry;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IBinaryParser; import org.eclipse.cdt.core.IBinaryParser;
@ -36,7 +34,6 @@ import org.eclipse.cdt.debug.core.ICDebugConfiguration;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
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.spawner.EnvironmentReader;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IMarker;
@ -52,9 +49,13 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.variables.IStringVariableManager;
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.IStatusHandler; import org.eclipse.debug.core.IStatusHandler;
import org.eclipse.debug.core.model.IPersistableSourceLocator; import org.eclipse.debug.core.model.IPersistableSourceLocator;
import org.eclipse.debug.core.model.LaunchConfigurationDelegate; import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
@ -77,149 +78,21 @@ abstract public class AbstractCLaunchDelegate extends LaunchConfigurationDelegat
* Return the save environment variables in the configuration. The array * Return the save environment variables in the configuration. The array
* does not include the default environment of the target. array[n] : * does not include the default environment of the target. array[n] :
* name=value * name=value
* @throws CoreException
*/ */
protected String[] getEnvironmentArray(ILaunchConfiguration config) { protected String[] getEnvironmentArray(ILaunchConfiguration config) throws CoreException {
Map env = null;
try { try {
env = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null); // Migrate old env settings to new.
Map map = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null);
if (map != null) {
ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
wc.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map);
wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null);
wc.doSave();
}
} catch (CoreException e) { } catch (CoreException e) {
} }
if (env == null) { return DebugPlugin.getDefault().getLaunchManager().getEnvironment(config);
return new String[0];
}
String[] array = new String[env.size()];
Iterator entries = env.entrySet().iterator();
Entry entry;
for (int i = 0; entries.hasNext() && i < array.length; i++) {
entry = (Entry)entries.next();
array[i] = ((String)entry.getKey()) + "=" + ((String)entry.getValue()); //$NON-NLS-1$
}
return array;
}
/**
* Return the save environment variables of this configuration. The array
* does not include the default environment of the target.
*/
protected Properties getEnvironmentProperty(ILaunchConfiguration config) {
Properties prop = new Properties();
Map env = null;
try {
env = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null);
} catch (CoreException e) {
}
if (env == null)
return prop;
Iterator entries = env.entrySet().iterator();
Entry entry;
while (entries.hasNext()) {
entry = (Entry)entries.next();
prop.setProperty((String)entry.getKey(), (String)entry.getValue());
}
return prop;
}
/**
* Return the default Environment of the target.
*/
protected Properties getDefaultEnvironment() {
return EnvironmentReader.getEnvVars();
}
/**
* Expand the variable with the format ${key}. example: HOME=/foobar NEWHOME =
* ${HOME}/project The environement NEWHOME will be /foobar/project.
*/
protected Properties expandEnvironment(ILaunchConfiguration config) {
return expandEnvironment(getEnvironmentProperty(config));
}
/**
* Expand the variable with the format ${key}. example: HOME=/foobar NEWHOME =
* ${HOME}/project The environement NEWHOME will be /foobar/project.
*/
protected Properties expandEnvironment(Properties props) {
Enumeration names = props.propertyNames();
if (names != null) {
while (names.hasMoreElements()) {
String key = (String)names.nextElement();
String value = props.getProperty(key);
if (value != null && value.indexOf('$') != -1) {
StringBuffer sb = new StringBuffer();
StringBuffer param = new StringBuffer();
char prev = '\n';
char ch = prev;
boolean inMacro = false;
boolean inSingleQuote = false;
for (int i = 0; i < value.length(); i++) {
ch = value.charAt(i);
switch (ch) {
case '\'' :
if (prev != '\\') {
inSingleQuote = !inSingleQuote;
}
break;
case '$' :
if (!inSingleQuote && prev != '\\') {
if (i < value.length() && value.indexOf('}', i) > 0) {
char c = value.charAt(i + 1);
if (c == '{') {
param.setLength(0);
inMacro = true;
prev = ch;
continue;
}
}
}
break;
case '}' :
if (inMacro) {
inMacro = false;
String v = null;
String p = param.toString();
/*
* Search in the current property only if it
* is not the same name.
*/
if (!p.equals(key)) {
v = props.getProperty(p);
}
/* Fallback to the default Environemnt. */
if (v == null) {
Properties def = getDefaultEnvironment();
if (def != null) {
v = def.getProperty(p);
}
}
if (v != null) {
sb.append(v);
}
param.setLength(0);
/* Skip the trailing } */
prev = ch;
continue;
}
break;
} /* switch */
if (!inMacro) {
sb.append(ch);
} else {
/* Do not had the '{' */
if (! (ch == '{' && prev == '$')) {
param.append(ch);
}
}
prev = (ch == '\\' && prev == '\\') ? '\n' : ch;
} /* for */
props.setProperty(key, sb.toString());
} /* !if (value ..) */
} /* while() */
} /* if (names != null) */
return props;
} }
/** /**
@ -253,10 +126,27 @@ abstract public class AbstractCLaunchDelegate extends LaunchConfigurationDelegat
return verifyWorkingDirectory(configuration); return verifyWorkingDirectory(configuration);
} }
/**
* Expands and returns the working directory attribute of the given launch
* configuration. Returns <code>null</code> if a working directory is not
* specified. If specified, the working is verified to point to an existing
* directory in the local file system.
*
* @param configuration launch configuration
* @return an absolute path to a directory in the local file system, or
* <code>null</code> if unspecified
* @throws CoreException if unable to retrieve the associated launch
* configuration attribute, if unable to resolve any variables, or if the
* resolved location does not point to an existing directory in the local
* file system
*/
protected IPath getWorkingDirectoryPath(ILaunchConfiguration config) throws CoreException { protected IPath getWorkingDirectoryPath(ILaunchConfiguration config) throws CoreException {
String path = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String)null); String location = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String)null);
if (path != null) { if (location != null) {
return new Path(path); String expandedLocation = getStringVariableManager().performStringSubstitution(location);
if (expandedLocation.length() > 0) {
return new Path(expandedLocation);
}
} }
return null; return null;
} }
@ -317,6 +207,10 @@ abstract public class AbstractCLaunchDelegate extends LaunchConfigurationDelegat
return new Path(path); return new Path(path);
} }
private static IStringVariableManager getStringVariableManager() {
return VariablesPlugin.getDefault().getStringVariableManager();
}
/** /**
* @param launch * @param launch
* @param config * @param config
@ -371,7 +265,11 @@ abstract public class AbstractCLaunchDelegate extends LaunchConfigurationDelegat
* @return the program arguments as a String * @return the program arguments as a String
*/ */
public String getProgramArguments(ILaunchConfiguration config) throws CoreException { public String getProgramArguments(ILaunchConfiguration config) throws CoreException {
return config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null); String args = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null);
if (args != null) {
args = getStringVariableManager().performStringSubstitution(args);
}
return args;
} }
/** /**
@ -545,7 +443,7 @@ abstract public class AbstractCLaunchDelegate extends LaunchConfigurationDelegat
LaunchMessages.getString("AbstractCLaunchDelegate.Working_directory_does_not_exist"), //$NON-NLS-1$ LaunchMessages.getString("AbstractCLaunchDelegate.Working_directory_does_not_exist"), //$NON-NLS-1$
new FileNotFoundException( new FileNotFoundException(
LaunchMessages.getFormattedString( LaunchMessages.getFormattedString(
"AbstractCLaunchDelegate.PROGRAM_PATH_not_found", path.toOSString())), //$NON-NLS-1$ "AbstractCLaunchDelegate.WORKINGDIRECTORY_PATH_not_found", path.toOSString())), //$NON-NLS-1$
ICDTLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_DOES_NOT_EXIST); ICDTLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_DOES_NOT_EXIST);
} else { } else {
IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(path); IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
@ -556,7 +454,7 @@ abstract public class AbstractCLaunchDelegate extends LaunchConfigurationDelegat
LaunchMessages.getString("AbstractCLaunchDelegate.Working_directory_does_not_exist"), //$NON-NLS-1$ LaunchMessages.getString("AbstractCLaunchDelegate.Working_directory_does_not_exist"), //$NON-NLS-1$
new FileNotFoundException( new FileNotFoundException(
LaunchMessages.getFormattedString( LaunchMessages.getFormattedString(
"AbstractCLaunchDelegate.PROGRAM_PATH_does_not_exist", path.toOSString())), //$NON-NLS-1$ "AbstractCLaunchDelegate.WORKINGDIRECTORY_PATH_not_found", path.toOSString())), //$NON-NLS-1$
ICDTLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_DOES_NOT_EXIST); ICDTLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_DOES_NOT_EXIST);
} }
} }
@ -869,4 +767,25 @@ abstract public class AbstractCLaunchDelegate extends LaunchConfigurationDelegat
return null; return null;
} }
/**
* @param config
* @return
* @throws CoreException
*/
protected Properties getEnvironmentProperty(ILaunchConfiguration config) throws CoreException {
String[] envp = getEnvironmentArray(config);
Properties p = new Properties( );
for( int i = 0; i < envp.length; i++ ) {
int idx = envp[i].indexOf('=');
if (idx != -1) {
String key = envp[i].substring(0, idx);
String value = envp[i].substring(idx + 1);
p.setProperty(key, value);
} else {
p.setProperty(envp[i], ""); //$NON-NLS-1$
}
}
return p;
}
} }

View file

@ -12,8 +12,6 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Enumeration;
import java.util.Properties;
import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable; import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
@ -69,7 +67,9 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate {
String debugMode = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, String debugMode = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN); ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) { if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) {
dsession = debugConfig.createDebugger().createDebuggerSession(launch, exeFile, new SubProgressMonitor(monitor, 8)); dsession = debugConfig.createDebugger().createDebuggerSession(launch, exeFile,
new SubProgressMonitor(monitor, 8));
try {
try { try {
ICDITarget[] dtargets = dsession.getTargets(); ICDITarget[] dtargets = dsession.getTargets();
for (int i = 0; i < dtargets.length; ++i) { for (int i = 0; i < dtargets.length; ++i) {
@ -79,20 +79,17 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate {
if (wd != null) { if (wd != null) {
opt.setWorkingDirectory(wd.getAbsolutePath()); opt.setWorkingDirectory(wd.getAbsolutePath());
} }
opt.setEnvironment(expandEnvironment(config)); opt.setEnvironment(getEnvironmentProperty(config));
} }
} catch (CDIException e) { } catch (CDIException e) {
try { abort(
dsession.terminate(); LaunchMessages
} catch (CDIException ex) { .getString("LocalRunLaunchDelegate.Failed_setting_runtime_option_though_debugger"), e, //$NON-NLS-1$
// ignore
}
abort(LaunchMessages.getString("LocalRunLaunchDelegate.Failed_setting_runtime_option_though_debugger"), e, //$NON-NLS-1$
ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
} }
monitor.worked(1); monitor.worked(1);
try { boolean stopInMain = config
boolean stopInMain = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false); .getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false);
ICDITarget[] targets = dsession.getTargets(); ICDITarget[] targets = dsession.getTargets();
for (int i = 0; i < targets.length; i++) { for (int i = 0; i < targets.length; i++) {
@ -123,7 +120,7 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate {
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()]);
monitor.worked(5); monitor.worked(5);
Process process = exec(commandArray, getEnvironmentProperty(config), wd); Process process = exec(commandArray, getEnvironmentArray(config), wd);
monitor.worked(3); monitor.worked(3);
DebugPlugin.newProcess(launch, process, renderProcessLabel(commandArray[0])); DebugPlugin.newProcess(launch, process, renderProcessLabel(commandArray[0]));
} }
@ -148,26 +145,14 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate {
* cancelled * cancelled
* @see Runtime * @see Runtime
*/ */
protected Process exec(String[] cmdLine, Properties environ, File workingDirectory) throws CoreException { protected Process exec(String[] cmdLine, String[] environ, File workingDirectory) throws CoreException {
Process p = null; Process p = null;
Properties props = getDefaultEnvironment();
props.putAll(expandEnvironment(environ));
String[] envp = null;
ArrayList envList = new ArrayList();
Enumeration names = props.propertyNames();
if (names != null) {
while (names.hasMoreElements()) {
String key = (String)names.nextElement();
envList.add(key + "=" + props.getProperty(key)); //$NON-NLS-1$
}
envp = (String[])envList.toArray(new String[envList.size()]);
}
try { try {
if (workingDirectory == null) { if (workingDirectory == null) {
p = ProcessFactory.getFactory().exec(cmdLine, envp); p = ProcessFactory.getFactory().exec(cmdLine, environ);
} else { } else {
p = ProcessFactory.getFactory().exec(cmdLine, envp, workingDirectory); p = ProcessFactory.getFactory().exec(cmdLine, environ, workingDirectory);
} }
} catch (IOException e) { } catch (IOException e) {
if (p != null) { if (p != null) {
@ -180,8 +165,8 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate {
// directory // directory
IStatus status = new Status(IStatus.ERROR, LaunchUIPlugin.getUniqueIdentifier(), IStatus status = new Status(IStatus.ERROR, LaunchUIPlugin.getUniqueIdentifier(),
ICDTLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_NOT_SUPPORTED, ICDTLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_NOT_SUPPORTED, LaunchMessages
LaunchMessages.getString("LocalRunLaunchDelegate.Does_not_support_working_dir"), //$NON-NLS-1$ .getString("LocalRunLaunchDelegate.Does_not_support_working_dir"), //$NON-NLS-1$
e); e);
IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(status); IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(status);

View file

@ -14,11 +14,11 @@ AbstractCLaunchDelegate.C_Project_not_specified=C Project not specified
AbstractCLaunchDelegate.Not_a_C_CPP_project=Project is not a C/C++ project AbstractCLaunchDelegate.Not_a_C_CPP_project=Project is not a C/C++ project
AbstractCLaunchDelegate.Program_file_not_specified=Program file not specified AbstractCLaunchDelegate.Program_file_not_specified=Program file not specified
AbstractCLaunchDelegate.Program_file_does_not_exist=Program file does not exist AbstractCLaunchDelegate.Program_file_does_not_exist=Program file does not exist
AbstractCLaunchDelegate.PROGRAM_PATH_not_found={0} not found
AbstractCLaunchDelegate.Working_directory_does_not_exist=Working directory does not exist AbstractCLaunchDelegate.Working_directory_does_not_exist=Working directory does not exist
AbstractCLaunchDelegate.WORKINGDIRECTORY_PATH_not_found=The working directory {0} does not exist.
AbstractCLaunchDelegate.Project_NAME_does_not_exist=Project {0} does not exist AbstractCLaunchDelegate.Project_NAME_does_not_exist=Project {0} does not exist
AbstractCLaunchDelegate.Project_NAME_is_closed=Project {0} is closed AbstractCLaunchDelegate.Project_NAME_is_closed=Project {0} is closed
AbstractCLaunchDelegate.PROGRAM_PATH_not_found={0} not found
AbstractCLaunchDelegate.PROGRAM_PATH_does_not_exist={0} Does not exist.
AbstractCLaunchDelegate.Debugger_Process=Debugger Process AbstractCLaunchDelegate.Debugger_Process=Debugger Process
AbstractCLaunchDelegate.building_projects=Building prerequisite project list AbstractCLaunchDelegate.building_projects=Building prerequisite project list
AbstractCLaunchDelegate.building=Building AbstractCLaunchDelegate.building=Building
@ -121,16 +121,15 @@ CEnvironmentTab.Environment_variable_NAME_exists=Environment variable \" {0} \"
CArgumentsTab.C/C++_Program_Arguments=C/C++ Program Arguments: CArgumentsTab.C/C++_Program_Arguments=C/C++ Program Arguments:
CArgumentsTab.Arguments=Arguments CArgumentsTab.Arguments=Arguments
WorkingDirectoryBlock.Wor&king_directory=Wor&king directory: WorkingDirectoryBlock.4=Select a &workspace relative working directory:
WorkingDirectoryBlock.Use_de&fault_working_directory=Use de&fault working directory WorkingDirectoryBlock.7=Select a working directory for the launch configuration:
WorkingDirectoryBlock.&Local_directory=&Local directory WorkingDirectoryBlock.0=W&orkspace...
WorkingDirectoryBlock.Works&pace=Works&pace WorkingDirectoryBlock.Working_Directory_8=Working Directory
WorkingDirectoryBlock.Select_&working_directory_for_launch_configuration=Select a &working directory for the launch configuration WorkingDirectoryBlock.10=Working directory does not exist
WorkingDirectoryBlock.Select_&workspace_relative_working_directory=Select a &workspace relative working directory WorkingDirectoryBlock.Use_de&fault_working_directory_4=Use default wor&king directory
WorkingDirectoryBlock.Working_directory_does_not_exist=Working directory does not exist WorkingDirectoryBlock.17=Variabl&es...
WorkingDirectoryBlock.Working_directory_is_not_a_directory=Working directory is not a directory WorkingDirectoryBlock.1=File S&ystem...
WorkingDirectoryBlock.Project_or_folder_does_not_exist=Specified project or folder does not exist. WorkingDirectoryBlock.Exception_occurred_reading_configuration___15=Exception occurred reading configuration:
WorkingDirectoryBlock.Working_Directory=Working Directory
Launch.common.Exception_occurred_reading_configuration_EXCEPTION=Exception occurred reading configuration {0} Launch.common.Exception_occurred_reading_configuration_EXCEPTION=Exception occurred reading configuration {0}
Launch.common.DebuggerColon=Debugger: Launch.common.DebuggerColon=Debugger:

View file

@ -12,7 +12,6 @@ package org.eclipse.cdt.launch.internal.ui;
import org.eclipse.cdt.launch.ui.CArgumentsTab; import org.eclipse.cdt.launch.ui.CArgumentsTab;
import org.eclipse.cdt.launch.ui.CDebuggerTab; import org.eclipse.cdt.launch.ui.CDebuggerTab;
import org.eclipse.cdt.launch.ui.CEnvironmentTab;
import org.eclipse.cdt.launch.ui.CMainTab; import org.eclipse.cdt.launch.ui.CMainTab;
import org.eclipse.cdt.launch.ui.CSourceLookupTab; import org.eclipse.cdt.launch.ui.CSourceLookupTab;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup; import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
@ -29,7 +28,7 @@ public class LocalRunLaunchConfigurationTabGroup extends AbstractLaunchConfigura
ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
new CMainTab(), new CMainTab(),
new CArgumentsTab(), new CArgumentsTab(),
new CEnvironmentTab(), new MigratingCEnvironmentTab(),
new CDebuggerTab(false), new CDebuggerTab(false),
new CSourceLookupTab(), new CSourceLookupTab(),
new CommonTab() new CommonTab()

View file

@ -0,0 +1,45 @@
/*
* Created on Oct 21, 2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package org.eclipse.cdt.launch.internal.ui;
import java.util.Map;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.ui.EnvironmentTab;
/**
* @author DInglis
* @deprecated - temporary class for while configs are migrated to new EnvironmentTab
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class MigratingCEnvironmentTab extends EnvironmentTab {
/* (non-Javadoc)
* @see org.eclipse.cdt.launch.ui.CEnvironmentTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
*/
public void initializeFrom(ILaunchConfiguration config) {
if (config instanceof ILaunchConfigurationWorkingCopy) {
ILaunchConfigurationWorkingCopy wc = (ILaunchConfigurationWorkingCopy) config;
try {
Map map = wc.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null);
if (map != null) {
wc.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map);
wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null);
}
} catch (CoreException e) {
}
}
super.initializeFrom(config);
}
}

View file

@ -1,41 +1,41 @@
/********************************************************************** /*******************************************************************************
* Copyright (c) 2002 - 2004 QNX Software Systems and others. * Copyright (c) 2000, 2004 IBM Corporation and others. All rights reserved.
* All rights reserved. This program and the accompanying materials * This program and the accompanying materials are made available under the
* are made available under the terms of the Common Public License v1.0 * terms of the Common Public License v1.0 which accompanies this distribution,
* which accompanies this distribution, and is available at * and is available at http://www.eclipse.org/legal/cpl-v10.html
* http://www.eclipse.org/legal/cpl-v10.html
* *
* Contributors: * Contributors: IBM Corporation - initial API and implementation
* QNX Software Systems - Initial API and implementation ******************************************************************************/
***********************************************************************/
package org.eclipse.cdt.launch.internal.ui; package org.eclipse.cdt.launch.internal.ui;
import java.io.File; import java.io.File;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.launch.AbstractCLaunchDelegate; import org.eclipse.cdt.launch.AbstractCLaunchDelegate;
import org.eclipse.cdt.launch.ui.CLaunchConfigurationTab;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path; import org.eclipse.core.variables.IStringVariableManager;
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; import org.eclipse.debug.internal.ui.stringsubstitution.StringVariableSelectionDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
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.graphics.Font;
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.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog; import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ContainerSelectionDialog; import org.eclipse.ui.dialogs.ContainerSelectionDialog;
@ -43,115 +43,103 @@ import org.eclipse.ui.dialogs.ContainerSelectionDialog;
* A control for setting the working directory associated with a launch * A control for setting the working directory associated with a launch
* configuration. * configuration.
*/ */
public class WorkingDirectoryBlock extends AbstractLaunchConfigurationTab { public class WorkingDirectoryBlock extends CLaunchConfigurationTab {
// Working directory UI widgets
protected Label fWorkingDirLabel;
// Local directory // Local directory
protected Button fLocalDirButton;
protected Text fWorkingDirText; protected Text fWorkingDirText;
protected Button fWorkingDirBrowseButton; protected Button fWorkspaceButton;
protected Button fFileSystemButton;
protected Button fVariablesButton;
// Workspace directory
protected Button fWorkspaceDirButton;
protected Text fWorkspaceDirText;
protected Button fWorkspaceDirBrowseButton;
// use default button // use default button
protected Button fUseDefaultWorkingDirButton; protected Button fUseDefaultWorkingDirButton;
protected static final String EMPTY_STRING = ""; //$NON-NLS-1$
/** /**
* The last launch config this tab was initialized from * The last launch config this tab was initialized from
*/ */
protected ILaunchConfiguration fLaunchConfiguration; protected ILaunchConfiguration fLaunchConfiguration;
/** /**
* @see ILaunchConfigurationTab#createControl(Composite) * A listener to update for text changes and widget selection
*/
private class WidgetListener extends SelectionAdapter implements ModifyListener {
public void modifyText(ModifyEvent e) {
updateLaunchConfigurationDialog();
}
public void widgetSelected(SelectionEvent e) {
Object source = e.getSource();
if (source == fWorkspaceButton) {
handleWorkspaceDirBrowseButtonSelected();
} else if (source == fFileSystemButton) {
handleWorkingDirBrowseButtonSelected();
} else if (source == fUseDefaultWorkingDirButton) {
handleUseDefaultWorkingDirButtonSelected();
} else if (source == fVariablesButton) {
handleWorkingDirVariablesButtonSelected();
}
}
}
private WidgetListener fListener = new WidgetListener();
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
*/ */
public void createControl(Composite parent) { public void createControl(Composite parent) {
Font font = parent.getFont();
Composite workingDirComp = new Composite(parent, SWT.NONE); Composite comp = new Composite(parent, SWT.NONE);
// WorkbenchHelp.setHelp(workingDirComp, IJavaDebugHelpContextIds.WORKING_DIRECTORY_BLOCK);; // WorkbenchHelp.setHelp(group,
// IJavaDebugHelpContextIds.WORKING_DIRECTORY_BLOCK);
GridLayout workingDirLayout = new GridLayout(); GridLayout workingDirLayout = new GridLayout();
workingDirLayout.numColumns = 3; workingDirLayout.numColumns = 2;
workingDirLayout.marginHeight = 0; workingDirLayout.makeColumnsEqualWidth = false;
workingDirLayout.marginWidth = 0; comp.setLayout(workingDirLayout);
workingDirComp.setLayout(workingDirLayout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL); GridData gd = new GridData(GridData.FILL_HORIZONTAL);
workingDirComp.setLayoutData(gd); comp.setLayoutData(gd);
setControl(workingDirComp); comp.setFont(font);
setControl(comp);
fWorkingDirLabel = new Label(workingDirComp, SWT.NONE); fWorkingDirText = new Text(comp, SWT.SINGLE | SWT.BORDER);
fWorkingDirLabel.setText(LaunchMessages.getString("WorkingDirectoryBlock.Wor&king_directory")); //$NON-NLS-1$
gd = new GridData();
gd.horizontalSpan = 3;
fWorkingDirLabel.setLayoutData(gd);
fUseDefaultWorkingDirButton = new Button(workingDirComp,SWT.CHECK);
fUseDefaultWorkingDirButton.setText(LaunchMessages.getString("WorkingDirectoryBlock.Use_de&fault_working_directory")); //$NON-NLS-1$
gd = new GridData();
gd.horizontalSpan = 3;
fUseDefaultWorkingDirButton.setLayoutData(gd);
fUseDefaultWorkingDirButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
handleUseDefaultWorkingDirButtonSelected();
}
});
fLocalDirButton = createRadioButton(workingDirComp, LaunchMessages.getString("WorkingDirectoryBlock.&Local_directory")); //$NON-NLS-1$
fLocalDirButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
handleLocationButtonSelected();
}
});
fWorkingDirText = new Text(workingDirComp, SWT.SINGLE | SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL); gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
fWorkingDirText.setLayoutData(gd); fWorkingDirText.setLayoutData(gd);
fWorkingDirText.addModifyListener(new ModifyListener() { fWorkingDirText.setFont(font);
public void modifyText(ModifyEvent evt) { fWorkingDirText.addModifyListener(fListener);
updateLaunchConfigurationDialog();
}
});
fWorkingDirBrowseButton = createPushButton(workingDirComp, LaunchMessages.getString("Launch.common.Browse_1"), null); //$NON-NLS-1$ fUseDefaultWorkingDirButton = new Button(comp, SWT.CHECK);
fWorkingDirBrowseButton.addSelectionListener(new SelectionAdapter() { fUseDefaultWorkingDirButton.setText(LaunchMessages.getString("WorkingDirectoryBlock.Use_de&fault_working_directory_4")); //$NON-NLS-1$
public void widgetSelected(SelectionEvent evt) {
handleWorkingDirBrowseButtonSelected();
}
});
fWorkspaceDirButton = createRadioButton(workingDirComp, LaunchMessages.getString("WorkingDirectoryBlock.Works&pace")); //$NON-NLS-1$
fWorkspaceDirButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
handleLocationButtonSelected();
}
});
fWorkspaceDirText = new Text(workingDirComp, SWT.SINGLE | SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL); gd = new GridData(GridData.FILL_HORIZONTAL);
fWorkspaceDirText.setLayoutData(gd); fUseDefaultWorkingDirButton.setLayoutData(gd);
fWorkspaceDirText.addModifyListener(new ModifyListener() { fUseDefaultWorkingDirButton.setFont(font);
public void modifyText(ModifyEvent evt) { fUseDefaultWorkingDirButton.addSelectionListener(fListener);
updateLaunchConfigurationDialog();
}
});
fWorkspaceDirBrowseButton = createPushButton(workingDirComp, LaunchMessages.getString("Launch.common.Browse_2"), null); //$NON-NLS-1$ Composite buttonComp = new Composite(comp, SWT.NONE);
fWorkspaceDirBrowseButton.addSelectionListener(new SelectionAdapter() { GridLayout layout = new GridLayout(3, false);
public void widgetSelected(SelectionEvent evt) { layout.marginHeight = 0;
handleWorkspaceDirBrowseButtonSelected(); layout.marginWidth = 0;
} buttonComp.setLayout(layout);
}); gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
buttonComp.setLayoutData(gd);
buttonComp.setFont(font);
fWorkspaceButton = createPushButton(buttonComp, LaunchMessages.getString("WorkingDirectoryBlock.0"), null); //$NON-NLS-1$
fWorkspaceButton.addSelectionListener(fListener);
fFileSystemButton = createPushButton(buttonComp, LaunchMessages.getString("WorkingDirectoryBlock.1"), null); //$NON-NLS-1$
fFileSystemButton.addSelectionListener(fListener);
fVariablesButton = createPushButton(buttonComp, LaunchMessages.getString("WorkingDirectoryBlock.17"), null); //$NON-NLS-1$
fVariablesButton.addSelectionListener(fListener);
} }
/** /*
* @see ILaunchConfigurationTab#dispose() * (non-Javadoc)
*
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#dispose()
*/ */
public void dispose() { public void dispose() {
} }
@ -161,9 +149,9 @@ public class WorkingDirectoryBlock extends AbstractLaunchConfigurationTab {
*/ */
protected void handleWorkingDirBrowseButtonSelected() { protected void handleWorkingDirBrowseButtonSelected() {
DirectoryDialog dialog = new DirectoryDialog(getShell()); DirectoryDialog dialog = new DirectoryDialog(getShell());
dialog.setMessage(LaunchMessages.getString("WorkingDirectoryBlock.Select_&working_directory_for_launch_configuration")); //$NON-NLS-1$ dialog.setMessage(LaunchMessages.getString("WorkingDirectoryBlock.7")); //$NON-NLS-1$
String currentWorkingDir = fWorkingDirText.getText(); String currentWorkingDir = fWorkingDirText.getText();
if (!currentWorkingDir.trim().equals(EMPTY_STRING)) { if (!currentWorkingDir.trim().equals("")) { //$NON-NLS-1$
File path = new File(currentWorkingDir); File path = new File(currentWorkingDir);
if (path.exists()) { if (path.exists()) {
dialog.setFilterPath(currentWorkingDir); dialog.setFilterPath(currentWorkingDir);
@ -177,14 +165,12 @@ public class WorkingDirectoryBlock extends AbstractLaunchConfigurationTab {
} }
/** /**
* Show a dialog that lets the user select a working directory from * Show a dialog that lets the user select a working directory from the
* the workspace * workspace
*/ */
protected void handleWorkspaceDirBrowseButtonSelected() { protected void handleWorkspaceDirBrowseButtonSelected() {
ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), false,
ResourcesPlugin.getWorkspace().getRoot(), LaunchMessages.getString("WorkingDirectoryBlock.4")); //$NON-NLS-1$
false,
LaunchMessages.getString("WorkingDirectoryBlock.Select_&workspace_relative_working_directory")); //$NON-NLS-1$
IContainer currentContainer = getContainer(); IContainer currentContainer = getContainer();
if (currentContainer != null) { if (currentContainer != null) {
@ -198,7 +184,7 @@ public class WorkingDirectoryBlock extends AbstractLaunchConfigurationTab {
if ((results != null) && (results.length > 0) && (results[0] instanceof IPath)) { if ((results != null) && (results.length > 0) && (results[0] instanceof IPath)) {
IPath path = (IPath) results[0]; IPath path = (IPath) results[0];
String containerName = path.makeRelative().toString(); String containerName = path.makeRelative().toString();
fWorkspaceDirText.setText(containerName); fWorkingDirText.setText("${workspace_loc:" + containerName + "}"); //$NON-NLS-1$ //$NON-NLS-2$
} }
} }
@ -206,164 +192,138 @@ public class WorkingDirectoryBlock extends AbstractLaunchConfigurationTab {
* Returns the selected workspace container,or <code>null</code> * Returns the selected workspace container,or <code>null</code>
*/ */
protected IContainer getContainer() { protected IContainer getContainer() {
IResource res = getResource(); String path = fWorkingDirText.getText().trim();
if (path.length() > 0) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource res = root.findMember(path);
if (res instanceof IContainer) { if (res instanceof IContainer) {
return (IContainer) res; return (IContainer) res;
} }
}
return null; return null;
} }
/**
* Returns the selected workspace resource, or <code>null</code>
*/
protected IResource getResource() {
IPath path = new Path(fWorkspaceDirText.getText());
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
return root.findMember(path);
}
/**
* The "local directory" or "workspace directory" button has been selected.
*/
protected void handleLocationButtonSelected() {
if (!isDefaultWorkingDirectory()) {
boolean local = isLocalWorkingDirectory();
fWorkingDirText.setEnabled(local);
fWorkingDirBrowseButton.setEnabled(local);
fWorkspaceDirText.setEnabled(!local);
fWorkspaceDirBrowseButton.setEnabled(!local);
}
updateLaunchConfigurationDialog();
}
/** /**
* The default working dir check box has been toggled. * The default working dir check box has been toggled.
*/ */
protected void handleUseDefaultWorkingDirButtonSelected() { protected void handleUseDefaultWorkingDirButtonSelected() {
if (isDefaultWorkingDirectory()) { boolean def = isDefaultWorkingDirectory();
if (def) {
setDefaultWorkingDir(); setDefaultWorkingDir();
fLocalDirButton.setEnabled(false);
fWorkingDirText.setEnabled(false);
fWorkingDirBrowseButton.setEnabled(false);
fWorkspaceDirButton.setEnabled(false);
fWorkspaceDirText.setEnabled(false);
fWorkspaceDirBrowseButton.setEnabled(false);
} else {
fLocalDirButton.setEnabled(true);
fWorkspaceDirButton.setEnabled(true);
handleLocationButtonSelected();
} }
fWorkingDirText.setEnabled(!def);
fWorkspaceButton.setEnabled(!def);
fVariablesButton.setEnabled(!def);
fFileSystemButton.setEnabled(!def);
}
protected void handleWorkingDirVariablesButtonSelected() {
String variableText = getVariable();
if (variableText != null) {
fWorkingDirText.append(variableText);
}
}
private String getVariable() {
StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell());
dialog.open();
return dialog.getVariableExpression();
} }
/** /**
* Sets the default working directory * Sets the default working directory
*/ */
protected void setDefaultWorkingDir() { protected void setDefaultWorkingDir() {
try {
ILaunchConfiguration config = getLaunchConfiguration(); ILaunchConfiguration config = getLaunchConfiguration();
if (config != null) { if (config != null) {
ICProject cProject = null; ICProject cProject = AbstractCLaunchDelegate.getCProject(config);
try {
cProject = AbstractCLaunchDelegate.getCProject(config);
} catch (CoreException e) {
}
if (cProject != null) { if (cProject != null) {
fWorkspaceDirText.setText(cProject.getPath().makeRelative().toOSString()); fWorkingDirText.setText("${workspace_loc:" + cProject.getPath().makeRelative().toOSString() + "}"); //$NON-NLS-1$ //$NON-NLS-2$
fLocalDirButton.setSelection(false);
fWorkspaceDirButton.setSelection(true);
return; return;
} }
} }
} catch (CoreException ce) {
}
fWorkingDirText.setText(System.getProperty("user.dir")); //$NON-NLS-1$ fWorkingDirText.setText(System.getProperty("user.dir")); //$NON-NLS-1$
fLocalDirButton.setSelection(true);
fWorkspaceDirButton.setSelection(false);
} }
/** /*
* @see ILaunchConfigurationTab#isValid(ILaunchConfiguration) * (non-Javadoc)
*
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
*/ */
public boolean isValid(ILaunchConfiguration config) { public boolean isValid(ILaunchConfiguration config) {
setErrorMessage(null); setErrorMessage(null);
setMessage(null); setMessage(null);
if (isLocalWorkingDirectory()) { // if variables are present, we cannot resolve the directory
String workingDirPath = fWorkingDirText.getText().trim(); String workingDirPath = fWorkingDirText.getText().trim();
if (workingDirPath.length() > 0) { if (workingDirPath.indexOf("${") >= 0) { //$NON-NLS-1$
IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
try {
manager.validateStringVariables(workingDirPath);
} catch (CoreException e) {
setErrorMessage(e.getMessage());
return false;
}
} else if (workingDirPath.length() > 0) {
IContainer container = getContainer();
if (container == null) {
File dir = new File(workingDirPath); File dir = new File(workingDirPath);
if (!dir.exists()) { if (dir.isDirectory()) {
setErrorMessage(LaunchMessages.getString("WorkingDirectoryBlock.Working_directory_does_not_exist")); //$NON-NLS-1$ return true;
return false;
} }
if (!dir.isDirectory()) { setErrorMessage(LaunchMessages.getString("WorkingDirectoryBlock.10")); //$NON-NLS-1$
setErrorMessage(LaunchMessages.getString("WorkingDirectoryBlock.Working_directory_is_not_a_directory")); //$NON-NLS-1$
return false; return false;
} }
} }
} else {
if (getContainer() == null) {
setErrorMessage(LaunchMessages.getString("WorkingDirectoryBlock.Project_or_folder_does_not_exist")); //$NON-NLS-1$
return false;
}
}
return true; return true;
} }
/** /**
* Defaults are empty. * Defaults are empty.
* *
* @see ILaunchConfigurationTab#setDefaults(ILaunchConfigurationWorkingCopy) * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
*/ */
public void setDefaults(ILaunchConfigurationWorkingCopy config) { public void setDefaults(ILaunchConfigurationWorkingCopy config) {
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null); // config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String)null); // (String)null);
} }
/** /*
* @see ILaunchConfigurationTab#initializeFrom(ILaunchConfiguration) * (non-Javadoc)
*
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
*/ */
public void initializeFrom(ILaunchConfiguration configuration) { public void initializeFrom(ILaunchConfiguration configuration) {
setLaunchConfiguration(configuration); setLaunchConfiguration(configuration);
try { try {
String wd = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String)null); String wd = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null); //$NON-NLS-1$
fWorkspaceDirText.setText(EMPTY_STRING); fWorkingDirText.setText(""); //$NON-NLS-1$
fWorkingDirText.setText(EMPTY_STRING);
if (wd == null) { if (wd == null) {
fUseDefaultWorkingDirButton.setSelection(true); fUseDefaultWorkingDirButton.setSelection(true);
} else { } else {
IPath path = new Path(wd);
if (path.isAbsolute()) {
fWorkingDirText.setText(wd); fWorkingDirText.setText(wd);
fLocalDirButton.setSelection(true);
fWorkspaceDirButton.setSelection(false);
} else {
fWorkspaceDirText.setText(wd);
fWorkspaceDirButton.setSelection(true);
fLocalDirButton.setSelection(false);
}
fUseDefaultWorkingDirButton.setSelection(false); fUseDefaultWorkingDirButton.setSelection(false);
} }
handleUseDefaultWorkingDirButtonSelected(); handleUseDefaultWorkingDirButtonSelected();
} catch (CoreException e) { } catch (CoreException e) {
setErrorMessage(LaunchMessages.getFormattedString("Launch.common.Exception_occurred_reading_configuration_EXCEPTION", e.getStatus().getMessage())); //$NON-NLS-1$ setErrorMessage(LaunchMessages.getString("WorkingDirectoryBlock.Exception_occurred_reading_configuration___15") + e.getStatus().getMessage()); //$NON-NLS-1$
LaunchUIPlugin.log(e); LaunchUIPlugin.log(e);
} }
} }
/** /*
* @see ILaunchConfigurationTab#performApply(ILaunchConfigurationWorkingCopy) * (non-Javadoc)
*
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
*/ */
public void performApply(ILaunchConfigurationWorkingCopy configuration) { public void performApply(ILaunchConfigurationWorkingCopy configuration) {
String wd = null; String wd = null;
if (!isDefaultWorkingDirectory()) { if (!isDefaultWorkingDirectory()) {
if (isLocalWorkingDirectory()) {
wd = getAttributeValueFrom(fWorkingDirText); wd = getAttributeValueFrom(fWorkingDirText);
} else {
IPath path = new Path(fWorkspaceDirText.getText());
path = path.makeRelative();
wd = path.toString();
}
} }
configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, wd); configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, wd);
} }
@ -381,11 +341,13 @@ public class WorkingDirectoryBlock extends AbstractLaunchConfigurationTab {
return null; return null;
} }
/** /*
* @see ILaunchConfigurationTab#getName() * (non-Javadoc)
*
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
*/ */
public String getName() { public String getName() {
return LaunchMessages.getString("WorkingDirectoryBlock.Working_Directory"); //$NON-NLS-1$ return LaunchMessages.getString("WorkingDirectoryBlock.Working_Directory_8"); //$NON-NLS-1$
} }
/** /**
@ -396,33 +358,19 @@ public class WorkingDirectoryBlock extends AbstractLaunchConfigurationTab {
} }
/** /**
* Returns whether the working directory is local * Sets the c project currently specified by the given launch config, if
*/ * any.
protected boolean isLocalWorkingDirectory() {
return fLocalDirButton.getSelection();
}
/**
* Sets the java project currently specified by the
* given launch config, if any.
*/ */
protected void setLaunchConfiguration(ILaunchConfiguration config) { protected void setLaunchConfiguration(ILaunchConfiguration config) {
fLaunchConfiguration = config; fLaunchConfiguration = config;
} }
/** /**
* Returns the current java project context * Returns the current c project context
*/ */
protected ILaunchConfiguration getLaunchConfiguration() { protected ILaunchConfiguration getLaunchConfiguration() {
return fLaunchConfiguration; return fLaunchConfiguration;
} }
/**
* @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#updateLaunchConfigurationDialog()
*/
protected void updateLaunchConfigurationDialog() {
super.updateLaunchConfigurationDialog();
}
} }

View file

@ -18,15 +18,22 @@ import org.eclipse.cdt.launch.internal.ui.WorkingDirectoryBlock;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.internal.ui.stringsubstitution.StringVariableSelectionDialog;
import org.eclipse.debug.ui.ILaunchConfigurationDialog; import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab; import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.accessibility.AccessibleAdapter;
import org.eclipse.swt.accessibility.AccessibleEvent;
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.SelectionEvent;
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.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
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.help.WorkbenchHelp; import org.eclipse.ui.help.WorkbenchHelp;
@ -44,6 +51,7 @@ public class CArgumentsTab extends CLaunchConfigurationTab {
// Program arguments UI widgets // Program arguments UI widgets
protected Label fPrgmArgumentsLabel; protected Label fPrgmArgumentsLabel;
protected Text fPrgmArgumentsText; protected Text fPrgmArgumentsText;
protected Button fArgumentVariablesButton;
// Working directory // Working directory
protected WorkingDirectoryBlock fWorkingDirectoryBlock = new WorkingDirectoryBlock(); protected WorkingDirectoryBlock fWorkingDirectoryBlock = new WorkingDirectoryBlock();
@ -60,13 +68,28 @@ public class CArgumentsTab extends CLaunchConfigurationTab {
GridLayout topLayout = new GridLayout(); GridLayout topLayout = new GridLayout();
comp.setLayout(topLayout); comp.setLayout(topLayout);
GridData gd;
createVerticalSpacer(comp, 1);
createArgumentComponent(comp, 1);
createVerticalSpacer(comp, 1); createVerticalSpacer(comp, 1);
fPrgmArgumentsLabel = new Label(comp, SWT.NONE); fWorkingDirectoryBlock.createControl(comp);
}
protected void createArgumentComponent(Composite comp, int i) {
Composite argsComp = new Composite(comp, SWT.NONE);
GridLayout projLayout = new GridLayout();
projLayout.numColumns = 1;
projLayout.marginHeight = 0;
projLayout.marginWidth = 0;
argsComp.setLayout(projLayout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = i;
argsComp.setLayoutData(gd);
fPrgmArgumentsLabel = new Label(argsComp, SWT.NONE);
fPrgmArgumentsLabel.setText(LaunchMessages.getString("CArgumentsTab.C/C++_Program_Arguments")); //$NON-NLS-1$ fPrgmArgumentsLabel.setText(LaunchMessages.getString("CArgumentsTab.C/C++_Program_Arguments")); //$NON-NLS-1$
fPrgmArgumentsText = new Text(comp, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); fPrgmArgumentsText = new Text(argsComp, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
gd = new GridData(GridData.FILL_HORIZONTAL); gd = new GridData(GridData.FILL_HORIZONTAL);
gd.heightHint = 40; gd.heightHint = 40;
fPrgmArgumentsText.setLayoutData(gd); fPrgmArgumentsText.setLayoutData(gd);
@ -75,10 +98,62 @@ public class CArgumentsTab extends CLaunchConfigurationTab {
updateLaunchConfigurationDialog(); updateLaunchConfigurationDialog();
} }
}); });
fArgumentVariablesButton= createPushButton(argsComp, "Varianbles...", null); //$NON-NLS-1$
gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
fArgumentVariablesButton.setLayoutData(gd);
fArgumentVariablesButton.addSelectionListener(new SelectionAdapter() {
createVerticalSpacer(comp, 1); /* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
public void widgetSelected(SelectionEvent arg0) {
handleVariablesButtonSelected(fPrgmArgumentsText);
}
});
// addControlAccessibleListener(fArgumentVariablesButton, fArgumentVariablesButton.getText()); // need to strip the mnemonic from buttons
}
/**
* A variable entry button has been pressed for the given text
* field. Prompt the user for a variable and enter the result
* in the given field.
*/
private void handleVariablesButtonSelected(Text textField) {
String variable = getVariable();
if (variable != null) {
textField.append(variable);
}
}
/**
* Prompts the user to choose and configure a variable and returns
* the resulting string, suitable to be used as an attribute.
*/
private String getVariable() {
StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell());
dialog.open();
return dialog.getVariableExpression();
}
public void addControlAccessibleListener(Control control, String controlName) {
//strip mnemonic (&)
String[] strs = controlName.split("&"); //$NON-NLS-1$
StringBuffer stripped = new StringBuffer();
for (int i = 0; i < strs.length; i++) {
stripped.append(strs[i]);
}
control.getAccessible().addAccessibleListener(new ControlAccessibleListener(stripped.toString()));
}
private class ControlAccessibleListener extends AccessibleAdapter {
private String controlName;
ControlAccessibleListener(String name) {
controlName = name;
}
public void getName(AccessibleEvent e) {
e.result = controlName;
}
fWorkingDirectoryBlock.createControl(comp);
} }
/** /**

View file

@ -275,14 +275,19 @@ public class CDebuggerTab extends AbstractCDebuggerTab {
protected void createOptionsComposite( Composite parent ) { protected void createOptionsComposite( Composite parent ) {
Composite optionsComp = new Composite( parent, SWT.NONE ); Composite optionsComp = new Composite( parent, SWT.NONE );
GridLayout layout = new GridLayout( 2, true );
optionsComp.setLayout( layout );
optionsComp.setLayoutData( new GridData( GridData.FILL, GridData.CENTER, true, false, 1, 1 ) );
if (fAttachMode == true) { if (fAttachMode == true) {
createVerticalSpacer(optionsComp, 1); GridLayout layout = new GridLayout( 1, false );
optionsComp.setLayout( layout );
optionsComp.setLayoutData( new GridData( GridData.END, GridData.CENTER, true, false, 1, 1 ) );
} else { } else {
GridLayout layout = new GridLayout( 2, false );
optionsComp.setLayout( layout );
optionsComp.setLayoutData( new GridData( GridData.END, GridData.CENTER, true, false, 1, 1 ) );
fStopInMain = createCheckButton( optionsComp, LaunchMessages.getString( "CDebuggerTab.Stop_at_main_on_startup" ) ); //$NON-NLS-1$ fStopInMain = createCheckButton( optionsComp, LaunchMessages.getString( "CDebuggerTab.Stop_at_main_on_startup" ) ); //$NON-NLS-1$
GridData data = new GridData();
data.horizontalAlignment = GridData.BEGINNING;
fStopInMain.setLayoutData( data );
fStopInMain.addSelectionListener( new SelectionAdapter() { fStopInMain.addSelectionListener( new SelectionAdapter() {
public void widgetSelected( SelectionEvent e ) { public void widgetSelected( SelectionEvent e ) {