[futurebasic] NavServices custom open and save dialogs

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : April 2002 : Group Archive : Group : All Groups

From: Heather Donahue <hdonahue@...>
Date: Fri, 26 Apr 2002 00:07:18 -0700
I wanted to give the list a heads up on something I decided to work 
on.  This is a little long, you have been warned.


I've worked with the Navigation Services dialogs a bit and had tried 
to figure out how to create custom open and save pop-up menus.  While 
I have some C code that did it well, it did it with DITLs and a fixed 
event procedure callback.  While anyone could take the code I ported 
and make custom controls like menus and checkboxes, it's a very 
custom affair.

What I wanted was something simpler and easy to build.

As it turns out, and why it can be confusing is, there are many, 
almost too many, features, options, and methods of modifying the 
NavServices dialogs.  I thought it would be great to allow each, or 
most, of these options to be called from the FILE$ function.  Then I 
realized that just might confuse things even more and make debugging 
nearly impossible.

After delving into the Apple documentation a bit more, I've found 
it's really pretty simple to create pop-up menus in both the save and 
open dialogs.

For the most part you just have to pass a list of menu items to the 
Nav functions and NavServices will create the menus for you.  It's in 
the form of an array so you can programmatically create them.  I 
think some people might want to load them from a resource as well. 
In order to create the resource, I've made a ResEdit template that 
simplifies creating them.  It's not as nice as the graphical MENU 
editor but it gets the job done and I think is easier than manually 
filling out the array.  It also makes localization easier.

I'm mostly done but need to finish an application and some 
documentation that shows how to use each option.

Here are the features that will be available in the override file 
when I release it:

1. Custom Open dialogs:

Create a pop-up that allows users to select from openable types.  If 
your app is myApp (creator "myAp") and you can open types "TEXT" and 
"PICT" then the user can filter the browser list by just one type or 
the other of only your creator code.

In addition you have the option to allow an "All Readable Documents" 
menu item and an "All Files" option.  These capabilities are built 
into the filtering callback procedure.

The default FB FILE$ function also now can filter by creator in 
addition to the type codes passed in the typeList$.

2. Custom Save Dialogs:

With this option you have a great deal of flexibility.  The format 
pop-up menu can be configured to say anything you want.  If you want 
a Save As: "Text Document" and a "Text (UNIX line endings)" you can 
do that.  The pop-up menus have three characteristics, title, type 
and creator codes.  You can make the title anything you want, and by 
making it "-" it will be a separator.  The type and creator fields 
are longs and are for your use.  After the user selects open or 
cancel the runtime will return the state of the menu to you.  It does 
this by returning the value of the type and creator fields.

If the user selects to overwrite an existing file that fact will be 
returned as well.

3. Multiple files selection:

Multiple file selection is supported if you want it.  This one turned 
out to be rather easy.  If used, the runtime uses AppleEvents to send 
itself the full list of selected items.  In order to retrieve the 
list you simply use the runtime function FinderInfo.  I haven't 
tested this but if you use a custom 'odoc' eventhandler you'll have 
to deal with it there (but then you already are).

4. Other options:

Some NavServices options are available regardless of whether or not 
you use the custom pop-up menus.  A few options will allow opening 
invisible files, telling the Finder to not resolve aliases and auto 
translation on open.

I've also found that MacOS 9 and MacOS X differ somewhat in how they 
implement some options.  For instance MacOS 9 has an 'Allow 
Stationery' option, it isn't available using OS X.  Also the 'Don't 
resolve aliases' option doesn't work with aliases to a folder in OS X 
but it does with OS 9.

-- 
Heather Donahue