comparison dwt/browser/PromptDialog.d @ 298:eec6ddb07873

More xpcom/mozilla port
author John Reimer<terminal.node@gmail.com>
date Sun, 10 Aug 2008 22:25:43 -0700
parents 4ee8c4237614
children bfe1c57259e3
comparison
equal deleted inserted replaced
297:2f204a4aebc6 298:eec6ddb07873
10 * Port to the D programming language: 10 * Port to the D programming language:
11 * John Reimer <terminal.node@gmail.com> 11 * John Reimer <terminal.node@gmail.com>
12 *******************************************************************************/ 12 *******************************************************************************/
13 module dwt.browser.PromptDialog; 13 module dwt.browser.PromptDialog;
14 14
15 import dwt.dwthelper.utils; 15 import Math = tango.math.Math;
16 //import dwt.dwthelper.utils;
16 17
17 import dwt.DWT; 18 import dwt.DWT;
18 import dwt.layout.GridData; 19 import dwt.layout.GridData;
19 import dwt.layout.GridLayout; 20 import dwt.layout.GridLayout;
20 import dwt.widgets.Button; 21 import dwt.widgets.Button;
37 38
38 this(Shell parent) { 39 this(Shell parent) {
39 this(parent, 0); 40 this(parent, 0);
40 } 41 }
41 42
42 void alertCheck(String title, String text, String check, /* final */ int[] checkValue) { 43 void alertCheck(String title, String text, String check, ref int checkValue) {
43 Shell parent = getParent(); 44 Shell parent = getParent();
44 /* final */ Shell shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL); 45 /* final */ Shell shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL);
45 if (title !is null) shell.setText(title); 46 if (title !is null) shell.setText(title);
46 GridLayout gridLayout = new GridLayout(); 47 GridLayout gridLayout = new GridLayout();
47 shell.setLayout(gridLayout); 48 shell.setLayout(gridLayout);
57 label.setLayoutData (data); 58 label.setLayoutData (data);
58 59
59 final Button checkButton = check !is null ? new Button(shell, DWT.CHECK) : null; 60 final Button checkButton = check !is null ? new Button(shell, DWT.CHECK) : null;
60 if (checkButton !is null) { 61 if (checkButton !is null) {
61 checkButton.setText(check); 62 checkButton.setText(check);
62 checkButton.setSelection(checkValue[0] !is 0); 63 checkButton.setSelection(checkValue !is 0);
63 data = new GridData (); 64 data = new GridData ();
64 data.horizontalAlignment = GridData.BEGINNING; 65 data.horizontalAlignment = GridData.BEGINNING;
65 checkButton.setLayoutData (data); 66 checkButton.setLayoutData (data);
66 } 67 }
67 Button okButton = new Button(shell, DWT.PUSH); 68 Button okButton = new Button(shell, DWT.PUSH);
68 okButton.setText(DWT.getMessage("SWT_OK")); //$NON-NLS-1$ 69 okButton.setText("OK"); // TODO: Need to do this through Resource Bundle
70 //okButton.setText(DWT.getMessage("SWT_OK")); //$NON-NLS-1$
69 data = new GridData (); 71 data = new GridData ();
70 data.horizontalAlignment = GridData.CENTER; 72 data.horizontalAlignment = GridData.CENTER;
71 okButton.setLayoutData (data); 73 okButton.setLayoutData (data);
72 okButton.addListener(DWT.Selection, new Listener() { 74 okButton.addListener(DWT.Selection, new Listener() {
73 public void handleEvent(Event event) { 75 public void handleEvent(Event event) {
74 if (checkButton !is null) checkValue[0] = checkButton.getSelection() ? 1 : 0; 76 if (checkButton !is null) checkValue = checkButton.getSelection() ? 1 : 0;
75 shell.close(); 77 shell.close();
76 } 78 }
77 }); 79 });
78 80
79 shell.pack(); 81 shell.pack();
82 while (!shell.isDisposed()) { 84 while (!shell.isDisposed()) {
83 if (!display.readAndDispatch()) display.sleep(); 85 if (!display.readAndDispatch()) display.sleep();
84 } 86 }
85 } 87 }
86 88
87 void confirmEx(String title, String text, String check, String button0, String button1, String button2, int defaultIndex, /* final */ int[] checkValue, /* final */ int[] result) { 89 void confirmEx(String title, String text, String check, String button0, String button1, String button2, int defaultIndex, ref int checkValue, ref int result) {
88 Shell parent = getParent(); 90 Shell parent = getParent();
89 /* final */ Shell shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL); 91 /* final */ Shell shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL);
90 shell.setText(title); 92 shell.setText(title);
91 GridLayout gridLayout = new GridLayout(); 93 GridLayout gridLayout = new GridLayout();
92 shell.setLayout(gridLayout); 94 shell.setLayout(gridLayout);
102 label.setLayoutData (data); 104 label.setLayoutData (data);
103 105
104 final Button[] buttons = new Button[4]; 106 final Button[] buttons = new Button[4];
105 Listener listener = new Listener() { 107 Listener listener = new Listener() {
106 public void handleEvent(Event event) { 108 public void handleEvent(Event event) {
107 if (buttons[0] !is null) checkValue[0] = buttons[0].getSelection() ? 1 : 0; 109 if (buttons[0] !is null) checkValue = buttons[0].getSelection() ? 1 : 0;
108 Widget widget = event.widget; 110 Widget widget = event.widget;
109 for (int i = 1; i < buttons.length; i++) { 111 for (int i = 1; i < buttons.length; i++) {
110 if (widget is buttons[i]) { 112 if (widget is buttons[i]) {
111 result[0] = i - 1; 113 result = i - 1;
112 break; 114 break;
113 } 115 }
114 } 116 }
115 shell.close(); 117 shell.close();
116 } 118 }
117 }; 119 };
118 if (check !is null) { 120 if (check !is null) {
119 buttons[0] = new Button(shell, DWT.CHECK); 121 buttons[0] = new Button(shell, DWT.CHECK);
120 buttons[0].setText(check); 122 buttons[0].setText(check);
121 buttons[0].setSelection(checkValue[0] !is 0); 123 buttons[0].setSelection(checkValue !is 0);
122 data = new GridData (); 124 data = new GridData ();
123 data.horizontalAlignment = GridData.BEGINNING; 125 data.horizontalAlignment = GridData.BEGINNING;
124 buttons[0].setLayoutData (data); 126 buttons[0].setLayoutData (data);
125 } 127 }
126 Composite composite = new Composite(shell, DWT.NONE); 128 Composite composite = new Composite(shell, DWT.NONE);
162 while (!shell.isDisposed()) { 164 while (!shell.isDisposed()) {
163 if (!display.readAndDispatch()) display.sleep(); 165 if (!display.readAndDispatch()) display.sleep();
164 } 166 }
165 } 167 }
166 168
167 void prompt(String title, String text, String check, /* final */ String[] value, /* final */ int[] checkValue, /* final */ int[] result) { 169 void prompt(String title, String text, String check, /* final */ref String value, /* final */ ref int checkValue, /* final */ref int result) {
168 Shell parent = getParent(); 170 Shell parent = getParent();
169 /* final */ Shell shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL); 171 /* final */ Shell shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL);
170 if (title !is null) shell.setText(title); 172 if (title !is null) shell.setText(title);
171 GridLayout gridLayout = new GridLayout(); 173 GridLayout gridLayout = new GridLayout();
172 shell.setLayout(gridLayout); 174 shell.setLayout(gridLayout);
180 data.horizontalAlignment = GridData.FILL; 182 data.horizontalAlignment = GridData.FILL;
181 data.grabExcessHorizontalSpace = true; 183 data.grabExcessHorizontalSpace = true;
182 label.setLayoutData (data); 184 label.setLayoutData (data);
183 185
184 final Text valueText = new Text(shell, DWT.BORDER); 186 final Text valueText = new Text(shell, DWT.BORDER);
185 if (value[0] !is null) valueText.setText(value[0]); 187 if (value !is null) valueText.setText(value);
186 data = new GridData(); 188 data = new GridData();
187 width = valueText.computeSize(DWT.DEFAULT, DWT.DEFAULT).x; 189 width = valueText.computeSize(DWT.DEFAULT, DWT.DEFAULT).x;
188 if (width > maxWidth) data.widthHint = maxWidth; 190 if (width > maxWidth) data.widthHint = maxWidth;
189 data.horizontalAlignment = GridData.FILL; 191 data.horizontalAlignment = GridData.FILL;
190 data.grabExcessHorizontalSpace = true; 192 data.grabExcessHorizontalSpace = true;
191 valueText.setLayoutData(data); 193 valueText.setLayoutData(data);
192 194
193 final Button[] buttons = new Button[3]; 195 final Button[] buttons = new Button[3];
194 Listener listener = new Listener() { 196 Listener listener = new Listener() {
195 public void handleEvent(Event event) { 197 public void handleEvent(Event event) {
196 if (buttons[0] !is null) checkValue[0] = buttons[0].getSelection() ? 1 : 0; 198 if (buttons[0] !is null) checkValue = buttons[0].getSelection() ? 1 : 0;
197 value[0] = valueText.getText(); 199 value = valueText.getText();
198 result[0] = event.widget is buttons[1] ? 1 : 0; 200 result = event.widget is buttons[1] ? 1 : 0;
199 shell.close(); 201 shell.close();
200 } 202 }
201 }; 203 };
202 if (check !is null) { 204 if (check !is null) {
203 buttons[0] = new Button(shell, DWT.CHECK); 205 buttons[0] = new Button(shell, DWT.CHECK);
204 buttons[0].setText(check); 206 buttons[0].setText(check);
205 buttons[0].setSelection(checkValue[0] !is 0); 207 buttons[0].setSelection(checkValue !is 0);
206 data = new GridData (); 208 data = new GridData ();
207 data.horizontalAlignment = GridData.BEGINNING; 209 data.horizontalAlignment = GridData.BEGINNING;
208 buttons[0].setLayoutData (data); 210 buttons[0].setLayoutData (data);
209 } 211 }
210 Composite composite = new Composite(shell, DWT.NONE); 212 Composite composite = new Composite(shell, DWT.NONE);
211 data = new GridData(); 213 data = new GridData();
212 data.horizontalAlignment = GridData.CENTER; 214 data.horizontalAlignment = GridData.CENTER;
213 composite.setLayoutData (data); 215 composite.setLayoutData (data);
214 composite.setLayout(new GridLayout(2, true)); 216 composite.setLayout(new GridLayout(2, true));
215 buttons[1] = new Button(composite, DWT.PUSH); 217 buttons[1] = new Button(composite, DWT.PUSH);
216 buttons[1].setText(DWT.getMessage("SWT_OK")); //$NON-NLS-1$ 218 //buttons[1].setText(DWT.getMessage("SWT_OK")); //$NON-NLS-1$
219 buttons[1].setText("OK");
217 buttons[1].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 220 buttons[1].setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
218 buttons[1].addListener(DWT.Selection, listener); 221 buttons[1].addListener(DWT.Selection, listener);
219 buttons[2] = new Button(composite, DWT.PUSH); 222 buttons[2] = new Button(composite, DWT.PUSH);
220 buttons[2].setText(DWT.getMessage("SWT_Cancel")); //$NON-NLS-1$ 223 //buttons[2].setText(DWT.getMessage("SWT_Cancel")); //$NON-NLS-1$
224 buttons[2].setText("Cancel");
221 buttons[2].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 225 buttons[2].setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
222 buttons[2].addListener(DWT.Selection, listener); 226 buttons[2].addListener(DWT.Selection, listener);
223 227
224 shell.pack(); 228 shell.pack();
225 shell.open(); 229 shell.open();
245 data.horizontalAlignment = GridData.FILL; 249 data.horizontalAlignment = GridData.FILL;
246 data.grabExcessHorizontalSpace = true; 250 data.grabExcessHorizontalSpace = true;
247 label.setLayoutData (data); 251 label.setLayoutData (data);
248 252
249 Label userLabel = new Label(shell, DWT.NONE); 253 Label userLabel = new Label(shell, DWT.NONE);
250 userLabel.setText(DWT.getMessage("SWT_Username")); //$NON-NLS-1$ 254 //userLabel.setText(DWT.getMessage("SWT_Username")); //$NON-NLS-1$
251 255 userLabel.setText("Username:");
252 final Text userText = new Text(shell, DWT.BORDER); 256 final Text userText = new Text(shell, DWT.BORDER);
253 if (user[0] !is null) userText.setText(user[0]); 257 if (user[0] !is null) userText.setText(user[0]);
254 data = new GridData(); 258 data = new GridData();
255 data.horizontalAlignment = GridData.FILL; 259 data.horizontalAlignment = GridData.FILL;
256 data.grabExcessHorizontalSpace = true; 260 data.grabExcessHorizontalSpace = true;
257 userText.setLayoutData(data); 261 userText.setLayoutData(data);
258 262
259 Label passwordLabel = new Label(shell, DWT.NONE); 263 Label passwordLabel = new Label(shell, DWT.NONE);
260 passwordLabel.setText(DWT.getMessage("SWT_Password")); //$NON-NLS-1$ 264 //passwordLabel.setText(DWT.getMessage("SWT_Password")); //$NON-NLS-1$
261 265 passwordLabel.setText("Password:");
262 final Text passwordText = new Text(shell, DWT.PASSWORD | DWT.BORDER); 266 final Text passwordText = new Text(shell, DWT.PASSWORD | DWT.BORDER);
263 if (pass[0] !is null) passwordText.setText(pass[0]); 267 if (pass[0] !is null) passwordText.setText(pass[0]);
264 data = new GridData(); 268 data = new GridData();
265 data.horizontalAlignment = GridData.FILL; 269 data.horizontalAlignment = GridData.FILL;
266 data.grabExcessHorizontalSpace = true; 270 data.grabExcessHorizontalSpace = true;
288 data = new GridData(); 292 data = new GridData();
289 data.horizontalAlignment = GridData.CENTER; 293 data.horizontalAlignment = GridData.CENTER;
290 composite.setLayoutData (data); 294 composite.setLayoutData (data);
291 composite.setLayout(new GridLayout(2, true)); 295 composite.setLayout(new GridLayout(2, true));
292 buttons[1] = new Button(composite, DWT.PUSH); 296 buttons[1] = new Button(composite, DWT.PUSH);
293 buttons[1].setText(DWT.getMessage("SWT_OK")); //$NON-NLS-1$ 297 //buttons[1].setText(DWT.getMessage("SWT_OK")); //$NON-NLS-1$
298 buttons[1].setText("OK");
294 buttons[1].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 299 buttons[1].setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
295 buttons[1].addListener(DWT.Selection, listener); 300 buttons[1].addListener(DWT.Selection, listener);
296 buttons[2] = new Button(composite, DWT.PUSH); 301 buttons[2] = new Button(composite, DWT.PUSH);
297 buttons[2].setText(DWT.getMessage("SWT_Cancel")); //$NON-NLS-1$ 302 //buttons[2].setText(DWT.getMessage("SWT_Cancel")); //$NON-NLS-1$
303 buttons[2].setText("Cancel");
298 buttons[2].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 304 buttons[2].setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
299 buttons[2].addListener(DWT.Selection, listener); 305 buttons[2].addListener(DWT.Selection, listener);
300 306
301 shell.setDefaultButton(buttons[1]); 307 shell.setDefaultButton(buttons[1]);
302 shell.pack(); 308 shell.pack();