twu@caip.rutgers.edu (Theodore Wu) (04/02/89)
I want to pictup directories as well as files using the Standard File routine SFGetFile. A new button "Use Directory" is added to the standard file window. If this button is pushed, I want SFGetFile to return the selected directory, or the current directory if nothing is sellected. I read all the related sections in Inside Macintosh, but still have trouble puttings things together and get it to work. Can anybody give me some ideas on how to do this? Code in any language that does similar things (or even code that uses the DlgHook) will be very helpful. Thanks in advance. -Ted.
tim@hoptoad.uucp (Tim Maroney) (04/08/89)
Awful puns having to do with blue body paint and Theodore's typo in the subject line are left as an exercise for the reader. In article <Apr.2.09.05.09.1989.13475@caip.rutgers.edu> twu@caip.rutgers.edu (Theodore Wu) writes: > > I want to pictup directories as well as files using the >Standard File routine SFGetFile. A new button "Use Directory" is >added to the standard file window. If this button is pushed, I >want SFGetFile to return the selected directory, or the current >directory if nothing is sellected. No, this is confusing. In fact, it's going to be confusing no matter what you do, since Standard File wasn't really built for this, but you can do better than this. Letting it be either the directory at the top or the directory selected in the list is a mess. Here's how you do it. Use SFPGetFile to do an SF dialog with your mutant items list. Since you're "extending the standard", be sure that you include a new text item with some explanation of what's going on. Forget about your reply record; you need to pass it as always, but ignore the contents on return. Your invisible button (Item 2) should be renamed "Use Folder" and moved into a prominent place. Declare a global called "good" and set it to false before calling SFPGetFile. Use a file filter that always returns true; this will mean no file can be chosen. Rename the OK button to Cancel. Move the Cancel button out of sight, preferably off the right edge or bottom of the items list.. With me so far? OK. Now the last part. You don't need an event filter, but you do need an item procedure. (There are three procedure pointers passed to SFPGetFile -- supply the file filter and item hook, but not the event filter.) The item filter is very short -- it just sets the global variable "good" to true and returns the Cancel button id when the Use Folder button is clicked. Here am it: pascal short FolderItems(item, dlog) short item; DialogPtr dlog; { if (item == 2) { good = true; item = 3; } return item; } Whew. Now when you call SFPGetFile, instead of checking reply.good, check "good" the global variable. If it's good, then the volume and folder selected can be extracted from the low-memory globals SFSaveDisk and CurDirStore. It's also a good idea, if this is meaningful in your application, to set up SFSaveDisk and CurDirStore to whetever the currently selected directory is. This will cause Standard File to start off with the proper folder. Note that this gives you the "current folder", that is, the folder or volume top-level that shows in the shadowed box above the folders list. It can still be confusing, since the user might think she's selected the folder chosen in the folder list instead. You ought to be able to get around that with a filter procedure that checks the reply record and disables the Use Folder button when anything is selected (that is, when fType is not zero). I haven't done this yet, but I probably will for my current project. Another approach to avoiding confusion would be to always ask for a confirmation and give the folder name when you confirm. This shows the user explicitly what she's done; while it allows an error to be made, it also makes it easy to notice and correct. As Peter Falk would say, there's just one more thing that bothers me. Don't assume your user knows the jargon term "directory". She may never have used anything but a Mac. Use "folder". >I read all the related sections >in Inside Macintosh, but still have trouble puttings things >together and get it to work. Can anybody give me some >ideas on how to do this? Code in any language that does similar >things (or even code that uses the DlgHook) will be very helpful. >Thanks in advance. -Ted. Hope this helps. Standard File hacking really isn't as scary as it looks from the documentation. -- Tim Maroney, Consultant, Eclectic Software, sun!hoptoad!tim "The negro slaves of the South are the happiest, and, in some sense, the freest people in the world. The children and the aged and infirm work not at all, and yet have all the comforts and neccessaries of life provided for them." -- George Fitzhugh, CANNIBALS ALL! OR, SLAVES WITHOUT MASTERS, 1857