From 1d1583f9d307db5e282b4812cf748527d115e599 Mon Sep 17 00:00:00 2001 From: Oleg Krasilnikov Date: Fri, 27 Apr 2007 08:03:25 +0000 Subject: [PATCH] Bug #183410: enhance CDT vars dialog --- .../cdt/ui/newui/AbstractCPropertyTab.java | 34 +----- .../cdt/ui/newui/BuildVarListDialog.java | 114 ++++++++++++++++++ .../cdt/ui/newui/PluginResources.properties | 14 ++- 3 files changed, 128 insertions(+), 34 deletions(-) create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/BuildVarListDialog.java diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractCPropertyTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractCPropertyTab.java index 2da6e0fdf2f..485979619b8 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractCPropertyTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractCPropertyTab.java @@ -10,8 +10,6 @@ *******************************************************************************/ package org.eclipse.cdt.ui.newui; -import java.util.Arrays; - import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; @@ -20,10 +18,6 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; @@ -44,7 +38,6 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; import org.eclipse.ui.dialogs.ISelectionStatusValidator; -import org.eclipse.ui.dialogs.ListDialog; import org.eclipse.ui.model.WorkbenchContentProvider; import org.eclipse.ui.model.WorkbenchLabelProvider; import org.eclipse.ui.views.navigator.ResourceComparator; @@ -396,32 +389,7 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { public static String getVariableDialog(Shell shell, ICConfigurationDescription cfgd) { ICdtVariableManager vm = CCorePlugin.getDefault().getCdtVariableManager(); - - ListDialog dialog = new ListDialog(shell); - dialog.setContentProvider(new IStructuredContentProvider() { - public Object[] getElements(Object inputElement) { - Object[] obs = (Object[])inputElement; - Arrays.sort(obs, CDTListComparator.getInstance()); - return obs; - } - public void dispose() {} - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} - }); - dialog.setLabelProvider(new ILabelProvider() { - public Image getImage(Object element) { return null; } - public String getText(Object element) { - if (element instanceof ICdtVariable) - return ((ICdtVariable)element).getName(); - return null; - } - public void addListener(ILabelProviderListener listener) {} - public void dispose() {} - public boolean isLabelProperty(Object element, String property) { return false; } - public void removeListener(ILabelProviderListener listener) { - }}); - - dialog.setInput(vm.getVariables(cfgd)); - dialog.setHeightInChars(10); + BuildVarListDialog dialog = new BuildVarListDialog(shell, vm.getVariables(cfgd)); dialog.setTitle(UIMessages.getString("AbstractCPropertyTab.0")); //$NON-NLS-1$ if (dialog.open() == Window.OK) { Object[] selected = dialog.getResult(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/BuildVarListDialog.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/BuildVarListDialog.java new file mode 100644 index 00000000000..688a2454cb2 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/BuildVarListDialog.java @@ -0,0 +1,114 @@ +package org.eclipse.cdt.ui.newui; + +import org.eclipse.core.variables.IStringVariable; +import org.eclipse.core.variables.VariablesPlugin; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.ElementListSelectionDialog; + +import org.eclipse.cdt.core.cdtvariables.ICdtVariable; + +import org.eclipse.cdt.internal.ui.wizards.indexwizards.Messages; + +public class BuildVarListDialog extends ElementListSelectionDialog { + + private static final String TYPE = UIMessages.getString("BuildVarListDialog_0"); //$NON-NLS-1$ + private IStringVariable[] sysVars = VariablesPlugin.getDefault().getStringVariableManager().getVariables(); + + private Text text; + private Label type; + + public BuildVarListDialog(Shell parent, Object[] input) { + super(parent, new LabelProvider () { + public String getText(Object element) { + if (element instanceof ICdtVariable) + return ((ICdtVariable)element).getName(); + return super.getText(element); + }}); + setShellStyle(getShellStyle() | SWT.RESIZE); + setMessage(Messages.StringVariableSelectionDialog_message); + setMultipleSelection(false); + setElements(input); + } + + protected Control createDialogArea(Composite container) { + Composite c = (Composite) super.createDialogArea(container); + + type = new Label(c, SWT.NONE); + type.setFont(container.getFont()); + type.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Label desc = new Label(c, SWT.NONE); + desc.setFont(c.getFont()); + desc.setText(Messages.StringVariableSelectionDialog_columnDescription); + desc.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + text = new Text(c, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL); + text.setFont(container.getFont()); + text.setEditable(false); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.heightHint = 50; + text.setLayoutData(gd); + return c; + } + + protected void handleSelectionChanged() { + super.handleSelectionChanged(); + Object[] objects = getSelectedElements(); + String descr = null; + if (objects.length == 1) { + ICdtVariable v = (ICdtVariable)objects[0]; + // update type name + type.setText(TYPE + " " + typeIntToString(v.getValueType())); //$NON-NLS-1$ + // search in system variables list + for (int i = 0; i < sysVars.length; i++) { + if (v.getName() == sysVars[i].getName()) { + descr = sysVars[i].getDescription(); + break; + } + } + } + if (descr == null) + descr = UIMessages.getString("BuildVarListDialog.0"); //$NON-NLS-1$ + text.setText(descr); + } + + public static String typeIntToString(int type){ + String stringType; + switch(type){ + case ICdtVariable.VALUE_TEXT_LIST: + stringType = UIMessages.getString("BuildVarListDialog_1"); //$NON-NLS-1$ + break; + case ICdtVariable.VALUE_PATH_FILE: + stringType = UIMessages.getString("BuildVarListDialog_2"); //$NON-NLS-1$ + break; + case ICdtVariable.VALUE_PATH_FILE_LIST: + stringType = UIMessages.getString("BuildVarListDialog_3"); //$NON-NLS-1$ + break; + case ICdtVariable.VALUE_PATH_DIR: + stringType = UIMessages.getString("BuildVarListDialog_4"); //$NON-NLS-1$ + break; + case ICdtVariable.VALUE_PATH_DIR_LIST: + stringType = UIMessages.getString("BuildVarListDialog_5"); //$NON-NLS-1$ + break; + case ICdtVariable.VALUE_PATH_ANY: + stringType = UIMessages.getString("BuildVarListDialog_6"); //$NON-NLS-1$ + break; + case ICdtVariable.VALUE_PATH_ANY_LIST: + stringType = UIMessages.getString("BuildVarListDialog_7"); //$NON-NLS-1$ + break; + case ICdtVariable.VALUE_TEXT: + default: + stringType = UIMessages.getString("BuildVarListDialog_8"); //$NON-NLS-1$ + break; + } + return stringType; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/PluginResources.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/PluginResources.properties index 271b6e935bb..2ed8a7cf815 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/PluginResources.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/PluginResources.properties @@ -543,4 +543,16 @@ NewModelProjectWizard.1=Create CDT project of selected type NewModelProjectWizard.2=C++ project NewModelProjectWizard.3=Create C++ project of selected type NewModelProjectWizard.4=C project -NewModelProjectWizard.5=Create C project of selected type \ No newline at end of file +NewModelProjectWizard.5=Create C project of selected type +BuildVarListDialog_0=Type : +BuildVarListDialog_1=Text list +BuildVarListDialog_2=File path +BuildVarListDialog_3=List of File paths +BuildVarListDialog_4=Directory path +BuildVarListDialog_5=List of Directory paths +BuildVarListDialog_6=Any path +BuildVarListDialog_7=List of any paths +BuildVarListDialog_8=Text +BuildVarListDialog.0= +StringVariableSelectionDialog_message=&Choose a variable (? = any character, * = any string): +StringVariableSelectionDialog_columnDescription=&Variable Description: