Ingo:
> what's the easiest way to find out, if a layout contains any dirty fields? 
>  (That is, fields that have been edited).

I don't know the *easiest* but what I do is set a global variable in each 
field I'm interested in. Something like:

; function to set global flag if field has changed
global-dirty?: false
set-dirty?: func [face [object!]]
        [
         if strict-not-equal? face/data  face/user-data
            [print "face value changed"
             face/user-data: copy face/data
             global-dirty?: true
            ]
        ]

;; sample layout using above function

unview/all
view layout [field [set-dirty? face]
            field [set-dirty? face]
            button "Exit" [If global-dirty?
                            [print "need to save here"
                             global-dirty?: false
                            ]
                        ]
            ]

This method is precise it that you set global-dirty? only for the fields you 
care about. But it's annoying in that you need to add a  [set-dirty? face] to 
all those fields.

It works for me in the application I use it in because the layout is built 
from a template, so I don't have to insert the [set-dirty? face] by hand 
everywhere.


You could play with making it more flexible by exploring using styles. This 
next example does that. It also defines its own 'last-user-value variable 
rather than using 'user-data. And it fixes the "false positive" when you tab out of 
a field for the first time:

global-dirty?: false
set-dirty?: func [face [object!]]
        [
         if strict-not-equal? face/data  face/last-user-value
            [print "face value changed"
             face/last-user-value: copy face/data
             global-dirty?: true
            ]
        ]

unview/all
view layout [style monitored-field field
                with [last-user-value: copy ""]
                    [set-dirty? face]
         
            monitored-field [set-dirty? face]
            monitored-field [set-dirty? face]
            button "Exit" [If global-dirty?
                            [print "need to save here"
                             global-dirty?: false
                            ]
                        ]
            ]

Sunanda.
-- 
To unsubscribe from this list, just send an email to
[EMAIL PROTECTED] with unsubscribe as the subject.

Reply via email to