Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet97.d @ 125:c43718956f21 default tip
Updated the snippets status.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Thu, 11 Aug 2011 19:55:14 +0200 |
parents | 9f4c18c268b2 |
children |
rev | line source |
---|---|
28 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2004 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 * D Port: | |
11 * Jesse Phillips <Jesse.K.Phillips+D> gmail.com | |
12 *******************************************************************************/ | |
13 module org.eclipse.swt.snippets.Snippet97; | |
14 | |
15 /* | |
16 * Menu example snippet: fill a menu dynamically (when menu shown) | |
17 * Select items then right click to show menu. | |
18 * | |
19 * For a list of all SWT example snippets see | |
20 * http://www.eclipse.org/swt/snippets/ | |
21 */ | |
22 import org.eclipse.swt.SWT; | |
23 import org.eclipse.swt.widgets.Display; | |
24 import org.eclipse.swt.widgets.Event; | |
25 import org.eclipse.swt.widgets.Listener; | |
26 import org.eclipse.swt.widgets.Menu; | |
27 import org.eclipse.swt.widgets.MenuItem; | |
28 import org.eclipse.swt.widgets.Shell; | |
29 import org.eclipse.swt.widgets.Tree; | |
30 import org.eclipse.swt.widgets.TreeItem; | |
112 | 31 import java.lang.all; |
28 | 32 |
112 | 33 version(Tango){ |
34 import tango.util.Convert; | |
35 } else { // Phobos | |
36 import std.conv; | |
37 } | |
28 | 38 |
39 void main () { | |
40 auto display = new Display (); | |
41 auto shell = new Shell (display); | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
42 auto tree = new Tree (shell, SWT.BORDER | SWT.MULTI); |
28 | 43 auto menu = new Menu (shell, SWT.POP_UP); |
44 tree.setMenu (menu); | |
45 for (int i=0; i<12; i++) { | |
46 auto item = new TreeItem (tree, SWT.NONE); | |
112 | 47 item.setText ("Item " ~ to!(String)(i)); |
28 | 48 } |
49 menu.addListener (SWT.Show, new class Listener { | |
50 public void handleEvent (Event event) { | |
51 auto menuItems = menu.getItems (); | |
52 foreach (item; menuItems) { | |
53 item.dispose (); | |
54 } | |
55 auto treeItems = tree.getSelection (); | |
56 foreach (item; treeItems) { | |
57 auto menuItem = new MenuItem (menu, SWT.PUSH); | |
58 menuItem.setText (item.getText ()); | |
59 } | |
60 } | |
61 }); | |
62 tree.setSize (200, 200); | |
63 shell.setSize (300, 300); | |
64 shell.open (); | |
65 while (!shell.isDisposed ()) { | |
66 if (!display.readAndDispatch ()) display.sleep (); | |
67 } | |
68 display.dispose (); | |
69 } |