comparison dynamin/gui/action.d @ 0:aa4efef0f0b1

Initial commit of code.
author Jordan Miner <jminer7@gmail.com>
date Mon, 15 Jun 2009 22:10:48 -0500
parents
children 73060bc3f004
comparison
equal deleted inserted replaced
-1:000000000000 0:aa4efef0f0b1
1 // Written in the D programming language
2 // www.digitalmars.com/d/
3
4 /*
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Dynamin library.
16 *
17 * The Initial Developer of the Original Code is Jordan Miner.
18 * Portions created by the Initial Developer are Copyright (C) 2008
19 * the Initial Developer. All Rights Reserved.
20 *
21 * Contributor(s):
22 * Jordan Miner <jminer7@gmail.com>
23 *
24 */
25
26 module dynamin.gui.action;
27
28 import dynamin.all_core;
29 import dynamin.all_gui;
30 import tango.util.collection.HashMap;
31
32 /**
33 * TODO: change to struct with D 2.0 and use ref return on ActionMap.addAction
34 * might not be possible...probably have to keep class
35 */
36 class Action {
37 /// The non-visible name of the action
38 string name; // no setter for this ...set with constructor
39 /// The text displayed on the menu item, tool bar button, etc.
40 string text;
41 ///
42 string shortcut; // TODO: how to store string and key/modifiers?
43 /**
44 * The icon displayed on the menu item, tool bar button, etc.
45 * Icons for disabled and hot controls are created automatically
46 * using the current theme.
47 */
48 string icon; // TODO: allow setting hot and disabled icons to override
49 ///
50 void delegate() invoke;
51 /**
52 * If toggle is true, then this action can be selected and deselected.
53 */
54 bool toggle = false;
55 /**
56 * Has no effect unless toggle is set to true.
57 * If the group is the default, the action can be selected/deselected
58 * regardless of other actions. If the group is set to another value, then
59 * selecting this action will deselect other actions with the same group.
60 */
61 // TODO: the deselecting of other actions w/same group should look through
62 // the ActionMap...will need ref
63 int group = -1; // TODO: a string is a lot easier to avoid conflicts
64 ///
65 bool selected = false;
66 ///
67 bool enabled;
68 // TODO: need to make getters and setters...have to fire event when changed
69 }
70
71 /**
72 * Example:
73 * -----
74 * with(actionMap.addAction("data-viewer")) {
75 * text = "Data Viewer";
76 * shortcut = "Ctrl+D";
77 * icon = "data-viewer.png";
78 * toggle = true;
79 * group = 2;
80 * invoke = {
81 * new DataViewerDialog().show();
82 * };
83 * }
84 * -----
85 */
86 class ActionMap : HashMap!(string, Action) {
87 Action addAction(string name) {
88 assert(!name.contains(' '), "action name cannot contain space");
89 Action a = new Action(name);
90 add(name, a);
91 }
92 }
93
94 unittest {
95 //
96 }
97