Call handler in document script from handler in app delegate

Hi -

I’ve learned how to call a handler in a Document script from the App Delegate script by connecting a button or menu item to the First Responder, but what if it’s not a button or a menu item, rather a notification like controlTextDidEndEditing_(aNotification)?

Another way to ask that is: I can call a handler in the App Delegate from the Document by referring to it as “current application’s NSApp’s delegate()'s theHandler()”. Is there an equivalent in the other direction like “current application’s First Responder()'s theHandler()”? I totally just made that up - I know I can’t do that - but hopefully it gets the point across.

Thanks,
Greg

Can you have another go at explaining what you’re trying to do? Perhaps a specific example would help.

Ok, I’ll give it a shot -

I have a Document based project. There is a table in the main window that is the app delegate. Data from each file that is opened gets entered into the table. Clicking on the rows of the table brings the designated document window to the front, making it First Responder. Some columns contain checkbox cells, which I linked to First Responder, so I can set a checkbox in the document window from the checkbox cell in the table in the main window.

This works great.

But I also have some text field cells that I want to do the same thing. I want to change the text in the table and have the corresponding text in the document update to match. When I try to link them to First Responder they do nothing. I expected them to send an action after editing them but apparently I have to use:


on controlTextDidEndEditing_(aNotification)
        log stringValue() of aNotification's object
end controlTextDidEndEditing_

Which works, but it has to be in the app delegate script. I’d like to call a handler in the document script from this handler but since I can’t actually connect anything in the interface I don’t know how to link it to First Responder. Of course if there’s a way to get the text field cell to send an action on end editing my problem would be solved.

Am I making sense?

Thanks,
Greg

OK, it sounds like you just want the front document:

set theDoc to current application's  NSDocumentController's sharedDocumentController()'s currentDocument()

Yep, that’s all I needed. Seems pretty elementary now that I see it, but that’s about where I’m at!

Thanks,
Greg