Mercurial > projects > mde
comparison mde/gui/content/Content.d @ 94:9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
This should facilitate generic option editing widgets.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 23 Oct 2008 17:45:49 +0100 |
parents | 4d5d53e4f881 |
children | 2a364c7d82c9 |
comparison
equal
deleted
inserted
replaced
93:08a4ae11454b | 94:9520cc0448e5 |
---|---|
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 − type agnostic part. | 16 /** The content system − common types. |
17 */ | 17 */ |
18 module mde.gui.content.Content; | 18 module mde.gui.content.Content; |
19 | 19 |
20 import Int = tango.text.convert.Integer; | 20 import Int = tango.text.convert.Integer; |
21 | 21 |
22 /** Content − universal part. | 22 debug { |
23 import tango.util.log.Log : Log, Logger; | |
24 private Logger logger; | |
25 static this () { | |
26 logger = Log.getLogger ("mde.gui.content.Content"); | |
27 } | |
28 } | |
29 | |
30 /** IContent − interface for all Content classes. | |
23 * | 31 * |
24 * Services like copy/paste could work on universal content. However, they would need to run a | 32 * Services like copy/paste could work on universal content. However, they would need to run a |
25 * conversion to the appropriate type (or try next-oldest item on clipboard?). | 33 * conversion to the appropriate type (or try next-oldest item on clipboard?). |
26 * | 34 * |
27 * Currently Content instances can only have their data set on creation. | 35 * Currently Content instances can only have their data set on creation. |
53 | 61 |
54 | 62 |
55 | 63 |
56 /** Generically return strings. | 64 /** Generically return strings. |
57 * | 65 * |
58 * Every Content should return a string for i == 0; preferably its value. Other values of i | 66 * This serves two purposes: generically returning a string of/related to the content (i == 0), |
59 * can be used to return other strings. For unsupported values of i, null should be returned. | 67 * and returning associated descriptors. Functions should adhere to (or add to) this table. |
60 */ | 68 * |
69 * $(TABLE | |
70 * $(TR $(TH i) $(TH returns)) | |
71 * $(TR $(TD 0) $(TD value)) | |
72 * $(TR $(TD 1) $(TD Translated name or null)) | |
73 * $(TR $(TD 2) $(TD Translated description or null)) | |
74 * $(TR $(TD other) $(TD null)) | |
75 * ) */ | |
61 char[] toString (uint i); | 76 char[] toString (uint i); |
62 } | 77 } |
63 /+ | 78 |
64 /** Extension to interface providing text-specific tools. */ | 79 /** Base class for content containing a simple value. |
65 interface IContentText : IContent | 80 * |
81 * All derived classes should support functions to set/get any ValueContent type, but return the | |
82 * default value of any type other than it's own. */ | |
83 abstract class ValueContent : IContent | |
66 { | 84 { |
67 char[] text (); /// Get/set the value. | 85 protected this () {} |
68 void text (char[] v); /// ditto | 86 |
69 } | 87 void name (char[] n, char[] d = null) { |
70 +/ | 88 name_ = n; |
71 /+ FIXME - use content lists or drop? | 89 desc_ = d; |
72 /** Get a content from the list (what list?). */ | 90 } |
73 ContentText getContentText (char[] id) { | 91 protected: |
74 return new ContentText (id); // forget the list for now | 92 char[] name_, desc_;// name and description, loaded by lookup.Translation |
75 } | 93 } |
76 | 94 |
77 /** ditto */ | 95 class BoolContent : ValueContent |
78 ContentInt getContentInt (char[] id) { | |
79 return new ContentInt (42); // forget the list for now | |
80 } | |
81 +/ | |
82 | |
83 /+FIXME - currently unused | |
84 /** Text content. */ | |
85 /* May end up extending a universal content type. | |
86 * Services like copy/paste could work on universal content. | |
87 * | |
88 * NOTE: Needs to be a reference type really. | |
89 * Could alternately be: | |
90 * alias ContentTextStruct* ContentText | |
91 * where ContentTextStruct is a struct. */ | |
92 class ContentText : IContent | |
93 { | 96 { |
94 this () {} | 97 this () {} |
95 this (char[] text) { | 98 this (bool val) { |
96 text_ = text; | 99 v = val; |
97 } | 100 } |
98 | 101 |
102 /// Get the text. | |
103 char[] toString (uint i) { | |
104 debug logger.trace ("BoolContent.toString"); | |
105 return (i == 0) ? v ? "true" : "false" | |
106 : (i == 1) ? name_ | |
107 : (i == 2) ? desc_ | |
108 : null; | |
109 } | |
110 | |
111 void opAssign (bool val) { | |
112 v = val; | |
113 } | |
114 bool opCall () { | |
115 return v; | |
116 } | |
117 | |
118 protected bool v; | |
119 } | |
120 | |
121 /** Text content. */ | |
122 class TextContent : ValueContent | |
123 { | |
124 this () {} | |
125 this (char[] text, char[] name = null) { | |
126 text_ = text; | |
127 name_ = name; | |
128 } | |
129 /+ | |
99 ContentText dup () { | 130 ContentText dup () { |
100 return new ContentText (text_); | 131 return new ContentText (text_); |
101 } | 132 } |
102 | 133 |
103 ContentText toText () { | 134 ContentText toText () { |
105 } | 136 } |
106 ContentInt toInt () { | 137 ContentInt toInt () { |
107 // FIXME: convert | 138 // FIXME: convert |
108 return null; | 139 return null; |
109 } | 140 } |
110 | 141 +/ |
111 alias toString text; | |
112 | 142 |
113 /// Get the text. | 143 /// Get the text. |
114 char[] toString () { | 144 char[] toString (uint i) { |
115 return text_; | 145 debug logger.trace ("TextContent.toString"); |
146 return (i == 0) ? text_ | |
147 : (i == 1) ? name_ | |
148 : (i == 2) ? desc_ | |
149 : null; | |
116 } | 150 } |
117 | 151 |
118 protected: | 152 protected: |
119 //NOTE: need to allow cache-invalidating when text changes! | |
120 char[] text_; | 153 char[] text_; |
121 } | 154 } |
122 | 155 /+ |
123 /** Integer content. */ | 156 /** Integer content. */ |
124 class ContentInt : IContent | 157 class ContentInt : IContent |
125 { | 158 { |
126 this () {} | 159 this () {} |
127 this (int integer) { | 160 this (int integer) { |