1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 542488: Remove duplicated code

When DSF was first created it was a separate project that borrowed
heavily from CDT, as such (AFAICT) some code was copied from
o.e.cdt.launch to DSF. This commit de-duplicates some of that code
as the DAP implementation wants to reuse the code too and another
copy is not wanted.

Change-Id: Ie54187dabc9c32224575c0bf51bcabfab00ca340
This commit is contained in:
Jonah Graham 2019-01-04 17:00:42 +00:00
parent edfc7d4c0e
commit f96971a278
13 changed files with 394 additions and 1053 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2016 QNX Software Systems and others.
* Copyright (c) 2005, 2019 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@ -15,31 +15,7 @@
*******************************************************************************/
package org.eclipse.cdt.dsf.gdb.internal.ui.launching;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin;
import org.eclipse.cdt.dsf.gdb.launching.LaunchMessages;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.StringVariableSelectionDialog;
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.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.cdt.launch.ui.CAbstractArgumentsTab;
/**
* A launch configuration tab that displays and edits program arguments,
@ -48,7 +24,7 @@ import org.eclipse.swt.widgets.Text;
* This class may be instantiated. This class is not intended to be subclassed.
* </p>
*/
public class CArgumentsTab extends CLaunchConfigurationTab {
public class CArgumentsTab extends CAbstractArgumentsTab {
/**
* Tab identifier used for ordering of tabs added using the
* <code>org.eclipse.debug.ui.launchConfigurationTabs</code>
@ -58,206 +34,8 @@ public class CArgumentsTab extends CLaunchConfigurationTab {
*/
public static final String TAB_ID = "org.eclipse.cdt.dsf.gdb.launch.argumentsTab"; //$NON-NLS-1$
// Program arguments UI widgets
protected Label fPrgmArgumentsLabel;
protected Text fPrgmArgumentsText;
protected Button fArgumentVariablesButton;
// Working directory
protected WorkingDirectoryBlock fWorkingDirectoryBlock = new WorkingDirectoryBlock();
@Override
public void createControl(Composite parent) {
Font font = parent.getFont();
Composite comp = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(1, true);
comp.setLayout(layout);
comp.setFont(font);
GridData gd = new GridData(GridData.FILL_BOTH);
comp.setLayoutData(gd);
setControl(comp);
GdbUIPlugin.getDefault().getWorkbench().getHelpSystem().setHelp(getControl(),
ICDTLaunchHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_ARGUMNETS_TAB);
createArgumentComponent(comp, 1);
fWorkingDirectoryBlock.createControl(comp);
}
protected void createArgumentComponent(Composite comp, int horizontalSpan) {
Font font = comp.getFont();
Group group = new Group(comp, SWT.NONE);
group.setFont(font);
group.setLayout(new GridLayout());
GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = horizontalSpan;
group.setLayoutData(gd);
group.setText(LaunchMessages.getString("CArgumentsTab.C/C++_Program_Arguments")); //$NON-NLS-1$
fPrgmArgumentsText = new Text(group, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
fPrgmArgumentsText.getAccessible().addAccessibleListener(new AccessibleAdapter() {
@Override
public void getName(AccessibleEvent e) {
e.result = LaunchMessages.getString("CArgumentsTab.C/C++_Program_Arguments"); //$NON-NLS-1$
}
});
gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 40;
gd.widthHint = 100;
fPrgmArgumentsText.setLayoutData(gd);
fPrgmArgumentsText.setFont(font);
fPrgmArgumentsText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent evt) {
updateLaunchConfigurationDialog();
}
});
fArgumentVariablesButton = createPushButton(group, LaunchMessages.getString("CArgumentsTab.Variables"), null); //$NON-NLS-1$
gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
fArgumentVariablesButton.setLayoutData(gd);
fArgumentVariablesButton.addSelectionListener(new SelectionAdapter() {
@Override
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.
*/
protected void handleVariablesButtonSelected(Text textField) {
String variable = getVariable();
if (variable != null) {
textField.insert(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$
StringBuilder stripped = new StringBuilder();
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;
}
@Override
public void getName(AccessibleEvent e) {
e.result = controlName;
}
}
@Override
public boolean isValid(ILaunchConfiguration config) {
return fWorkingDirectoryBlock.isValid(config);
}
@Override
public void setDefaults(ILaunchConfigurationWorkingCopy config) {
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String) null);
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null);
}
@Override
public void initializeFrom(ILaunchConfiguration configuration) {
try {
fPrgmArgumentsText
.setText(configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, "")); //$NON-NLS-1$
fWorkingDirectoryBlock.initializeFrom(configuration);
} catch (CoreException e) {
setErrorMessage(LaunchMessages.getFormattedString(
"Launch.common.Exception_occurred_reading_configuration_EXCEPTION", e.getStatus().getMessage())); //$NON-NLS-1$
GdbUIPlugin.log(e);
}
}
@Override
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
getAttributeValueFrom(fPrgmArgumentsText));
fWorkingDirectoryBlock.performApply(configuration);
}
/**
* Returns the string in the text widget, or <code>null</code> if empty.
*
* @return text or <code>null</code>
*/
protected String getAttributeValueFrom(Text text) {
String content = text.getText().trim();
// Bug #131513 - eliminate Windows \r line delimiter
content = content.replaceAll("\r\n", "\n"); //$NON-NLS-1$//$NON-NLS-2$
if (!content.isEmpty()) {
return content;
}
return null;
}
@Override
public String getId() {
return TAB_ID;
}
@Override
public String getName() {
return LaunchMessages.getString("CArgumentsTab.Arguments"); //$NON-NLS-1$
}
@Override
public void setLaunchConfigurationDialog(ILaunchConfigurationDialog dialog) {
super.setLaunchConfigurationDialog(dialog);
fWorkingDirectoryBlock.setLaunchConfigurationDialog(dialog);
}
@Override
public String getErrorMessage() {
String m = super.getErrorMessage();
if (m == null) {
return fWorkingDirectoryBlock.getErrorMessage();
}
return m;
}
@Override
public String getMessage() {
String m = super.getMessage();
if (m == null) {
return fWorkingDirectoryBlock.getMessage();
}
return m;
}
@Override
public Image getImage() {
return LaunchImages.get(LaunchImages.IMG_VIEW_ARGUMENTS_TAB);
}
@Override
protected void updateLaunchConfigurationDialog() {
super.updateLaunchConfigurationDialog();
}
}

View file

@ -28,6 +28,7 @@ import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants;
import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin;
import org.eclipse.cdt.dsf.gdb.launching.LaunchMessages;
import org.eclipse.cdt.dsf.gdb.service.SessionType;
import org.eclipse.cdt.launch.ui.CLaunchConfigurationTab;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;

View file

@ -1,167 +0,0 @@
/*******************************************************************************
* Copyright (c) 2008, 2016 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Ken Ryall (Nokia) - bug 178731
*******************************************************************************/
package org.eclipse.cdt.dsf.gdb.internal.ui.launching;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IWorkbenchPage;
public abstract class CLaunchConfigurationTab extends AbstractLaunchConfigurationTab {
/**
* Returns the current C element context from which to initialize default
* settings, or <code>null</code> if none. Note, if possible we will
* return the IBinary based on config entry as this may be more usefull then
* just the project.
*
* @return C element context.
*/
protected ICElement getContext(ILaunchConfiguration config, String platform) {
String projectName = null;
String programName = null;
IWorkbenchPage page = GdbUIPlugin.getActivePage();
Object obj = null;
try {
projectName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String) null);
programName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, (String) null);
if (programName != null) {
programName = VariablesPlugin.getDefault().getStringVariableManager()
.performStringSubstitution(programName);
}
} catch (CoreException e) {
}
if (projectName != null && !projectName.isEmpty()) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
ICProject cProject = CCorePlugin.getDefault().getCoreModel().create(project);
if (cProject != null && cProject.exists()) {
obj = cProject;
}
} else {
if (page != null) {
ISelection selection = page.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection) selection;
if (!ss.isEmpty()) {
obj = ss.getFirstElement();
}
}
}
}
if (obj instanceof IResource) {
ICElement ce = CoreModel.getDefault().create((IResource) obj);
if (ce == null) {
IProject pro = ((IResource) obj).getProject();
ce = CoreModel.getDefault().create(pro);
}
obj = ce;
}
if (obj instanceof ICElement) {
if (platform != null && !platform.equals("*")) { //$NON-NLS-1$
ICDescriptor descriptor;
try {
descriptor = CCorePlugin.getDefault()
.getCProjectDescription(((ICElement) obj).getCProject().getProject(), false);
if (descriptor != null) {
String projectPlatform = descriptor.getPlatform();
if (!projectPlatform.equals(platform) && !projectPlatform.equals("*")) { //$NON-NLS-1$
obj = null;
}
}
} catch (CoreException e) {
}
}
if (obj != null) {
if (programName == null || programName.isEmpty()) {
return (ICElement) obj;
}
ICElement ce = (ICElement) obj;
IProject project;
project = (IProject) ce.getCProject().getResource();
IPath programFile = project.getFile(programName).getLocation();
ce = CCorePlugin.getDefault().getCoreModel().create(programFile);
if (ce != null && ce.exists()) {
return ce;
}
return (ICElement) obj;
}
}
if (page != null) {
IEditorPart part = page.getActiveEditor();
if (part != null) {
IEditorInput input = part.getEditorInput();
if (input instanceof IFileEditorInput) {
IFile file = ((IFileEditorInput) input).getFile();
if (file != null) {
ICElement ce = CoreModel.getDefault().create(file);
if (ce == null) {
IProject pro = file.getProject();
ce = CoreModel.getDefault().create(pro);
}
return ce;
}
}
}
}
return null;
}
/**
* Set the C project attribute based on the ICElement.
*/
protected void initializeCProject(ICElement cElement, ILaunchConfigurationWorkingCopy config) {
ICProject cProject = cElement.getCProject();
String name = null;
if (cProject != null && cProject.exists()) {
name = cProject.getElementName();
config.setMappedResources(new IResource[] { cProject.getProject() });
ICProjectDescription projDes = CCorePlugin.getDefault().getProjectDescription(cProject.getProject());
String buildConfigID = projDes.getActiveConfiguration().getId();
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, buildConfigID);
}
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, name);
}
protected String getPlatform(ILaunchConfiguration config) {
String platform = Platform.getOS();
try {
return config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PLATFORM, platform);
} catch (CoreException e) {
return platform;
}
}
}

View file

@ -1,372 +0,0 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
* Ericsson - Updated for DSF
*******************************************************************************/
package org.eclipse.cdt.dsf.gdb.internal.ui.launching;
import java.io.File;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin;
import org.eclipse.cdt.dsf.gdb.launching.LaunchUtils;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.variables.IStringVariableManager;
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.StringVariableSelectionDialog;
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.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ContainerSelectionDialog;
/**
* A control for setting the working directory associated with a launch
* configuration.
*/
public class WorkingDirectoryBlock extends CLaunchConfigurationTab {
// Local directory
protected Text fWorkingDirText;
protected Button fWorkspaceButton;
protected Button fFileSystemButton;
protected Button fVariablesButton;
// use default button
protected Button fUseDefaultWorkingDirButton;
/**
* The last launch config this tab was initialized from
*/
protected ILaunchConfiguration fLaunchConfiguration;
/**
* A listener to update for text changes and widget selection
*/
private class WidgetListener extends SelectionAdapter implements ModifyListener {
@Override
public void modifyText(ModifyEvent e) {
updateLaunchConfigurationDialog();
}
@Override
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();
@Override
public void createControl(Composite parent) {
Font font = parent.getFont();
Group group = new Group(parent, SWT.NONE);
// WorkbenchHelp.setHelp(group,
// IJavaDebugHelpContextIds.WORKING_DIRECTORY_BLOCK);
GridLayout workingDirLayout = new GridLayout();
workingDirLayout.makeColumnsEqualWidth = false;
group.setLayout(workingDirLayout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
group.setLayoutData(gd);
group.setFont(font);
setControl(group);
group.setText(LaunchUIMessages.getString("WorkingDirectoryBlock.Working_directory")); //$NON-NLS-1$
fWorkingDirText = new Text(group, SWT.SINGLE | SWT.BORDER);
fWorkingDirText.getAccessible().addAccessibleListener(new AccessibleAdapter() {
@Override
public void getName(AccessibleEvent e) {
e.result = LaunchUIMessages.getString("WorkingDirectoryBlock.Working_directory"); //$NON-NLS-1$
}
});
gd = new GridData(GridData.FILL_HORIZONTAL);
fWorkingDirText.setLayoutData(gd);
fWorkingDirText.setFont(font);
fWorkingDirText.addModifyListener(fListener);
fUseDefaultWorkingDirButton = new Button(group, SWT.CHECK);
fUseDefaultWorkingDirButton.setText(LaunchUIMessages.getString("WorkingDirectoryBlock.Use_default")); //$NON-NLS-1$
gd = new GridData(GridData.FILL, GridData.BEGINNING, true, false);
fUseDefaultWorkingDirButton.setLayoutData(gd);
fUseDefaultWorkingDirButton.setFont(font);
fUseDefaultWorkingDirButton.addSelectionListener(fListener);
Composite buttonComp = new Composite(group, SWT.NONE);
GridLayout layout = new GridLayout(3, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
buttonComp.setLayout(layout);
gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
buttonComp.setLayoutData(gd);
buttonComp.setFont(font);
fWorkspaceButton = createPushButton(buttonComp, LaunchUIMessages.getString("WorkingDirectoryBlock.0"), null); //$NON-NLS-1$
fWorkspaceButton.addSelectionListener(fListener);
fFileSystemButton = createPushButton(buttonComp, LaunchUIMessages.getString("WorkingDirectoryBlock.1"), null); //$NON-NLS-1$
fFileSystemButton.addSelectionListener(fListener);
fVariablesButton = createPushButton(buttonComp, LaunchUIMessages.getString("WorkingDirectoryBlock.17"), null); //$NON-NLS-1$
fVariablesButton.addSelectionListener(fListener);
}
@Override
public void dispose() {
}
/**
* Show a dialog that lets the user select a working directory
*/
protected void handleWorkingDirBrowseButtonSelected() {
DirectoryDialog dialog = new DirectoryDialog(getShell());
dialog.setMessage(LaunchUIMessages.getString("WorkingDirectoryBlock.7")); //$NON-NLS-1$
String currentWorkingDir = fWorkingDirText.getText();
if (!currentWorkingDir.trim().isEmpty()) {
File path = new File(currentWorkingDir);
if (path.exists()) {
dialog.setFilterPath(currentWorkingDir);
}
}
String selectedDirectory = dialog.open();
if (selectedDirectory != null) {
fWorkingDirText.setText(selectedDirectory);
}
}
/**
* Show a dialog that lets the user select a working directory from the
* workspace
*/
protected void handleWorkspaceDirBrowseButtonSelected() {
ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(),
ResourcesPlugin.getWorkspace().getRoot(), false, LaunchUIMessages.getString("WorkingDirectoryBlock.4")); //$NON-NLS-1$
IContainer currentContainer = getContainer();
if (currentContainer != null) {
IPath path = currentContainer.getFullPath();
dialog.setInitialSelections(new Object[] { path });
}
dialog.showClosedProjects(false);
dialog.open();
Object[] results = dialog.getResult();
if ((results != null) && (results.length > 0) && (results[0] instanceof IPath)) {
IPath path = (IPath) results[0];
String containerName = path.makeRelative().toString();
fWorkingDirText.setText("${workspace_loc:" + containerName + "}"); //$NON-NLS-1$ //$NON-NLS-2$
}
}
/**
* Returns the selected workspace container,or <code>null</code>
*/
protected IContainer getContainer() {
String path = fWorkingDirText.getText().trim();
if (!path.isEmpty()) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource res = root.findMember(path);
if (res instanceof IContainer) {
return (IContainer) res;
}
}
return null;
}
/**
* The default working dir check box has been toggled.
*/
protected void handleUseDefaultWorkingDirButtonSelected() {
boolean def = isDefaultWorkingDirectory();
if (def) {
setDefaultWorkingDir();
}
fWorkingDirText.setEnabled(!def);
fWorkspaceButton.setEnabled(!def);
fVariablesButton.setEnabled(!def);
fFileSystemButton.setEnabled(!def);
}
protected void handleWorkingDirVariablesButtonSelected() {
String variableText = getVariable();
if (variableText != null) {
fWorkingDirText.insert(variableText);
}
}
private String getVariable() {
StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell());
dialog.open();
return dialog.getVariableExpression();
}
/**
* Sets the default working directory
*/
protected void setDefaultWorkingDir() {
try {
ILaunchConfiguration config = getLaunchConfiguration();
if (config != null) {
ICProject cProject = LaunchUtils.getCProject(config);
if (cProject != null) {
fWorkingDirText.setText("${workspace_loc:" + cProject.getPath().makeRelative().toOSString() + "}"); //$NON-NLS-1$ //$NON-NLS-2$
return;
}
}
} catch (CoreException ce) {
}
fWorkingDirText.setText(System.getProperty("user.dir")); //$NON-NLS-1$
}
@Override
public boolean isValid(ILaunchConfiguration config) {
setErrorMessage(null);
setMessage(null);
// if variables are present, we cannot resolve the directory
String workingDirPath = fWorkingDirText.getText().trim();
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.isEmpty()) {
IContainer container = getContainer();
if (container == null) {
File dir = new File(workingDirPath);
if (dir.isDirectory()) {
return true;
}
setErrorMessage(LaunchUIMessages.getString("WorkingDirectoryBlock.10")); //$NON-NLS-1$
return false;
}
}
return true;
}
/**
* Defaults are empty.
*
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
*/
@Override
public void setDefaults(ILaunchConfigurationWorkingCopy config) {
// config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
// (String)null);
}
@Override
public void initializeFrom(ILaunchConfiguration configuration) {
setLaunchConfiguration(configuration);
try {
String wd = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
(String) null);
fWorkingDirText.setText(""); //$NON-NLS-1$
if (wd == null) {
fUseDefaultWorkingDirButton.setSelection(true);
} else {
fWorkingDirText.setText(wd);
fUseDefaultWorkingDirButton.setSelection(false);
}
handleUseDefaultWorkingDirButtonSelected();
} catch (CoreException e) {
setErrorMessage(
LaunchUIMessages.getString("WorkingDirectoryBlock.Exception_occurred_reading_configuration___15") //$NON-NLS-1$
+ e.getStatus().getMessage());
GdbUIPlugin.log(e);
}
}
@Override
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
String wd = null;
if (!isDefaultWorkingDirectory()) {
wd = getAttributeValueFrom(fWorkingDirText);
}
configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, wd);
}
/**
* Retuns the string in the text widget, or <code>null</code> if empty.
*
* @return text or <code>null</code>
*/
protected String getAttributeValueFrom(Text text) {
String content = text.getText().trim();
if (!content.isEmpty()) {
return content;
}
return null;
}
@Override
public String getName() {
return LaunchUIMessages.getString("WorkingDirectoryBlock.Working_Directory_8"); //$NON-NLS-1$
}
/**
* Returns whether the default working directory is to be used
*/
protected boolean isDefaultWorkingDirectory() {
return fUseDefaultWorkingDirButton.getSelection();
}
/**
* Sets the c project currently specified by the given launch config, if
* any.
*/
protected void setLaunchConfiguration(ILaunchConfiguration config) {
fLaunchConfiguration = config;
}
/**
* Returns the current c project context
*/
protected ILaunchConfiguration getLaunchConfiguration() {
return fLaunchConfiguration;
}
}

View file

@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-SymbolicName: org.eclipse.cdt.dsf.gdb;singleton:=true
Bundle-Version: 5.7.100.qualifier
Bundle-Version: 5.7.200.qualifier
Bundle-Activator: org.eclipse.cdt.dsf.gdb.internal.GdbPlugin
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime,
@ -12,7 +12,7 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.cdt.core,
org.eclipse.cdt.debug.core,
org.eclipse.core.variables,
org.eclipse.cdt.launch;bundle-version="6.1.0",
org.eclipse.cdt.launch;bundle-version="9.3.0",
org.eclipse.cdt.gdb;bundle-version="7.0.0",
org.eclipse.core.resources,
org.eclipse.launchbar.core;bundle-version="2.0.0";visibility:=reexport,

View file

@ -19,7 +19,6 @@ package org.eclipse.cdt.dsf.gdb.launching;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@ -72,7 +71,6 @@ import org.eclipse.cdt.dsf.service.DsfServiceEventHandler;
import org.eclipse.cdt.dsf.service.DsfServicesTracker;
import org.eclipse.cdt.dsf.service.DsfSession;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
@ -614,27 +612,8 @@ public class GdbLaunch extends DsfLaunch implements ITerminate, IDisconnect, ITr
}
private IProject getProject() throws CoreException {
String projectName = getLaunchConfiguration().getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME,
(String) null);
IProject project = null;
if (projectName == null) {
IResource[] resources = getLaunchConfiguration().getMappedResources();
if (resources != null && resources.length > 0 && resources[0] instanceof IProject) {
project = (IProject) resources[0];
}
} else {
projectName = projectName.trim();
if (projectName.length() == 0) {
return null;
}
project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
}
if (project == null || !project.isAccessible()) {
// No project
return null;
}
return project;
ILaunchConfiguration configuration = getLaunchConfiguration();
return org.eclipse.cdt.launch.LaunchUtils.getProject(configuration);
}
/**
@ -725,15 +704,7 @@ public class GdbLaunch extends DsfLaunch implements ITerminate, IDisconnect, ITr
* @since 5.0
*/
public String getProgramArguments() throws CoreException {
String programArguments = getLaunchConfiguration()
.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String) null);
if (programArguments != null) {
programArguments = VariablesPlugin.getDefault().getStringVariableManager()
.performStringSubstitution(programArguments);
}
return programArguments;
return org.eclipse.cdt.launch.LaunchUtils.getProgramArguments(getLaunchConfiguration());
}
/**
@ -743,60 +714,9 @@ public class GdbLaunch extends DsfLaunch implements ITerminate, IDisconnect, ITr
* @since 5.0
*/
public String getProgramPath() throws CoreException {
ILaunchConfiguration configuration = getLaunchConfiguration();
String programName = getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME);
if (programName == null) {
programName = getLaunchConfiguration().getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME,
(String) null);
}
if (programName == null) {
throwException(LaunchMessages.getString("AbstractCLaunchDelegate.Program_file_not_specified"), null, //$NON-NLS-1$
ICDTLaunchConfigurationConstants.ERR_UNSPECIFIED_PROGRAM);
}
programName = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(programName);
IPath programPath = new Path(programName);
if (programPath.isEmpty()) {
throwException(LaunchMessages.getString("AbstractCLaunchDelegate.Program_file_does_not_exist"), null, //$NON-NLS-1$
ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST);
}
if (!programPath.isAbsolute()) {
IProject project = getProject();
ICProject cproject = CCorePlugin.getDefault().getCoreModel().create(project);
if (cproject != null) {
// Find the specified program within the specified project
IFile wsProgramPath = cproject.getProject().getFile(programPath);
programPath = wsProgramPath.getLocation();
}
}
if (!programPath.toFile().exists()) {
throwException(LaunchMessages.getString("AbstractCLaunchDelegate.Program_file_does_not_exist"), //$NON-NLS-1$
new FileNotFoundException(
LaunchMessages.getFormattedString("AbstractCLaunchDelegate.PROGRAM_PATH_not_found", //$NON-NLS-1$
programPath.toOSString())),
ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST);
}
return programPath.toOSString();
}
/**
* Throws a core exception with an error status object built from the given
* message, lower level exception, and error code.
*
* @param message
* the status message
* @param exception
* lower level exception associated with the error, or
* <code>null</code> if none
* @param code
* error code
*/
private static void throwException(String message, Throwable exception, int code) throws CoreException {
MultiStatus status = new MultiStatus(GdbPlugin.PLUGIN_ID, code, message, exception);
status.add(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, code,
exception == null ? "" : exception.getLocalizedMessage(), //$NON-NLS-1$
exception));
throw new CoreException(status);
return org.eclipse.cdt.launch.LaunchUtils.resolveProgramPath(configuration, programName);
}
/**

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.launch; singleton:=true
Bundle-Version: 9.2.1.qualifier
Bundle-Version: 9.3.0.qualifier
Bundle-Activator: org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin

View file

@ -15,6 +15,7 @@
*******************************************************************************/
package org.eclipse.cdt.launch;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
@ -24,6 +25,7 @@ import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.CoreModelUtil;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICOutputEntry;
@ -33,14 +35,19 @@ import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.internal.core.resources.ResourceLookup;
import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
import org.eclipse.cdt.utils.CommandLineUtil;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.variables.IStringVariableManager;
import org.eclipse.core.variables.VariablesPlugin;
@ -49,6 +56,8 @@ import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.activities.IActivityManager;
import org.eclipse.ui.activities.IWorkbenchActivitySupport;
import com.ibm.icu.text.MessageFormat;
/**
* Utility methods.
*/
@ -102,6 +111,90 @@ public class LaunchUtils {
return args;
}
/**
* Return the program path
*
* @param configuration Launch configuration to obtain paths from
* @return the program path
* @throws CoreException if program path can not be resolved.
*/
public static String getProgramPath(ILaunchConfiguration configuration) throws CoreException {
return resolveProgramPath(configuration, null);
}
/**
* Return the program path, resolved as an absolute OS string.
*
* @param configuration Launch configuration to obtain paths from
* @param programName Optional (can be null) starting point for program name
* @return the program path
* @throws CoreException if program path can not be resolved.
*/
public static String resolveProgramPath(ILaunchConfiguration configuration, String programName)
throws CoreException {
if (programName == null) {
programName = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, (String) null);
}
if (programName == null) {
throwException(Messages.LaunchUtils_program_file_not_specified, null,
ICDTLaunchConfigurationConstants.ERR_UNSPECIFIED_PROGRAM);
}
programName = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(programName);
IPath programPath = new Path(programName);
if (programPath.isEmpty()) {
throwException(Messages.LaunchUtils_program_file_does_not_exist, null,
ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST);
}
if (!programPath.isAbsolute()) {
IProject project = getProject(configuration);
ICProject cproject = CCorePlugin.getDefault().getCoreModel().create(project);
if (cproject != null) {
// Find the specified program within the specified project
IFile wsProgramPath = cproject.getProject().getFile(programPath);
programPath = wsProgramPath.getLocation();
}
}
if (!programPath.toFile().exists()) {
throwException(Messages.LaunchUtils_program_file_does_not_exist,
new FileNotFoundException(
MessageFormat.format(Messages.LaunchUtils__0_not_found, programPath.toOSString())),
ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST);
}
return programPath.toOSString();
}
/**
* Return project or <code>null</code> if project is not accessible or not specified.
* @param configuration Launch configuration to obtain project from
* @return the project
* @throws CoreException
*/
public static IProject getProject(ILaunchConfiguration configuration) throws CoreException {
String projectName = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME,
(String) null);
IProject project = null;
if (projectName == null) {
IResource[] resources = configuration.getMappedResources();
if (resources != null && resources.length > 0 && resources[0] instanceof IProject) {
project = (IProject) resources[0];
}
} else {
projectName = projectName.trim();
if (projectName.length() == 0) {
return null;
}
project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
}
if (project == null || !project.isAccessible()) {
// No project
return null;
}
return project;
}
/**
* @since 6.0
*/
@ -243,4 +336,24 @@ public class LaunchUtils {
}
return buildConfig;
}
/**
* Throws a core exception with an error status object built from the given
* message, lower level exception, and error code.
*
* @param message
* the status message
* @param exception
* lower level exception associated with the error, or
* <code>null</code> if none
* @param code
* error code
*/
private static void throwException(String message, Throwable exception, int code) throws CoreException {
MultiStatus status = new MultiStatus(LaunchUIPlugin.PLUGIN_ID, code, message, exception);
status.add(new Status(IStatus.ERROR, LaunchUIPlugin.PLUGIN_ID, code,
exception == null ? "" : exception.getLocalizedMessage(), //$NON-NLS-1$
exception));
throw new CoreException(status);
}
}

View file

@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2019 Kichwa Coders and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.cdt.launch;
import org.eclipse.osgi.util.NLS;
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.cdt.launch.messages"; //$NON-NLS-1$
public static String LaunchUtils__0_not_found;
public static String LaunchUtils_program_file_does_not_exist;
public static String LaunchUtils_program_file_not_specified;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}
private Messages() {
}
}

View file

@ -0,0 +1,13 @@
###############################################################################
# Copyright (c) 2019 Kichwa Coders and others.
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
# https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
###############################################################################
LaunchUtils__0_not_found={0} not found
LaunchUtils_program_file_does_not_exist=Program file does not exist
LaunchUtils_program_file_not_specified=Program file not specified

View file

@ -0,0 +1,224 @@
/*******************************************************************************
* Copyright (c) 2005, 2016 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* IBM Corporation
*******************************************************************************/
package org.eclipse.cdt.launch.ui;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.launch.internal.ui.LaunchImages;
import org.eclipse.cdt.launch.internal.ui.LaunchMessages;
import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
import org.eclipse.cdt.launch.internal.ui.WorkingDirectoryBlock;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.osgi.util.NLS;
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.ModifyListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
/**
* A launch configuration tab that displays and edits program arguments,
* and working directory launch configuration attributes.
*/
public abstract class CAbstractArgumentsTab extends CLaunchConfigurationTab {
// Program arguments UI widgets
protected Label fPrgmArgumentsLabel;
protected Text fPrgmArgumentsText;
protected Button fArgumentVariablesButton;
/**
* Working Directory
* @noreference This field is not intended to be referenced by clients.
*/
protected WorkingDirectoryBlock fWorkingDirectoryBlock = new WorkingDirectoryBlock();
@Override
public void createControl(Composite parent) {
Font font = parent.getFont();
Composite comp = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(1, true);
comp.setLayout(layout);
comp.setFont(font);
GridData gd = new GridData(GridData.FILL_BOTH);
comp.setLayoutData(gd);
setControl(comp);
LaunchUIPlugin.getDefault().getWorkbench().getHelpSystem().setHelp(getControl(),
ICDTLaunchHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_ARGUMNETS_TAB);
createArgumentComponent(comp, 1);
fWorkingDirectoryBlock.createControl(comp);
}
protected void createArgumentComponent(Composite comp, int horizontalSpan) {
Font font = comp.getFont();
Group group = new Group(comp, SWT.NONE);
group.setFont(font);
group.setLayout(new GridLayout());
GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = horizontalSpan;
group.setLayoutData(gd);
group.setText(LaunchMessages.CArgumentsTab_C_Program_Arguments);
fPrgmArgumentsText = new Text(group, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
fPrgmArgumentsText.getAccessible().addAccessibleListener(new AccessibleAdapter() {
@Override
public void getName(AccessibleEvent e) {
e.result = LaunchMessages.CArgumentsTab_C_Program_Arguments;
}
});
gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 40;
gd.widthHint = 100;
fPrgmArgumentsText.setLayoutData(gd);
fPrgmArgumentsText.setFont(font);
fPrgmArgumentsText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent evt) {
updateLaunchConfigurationDialog();
}
});
fArgumentVariablesButton = createVariablesButton(group, LaunchMessages.CArgumentsTab_Variables,
fPrgmArgumentsText);
gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
fArgumentVariablesButton.setLayoutData(gd);
addControlAccessibleListener(fArgumentVariablesButton, fArgumentVariablesButton.getText()); // need to strip the mnemonic from buttons
}
public void addControlAccessibleListener(Control control, String controlName) {
// Strip mnemonic (&)
String[] strs = controlName.split("&"); //$NON-NLS-1$
StringBuilder stripped = new StringBuilder();
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;
}
@Override
public void getName(AccessibleEvent e) {
e.result = controlName;
}
}
@Override
public boolean isValid(ILaunchConfiguration config) {
return fWorkingDirectoryBlock.isValid(config);
}
@Override
public void setDefaults(ILaunchConfigurationWorkingCopy config) {
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String) null);
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null);
}
@Override
public void initializeFrom(ILaunchConfiguration configuration) {
try {
fPrgmArgumentsText
.setText(configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, "")); //$NON-NLS-1$
fWorkingDirectoryBlock.initializeFrom(configuration);
} catch (CoreException e) {
setErrorMessage(NLS.bind(LaunchMessages.Launch_common_Exception_occurred_reading_configuration_EXCEPTION,
e.getStatus().getMessage()));
LaunchUIPlugin.log(e);
}
}
@Override
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
getAttributeValueFrom(fPrgmArgumentsText));
fWorkingDirectoryBlock.performApply(configuration);
}
/**
* Returns the string in the text widget, or <code>null</code> if empty.
*
* @return text or <code>null</code>
*/
protected String getAttributeValueFrom(Text text) {
String content = text.getText().trim();
// Bug #131513 - eliminate Windows \r line delimiter
content = content.replaceAll("\r\n", "\n"); //$NON-NLS-1$//$NON-NLS-2$
if (!content.isEmpty()) {
return content;
}
return null;
}
@Override
abstract public String getId();
@Override
public String getName() {
return LaunchMessages.CArgumentsTab_Arguments;
}
@Override
public void setLaunchConfigurationDialog(ILaunchConfigurationDialog dialog) {
super.setLaunchConfigurationDialog(dialog);
fWorkingDirectoryBlock.setLaunchConfigurationDialog(dialog);
}
@Override
public String getErrorMessage() {
String m = super.getErrorMessage();
if (m == null) {
return fWorkingDirectoryBlock.getErrorMessage();
}
return m;
}
@Override
public String getMessage() {
String m = super.getMessage();
if (m == null) {
return fWorkingDirectoryBlock.getMessage();
}
return m;
}
@Override
public Image getImage() {
return LaunchImages.get(LaunchImages.IMG_VIEW_ARGUMENTS_TAB);
}
@Override
protected void updateLaunchConfigurationDialog() {
super.updateLaunchConfigurationDialog();
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2016 QNX Software Systems and others.
* Copyright (c) 2005, 2019 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@ -14,32 +14,6 @@
*******************************************************************************/
package org.eclipse.cdt.launch.ui;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.launch.internal.ui.LaunchImages;
import org.eclipse.cdt.launch.internal.ui.LaunchMessages;
import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
import org.eclipse.cdt.launch.internal.ui.WorkingDirectoryBlock;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.osgi.util.NLS;
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.ModifyListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
/**
* A launch configuration tab that displays and edits program arguments,
* and working directory launch configuration attributes.
@ -48,7 +22,7 @@ import org.eclipse.swt.widgets.Text;
* </p>
* @noextend This class is not intended to be subclassed by clients.
*/
public class CArgumentsTab extends CLaunchConfigurationTab {
public class CArgumentsTab extends CAbstractArgumentsTab {
/**
* Tab identifier used for ordering of tabs added using the
* <code>org.eclipse.debug.ui.launchConfigurationTabs</code>
@ -58,179 +32,8 @@ public class CArgumentsTab extends CLaunchConfigurationTab {
*/
public static final String TAB_ID = "org.eclipse.cdt.cdi.launch.argumentsTab"; //$NON-NLS-1$
// Program arguments UI widgets
protected Label fPrgmArgumentsLabel;
protected Text fPrgmArgumentsText;
protected Button fArgumentVariablesButton;
// Working directory
protected WorkingDirectoryBlock fWorkingDirectoryBlock = new WorkingDirectoryBlock();
@Override
public void createControl(Composite parent) {
Font font = parent.getFont();
Composite comp = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(1, true);
comp.setLayout(layout);
comp.setFont(font);
GridData gd = new GridData(GridData.FILL_BOTH);
comp.setLayoutData(gd);
setControl(comp);
LaunchUIPlugin.getDefault().getWorkbench().getHelpSystem().setHelp(getControl(),
ICDTLaunchHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_ARGUMNETS_TAB);
createArgumentComponent(comp, 1);
fWorkingDirectoryBlock.createControl(comp);
}
protected void createArgumentComponent(Composite comp, int horizontalSpan) {
Font font = comp.getFont();
Group group = new Group(comp, SWT.NONE);
group.setFont(font);
group.setLayout(new GridLayout());
GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = horizontalSpan;
group.setLayoutData(gd);
group.setText(LaunchMessages.CArgumentsTab_C_Program_Arguments);
fPrgmArgumentsText = new Text(group, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
fPrgmArgumentsText.getAccessible().addAccessibleListener(new AccessibleAdapter() {
@Override
public void getName(AccessibleEvent e) {
e.result = LaunchMessages.CArgumentsTab_C_Program_Arguments;
}
});
gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 40;
gd.widthHint = 100;
fPrgmArgumentsText.setLayoutData(gd);
fPrgmArgumentsText.setFont(font);
fPrgmArgumentsText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent evt) {
updateLaunchConfigurationDialog();
}
});
fArgumentVariablesButton = createVariablesButton(group, LaunchMessages.CArgumentsTab_Variables,
fPrgmArgumentsText);
gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
fArgumentVariablesButton.setLayoutData(gd);
addControlAccessibleListener(fArgumentVariablesButton, fArgumentVariablesButton.getText()); // need to strip the mnemonic from buttons
}
public void addControlAccessibleListener(Control control, String controlName) {
// Strip mnemonic (&)
String[] strs = controlName.split("&"); //$NON-NLS-1$
StringBuilder stripped = new StringBuilder();
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;
}
@Override
public void getName(AccessibleEvent e) {
e.result = controlName;
}
}
@Override
public boolean isValid(ILaunchConfiguration config) {
return fWorkingDirectoryBlock.isValid(config);
}
@Override
public void setDefaults(ILaunchConfigurationWorkingCopy config) {
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String) null);
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null);
}
@Override
public void initializeFrom(ILaunchConfiguration configuration) {
try {
fPrgmArgumentsText
.setText(configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, "")); //$NON-NLS-1$
fWorkingDirectoryBlock.initializeFrom(configuration);
} catch (CoreException e) {
setErrorMessage(NLS.bind(LaunchMessages.Launch_common_Exception_occurred_reading_configuration_EXCEPTION,
e.getStatus().getMessage()));
LaunchUIPlugin.log(e);
}
}
@Override
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
getAttributeValueFrom(fPrgmArgumentsText));
fWorkingDirectoryBlock.performApply(configuration);
}
/**
* Returns the string in the text widget, or <code>null</code> if empty.
*
* @return text or <code>null</code>
*/
protected String getAttributeValueFrom(Text text) {
String content = text.getText().trim();
// Bug #131513 - eliminate Windows \r line delimiter
content = content.replaceAll("\r\n", "\n"); //$NON-NLS-1$//$NON-NLS-2$
if (!content.isEmpty()) {
return content;
}
return null;
}
@Override
public String getId() {
return TAB_ID;
}
@Override
public String getName() {
return LaunchMessages.CArgumentsTab_Arguments;
}
@Override
public void setLaunchConfigurationDialog(ILaunchConfigurationDialog dialog) {
super.setLaunchConfigurationDialog(dialog);
fWorkingDirectoryBlock.setLaunchConfigurationDialog(dialog);
}
@Override
public String getErrorMessage() {
String m = super.getErrorMessage();
if (m == null) {
return fWorkingDirectoryBlock.getErrorMessage();
}
return m;
}
@Override
public String getMessage() {
String m = super.getMessage();
if (m == null) {
return fWorkingDirectoryBlock.getMessage();
}
return m;
}
@Override
public Image getImage() {
return LaunchImages.get(LaunchImages.IMG_VIEW_ARGUMENTS_TAB);
}
@Override
protected void updateLaunchConfigurationDialog() {
super.updateLaunchConfigurationDialog();
}
}

View file

@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-SymbolicName: org.eclipse.cdt.llvm.dsf.lldb.ui;singleton:=true
Bundle-Version: 1.0.1.qualifier
Bundle-Version: 1.0.100.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Localization: plugin
Require-Bundle: org.eclipse.cdt.debug.ui,
@ -16,7 +16,8 @@ Require-Bundle: org.eclipse.cdt.debug.ui,
org.eclipse.jface,
org.eclipse.cdt.llvm.dsf.lldb.core,
org.eclipse.cdt.dsf.ui,
org.eclipse.cdt.debug.core
org.eclipse.cdt.debug.core,
org.eclipse.cdt.launch
Bundle-Activator: org.eclipse.cdt.llvm.dsf.lldb.ui.internal.LLDBUIPlugin
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.cdt.llvm.dsf.lldb.ui.internal;x-internal:=true