# HG changeset patch # User Diggory Hardy # Date 1217351693 -3600 # Node ID 79a1809421aa94b12151d91f4e6178d5b733b9c9 # Parent 3dfd934100f722eb8b5a92c1de0087be12d86cd8 Widget data saving reimplemented for the new data system. (Now grid layout widgets remember their row & column sizes.) diff -r 3dfd934100f7 -r 79a1809421aa data/conf/gui.mtt --- 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} - + diff -r 3dfd934100f7 -r 79a1809421aa mde/gui/WidgetData.d --- 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. diff -r 3dfd934100f7 -r 79a1809421aa mde/gui/widget/Ifaces.d --- 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. * diff -r 3dfd934100f7 -r 79a1809421aa mde/gui/widget/Widget.d --- 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; diff -r 3dfd934100f7 -r 79a1809421aa mde/gui/widget/layout.d --- 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 diff -r 3dfd934100f7 -r 79a1809421aa mde/setup/paths.d --- 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;