Re-usings windows without having to manually flush out fields

I have an app that uses two windows. One lets you enter some details, then you hit Done it disappears: your entry is shoved into a table on the other window. When you go to make a new entry, the ‘add’ window is called up again but it still has all the old entries in it.

Now, you can set all fields to empty through code, but is there a better way of doing this? Reloading the nib somehow?

No there’s no “better” way. I’m not sure how I see what’s so difficult about resetting the fields. While it’s a bit of coding, even with 100 text fields you still could generate the code in only a couple minutes. What I might recommend is putting the code in a subroutine, which could then be called from any number of places in your application when required. In this case, the “will open” handler of the window would be an ideal place.

on will open theObject
	if name of theObject is "inputWindow" then
	end if
end will open

to resetInputWindow()
	tell window "inputWindow"
		set content of text field "input1" to ""
		set content of text field "input2" to ""
		set content of text field "input3" to ""
		set content of text field "input4" to ""
	end tell
end resetInputWindow

or if you want to reset all items of a kind you can use something like this:

to resetInputWindow()
   tell window "inputWindow" to set content of (text fields) to ""
end resetInputWindow

or you could bundle the resetting with a naming scheme - for example:

set state of (buttons whose name starts with "prefs_") to false

hope that helps …


Ah… brilliant… I didn’t realise you could make a whole bunch of changes in one statement. Thanks!