changeset 78:79a1809421aa

Widget data saving reimplemented for the new data system. (Now grid layout widgets remember their row & column sizes.)
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 29 Jul 2008 18:14:53 +0100
parents 3dfd934100f7
children 61ea26abe4dd
files data/conf/gui.mtt mde/gui/WidgetData.d mde/gui/widget/Ifaces.d mde/gui/widget/Widget.d mde/gui/widget/layout.d mde/setup/paths.d
diffstat 6 files changed, 33 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/data/conf/gui.mtt	Tue Jul 29 17:11:22 2008 +0100
+++ b/data/conf/gui.mtt	Tue Jul 29 18:14:53 2008 +0100
@@ -4,7 +4,7 @@
 {Working}
 <WidgetData|root=[0xB004,3,3],["square","blank","square","blank","content","blank","square","blank","square"]>
 <WidgetData|square=[0x1,6,6],[]>
-<WidgetData|content=[0xB004,3,2],["blank","button","blank","blank","blank","opts"]>
+<WidgetData|content=[0xB004,4,2],["blank","button","blank","blank","blank","opts","blank","blank"]>
 <WidgetData|button=[0x4010,200,200],[]>
 <WidgetData|blank=[0x3001],[]>
 <WidgetData|opts=[0xB005, 0xfe8c00],[]>
--- a/mde/gui/WidgetData.d	Tue Jul 29 17:11:22 2008 +0100
+++ b/mde/gui/WidgetData.d	Tue Jul 29 18:14:53 2008 +0100
@@ -179,7 +179,8 @@
         mutex.lock;
         scope(exit) mutex.unlock;
         
-        if (noChanges)
+        // Make all widgets save any changed data; return if no changes:
+        if (!child.saveChanges ("root"))
             return;
         
         if (loadUserFile) { // merge entries from user file into current changes
@@ -234,7 +235,6 @@
     
     /** For making changes. */
     void setData (widgetID id, WidgetData d) {
-        noChanges = false;
         changes[id] = d;        // also updates WidgetDataSet in data.
     }
     
@@ -264,7 +264,6 @@
     WidgetDataChanges changes;  // Changes for the current design.
     scope mt.DataSet changesDS; // changes and sections from user file (used for saving)
     bool loadUserFile = true;   // still need to load user file for saving?
-    bool noChanges = true;      // do we have any changes to save?
     
     scope IChildWidget child;   // The primary widget.
     
--- a/mde/gui/widget/Ifaces.d	Tue Jul 29 17:11:22 2008 +0100
+++ b/mde/gui/widget/Ifaces.d	Tue Jul 29 18:14:53 2008 +0100
@@ -174,6 +174,14 @@
 interface IChildWidget : IWidget
 {
 //BEGIN Load and save
+    /** When this is called, if the widget has any changed data to save it should call
+     * IWidgetManager.setData (id, data) to set it and return true. Otherwise it should return
+     * false.
+     * 
+     * If the widget has subwidgets, it should also be recursively called on these (passing their 
+     * ids). */
+    bool saveChanges (widgetID id);
+    
     /** Called when the renderer is changed (at least when the changes affect dimensions).
      * Also called after widget creation, before any other methods are called.
      * 
--- a/mde/gui/widget/Widget.d	Tue Jul 29 17:11:22 2008 +0100
+++ b/mde/gui/widget/Widget.d	Tue Jul 29 18:14:53 2008 +0100
@@ -58,6 +58,11 @@
         this.mgr = mgr;
     }
     
+    // Don't save any data: fine for many widgets.
+    bool saveChanges (widgetID) {
+        return false;
+    }
+    
     // Very basic implementation which assumes the renderer cannot affect the widget's size.
     bool rendererChanged () {
         return false;
--- a/mde/gui/widget/layout.d	Tue Jul 29 17:11:22 2008 +0100
+++ b/mde/gui/widget/layout.d	Tue Jul 29 18:14:53 2008 +0100
@@ -61,6 +61,7 @@
             (data.ints.length != 3 && data.ints.length != 3 + rows + cols) ||
             data.strings.length != rows * cols)
             throw new WidgetDataException;
+        this.data = data;
         
         // Get all sub-widgets
         subWidgets.length = rows*cols;
@@ -79,19 +80,20 @@
         }
         adjustCache;
     }
-    /+FIXME
-    /** Return construction data to recreate this GridLayoutWidget. */
-    int[] getCreationData () {
-        int[] ret;
-        ret.length = 3 + subWidgets.length;
-        
-        ret [0..3] = [widgetType, rows, cols];  // first data
-        
-        foreach (i,widget; subWidgets)          // sub widgets
-            ret[i+3] = window.addCreationData (widget);
-        
-        return ret;
-    }+/
+    
+    // Save column/row sizes. Currently always do so.
+    bool saveChanges (widgetID id) {
+        with (data) {
+            foreach (i, widget; subWidgets) // recurse on subwidgets
+                widget.saveChanges (strings[i]);
+            
+            ints = ints[0..3] ~ cast(int[])col.width ~ cast(int[])row.width;
+        }
+        mgr.setData (id, data);
+        return true;
+    }
+protected:
+    WidgetData data;
 }
 
 
@@ -124,11 +126,6 @@
         adjustCache;
     }
     
-    /+FIXME
-    int[] getCreationData () {
-        return [widgetType];
-    }+/
-    
 private:
     OptionList optsList;
 }
@@ -183,16 +180,6 @@
             widget.setHeight (row.width[i / cols], -1);
         }
     }
-    /+ FIXME - saving
-    /** Returns sub-widget mutable data along with column widths and row heights, as used by
-     *  adjust(). */
-    int[] getMutableData () {
-        int[] ret;
-        foreach (widget; subWidgets)
-            ret ~= widget.getMutableData;
-        
-        return ret ~ cast(int[])col.width ~ cast(int[])row.width;
-    }+/
     //END Creation & saving
     
     //BEGIN Size & position
--- a/mde/setup/paths.d	Tue Jul 29 17:11:22 2008 +0100
+++ b/mde/setup/paths.d	Tue Jul 29 18:14:53 2008 +0100
@@ -151,10 +151,9 @@
             
             for (int i = pathsLen - 1; i >= 0; --i) {
                 FilePath file = findFile (paths[i]~filename);
-                if (file !is null) {
+                if (file !is null)
                     ret ~= file;
-                    if (readOrder == PRIORITY.HIGH_ONLY) break;
-                }
+                if (readOrder == PRIORITY.HIGH_ONLY) break;
             }
         }
         return ret;