Mercurial > projects > mde
diff mde/gui/content/options.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 |
line wrap: on
line diff
--- a/mde/gui/content/options.d Tue Oct 21 11:35:15 2008 +0100 +++ b/mde/gui/content/options.d Thu Oct 23 17:45:49 2008 +0100 @@ -25,36 +25,53 @@ import mde.lookup.Options; import mde.lookup.Translation; +debug { + import tango.util.log.Log : Log, Logger; + private Logger logger; + static this () { + logger = Log.getLogger ("mde.gui.content.options"); + } +} + class OptionList { - this (Options opts, char[] i18nOptionsName) - in { assert (opts !is null, "OptionList: invalid Options instance"); } - body { - Translation trans = Translation.load (i18nOptionsName); + this (char[] optsName) + { + auto p = optsName in Options.subClasses; + if (p is null) { + logger.error ("OptionList created with invalid options class name."); + return; // list is empty, nothing displayed + } + Options opts = *p; + + Translation trans = Translation.load ("L10n/"~optsName); + char[][] list = opts.list; - char[][] list = opts.list!(char[])(); + textOpts.length = list.length + opts.content.length; + size_t i; + foreach (s; list) { + Translation.Entry transled = trans.getStruct (s); + textOpts[i] = new OptionContent(opts, s, transled.name, transled.desc); + ++i; + } + foreach (s, v; opts.content) { + Translation.Entry transled = trans.getStruct (s); + v.name (transled.name, transled.desc); // set Content name & desc. Only needs doing once + textOpts[i++] = v; + } - textOpts.length = list.length; - foreach (i,s; list) { - Translation.Entry transled = trans.getStruct (s); - textOpts[i] = new ContentOptionText(opts, s, transled.name, transled.desc); - } } - ContentOption[] list () { + IContent[] list () { return textOpts; } - static OptionList trial () { - return new OptionList (miscOpts, "L10n/OptionsMisc"); - } - protected: - ContentOption[] textOpts; + IContent[] textOpts; } //FIXME - todo.txt -class ContentOptionText : ContentOption +class OptionContent : IContent { this (Options o, char[] s, char[] name, char[] desc) { opts = o; @@ -65,7 +82,7 @@ char[] toString (uint i) { if (i == 0) - return opts.get!(char[])(symb); + return "dummy"; //opts.get!(char[])(symb); else if (i == 1) return name_; else if (i == 2) @@ -77,22 +94,6 @@ void value (char[] v) { opts.set!(char[])(symb, v); }+/ -} - -abstract class ContentOption : IContent -{ - // Get the symbol name (useful?) - /+ - /// Get the translated name - char[] name () { - return name_; - } - - /// Get the description (translated) - char[] description () { - return desc_; - } - +/ protected: Options opts; // the set of options within which our option lies char[] symb; // the symbol name of our option