Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: deb69fc56f9017243e1d26eaecbf5dc3559ee143 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*******************************************************************************
 * Copyright (c) 2007, 2011 Intel Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Intel Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.ui.newui;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
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.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.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;

import org.eclipse.cdt.internal.ui.newui.Messages;

/**
 * @noextend This class is not intended to be subclassed by clients.
 */
public class EnvDialog extends Dialog {
	IEnvironmentVariable var;
	Button b_add2all;
	private Text text1;
	private Text text2;
	private boolean newAction;
	private boolean multiCfg;
	private ICConfigurationDescription cfgd;
	public String t1 = AbstractCPropertyTab.EMPTY_STR;
	public String t2 = AbstractCPropertyTab.EMPTY_STR;
	public boolean toAll = false;
	private String title;

	public EnvDialog(Shell parent,
			IEnvironmentVariable _var,
			String _title,
			boolean _newAction,
			boolean _multiCfg,
			ICConfigurationDescription _cfgd) {
		super(parent);
		var = _var;
		newAction = _newAction;
		multiCfg = _multiCfg;
		cfgd = _cfgd;
		title = _title;
	}

	/**
	 * Method is overridden to disable "OK" button at start
	 */
	@Override
	protected Control createContents(Composite parent) {
		Control out = super.createContents(parent);
		setButtons();
		return out;
	}

	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText(title);
	}

	@Override
	protected Control createDialogArea(Composite c) {
		c.setLayout(new GridLayout(3, false));
		GridData gd;

		Label l1 = new Label(c, SWT.NONE);
		l1.setText(Messages.EnvDialog_0);
		l1.setLayoutData(new GridData(GridData.BEGINNING));

		text1 = new Text(c, SWT.SINGLE | SWT.BORDER);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		gd.horizontalSpan = 2;
		gd.widthHint = 400;
		text1.setLayoutData(gd);
		text1.addModifyListener(new ModifyListener () {
			@Override
			public void modifyText(ModifyEvent e) { setButtons(); }});

		Label l2 = new Label(c, SWT.NONE);
		l2.setText(Messages.EnvDialog_1);
		l2.setLayoutData(new GridData(GridData.BEGINNING));

		text2 = new Text(c, SWT.SINGLE | SWT.BORDER);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		gd.widthHint = 250;
		text2.setLayoutData(gd);
		text2.addModifyListener(new ModifyListener () {
			@Override
			public void modifyText(ModifyEvent e) { setButtons(); }});

		final Button b = new Button(c, SWT.PUSH);
		b.setText(Messages.EnvDialog_2);
		b.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				String x = AbstractCPropertyTab.getVariableDialog(b.getShell(), cfgd);
				if (x != null) {
					text2.insert(x);
					setButtons();
				}
			}});
		gd = new GridData(GridData.FILL_HORIZONTAL);
		gd.widthHint = AbstractCPropertyTab.BUTTON_WIDTH;
		b.setLayoutData(gd);

		b_add2all = new Button(c, SWT.CHECK);
		b_add2all.setText(Messages.EnvDialog_3);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		if (cfgd == null)
			b_add2all.setVisible(false);
		else
			b_add2all.addSelectionListener(new SelectionAdapter() {
				@Override
				public void widgetSelected(SelectionEvent e) {
					toAll = b_add2all.getSelection();
				}});

		if (multiCfg)
			b_add2all.setVisible(false);

		if (!newAction) {
			gd.heightHint = 1;
			b_add2all.setVisible(false);

			text1.setText(var.getName());
			text1.setEnabled(false); // don't change name
			String s = var.getValue();
			text2.setText(s == null ? AbstractCPropertyTab.EMPTY_STR : s);
		}

		gd.horizontalSpan = 3;
		b_add2all.setLayoutData(gd);
		setButtons();
		return c;
	}

	private void setButtons() {
		t1 = text1.getText();
		t2 = text2.getText();
		Button b = getButton(IDialogConstants.OK_ID);
		if (b != null)
			b.setEnabled(t1.trim().length() > 0);
	}
}

Back to the top