comparison mde/content/Content.d @ 112:fe061009029d

EnumContent; log level can be selected from a popup list. New EnumContent, with code to load translations in Items. Editable as an AStringContent. Hacked OptionsMisc to use an EnumContent. Implemented a EnumContentWidget providing a pop-up list to select from (still needs improving). Moved IContent to its own module. ContentExceptions thrown via WDCCheck now. Fixed a small bug with reloading translations.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 13 Dec 2008 12:54:43 +0000
parents 6acd96f8685f
children 1b1e2297e2fc
comparison
equal deleted inserted replaced
111:1655693702fc 112:fe061009029d
11 See the GNU General Public License for more details. 11 See the GNU General Public License for more details.
12 12
13 You should have received a copy of the GNU General Public License 13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
15 15
16 /** The content system − common interface and a few classes without external dependencies. 16 /*************************************************************************************************
17 */ 17 * The content system − a few content classes.
18 *************************************************************************************************/
18 module mde.content.Content; 19 module mde.content.Content;
19 20
21 public import mde.content.IContent;
20 import util = mde.util; 22 import util = mde.util;
21 23
22 debug { 24 debug {
23 import tango.util.log.Log : Log, Logger; 25 import tango.util.log.Log : Log, Logger;
24 private Logger logger; 26 private Logger logger;
25 static this () { 27 static this () {
26 logger = Log.getLogger ("mde.content.Content"); 28 logger = Log.getLogger ("mde.content.Content");
27 } 29 }
28 }
29
30 /** IContent − interface for all Content classes.
31 *
32 * Services like copy/paste could work on universal content. However, they would need to run a
33 * conversion to the appropriate type (or try next-oldest item on clipboard?). */
34 interface IContent
35 {
36 /** Generically return strings.
37 *
38 * This serves two purposes: generically returning a string of/related to the content (i == 0),
39 * and returning associated descriptors. Functions should adhere to (or add to) this table.
40 *
41 * $(TABLE
42 * $(TR $(TH i) $(TH returns))
43 * $(TR $(TD 0) $(TD value))
44 * $(TR $(TD 1) $(TD Translated name or null))
45 * $(TR $(TD 2) $(TD Translated description or null))
46 * $(TR $(TD other) $(TD null))
47 * ) */
48 char[] toString (uint i);
49 } 30 }
50 31
51 /** The base for $(I most) content classes. 32 /** The base for $(I most) content classes.
52 * 33 *
53 * Includes generic callback support, toString implementation and symbol access. 34 * Includes generic callback support, toString implementation and symbol access.
61 * --- */ 42 * --- */
62 class AContent : IContent 43 class AContent : IContent
63 { 44 {
64 this (char[] symbol) { 45 this (char[] symbol) {
65 this.symbol = symbol; 46 this.symbol = symbol;
47 name_ = symbol; // provide a temporary name
66 } 48 }
67 49
68 void name (char[] n, char[] d = null) { 50 void name (char[] name, char[] desc = null) {
69 name_ = n; 51 name_ = name;
70 desc_ = d; 52 desc_ = desc;
71 } 53 }
72 54
73 /** Add a callback. Callbacks are called in the order added. */ 55 /** Add a callback. Callbacks are called in the order added. */
74 EventContent addCallback (void delegate (AContent) cb) { 56 EventContent addCallback (void delegate (AContent) cb) {
75 this.cb ~= cb; 57 this.cb ~= cb;
127 109
128 /** Created on errors to display and log a message. */ 110 /** Created on errors to display and log a message. */
129 class ErrorContent : IContent 111 class ErrorContent : IContent
130 { 112 {
131 this (char[] msg) { 113 this (char[] msg) {
132 msg_ = msg; 114 this.msg = msg;
133 } 115 }
134 116
135 char[] toString (uint i) { 117 char[] toString (uint i) {
136 return i == 0 ? msg_ 118 return i == 0 ? msg
137 : i == 1 ? "Error" 119 : i == 1 ? "Error"
138 : null; 120 : null;
139 } 121 }
140 122
141 protected: 123 protected:
142 char[] msg_; 124 char[] msg;
143 } 125 }
144 126
145 /** A Content with no value but able to pass on an event. 127 /** A Content with no value but able to pass on an event.
146 * 128 *
147 * The point being that a button can be tied to one of these. */ 129 * The point being that a button can be tied to one of these. */