Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet258.d @ 112:9f4c18c268b2
Update to compile and execute with dmd 2.052.
author | kntroh |
---|---|
date | Wed, 16 Mar 2011 21:53:53 +0900 |
parents | 4e5843b771cc |
children |
rev | line source |
---|---|
28 | 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 org.eclipse.swt.snippets.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 org.eclipse.swt.SWT; | |
25 import java.io.ByteArrayInputStream; | |
26 import org.eclipse.swt.events.SelectionAdapter; | |
27 import org.eclipse.swt.events.SelectionEvent; | |
28 import org.eclipse.swt.graphics.Image; | |
29 import org.eclipse.swt.graphics.ImageData; | |
30 import org.eclipse.swt.layout.GridLayout; | |
31 import org.eclipse.swt.layout.GridData; | |
32 import org.eclipse.swt.widgets.Display; | |
33 import org.eclipse.swt.widgets.Shell; | |
34 import org.eclipse.swt.widgets.Text; | |
35 import org.eclipse.swt.widgets.ToolBar; | |
36 import org.eclipse.swt.widgets.ToolItem; | |
37 | |
112 | 38 version(Tango){ |
39 import tango.io.Stdout; | |
40 } else { // Phobos | |
41 import std.stdio; | |
42 } | |
28 | 43 |
44 void main() { | |
45 auto display = new Display(); | |
46 auto shell = new Shell(display); | |
47 shell.setLayout(new GridLayout(2, false)); | |
48 | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
49 auto text = new Text(shell, SWT.SEARCH | SWT.CANCEL); |
28 | 50 Image image = null; |
51 if ((text.getStyle() & SWT.CANCEL) == 0) { | |
52 image = new Image (display, new ImageData(new ByteArrayInputStream( cast(byte[]) import("links_obj.gif" )))); | |
53 auto toolBar = new ToolBar (shell, SWT.FLAT); | |
54 auto item = new ToolItem (toolBar, SWT.PUSH); | |
55 item.setImage (image); | |
56 item.addSelectionListener(new class SelectionAdapter { | |
57 public void widgetSelected(SelectionEvent e) { | |
58 text.setText(""); | |
112 | 59 version(Tango){ |
60 Stdout("Search cancelled").newline; | |
61 } else { // Phobos | |
62 writeln("Search cancelled"); | |
63 } | |
28 | 64 } |
65 }); | |
66 } | |
67 text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | |
68 text.setText("Search text"); | |
69 text.addSelectionListener(new class SelectionAdapter { | |
70 public void widgetDefaultSelected(SelectionEvent e) { | |
112 | 71 version(Tango){ |
72 if (e.detail == SWT.CANCEL) { | |
73 Stdout("Search cancelled").newline; | |
74 } else { | |
75 Stdout("Searching for: ")(text.getText())("...").newline; | |
76 } | |
77 } else { // Phobos | |
78 if (e.detail == SWT.CANCEL) { | |
79 writeln("Search cancelled"); | |
80 } else { | |
81 writeln("Searching for: " ~ text.getText() ~ "..."); | |
82 } | |
28 | 83 } |
84 } | |
85 }); | |
86 | |
87 shell.pack(); | |
88 shell.open(); | |
89 while (!shell.isDisposed()) { | |
90 if (!display.readAndDispatch()) display.sleep(); | |
91 } | |
92 if (image !is null) image.dispose(); | |
93 display.dispose(); | |
94 } |