comparison mde/gui/content/Content.d @ 104:ee209602770d

Cleaned up Options.d removing old storage method. It's now possible to get a ContentList of the whole of Options. Tweaked translation strings (added name and desc to Options classes). Replaced Options.addSubClass (class, "name") with Options.this("name").
author Diggory Hardy <diggory.hardy@gmail.com>
date Wed, 26 Nov 2008 13:07:46 +0000
parents 42e241e7be3e
children
comparison
equal deleted inserted replaced
103:42e241e7be3e 104:ee209602770d
63 } 63 }
64 64
65 /** A generic way to handle a list of type IContent. */ 65 /** A generic way to handle a list of type IContent. */
66 class ContentList : IContent 66 class ContentList : IContent
67 { 67 {
68 this (IContent[] list = null) { 68 this (IContent[] list = null, char[] n = null, char[] d = null) {
69 list_ = list; 69 list_ = list;
70 } 70 name_ = n;
71 this (ValueContent[char[]] l) { 71 desc_ = d;
72 }
73 this (ValueContent[char[]] l, char[] n = null, char[] d = null) {
72 list_.length = l.length; 74 list_.length = l.length;
73 size_t i; 75 size_t i;
74 foreach (c; l) 76 foreach (c; l)
75 list_[i++] = c; 77 list_[i++] = c;
78 name_ = n;
79 desc_ = d;
76 } 80 }
77 81
78 char[] toString (uint i) { 82 char[] toString (uint i) {
79 return i == 0 ? Int.toString (list_.length) ~ " elements" 83 return i == 0 ? Int.toString (list_.length) ~ " elements"
80 : i == 1 ? "ContentList" 84 : i == 1 ? name_
81 : null; 85 : i == 2 ? desc_
86 : null;
82 } 87 }
83 88
84 IContent[] list () { 89 IContent[] list () {
85 return list_; 90 return list_;
86 } 91 }
89 return this; 94 return this;
90 } 95 }
91 96
92 protected: 97 protected:
93 IContent[] list_; 98 IContent[] list_;
99 char[] name_, desc_; // name and description
94 } 100 }
95 101
96 /** Created on errors to display and log a message. */ 102 /** Created on errors to display and log a message. */
97 class ErrorContent : IContent 103 class ErrorContent : IContent
98 { 104 {
133 desc_ = d; 139 desc_ = d;
134 } 140 }
135 141
136 /// Get the text. 142 /// Get the text.
137 char[] toString (uint i) { 143 char[] toString (uint i) {
138 return (i == 0) ? sv 144 return i == 0 ? sv
139 : (i == 1) ? name_ 145 : i == 1 ? name_
140 : (i == 2) ? desc_ 146 : i == 2 ? desc_
141 : null; 147 : null;
142 } 148 }
143 149
144 /** Acts on a keystroke and returns the new value. 150 /** Acts on a keystroke and returns the new value.
145 * 151 *
199 void endEdit (); 205 void endEdit ();
200 protected: 206 protected:
201 char[] sv; // string of value; updated on assignment for displaying and editing 207 char[] sv; // string of value; updated on assignment for displaying and editing
202 size_t pos; // editing position; used by keyStroke 208 size_t pos; // editing position; used by keyStroke
203 char[] symb; 209 char[] symb;
204 char[] name_, desc_;// name and description, loaded by lookup.Translation 210 char[] name_, desc_;// name and description
205 } 211 }
206 212
207 template VContentN(T) { 213 template VContentN(T) {
208 static if (is(T == bool)) { 214 static if (is(T == bool)) {
209 const char[] VContentN = "BoolContent"; 215 const char[] VContentN = "BoolContent";