[REBOL] VID: clear-fields - how to improve it
From: greggirwin::mindspring::com at: 27-Mar-2003 13:55
Hi All,
CLEAR-FIELDS is one of those really handy functions that annoys me. :\
It's very useful, but also problematic in that it only clears FIELD
faces, not AREAs; much less CHECK, RADIO, etc. *and* it only works if
a field contains a SERIES! value.
Admittedly, coming up with a completely general solution would probably
add lots of code, but can it be made better without too much effort
and added code? I think so, but I'm not sure how far to go, assuming we
want to submit the improved version to RT for future inclusion.
Here's the standard version:
clear-fields: func [
"Clear all text fields faces of a layout."
panel [object!]
][
if not all [in panel 'type panel/type = 'face] [exit]
unfocus
foreach face panel/pane [
if all [series? face/text flag-face? face field] [
clear face/text
face/line-list: none
]
]
]
This one works for AREAs as well, and sets non-series values to NONE:
clear-fields: func [
"Clear all text fields faces of a layout."
panel [object!]
][
if not all [in panel 'type panel/type = 'face] [exit]
unfocus
foreach face panel/pane [
if any [flag-face? face field flag-face? face area][
either series? face/text [
clear face/text
face/line-list: none
][
face/text: none
]
]
]
]
This one does the same as above, but tries to MAKE the type of value
that's in the field. E.g. numeric fields would reset to 0:
clear-fields: func [
"Clear all text fields faces of a layout."
panel [object!]
][
if not all [in panel 'type panel/type = 'face] [exit]
unfocus
foreach face panel/pane [
if any [flag-face? face field flag-face? face area][
either series? face/text [
clear face/text
face/line-list: none
][
face/text: attempt [make face/text none]
]
]
]
]
Beyond these simple kinds of changes, should we directly add support
for CHECK, RADIO, etc. or is it better to adopt a more general approach,
e.g. using a dialected block as a parameter, that you use to reset the
display in your app? The latter approach makes it more effort to use,
but potentially much more useful as well.
Any thoughts, or other implementations would be welcome.
-- Gregg