Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e4bdb6046cf1de4d5606d62d4a58a6a5baa1500f (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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*******************************************************************************
 * Copyright (c) 2007, 2009 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.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICMultiConfigDescription;
import org.eclipse.cdt.core.settings.model.ICSettingEntry;

/**
 * @noextend This class is not intended to be subclassed by clients.
 */
public class IncludeDialog extends AbstractPropertyDialog {
	public String sdata;
	private Button b_add2confs;
	private Button b_add2langs;
	public Text text;
	private Button b_work;
	private Button b_file;
	private Button b_vars;
	private Button b_ok;
	private Button b_ko;
	private int mode;
	private Button c_wsp;
	private ICConfigurationDescription cfgd;
	private boolean isWsp = false;
	
	static final int NEW_FILE = 0;
	static final int NEW_DIR  = 1;
	static final int OLD_FILE = 2;
	static final int OLD_DIR  = 3;
	
	static final int DIR_MASK = 1;	
	static final int OLD_MASK = 2;	
	
	public IncludeDialog(Shell parent, int _mode,
		String title, String _data, ICConfigurationDescription _cfgd, int flags) {
		super(parent, title);
		mode = _mode;
		sdata = _data;
		cfgd = _cfgd;
		if (flags == ICSettingEntry.VALUE_WORKSPACE_PATH)
			isWsp = true;
	}

	@Override
	protected Control createDialogArea(Composite c) {
		c.setLayout(new GridLayout(2, false));
		GridData gd;
		
		Label l1 = new Label(c, SWT.NONE);
		if ((mode & DIR_MASK) == DIR_MASK)
			l1.setText(UIMessages.getString("IncludeDialog.0")); //$NON-NLS-1$
		else
			l1.setText(UIMessages.getString("IncludeDialog.1")); //$NON-NLS-1$
		gd = new GridData(GridData.FILL_HORIZONTAL);
		gd.horizontalSpan = 2;
		l1.setLayoutData(gd);
		
		text = new Text(c, SWT.SINGLE | SWT.BORDER);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		gd.horizontalSpan = 2;
		gd.widthHint = 300;
		text.setLayoutData(gd);
		if ((mode & OLD_MASK) == OLD_MASK) { text.setText(sdata); }
		text.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				setButtons();
			}});
		
// Checkboxes
		Composite c1 = new Composite (c, SWT.NONE); 
		gd = new GridData(GridData.FILL_HORIZONTAL);
		gd.verticalAlignment = SWT.TOP;
		c1.setLayoutData(gd);
		c1.setLayout(new GridLayout(1, false));
		
		b_add2confs = new Button(c1, SWT.CHECK);
		b_add2confs.setText(UIMessages.getString("IncludeDialog.2")); //$NON-NLS-1$
		gd = new GridData(GridData.FILL_HORIZONTAL);
		if (((mode & OLD_MASK) == OLD_MASK) ||
				(cfgd instanceof ICMultiConfigDescription)) {
			gd.heightHint = 1;
			b_add2confs.setVisible(false);
		}
		b_add2confs.setLayoutData(gd);

		b_add2langs = new Button(c1, SWT.CHECK);
		b_add2langs.setText(UIMessages.getString("IncludeDialog.3")); //$NON-NLS-1$
		gd = new GridData(GridData.FILL_HORIZONTAL);
		if ((mode & OLD_MASK) == OLD_MASK) {
			gd.heightHint = 1;
			b_add2langs.setVisible(false);
		}
		b_add2langs.setLayoutData(gd);

		c_wsp = new Button(c1, SWT.CHECK);
		c_wsp.setText(UIMessages.getString("ExpDialog.4")); //$NON-NLS-1$
		gd = new GridData(GridData.FILL_HORIZONTAL);
		c_wsp.setLayoutData(gd);
		c_wsp.setSelection(isWsp);
		c_wsp.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				c_wsp.setImage(AbstractExportTab.getWspImage(c_wsp.getSelection()));
			}});
		c_wsp.setImage(AbstractExportTab.getWspImage(isWsp));

// Buttons		
		Composite c2 = new Composite (c, SWT.NONE); 
		gd = new GridData(GridData.END);
		c2.setLayoutData(gd);
		c2.setLayout(new GridLayout(2, true));
		
		new Label(c2, 0).setLayoutData(new GridData()); // placeholder
		b_vars = setupButton(c2, AbstractCPropertyTab.VARIABLESBUTTON_NAME);

		new Label(c2, 0).setLayoutData(new GridData()); // placeholder
		b_work = setupButton(c2, AbstractCPropertyTab.WORKSPACEBUTTON_NAME);

		new Label(c2, 0).setLayoutData(new GridData()); // placeholder
		b_file = setupButton(c2, AbstractCPropertyTab.FILESYSTEMBUTTON_NAME);

		b_ok = setupButton(c2, IDialogConstants.OK_LABEL);
		b_ko = setupButton(c2, IDialogConstants.CANCEL_LABEL);
		
		c.getShell().setDefaultButton(b_ok);
		c.pack();
		
		// resize (bug #189333)
		int x = b_ko.getBounds().width * 3 + 10;
		int y = c.getBounds().width - 10; 
		if (x > y) {
			((GridData)(text.getLayoutData())).widthHint = x;
			c.pack();
		}
		
		setButtons();
		return c;
	}	
	
	private void setButtons() {
		b_ok.setEnabled(text.getText().trim().length() > 0);
	}
	
	@Override
	public void buttonPressed(SelectionEvent e) {
		String s;
		if (e.widget.equals(b_ok)) { 
			text1 = text.getText();
			check1 = b_add2confs.getSelection();
			check2 = c_wsp.getSelection();
			check3 = b_add2langs.getSelection();
			result = true;
			shell.dispose(); 
		} else if (e.widget.equals(b_ko)) {
			shell.dispose();
		} else if (e.widget.equals(b_work)) {
			if ((mode & DIR_MASK)== DIR_MASK)
				s = AbstractCPropertyTab.getWorkspaceDirDialog(shell, text.getText());
			else 
				s = AbstractCPropertyTab.getWorkspaceFileDialog(shell, text.getText());
			if (s != null) {
				s = strip_wsp(s);
				text.setText(s);
				c_wsp.setSelection(true);
				c_wsp.setImage(AbstractExportTab.getWspImage(c_wsp.getSelection()));
			}
		} else if (e.widget.equals(b_file)) {
			if ((mode & DIR_MASK)== DIR_MASK)
				s = AbstractCPropertyTab.getFileSystemDirDialog(shell, text.getText());
			else 
				s = AbstractCPropertyTab.getFileSystemFileDialog(shell, text.getText());
			if (s != null) {
				text.setText(s);
				c_wsp.setSelection(false);
				c_wsp.setImage(AbstractExportTab.getWspImage(c_wsp.getSelection()));
			}
		} else if (e.widget.equals(b_vars)) {
			s = AbstractCPropertyTab.getVariableDialog(shell, cfgd);
			if (s != null) text.insert(s);
		}
	}
}

Back to the top