Notification of script by cocoa object

I was given a cocoa class written by Craig Williams that inherits from NSTextField and handles Drag and Drop. I use it for a set of text fields. My problem is that I don’t know how to get a cocoa object to notify the main script that something has been done - in this case, the text field string has been changed.
This is necessary in order to verify that the string is a path of a certain type of file, or a folder, and then change certain other script variables accordingly. The working method is in the implementation section:


- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>) sender
{
	highlighted = YES;
	[self setStringValue:@""];
	[self becomeFirstResponder];
	return NSDragOperationCopy;
}

Applescript Studio handled drag and drop a bit awkwardly but at least it was in the same script and other script variables could be affected by the drop. A solution to my notification problem would go a long way helping me to learn ObjectiveC

Well, I’m not exactly sure of the answer. And thought I’d wait to see if someone else has a solution. But I have some ideas that I think might pan out for you. It’s also hard because you didn’t post much detail on how the rest of your app is structured… But here’s a couple things I’d try, assuming you’re trying to pass a notification from the Obj-C class you got to your AppDelegate.applescript:

in your AppDelegate, create a handler that’s

you’ll want to make sure the variables you need changed are global.

Then, in interface builder:

go to the library and search in classes for the Obj-C class you got, and drag that (should be a blue cube) onto your MainMenu.xib. Hold control and drag from that class to your AppDelegate’s blue cube. A list of receivers should pop-up, and select “yourNewHandler”.

Now what I don’t know, partly because I don’t know how you set up your app, and partly because I don’t know Obj-C (so I’m not exactly sure how that class works), is how to get the text that was dragged into yourNewHandler. If your text is dragged into a textfield,
then your newHandler would be something like

Should be something like that…

G’day

I also need an answer to this.

I’ve got a text field that’s populated with a file path from a pop up button and a file that the usernavigates to.

Trouble is, just plonking the text into the field doesn’t generate a call to a method, so the routine ‘on yourNewHandler_(sender)’ mentioned above won’t get called, unless the field is actually edited.

We need some way of updating the preference bindings. Is there such a way?

Regards

Santa

Bonjour.
I have a clumsy solution to my problem. It’s too involved. There must be something simpler.
I have an ASOC AppDelegate containing ids for 2 text fields of class “TextFieldDrop”. The awakeFromNib method passes the id of the main script to the text fields. The continueDrop method is the one contacted when the text field has accepted a drop. continueDrop is called before the text is changed in the text field. I’m not convinced this is the best way to do it.


script TextFieldDropAppDelegate
	property parent : class "NSObject"
	
	property gedFileTextField : missing value
	property outFolderTextField : missing value
	property gedFileText : missing value
	property outFolderText : missing value
	
	property gedFound : true
	
	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_
	
	on continueDrop_(theField)
		log "continueDrop"
		theField's setStringValue_("text string changed")
	end continueDrop_
	
	on awakeFromNib()
		my gedFileTextField's setMainScript_(me)
		my outFolderTextField's setMainScript_(me)
	end awakeFromNib
	
end script

I added a variable and a method to Craig Williams’ TextField class:


#import <Cocoa/Cocoa.h>

@interface TextFieldDrop : NSTextField {
	
	BOOL highlighted;
	NSApplication * mainScript;
}
- (void) setMainScript:(NSApplication *) theScript;

@end

The added method setMainScript sets the variable mainScript to the id of the AppDelegate script.
The method draggingEntered contains a call to the AppDelegate script method continueDrop


#import "TextFieldDrop.h"


@implementation TextFieldDrop

- (void) awakeFromNib
{
	[self registerForDraggedTypes: [NSArray arrayWithObjects: @"NSFilenamesPboardType", nil]];
}

-(NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)flag
{
	return NSDragOperationCopy;
}

- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>) sender
{
	highlighted = YES;
	[self setStringValue:@""];
	[self becomeFirstResponder];
	[mainScript continueDrop: self];
	return NSDragOperationCopy;
}

- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
{
	return NSDragOperationCopy;
}

- (void)draggingExited:(id <NSDraggingInfo>)sender
{
	highlighted = NO;
}

- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
	return YES;
}

- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
	return YES;
}
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
{
	highlighted = NO;
}

- (void) setMainScript:(NSApplication *) theScript
{
	NSLog(@"get main script id");
	mainScript = theScript;
}

@end