78
|
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 snippets.menu.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 dwt.DWT;
|
|
23 import dwt.widgets.Display;
|
|
24 import dwt.widgets.Event;
|
|
25 import dwt.widgets.Listener;
|
|
26 import dwt.widgets.Menu;
|
|
27 import dwt.widgets.MenuItem;
|
|
28 import dwt.widgets.Shell;
|
|
29 import dwt.widgets.Tree;
|
|
30 import dwt.widgets.TreeItem;
|
|
31
|
|
32 import tango.util.Convert;
|
|
33
|
|
34 void main () {
|
|
35 auto display = new Display ();
|
|
36 auto shell = new Shell (display);
|
|
37 auto tree = new Tree (shell, DWT.BORDER | DWT.MULTI);
|
|
38 auto menu = new Menu (shell, DWT.POP_UP);
|
|
39 tree.setMenu (menu);
|
|
40 for (int i=0; i<12; i++) {
|
|
41 auto item = new TreeItem (tree, DWT.NONE);
|
|
42 item.setText ("Item " ~ to!(char[])(i));
|
|
43 }
|
|
44 menu.addListener (DWT.Show, new class Listener {
|
|
45 public void handleEvent (Event event) {
|
|
46 auto menuItems = menu.getItems ();
|
|
47 foreach (item; menuItems) {
|
|
48 item.dispose ();
|
|
49 }
|
|
50 auto treeItems = tree.getSelection ();
|
|
51 foreach (item; treeItems) {
|
|
52 auto menuItem = new MenuItem (menu, DWT.PUSH);
|
|
53 menuItem.setText (item.getText ());
|
|
54 }
|
|
55 }
|
|
56 });
|
|
57 tree.setSize (200, 200);
|
|
58 shell.setSize (300, 300);
|
|
59 shell.open ();
|
|
60 while (!shell.isDisposed ()) {
|
|
61 if (!display.readAndDispatch ()) display.sleep ();
|
|
62 }
|
|
63 display.dispose ();
|
|
64 }
|