diff mde/gui/WidgetManager.d @ 137:9f035cd139c6

BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed. Content restrutured a lot: New IContent module, Content module includes more functionality. New ContentLoader module to manage content loading/saving/translation. Translation module moved to content dir and cut down to reflect current usage. File format unchanged except renames: FontOptions -> Font, VideoOptions -> Screen. Font render mode and LCD filter options are now enums. GUI loading needs to create content (and set type for enums), but doesn't save/load value. Some setup of mainSchedule moved to mde.mainLoop. Content callbacks are called on content change now. ContentLists are set up implicitly from content symbols. Not as fast but much easier! Bug-fix in the new MTTagReader. Renamed MT *Reader maker functions to avoid confusion in paths.d. New mde.setup.logger module to allow logger setup before any other module's static this().
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 07 Feb 2009 12:46:03 +0000
parents 7ababdf97748
children 3468e9bfded1
line wrap: on
line diff
--- a/mde/gui/WidgetManager.d	Sun Feb 01 12:36:21 2009 +0000
+++ b/mde/gui/WidgetManager.d	Sat Feb 07 12:46:03 2009 +0000
@@ -29,9 +29,7 @@
 import mde.gui.exception;
 
 import imde = mde.imde;
-import mde.lookup.Options;	// miscOpts.L10n callback
 import mde.content.Content;
-import Items = mde.content.Items;	// loadTranslation
 debug import mde.content.miscContent;	// Debug menu
 
 import mt = mde.file.mergetag.DataSet;
@@ -73,15 +71,16 @@
     protected this (char[] file) {
         mutex = new Mutex;  // Used on functions intended to be called from outside the gui package.
         fileName = file;
-        miscOpts.L10n.addCallback (&reloadStrings);
         
         clickCallbacks = new typeof(clickCallbacks);
         motionCallbacks = new typeof(motionCallbacks);
         
-        debug {
-            auto lWS = new EventContent ("logWidgetSize");
+        auto p = "MiscOptions.l10n" in Content.allContent;
+        assert (p, "MiscOptions.l10n not created!");
+        p.addCallback (&reloadStrings);
+        debug {	// add a debug-mode menu
+            auto lWS = new EventContent ("menus.debug."~file~".logWidgetSize");
             lWS.addCallback (&logWidgetSize);
-            imde.menus.append (new ContentList ("debug", [cast(Content)lWS]));
         }
     }
     
@@ -142,8 +141,6 @@
             logger.error (e.msg);
             throw new GuiException ("Failure parsing config file");
         }
-	
-        Items.loadTranslation ();
     }
     
     /** Load the gui from some design.
@@ -252,14 +249,18 @@
         }
     }
     
-    /** Called when translation strings have been reloaded. */
+    /** A change callback on MiscOptions.l10n content to update widgets.
+     *
+     * Relies on another callback reloading translations to content first! */
     protected void reloadStrings (Content) {
-	Items.loadTranslation;
-	child.setup (++setupN, 2);
-	child.setWidth  (w, -1);
-	child.setHeight (h, -1);
-	child.setPosition (0,0);
-	requestRedraw;
+        synchronized(mutex) {
+            if (child is null) return;
+            child.setup (++setupN, 2);
+            child.setWidth  (w, -1);
+            child.setHeight (h, -1);
+            child.setPosition (0,0);
+            requestRedraw;
+        }
     }
     
     // These methods are only intended for use within the gui package.
@@ -372,7 +373,7 @@
             logger.error ("Error creating widget: {}; creating a debug widget instead.", e.msg);
         }
     
-        return new DebugWidget (this, this, id, data);
+        return new DebugWidget (this, this, id, data, content);
     }
     
     override WidgetData widgetData (widgetID id) {
@@ -483,7 +484,7 @@
     // blank: 0x1
     FixedBlank		= 0x1,
     SizableBlank	= 0x2,
-    Debug		= 0xF,
+    Debug		= TAKES_CONTENT | 0xF,
     
     // popup widgets: 0x10
     PopupMenu		= TAKES_CONTENT | 0x11,
@@ -514,9 +515,9 @@
 const char[][] WIDGETS = [
         "FixedBlank",
         "SizableBlank",
-        "Debug",
 	"TextLabel",
 	"addContent",
+        "Debug",
 	"PopupMenu",
 	"ContentLabel",
         "DisplayContent",