Multiple-windows/multi-threading?

If I double-click on a data file that my application has created, it will open up in my application. How do I set up my project so that subsequently double-clicking other such data files will open up multiple windows, one for each file?

Currently all double-clicking a second data file does is make my application active with the window of the first file showing.

The second double-clicking seems to reach only the “on open” handler, none of the “launched”, “will finish launching”, etc. handlers or the “awake from nib” handler. The “names” parameter for “on open” always shows the alias of the file that was double-clicked.

Can I just somehow create a new instance of the window here? And do I simulate multi-threading by giving the new window (if I’m able to create one) a different name and examine the active window name whenever a handler is entered? Will I have to use to Objective-C calls?

I’ve looked through the Developer/Examples/AppleScript Studio projects but don’t see anything helpful there.

Thanks a lot…

  • Dan

Hi dant,

The document based example Plain Text Editor opens documents in new windows. I modified it to open on double click in the app using the creator type method. Here’s the modified version if you’re interested:


on read from file theObject path name pathName of type ofType
	set theFile to open for access (pathName as POSIX file)
	set theData to read theFile as string
	close access theFile
	set contents of text view "editor" of scroll view "editor" of window of theObject to theData
	return true
end read from file
--
on write to file theObject path name pathName of type ofType
	set theData to contents of text view "editor" of scroll view "editor" of window of theObject
	set theFile to open for access (pathName as POSIX file) with write permission
	write theData to theFile as string
	close access theFile
	set my_path to (path to me)
	set my_info to (info for my_path)
	set my_ct to file creator of my_info
	set file_ref to (pathName as POSIX file) as alias
	tell application "Finder"
		set creator type of file_ref to my_ct
	end tell
	return true
end write to file

gl,

Thanks a lot kel (again!) - I must have a blind spot because Plain Text Editor was one of the first examples that I looked at. I’ve got a ton of code in this and I wonder how difficult it will be to make a document-based app from it. (Probably not much for the average competent developer but for me…) I wasn’t clear on exactly what a document-based app buys you, I guess, but I suppose this is it.

(Edit: Actually your post inspired me to look more closely at document-based apps in the Learning Cocoa with Objective-C book and I found that’s exactly what I want.)

Thanks!

  • Dan