Changeset 78:79a1809421aa
- Timestamp:
- 07/29/08 13:14:53
(5 months ago)
- Author:
- Diggory Hardy <diggory.hardy@gmail.com>
- branch:
- default
- Message:
Widget data saving reimplemented for the new data system. (Now grid layout widgets remember their row & column sizes.)
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r77 |
r78 |
|
| 5 | 5 | <WidgetData|root=[0xB004,3,3],["square","blank","square","blank","content","blank","square","blank","square"]> |
|---|
| 6 | 6 | <WidgetData|square=[0x1,6,6],[]> |
|---|
| 7 | | <WidgetData|content=[0xB004,3,2],["blank","button","blank","blank","blank","opts"]> |
|---|
| | 7 | <WidgetData|content=[0xB004,4,2],["blank","button","blank","blank","blank","opts","blank","blank"]> |
|---|
| 8 | 8 | <WidgetData|button=[0x4010,200,200],[]> |
|---|
| 9 | 9 | <WidgetData|blank=[0x3001],[]> |
|---|
| r77 |
r78 |
|
| 180 | 180 | scope(exit) mutex.unlock; |
|---|
| 181 | 181 | |
|---|
| 182 | | if (noChanges) |
|---|
| | 182 | // Make all widgets save any changed data; return if no changes: |
|---|
| | 183 | if (!child.saveChanges ("root")) |
|---|
| 183 | 184 | return; |
|---|
| 184 | 185 | |
|---|
| … | … | |
| 235 | 236 | /** For making changes. */ |
|---|
| 236 | 237 | void setData (widgetID id, WidgetData d) { |
|---|
| 237 | | noChanges = false; |
|---|
| 238 | 238 | changes[id] = d; // also updates WidgetDataSet in data. |
|---|
| 239 | 239 | } |
|---|
| … | … | |
| 265 | 265 | scope mt.DataSet changesDS; // changes and sections from user file (used for saving) |
|---|
| 266 | 266 | bool loadUserFile = true; // still need to load user file for saving? |
|---|
| 267 | | bool noChanges = true; // do we have any changes to save? |
|---|
| 268 | 267 | |
|---|
| 269 | 268 | scope IChildWidget child; // The primary widget. |
|---|
| r77 |
r78 |
|
| 175 | 175 | { |
|---|
| 176 | 176 | //BEGIN Load and save |
|---|
| | 177 | /** When this is called, if the widget has any changed data to save it should call |
|---|
| | 178 | * IWidgetManager.setData (id, data) to set it and return true. Otherwise it should return |
|---|
| | 179 | * false. |
|---|
| | 180 | * |
|---|
| | 181 | * If the widget has subwidgets, it should also be recursively called on these (passing their |
|---|
| | 182 | * ids). */ |
|---|
| | 183 | bool saveChanges (widgetID id); |
|---|
| | 184 | |
|---|
| 177 | 185 | /** Called when the renderer is changed (at least when the changes affect dimensions). |
|---|
| 178 | 186 | * Also called after widget creation, before any other methods are called. |
|---|
| r77 |
r78 |
|
| 57 | 57 | this (IWidgetManager mgr, WidgetData data) { |
|---|
| 58 | 58 | this.mgr = mgr; |
|---|
| | 59 | } |
|---|
| | 60 | |
|---|
| | 61 | // Don't save any data: fine for many widgets. |
|---|
| | 62 | bool saveChanges (widgetID) { |
|---|
| | 63 | return false; |
|---|
| 59 | 64 | } |
|---|
| 60 | 65 | |
|---|
| r77 |
r78 |
|
| 62 | 62 | data.strings.length != rows * cols) |
|---|
| 63 | 63 | throw new WidgetDataException; |
|---|
| | 64 | this.data = data; |
|---|
| 64 | 65 | |
|---|
| 65 | 66 | // Get all sub-widgets |
|---|
| … | … | |
| 80 | 81 | adjustCache; |
|---|
| 81 | 82 | } |
|---|
| 82 | | /+FIXME |
|---|
| 83 | | /** Return construction data to recreate this GridLayoutWidget. */ |
|---|
| 84 | | int[] getCreationData () { |
|---|
| 85 | | int[] ret; |
|---|
| 86 | | ret.length = 3 + subWidgets.length; |
|---|
| 87 | | |
|---|
| 88 | | ret [0..3] = [widgetType, rows, cols]; // first data |
|---|
| 89 | | |
|---|
| 90 | | foreach (i,widget; subWidgets) // sub widgets |
|---|
| 91 | | ret[i+3] = window.addCreationData (widget); |
|---|
| 92 | | |
|---|
| 93 | | return ret; |
|---|
| 94 | | }+/ |
|---|
| | 83 | |
|---|
| | 84 | // Save column/row sizes. Currently always do so. |
|---|
| | 85 | bool saveChanges (widgetID id) { |
|---|
| | 86 | with (data) { |
|---|
| | 87 | foreach (i, widget; subWidgets) // recurse on subwidgets |
|---|
| | 88 | widget.saveChanges (strings[i]); |
|---|
| | 89 | |
|---|
| | 90 | ints = ints[0..3] ~ cast(int[])col.width ~ cast(int[])row.width; |
|---|
| | 91 | } |
|---|
| | 92 | mgr.setData (id, data); |
|---|
| | 93 | return true; |
|---|
| | 94 | } |
|---|
| | 95 | protected: |
|---|
| | 96 | WidgetData data; |
|---|
| 95 | 97 | } |
|---|
| 96 | 98 | |
|---|
| … | … | |
| 124 | 126 | adjustCache; |
|---|
| 125 | 127 | } |
|---|
| 126 | | |
|---|
| 127 | | /+FIXME |
|---|
| 128 | | int[] getCreationData () { |
|---|
| 129 | | return [widgetType]; |
|---|
| 130 | | }+/ |
|---|
| 131 | 128 | |
|---|
| 132 | 129 | private: |
|---|
| … | … | |
| 184 | 181 | } |
|---|
| 185 | 182 | } |
|---|
| 186 | | /+ FIXME - saving |
|---|
| 187 | | /** Returns sub-widget mutable data along with column widths and row heights, as used by |
|---|
| 188 | | * adjust(). */ |
|---|
| 189 | | int[] getMutableData () { |
|---|
| 190 | | int[] ret; |
|---|
| 191 | | foreach (widget; subWidgets) |
|---|
| 192 | | ret ~= widget.getMutableData; |
|---|
| 193 | | |
|---|
| 194 | | return ret ~ cast(int[])col.width ~ cast(int[])row.width; |
|---|
| 195 | | }+/ |
|---|
| 196 | 183 | //END Creation & saving |
|---|
| 197 | 184 | |
|---|
| r75 |
r78 |
|
| 152 | 152 | for (int i = pathsLen - 1; i >= 0; --i) { |
|---|
| 153 | 153 | FilePath file = findFile (paths[i]~filename); |
|---|
| 154 | | if (file !is null) { |
|---|
| | 154 | if (file !is null) |
|---|
| 155 | 155 | ret ~= file; |
|---|
| 156 | | if (readOrder == PRIORITY.HIGH_ONLY) break; |
|---|
| 157 | | } |
|---|
| | 156 | if (readOrder == PRIORITY.HIGH_ONLY) break; |
|---|
| 158 | 157 | } |
|---|
| 159 | 158 | } |
|---|