I am currently working through Shane Stanley's book, and I am trying to put the cancel button into the app "Making progress" as is explained in chapter 13 of the book. I have wired up all the bindings and handlers correctly, but then I get an "unrecognized selector" error when I press the cancel button (it would be really helpful if the system told me *what* selector it doesn't recognize). The point is, for the life of me I cannot see how my code is any different from the code in chapter 13 of the book--- which works, of course. Can anybody see what I am missing? My code is:
script Making_ProgressAppDelegate
property parent : class "NSObject"
property theFilename : "App test file" -- bound property
property theFruit : "Orange" -- bound property
property theNumber : 10 -- bound property
property statusMessage : "App is idle" -- bound property
property theCounter : 0 -- bound property
property theWindow : missing value -- outlet connected to the window
property isIdle : true -- bound to enabled property of most elements
property shouldStop: false
on doProcess_(sender)
try -- for testing
log "Begin" -- for testing
set my isIdle to false -- app is no longer idle
-- build file path and open file
set deskPath to path to desktop as text
set proposedPath to deskPath & theFilename & " (test only).txt"
try -- in case file was left open
tell current application to close access file proposedPath
end try
tell current application to set fileRef to (open for access file proposedPath with write permission)
set eof fileRef to 0
repeat with i from 1 to (theNumber as integer)
log "0"
handleEvents()
if shouldStop is true then exit repeat
set my statusMessage to "Processing number " & i
set my theCounter to i
-- this where you would do your stuff
write (theFruit as text) & " number " & (i as text) & return to fileRef as text
tell theWindow to displayIfNeeded()
do shell script "sleep 0.25"
end repeat
-- close file and clean up
close access fileRef
set my theCounter to 0
if shouldStop is true then
set my statusMessage to "Cancelled after " & (i-1) & " times."
set shouldStop to false
else
set my statusMessage to "Finished processing " & i & " times."
end if
set my isIdle to true
log "End" -- for testing
-- for testing
on error errMess
log errMess
end try
end doProcess_
on handleEvents()
repeat
log "1"
tell current application's NSApp to set theEvent to nextEventMatchingMask_untilDate_inMode_dequeue(((current application's NSLeftMouseDownMask) as integer), missing value, current application's NSEventTrackingRunLoopMode, true)
log "2"
if theEvent is missing value then
exit repeat
else
tell current application's NSApp to sendEvent_(theEvent)
end if
end repeat
end handleEvents
on cancelPressed_(sender)
set my shouldStop to true
end cancelPressed_
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
end script