comparison snippets/text/Snippet258.d @ 78:4a04b6759f98

Clean up directory names
author John Reimer <terminal.node@gmail.com>
date Sat, 10 May 2008 13:32:45 -0700
parents
children 1f0a7a472680
comparison
equal deleted inserted replaced
76:04f122e90b0a 78:4a04b6759f98
1 /*******************************************************************************
2 * Copyright (c) 2007 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Jesse Phillips <Jesse.K.Phillips+D> gmail.com
12 *******************************************************************************/
13
14 module snippets.text.Snippet258;
15
16 /*
17 * Create a search text control
18 *
19 * For a list of all SWT example snippets see
20 * http://www.eclipse.org/swt/snippets/
21 *
22 * @since 3.3
23 */
24 import dwt.DWT;
25 import dwt.dwthelper.ByteArrayInputStream;
26 import dwt.events.SelectionAdapter;
27 import dwt.events.SelectionEvent;
28 import dwt.graphics.Image;
29 import dwt.graphics.ImageData;
30 import dwt.layout.GridLayout;
31 import dwt.layout.GridData;
32 import dwt.widgets.Display;
33 import dwt.widgets.Shell;
34 import dwt.widgets.Text;
35 import dwt.widgets.ToolBar;
36 import dwt.widgets.ToolItem;
37
38 import tango.io.Stdout;
39
40 void main() {
41 auto display = new Display();
42 auto shell = new Shell(display);
43 shell.setLayout(new GridLayout(2, false));
44
45 auto text = new Text(shell, DWT.SEARCH | DWT.CANCEL);
46 Image image = null;
47 if ((text.getStyle() & DWT.CANCEL) == 0) {
48 image = new Image (display, new ImageData(new ByteArrayInputStream( cast(byte[]) import("cancel.gif" ))));
49 auto toolBar = new ToolBar (shell, DWT.FLAT);
50 auto item = new ToolItem (toolBar, DWT.PUSH);
51 item.setImage (image);
52 item.addSelectionListener(new class SelectionAdapter {
53 public void widgetSelected(SelectionEvent e) {
54 text.setText("");
55 Stdout("Search cancelled").newline;
56 }
57 });
58 }
59 text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
60 text.setText("Search text");
61 text.addSelectionListener(new class SelectionAdapter {
62 public void widgetDefaultSelected(SelectionEvent e) {
63 if (e.detail == DWT.CANCEL) {
64 Stdout("Search cancelled").newline;
65 } else {
66 Stdout("Searching for: ")(text.getText())("...").newline;
67 }
68 }
69 });
70
71 shell.pack();
72 shell.open();
73 while (!shell.isDisposed()) {
74 if (!display.readAndDispatch()) display.sleep();
75 }
76 if (image !is null) image.dispose();
77 display.dispose();
78 }