[1/8] from: ingo:2b1 at: 10-Oct-2003 11:25
Hi All, what's the easiest way to find out, if a layout contains any dirty fields? (That is, fields that have been edited). Thanks to all who might anwer Ingo
[2/8] from: cyphre:seznam:cz at: 10-Oct-2003 12:30
Hi Ingo, I don't know it this if easiest but try this: find-dirty: func [fac][ if fac/pane [ foreach f reduce to-block fac/pane [ first f if all [find first f 'dirty? f/dirty?][ print [f/var "is dirty!"] ] find-dirty f ] ] ] example: view lay: layout [ f1: field panel yellow 240x65 [ f2: field ] button "find dirty" [ find-dirty lay ] ] You can generalize the function for recursive search of any face's property... regards, Cyphre
[3/8] from: brett::codeconscious::com at: 11-Oct-2003 0:57
Hi Ingo, Cyphre, I'm not sure you can use the dirty? flag for testing if data has changed. It doesn't seem to behave as I would expect. For example, in Cyphre's example without hitting the Enter key or the Tab key, enter some information into both the fields and try the button. For me, no dirty faces are found. Only once I hit the Enter key does the routine work. I think it might be better to set your own dirty flag during an action block, or check for differences between old-values and new-values at an appropriate moment (eg close window / save, etc.). Cyphre, the find-dirty function has a little problem - it does not take into account where a pane is of type function!. For example, include a text-list in the panel. Ingo, don't forget to check what happens when you enter a value in the field and immediately close the window without hitting the Enter key - you might need a event handler function. Details here: http://www.codeconscious.com/rebol/view-notes.html#DirtyFaces For interest, here's some face searching functions I made: http://www.codeconscious.com/rebsite/rebol-library/face-searches.r and Cyphre's example modified a bit to use one of them: view lay: layout [ f1: field [probe "f1"] panel yellow 240x400 [ f2: field [probe "f2"] f3: text-list data copy/deep system/locale/months [probe "f3"] ] button "find dirty" [ repeat f find-faces [ all [in face 'dirty? face/dirty?] ] [ print [f/var "is dirty!"] ] ] ] Regards, Brett.
[4/8] from: SunandaDH:aol at: 10-Oct-2003 11:56
> 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.
[5/8] from: rotenca:telvia:it at: 10-Oct-2003 20:35
> I'm not sure you can use the dirty? flag for testing if data has changed. It > doesn't seem to behave as I would expect. For example, in Cyphre's example > without hitting the Enter key or the Tab key, enter some information into > both the fields and try the button. For me, no dirty faces are found. Only > once I hit the Enter key does the routine work.
dirty? is used internally by the standard rebol focus system. I would not use it to check if a field changed, because it is cleared by the focus system under some conditions (which could change in future). I would consider it a private flag. --- Ciao Romano
[6/8] from: antonr:iinet:au at: 11-Oct-2003 13:20
You could use query on the face, which is, after all, just an object. que: does [probe query/clear f] query-f: does [que show f que] view layout [ f: field "hello" button "change text" [f/text: random "abcd" query-f] button "change size" [f/size/x: 100 + random 100 query-f] ] Anton.
[7/8] from: nitsch-lists:netcologne at: 15-Oct-2003 16:38
my most robust approach is: keep a copy of the last content and compare. rebol has a "culture" of changing variables directly (face/text: "Hello") and then calling a general process-function (like show face -> face/feel/redraw) with "keeping old version" you can change face/text with no need for some [face/dirty: true] -Volker Am Freitag, 10. Oktober 2003 17:56 schrieb [SunandaDH--aol--com]:
[8/8] from: ingo:2b1 at: 18-Oct-2003 11:35
Thanks to all who answered, Volker Nitsch wrote:
> my most robust approach is: > keep a copy of the last content and compare.
<<quoted lines omitted: 5>>> face/text with no need for some [face/dirty: true] > -Volker
The "problem" in my case is, that I don't have a special edit mode, I display the information, and it can at the same time be altered by the user. Furthermore, it is a dynamically created layout with no _single_ point of exit. It had been so nice, if the dirty flag would have been accurate, and promoted through the hierarchy - a face get dirty, whenever one of its subfaces gets dirty, if a parent face gets the dirty bit cleared, all subfaces get it cleared, too. Kind regards, Ingo
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted