Disable Save button in AppleScriptObjC Explored v4.0.1

I’m working my way through Shane Stanley’s book about AppleScript Objective-C (excellent, btw). I’m on chapter 7 (A Class of Our Own). I’ve finished the chapter, but I have one abnormality that I see when testing that I’m wondering about.

The application “Ad Table” has a table view in it as well as push buttons for Add, Delete, Save, Import. My question regards the Save button.

When I click into a row in the table and edit a value, the Save button is still enabled. If, while I’m still in the row editing and I change a value, but before I click out of the row I press the Save button, what is committed to the log or to disk is the value from before I edited the cell.

Is there a way to either force the table to commit the value prior to saving? Or is there a way for the interface to disable the “Save” button while a user is actively editing a cell?


Assuming you have an outlet to the main window, insert this at the start of the save handler:

mainWindow's makeFirstResponder_(missing value)

That should take the focus off the table, and hence commit the editing.

That worked! Thanks.

Now, the only problem on pressing the Save button is that if you type in a number in a column that has a min-max and you violate the validation, the table attempts to commits the data, but displays the dialog “The value is N is too large. Please provide a valid value.” {Discard Change or OK}, but this is happening simultaneously with the handler running the “Save”. So you end up with two dialogs simultaneously.

Is there a way to perform the commit and know whether a validation error has happened, and then, if it hasn’t, continue with the “Save” handler?

makeFirstResponder_ returns a boolean to let you know if it worked; just abort the save if it returns false.