1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-09 09:15:38 +02:00

Bug #183410: enhance CDT vars dialog

This commit is contained in:
Oleg Krasilnikov 2007-04-27 08:03:25 +00:00
parent 08d67267bc
commit 1d1583f9d3
3 changed files with 128 additions and 34 deletions

View file

@ -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();

View file

@ -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;
}
}

View file

@ -544,3 +544,15 @@ NewModelProjectWizard.2=C++ project
NewModelProjectWizard.3=Create C++ project of selected type
NewModelProjectWizard.4=C project
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=<not available>
StringVariableSelectionDialog_message=&Choose a variable (? = any character, * = any string):
StringVariableSelectionDialog_columnDescription=&Variable Description: