diff mde/gui/content/Items.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
line wrap: on
line diff
--- a/mde/gui/content/Items.d	Tue Nov 25 18:01:44 2008 +0000
+++ b/mde/gui/content/Items.d	Wed Nov 26 13:07:46 2008 +0000
@@ -24,6 +24,14 @@
 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.Items");
+    }
+}
+
     /** Get a specific content item.
      *
      * E.g. get ("Options.MiscOptions.L10n") returns miscOpts.L10n,
@@ -37,20 +45,24 @@
     
     /** Same as calling get("Options."~item). */
     IContent getOptions (char[] item) {
+	if (item is null) {
+	    IContent[] list;
+	    list.length = Options.optionsClasses.length;
+	    size_t i;
+	    foreach (n,opts; Options.optionsClasses) {
+		if (opts.name is null) loadTransl (opts, n);
+		list[i++] = new ContentList (opts.content, opts.name, opts.desc);
+	    }
+		
+	    return new ContentList (list, "Options");
+	}
 	char[] h = head (item);
 	auto p = h in Options.optionsClasses;
 	if (p) {
-	    if (!p.transLoaded) {
-		Translation trans = Translation.load ("L10n/"~h);
-		foreach (s, v; p.content) {
-		    Translation.Entry transled = trans.getStruct (s);
-		    v.name (transled.name, transled.desc);
-		}
-		p.transLoaded = true;
-	    }
+	    if (p.name is null) loadTransl (*p, h);
 	    
 	    if (item == null)
-		return new ContentList (p.content);
+		return new ContentList (p.content, p.name, p.desc);
 	    
 	    auto q = (h = head (item)) in p.content;
 	    if (q && item is null)	// enforce item is an exact match
@@ -73,3 +85,15 @@
 	    str = str[i+1..$];
 	return ret;
     }
+    
+    void loadTransl (Options p, char[] n) {
+	debug logger.trace ("Loading translation strings for Options."~n);
+	Translation trans = Translation.load ("L10n/"~n);
+	Translation.Entry transled = trans.getStruct (n);
+	p.name = transled.name;
+	p.desc = transled.desc;
+	foreach (s, v; p.content) {
+	    transled = trans.getStruct (s);
+	    v.name (transled.name, transled.desc);
+	}
+    }