diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index d4b828fb19c..39f2f12ae1d 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -1,3 +1,14 @@ +2003-06-26 Sean Evoy + Added methods to add and extract include paths and preprocessor + symbols from standard make C and C++ projects. + + Getter and setter methods in: + * src/org/eclipse/cdt/core/BuildInfoFactory.java + * src/org/eclipse/cdt/core/CProjectNature.java + + Added new constant for comma-separated lists + * src/org/eclipse/cdt/core/resources/IBuildInfo.java + 2003-06-24 Alain Magloire Patch form ando@park.ruru.ne.jp, to deal diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/BuildInfoFactory.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/BuildInfoFactory.java index eb31bceeca9..90ab6163217 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/BuildInfoFactory.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/BuildInfoFactory.java @@ -25,6 +25,8 @@ public class BuildInfoFactory { public static final String STOP_ON_ERROR = "stopOnError"; // public static final String CLEAR_CONSOLE = "clearConsole"; public static final String DEFAULT_BUILD_CMD = "useDefaultBuildCmd"; + public static final String INCLUDE_PATHS = "includePaths"; + public static final String DEFINED_SYMBOLS = "definedSymbols"; public static abstract class Store implements IBuildInfo { public String getBuildLocation() { @@ -49,10 +51,18 @@ public class BuildInfoFactory { return getString(LOCATION); } + public String getDefinedSymbols() { + return getString(DEFINED_SYMBOLS); + } + public String getFullBuildArguments() { return getString(FULL_ARGUMENTS); } + public String getIncludePaths() { + return getString(INCLUDE_PATHS); + } + public String getIncrementalBuildArguments() { return getString(INCREMENTAL_ARGUMENTS); } @@ -65,14 +75,22 @@ public class BuildInfoFactory { putValue(LOCATION, location); } + public void setDefinedSymbols(String argument) { + putValue(DEFINED_SYMBOLS, argument); + } + public void setFullBuildArguments(String arguments) { putValue(FULL_ARGUMENTS, arguments); } + public void setIncludePaths(String arguments) { + putValue(INCLUDE_PATHS, arguments); + } + public void setIncrementalBuildArguments(String arguments) { putValue(INCREMENTAL_ARGUMENTS, arguments); } - + public void setStopOnError(boolean on) { putValue(STOP_ON_ERROR, new Boolean(on).toString()); } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CProjectNature.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CProjectNature.java index 1d986ce62aa..c1ab2814e66 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CProjectNature.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CProjectNature.java @@ -106,6 +106,30 @@ public class CProjectNature implements IProjectNature { return new Path(buildLocation); } + /** + * Answers a comma-separated list of defined preprocessor symbols + * for the project, or an empty string if there are none. + * + * @return + * @throws CoreException + */ + public String getDefinedSymbols() throws CoreException { + String symbols = fBuildInfo.getDefinedSymbols(); + return symbols == null ? new String() : symbols; + } + + /** + * Sets the defined symbols for the project. + * + * @param symbols + */ + public void setDefinedSymbols(String symbols, IProgressMonitor monitor) throws CoreException { + String oldSymbols = fBuildInfo.getDefinedSymbols(); + if (symbols != null && !symbols.equals(oldSymbols)) { + fBuildInfo.setDefinedSymbols(symbols); + } + } + /** * Sets the arguments for the full build. */ @@ -126,7 +150,33 @@ public class CProjectNature implements IProjectNature { } return buildArguments; } + + /** + * Answers a comma-separated list of include paths defined for + * the project, or an empty string if there are none. + * + * @return + * @throws CoreException + */ + public String getIncludePaths() throws CoreException { + String paths = fBuildInfo.getIncludePaths(); + return paths == null ? new String() : paths; + } + /** + * Sets the include path information for the project. + * + * @param paths + * @param monitor + * @throws CoreException + */ + public void setIncludePaths(String paths, IProgressMonitor monitor) throws CoreException { + String oldPaths = fBuildInfo.getIncludePaths(); + if (paths != null && !paths.equals(oldPaths)) { + fBuildInfo.setIncludePaths(paths); + } + } + /** * Sets the arguments for the incremental build. */ diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IBuildInfo.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IBuildInfo.java index 276341c3606..b05e68b3b6f 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IBuildInfo.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IBuildInfo.java @@ -6,14 +6,19 @@ package org.eclipse.cdt.core.resources; */ public interface IBuildInfo { - + public static final String SEPARATOR = ","; + String getBuildLocation(); + String getDefinedSymbols(); String getFullBuildArguments(); + String getIncludePaths(); String getIncrementalBuildArguments(); boolean isStopOnError(); void setBuildLocation(String location); + void setDefinedSymbols(String symbols); void setFullBuildArguments(String arguments); + void setIncludePaths(String paths); void setIncrementalBuildArguments(String arguments); void setStopOnError(boolean on); diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index bcd2c257528..52b95a38aa5 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,12 @@ +2003-06-26 Sean Evoy + Added a tab to the new standard make project wizard and CNature project + property page. User interacts with two list controls to add include paths + and proprocessor symbols to a standard make project. + * src/org/eclipse/cdt/ui/wizards/BuildPathInfoBlock.java + * src/org/eclipse/cdt/ui/wizards/StdMakeProjectWizard.java + * src/org/eclipse/cdt/internal/ui/preferences/CProjectPropertyPage.java + * src/org/eclipse/cdt/internal/ui/CPluginResources.properties + 2003-06-25 John Camelon Create new interface and support for calculating lineNumber/offset mapping. Updated IASTClassSpecifier for qualified name query. diff --git a/core/org.eclipse.cdt.ui/build/org/eclipse/cdt/ui/build/properties/BuildOptionListFieldEditor.java b/core/org.eclipse.cdt.ui/build/org/eclipse/cdt/ui/build/properties/BuildOptionListFieldEditor.java index 34300a4a479..52b3f5807cb 100644 --- a/core/org.eclipse.cdt.ui/build/org/eclipse/cdt/ui/build/properties/BuildOptionListFieldEditor.java +++ b/core/org.eclipse.cdt.ui/build/org/eclipse/cdt/ui/build/properties/BuildOptionListFieldEditor.java @@ -46,10 +46,11 @@ public class BuildOptionListFieldEditor extends ListEditor { protected String getNewInputObject() { // Create a dialog to prompt for a new symbol or path InputDialog dialog = new InputDialog(getShell(), CUIPlugin.getResourceString(TITLE), fieldName, new String(), null); + String input = null; if (dialog.open() == InputDialog.OK) { - return dialog.getValue(); + input = dialog.getValue(); } - return new String(); + return input.length() == 0 ? null : input; } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties index 81afbbb966a..99a519613e2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties @@ -79,6 +79,15 @@ ConfigurationBlock.build.label=Build Settings ConfigurationBlock.build.continue=Continue On Error ConfigurationBlock.build.stop=Stop On Error +# String constants for the build include path and preprocessor symbols +BuildPathInfoBlock.label=Paths and Symbols +BuildPathInfoBlock.paths=Include paths: +BuildPathInfoBlock.symbols=Defined symbols: +BuildPathInfoBlock.browse.path=New Include Path +BuildPathInfoBlock.browse.path.label=Path: +BuildPathInfoBlock.browse.symbol=New Defined Symbol +BuildPathInfoBlock.browse.symbol.label=Symbol: + StdMakeProjectWizard.op_error=Standard Make Error StdMakeProjectWizard.title=Standard Make Project StdMakeProjectWizard.description=Create a new Standard Make project. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CProjectPropertyPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CProjectPropertyPage.java index eb9b058e767..c8ffa038716 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CProjectPropertyPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CProjectPropertyPage.java @@ -12,6 +12,7 @@ import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener; import org.eclipse.cdt.internal.ui.dialogs.StatusTool; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.wizards.BinaryParserBlock; +import org.eclipse.cdt.ui.wizards.BuildPathInfoBlock; import org.eclipse.cdt.ui.wizards.IndexerBlock; import org.eclipse.cdt.ui.wizards.SettingsBlock; import org.eclipse.cdt.utils.ui.controls.TabFolderLayout; @@ -43,6 +44,7 @@ public class CProjectPropertyPage extends PropertyPage implements IStatusChangeL SettingsBlock settingsBlock; IndexerBlock indexerBlock; BinaryParserBlock binaryParserBlock; + private BuildPathInfoBlock pathInfoBlock; protected Control createContents(Composite parent) { Composite composite= new Composite(parent, SWT.NONE); @@ -88,6 +90,16 @@ public class CProjectPropertyPage extends PropertyPage implements IStatusChangeL item4.setImage(img4); item4.setData(binaryParserBlock); item4.setControl(binaryParserBlock.getControl(folder)); + + pathInfoBlock = new BuildPathInfoBlock(this, getProject()); + TabItem pathItem = new TabItem(folder, SWT.NONE); + pathItem.setText(pathInfoBlock.getLabel()); + Image pathImg = pathInfoBlock.getImage(); + if (pathImg != null) { + pathItem.setImage(pathImg); + } + pathItem.setData(pathInfoBlock); + pathItem.setControl(pathInfoBlock.getControl(folder)); WorkbenchHelp.setHelp(parent, ICHelpContextIds.PROJECT_PROPERTY_PAGE); } @@ -112,6 +124,9 @@ public class CProjectPropertyPage extends PropertyPage implements IStatusChangeL if (ok && binaryParserBlock != null) { ok = binaryParserBlock.isValid(); } + if (ok && pathInfoBlock != null) { + ok = pathInfoBlock.isValid(); + } setValid(ok); } @@ -134,6 +149,10 @@ public class CProjectPropertyPage extends PropertyPage implements IStatusChangeL if (binaryParserBlock != null) { binaryParserBlock.doRun(getProject(), monitor); } + monitor.worked(15); + if (pathInfoBlock != null) { + pathInfoBlock.doRun(getProject(), monitor); + } monitor.worked(19); monitor.done(); } @@ -167,6 +186,7 @@ public class CProjectPropertyPage extends PropertyPage implements IStatusChangeL settingsBlock.setVisible(visible); indexerBlock.setVisible(visible); binaryParserBlock.setVisible(visible); + pathInfoBlock.setVisible(visible); folder.setFocus(); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/BuildPathInfoBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/BuildPathInfoBlock.java new file mode 100644 index 00000000000..aa6aecdb1c7 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/BuildPathInfoBlock.java @@ -0,0 +1,660 @@ +package org.eclipse.cdt.ui.wizards; + +import java.util.StringTokenizer; + +import org.eclipse.cdt.core.CProjectNature; +import org.eclipse.cdt.core.resources.IBuildInfo; +import org.eclipse.cdt.internal.ui.util.SWTUtil; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.utils.ui.controls.ControlFactory; +import org.eclipse.cdt.utils.ui.swt.IValidation; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +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.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Shell; + +/********************************************************************** + * Copyright (c) 2002,2003 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ + +public class BuildPathInfoBlock implements IWizardTab { + private static final String PREFIX = "BuildPathInfoBlock"; //$NON-NLS-1$ + private static final String LABEL = PREFIX + ".label"; //$NON-NLS-1$ + private static final String PATHS = PREFIX + ".paths"; //$NON-NLS-1$ + private static final String SYMBOLS = PREFIX + ".symbols"; //$NON-NLS-1$ + private static final String BROWSE = PREFIX + ".browse"; //$NON-NLS-1$ + private static final String PATH_TITLE = BROWSE + ".path"; //$NON-NLS-1$ + private static final String PATH_LABEL = BROWSE + ".path.label"; //$NON-NLS-1$ + private static final String SYMBOL_TITLE = BROWSE + ".symbol"; //$NON-NLS-1$ + private static final String SYMBOL_LABEL = BROWSE + ".symbol.label"; //$NON-NLS-1$ + private static final String NEW = "BuildPropertyCommon.label.new"; //$NON-NLS-1$ + private static final String REMOVE = "BuildPropertyCommon.label.remove"; //$NON-NLS-1$ + private static final String UP = "BuildPropertyCommon.label.up"; //$NON-NLS-1$ + private static final String DOWN = "BuildPropertyCommon.label.down"; //$NON-NLS-1$ + + private IProject project; + private IValidation page; + private List pathList; + private List symbolList; + private Composite pathButtonComp; + private Button addPath; + private Button removePath; + private Button pathUp; + private Button pathDown; + private Composite symbolButtonComp; + private Button addSymbol; + private Button removeSymbol; + private Button symbolUp; + private Button symbolDown; + private Shell shell; + + + /** + * @param valid + */ + public BuildPathInfoBlock(IValidation valid) { + this(valid, null); + } + + /** + * @param page + * @param project + */ + public BuildPathInfoBlock(IValidation valid, IProject project) { + this.page = valid; + this.project = project; + } + + /** + * @param composite + */ + private void createPathListButtons(Composite parent) { + // Create a composite for the buttons + pathButtonComp = ControlFactory.createComposite(parent, 1); + GridData gd = new GridData(GridData.FILL_BOTH); + pathButtonComp.setFont(parent.getFont()); + + // Add the buttons + addPath = ControlFactory.createPushButton(pathButtonComp, CUIPlugin.getResourceString(NEW)); + addPath.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleAddPath(); + } + }); + addPath.setEnabled(true); + addPath.setFont(parent.getFont()); + addPath.setLayoutData(new GridData()); + SWTUtil.setButtonDimensionHint(addPath); + + removePath = ControlFactory.createPushButton(pathButtonComp, CUIPlugin.getResourceString(REMOVE)); + removePath.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleRemovePath(); + } + }); + removePath.setFont(parent.getFont()); + removePath.setLayoutData(new GridData()); + SWTUtil.setButtonDimensionHint(removePath); + + pathUp = ControlFactory.createPushButton(pathButtonComp, CUIPlugin.getResourceString(UP)); + pathUp.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handlePathUp(); + } + }); + pathUp.setFont(parent.getFont()); + pathUp.setLayoutData(new GridData()); + SWTUtil.setButtonDimensionHint(pathUp); + + pathDown = ControlFactory.createPushButton(pathButtonComp, CUIPlugin.getResourceString(DOWN)); + pathDown.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handlePathDown(); + } + }); + pathDown.setFont(parent.getFont()); + pathDown.setLayoutData(new GridData()); + SWTUtil.setButtonDimensionHint(pathDown); + + } + + /** + * @param composite + */ + private void createPathListControl(Composite parent, int numColumns) { + // Create the list + pathList = new List(parent, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL); + pathList.addSelectionListener(new SelectionAdapter () { + public void widgetSelected(SelectionEvent e) { + enablePathButtons(); + } + }); + pathList.addMouseListener(new MouseListener() { + + public void mouseDoubleClick(MouseEvent e) { + editPathListItem(); + } + + public void mouseDown(MouseEvent e) { + // Handled by the selection listener + } + + public void mouseUp(MouseEvent e) { + // Handled by the selection listener + } + + }); + + // Make it occupy the first 2 columns + GridData gd = new GridData(GridData.FILL_BOTH); + gd.horizontalSpan = numColumns - 1; + pathList.setLayoutData(gd); + pathList.setFont(parent.getFont()); + } + + /** + * @param composite + */ + private void createSymbolListButtons(Composite parent) { + // Create a composite for the buttons + symbolButtonComp = ControlFactory.createComposite(parent, 1); + GridData gd = new GridData(GridData.FILL_BOTH); + symbolButtonComp.setFont(parent.getFont()); + + // Add the buttons + addSymbol = ControlFactory.createPushButton(symbolButtonComp, CUIPlugin.getResourceString(NEW)); + addSymbol.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleAddSymbol(); + } + }); + addSymbol.setEnabled(true); + addSymbol.setFont(parent.getFont()); + addSymbol.setLayoutData(new GridData()); + SWTUtil.setButtonDimensionHint(addSymbol); + + removeSymbol = ControlFactory.createPushButton(symbolButtonComp, CUIPlugin.getResourceString(REMOVE)); + removeSymbol.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleRemoveSymbol(); + } + }); + removeSymbol.setFont(parent.getFont()); + removeSymbol.setLayoutData(new GridData()); + SWTUtil.setButtonDimensionHint(removeSymbol); + + symbolUp = ControlFactory.createPushButton(symbolButtonComp, CUIPlugin.getResourceString(UP)); + symbolUp.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleSymbolUp(); + } + }); + symbolUp.setFont(parent.getFont()); + symbolUp.setLayoutData(new GridData()); + SWTUtil.setButtonDimensionHint(symbolUp); + + symbolDown = ControlFactory.createPushButton(symbolButtonComp, CUIPlugin.getResourceString(DOWN)); + symbolDown.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleSymbolDown(); + } + }); + symbolDown.setFont(parent.getFont()); + symbolDown.setLayoutData(new GridData()); + SWTUtil.setButtonDimensionHint(symbolDown); + } + + /** + * @param composite + */ + private void createSymbolListControl(Composite parent, int numColumns) { + // Create the list + symbolList = new List(parent, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL); + symbolList.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + enableSymbolButtons(); + } + }); + symbolList.addMouseListener(new MouseListener() { + + public void mouseDoubleClick(MouseEvent e) { + editSymbolListItem(); + } + + public void mouseDown(MouseEvent e) { + // Handled by the selection event + } + + public void mouseUp(MouseEvent e) { + // Handled by the selection event + } + }); + + // Make it occupy the first n-1 columns + GridData gd = new GridData(GridData.FILL_BOTH); + gd.horizontalSpan = numColumns - 1; + symbolList.setLayoutData(gd); + symbolList.setFont(parent.getFont()); + + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.ui.wizards.IWizardTab#doRun(org.eclipse.core.resources.IProject, org.eclipse.core.runtime.IProgressMonitor) + */ + public void doRun(IProject project, IProgressMonitor monitor) { + try { + if (monitor == null) { + monitor = new NullProgressMonitor(); + } + // Store the paths and symbols as comma-separated lists in the project's nature + CProjectNature nature = (CProjectNature) project.getNature(CProjectNature.C_NATURE_ID); + monitor.beginTask("Setting Include Paths", 1); + String paths = getPathListContents(); + nature.setIncludePaths(paths, monitor); + monitor.beginTask("Setting Defined Symbols", 1); + String symbols = getSymbolListContents(); + nature.setDefinedSymbols(symbols, monitor); + + } + catch (CoreException e) { + } + + } + + /* + * Double-click handler to allow edit of path information + */ + protected void editPathListItem() { + // Edit the selection index + int index = pathList.getSelectionIndex(); + if (index != -1) { + String selItem = pathList.getItem(index); + if (selItem != null) { + InputDialog dialog = new InputDialog(shell, CUIPlugin.getResourceString(PATH_TITLE), CUIPlugin.getResourceString(PATH_LABEL), selItem, null); + String newItem = null; + if (dialog.open() == InputDialog.OK) { + newItem = dialog.getValue(); + if (newItem != null && !newItem.equals(selItem)) { + pathList.setItem(index, newItem); + } + } + } + } + } + + /* + * Double-click handler to allow edit of symbol information + */ + protected void editSymbolListItem() { + // Edit the selection index + int index = symbolList.getSelectionIndex(); + if (index != -1) { + String selItem = symbolList.getItem(index); + if (selItem != null) { + InputDialog dialog = new InputDialog(shell, CUIPlugin.getResourceString(SYMBOL_TITLE), CUIPlugin.getResourceString(SYMBOL_LABEL), selItem, null); + String newItem = null; + if (dialog.open() == InputDialog.OK) { + newItem = dialog.getValue(); + if (newItem != null && !newItem.equals(selItem)) { + symbolList.setItem(index, newItem); + } + } + } + } + } + + /* + * Enables the buttons on the path control if the right conditions are met + */ + private void enablePathButtons() { + // Enable the remove button if there is at least 1 item in the list + int items = pathList.getItemCount(); + if (items > 0){ + removePath.setEnabled(true); + // Enable the up/down buttons depending on what item is selected + int index = pathList.getSelectionIndex(); + pathUp.setEnabled(items > 1 && index > 0); + pathDown.setEnabled(items > 1 && index < (items - 1)); + } else { + removePath.setEnabled(false); + pathUp.setEnabled(false); + pathDown.setEnabled(false); + } + } + + private void enableSymbolButtons() { + // Enable the remove button if there is at least 1 item in the list + int items = symbolList.getItemCount(); + if (items > 0){ + removeSymbol.setEnabled(true); + // Enable the up/down buttons depending on what item is selected + int index = symbolList.getSelectionIndex(); + symbolUp.setEnabled(items > 1 && index > 0); + symbolDown.setEnabled(items > 1 && index < (items - 1)); + } else { + removeSymbol.setEnabled(false); + symbolUp.setEnabled(false); + symbolDown.setEnabled(false); + } + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.ui.wizards.IWizardTab#getControl(org.eclipse.swt.widgets.Composite) + */ + public Composite getControl(Composite parent) { + this.shell = parent.getShell(); + + // Create the composite control for the tab + int tabColumns = 3; + Font font = parent.getFont(); + Composite composite = ControlFactory.createComposite(parent, tabColumns); + composite.setFont(font); + GridData gd; + + // Create a label for the include paths control + Label paths = ControlFactory.createLabel(composite, CUIPlugin.getResourceString(PATHS)); + gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = tabColumns; + paths.setLayoutData(gd); + paths.setFont(font); + + //Create the list and button controls + createPathListControl(composite, tabColumns); + createPathListButtons(composite); + enablePathButtons(); + + // Create a label for the symbols control + Label symbols = ControlFactory.createLabel(composite, CUIPlugin.getResourceString(SYMBOLS)); + gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = tabColumns; + symbols.setLayoutData(gd); + symbols.setFont(font); + + // Create list and button controls for symbols + createSymbolListControl(composite, tabColumns); + createSymbolListButtons(composite); + enableSymbolButtons(); + + return composite; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.ui.wizards.IWizardTab#getImage() + */ + public Image getImage() { + // We don't decorate the tabs for the wizard or property page + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.ui.wizards.IWizardTab#getLabel() + */ + public String getLabel() { + // Return the label defined in the CPluginProperties.resource file + return CUIPlugin.getResourceString(LABEL); + } + + /** + * @return + */ + private String getPathListContents() { + // Convert the contents of the path list into a comma-separated list + StringBuffer buffer = new StringBuffer(); + if (pathList != null) { + String[] paths = pathList.getItems(); + for (int i = 0; i < paths.length; i++) { + String string = paths[i]; + buffer.append(string + IBuildInfo.SEPARATOR); + } + } + return buffer.toString(); + } + + /** + * @return + */ + private String getSymbolListContents() { + // Convert the contents of the symbol list into a comma-separated list + StringBuffer buffer = new StringBuffer(); + if (symbolList != null) { + String[] symbols = symbolList.getItems(); + for (int i = 0; i < symbols.length; i++) { + String symbol = symbols[i]; + buffer.append(symbol + IBuildInfo.SEPARATOR); + } + } + return buffer.toString(); + } + + /** + * + */ + protected void handleAddPath() { + // Popup an entry dialog + InputDialog dialog = new InputDialog(shell, CUIPlugin.getResourceString(PATH_TITLE), CUIPlugin.getResourceString(PATH_LABEL), "", null); + String path = null; + if (dialog.open() == InputDialog.OK) { + path = dialog.getValue(); + } + if (path != null && path.length() > 0) { + pathList.add(path); + pathList.select(pathList.getItemCount() - 1); + enablePathButtons(); + } + } + + /** + * + */ + protected void handleAddSymbol() { + // Popup an entry dialog + InputDialog dialog = new InputDialog(shell, CUIPlugin.getResourceString(SYMBOL_TITLE), CUIPlugin.getResourceString(SYMBOL_LABEL), "", null); + String symbol = null; + if (dialog.open() == InputDialog.OK) { + symbol = dialog.getValue(); + } + if (symbol != null && symbol.length() > 0) { + symbolList.add(symbol); + symbolList.select(symbolList.getItemCount() - 1); + enableSymbolButtons(); + } + } + + /** + * + */ + protected void handlePathDown() { + // Get the selection index + int index = pathList.getSelectionIndex(); + int items = pathList.getItemCount(); + if (index == -1 || index == items - 1) { + return; + } + // Swap the items in the list + String selItem = pathList.getItem(index); + pathList.remove(index); + if (index + 1 == items) { + pathList.add(selItem); + } else { + pathList.add(selItem, ++index); + } + + // Keep the swapped item selected + pathList.select(index); + enablePathButtons(); + } + + /** + * + */ + protected void handlePathUp() { + // Get the selection index + int index = pathList.getSelectionIndex(); + if (index == -1 || index == 0) { + return; + } + // Swap the items in the list + String selItem = pathList.getItem(index); + pathList.remove(index); + pathList.add(selItem, --index); + + // Keep the index selected + pathList.select(index); + enablePathButtons(); + } + + /** + * + */ + protected void handleRemovePath() { + // Get the selection index + int index = pathList.getSelectionIndex(); + if (index == -1) { + return; + } + + // Remove the element at that index + pathList.remove(index); + index = index - 1 < 0 ? 0 : index -1; + pathList.select(index); + + // Check if the buttons should still be enabled + enablePathButtons(); + } + + /** + * + */ + protected void handleRemoveSymbol() { + // Get the selection index + int index = symbolList.getSelectionIndex(); + if (index == -1) { + return; + } + // Remove the item at that index + symbolList.remove(index); + index = index - 1 < 0 ? 0 : index -1; + symbolList.select(index); + // Check if the button state should be toggled + enableSymbolButtons(); + } + + /** + * + */ + protected void handleSymbolDown() { + // Get the selection index + int index = symbolList.getSelectionIndex(); + int items = symbolList.getItemCount(); + if (index == -1 || index == items - 1) { + return; + } + // Swap the items in the list + String selItem = symbolList.getItem(index); + symbolList.remove(index); + if (index + 1 == items) { + symbolList.add(selItem); + } else { + symbolList.add(selItem, ++index); + } + + // Keep the swapped item selected + symbolList.select(index); + enableSymbolButtons(); + } + + /** + * + */ + protected void handleSymbolUp() { + // Get the selection index + int index = symbolList.getSelectionIndex(); + if (index == -1 || index == 0) { + return; + } + // Swap the items in the list + String selItem = symbolList.getItem(index); + symbolList.remove(index); + symbolList.add(selItem, --index); + + // Keep the index selected + symbolList.select(index); + enableSymbolButtons(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.ui.wizards.IWizardTab#isValid() + */ + public boolean isValid() { + // Info on this page is not critical + return true; + } + + private void setPathListContents() { + if (project != null) { + try { + CProjectNature nature = (CProjectNature)project.getNature(CProjectNature.C_NATURE_ID); + if (nature != null) { + String paths = nature.getIncludePaths(); + StringTokenizer tokens = new StringTokenizer(paths, IBuildInfo.SEPARATOR); + while (tokens.hasMoreTokens()) { + pathList.add(tokens.nextToken()); + } + } + } catch (CoreException e) { + // Just have an empty list + } + } + } + + private void setSymbolListContents() { + if (project != null) { + try { + CProjectNature nature = (CProjectNature)project.getNature(CProjectNature.C_NATURE_ID); + if (nature != null) { + String symbols = nature.getDefinedSymbols(); + StringTokenizer tokens = new StringTokenizer(symbols, IBuildInfo.SEPARATOR); + while (tokens.hasMoreTokens()) { + symbolList.add(tokens.nextToken()); + } + } + } catch (CoreException e) { + // Just have an empty list + } + } + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.ui.wizards.IWizardTab#setVisible(boolean) + */ + public void setVisible(boolean visible) { + // Set the content from the project + setPathListContents(); + pathList.select(0); + enablePathButtons(); + setSymbolListContents(); + symbolList.select(0); + enableSymbolButtons(); + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/StdMakeProjectWizard.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/StdMakeProjectWizard.java index 5a3245cd4d2..d083aadd335 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/StdMakeProjectWizard.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/StdMakeProjectWizard.java @@ -30,6 +30,7 @@ public abstract class StdMakeProjectWizard extends CProjectWizard { private ReferenceBlock referenceBlock; private SettingsBlock settingsBlock; private BinaryParserBlock binaryParserBlock; + private BuildPathInfoBlock pathInfoBlock; public StdMakeProjectWizard() { this(CUIPlugin.getResourceString(WZ_TITLE), CUIPlugin.getResourceString(WZ_DESC)); @@ -72,6 +73,17 @@ public abstract class StdMakeProjectWizard extends CProjectWizard { item3.setData(binaryParserBlock); item3.setControl(binaryParserBlock.getControl(folder)); addTabItem(binaryParserBlock); + + pathInfoBlock = new BuildPathInfoBlock(getValidation()); + TabItem pathItem = new TabItem(folder, SWT.NONE); + pathItem.setText(pathInfoBlock.getLabel()); + Image pathImg = pathInfoBlock.getImage(); + if (pathImg != null) { + pathItem.setImage(pathImg); + } + pathItem.setData(pathInfoBlock); + pathItem.setControl(pathInfoBlock.getControl(folder)); + addTabItem(pathInfoBlock); } protected void doRunPrologue(IProgressMonitor monitor) { @@ -89,7 +101,7 @@ public abstract class StdMakeProjectWizard extends CProjectWizard { if (monitor == null) { monitor = new NullProgressMonitor(); } - monitor.beginTask("Standard Make", 3); + monitor.beginTask("Standard Make", 4); // Update the referenced project if provided. if (referenceBlock != null) { referenceBlock.doRun(newProject, new SubProgressMonitor(monitor, 1)); @@ -102,6 +114,10 @@ public abstract class StdMakeProjectWizard extends CProjectWizard { if (binaryParserBlock != null) { binaryParserBlock.doRun(newProject, new SubProgressMonitor(monitor, 1)); } + // Update the binary parser + if (pathInfoBlock != null) { + pathInfoBlock.doRun(newProject, new SubProgressMonitor(monitor, 1)); + } } }