[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Using Mac:: '...' Modules



Here is a working example.

Note that I never got the NavTypeList stuff to work, so I just constructed
my own object from scratch of type NavTypeList and provided a subroutine to
do the work.

So essentially:

DEFAULTLOCATION is just a path.  I believe it is converted to an AEDesc for
you.
DIALOGOPTIONS is a data structure object (a good way to start is with
NavGetDefaultDialogOptions) that is changed with:

   $options->somefield($somedata)

And TYPELIST is, from all I can do, simply an empty hashref object of type
NavTypeListHandle.  There isat least one a bug in NavTypeListHandle()
anyway ... it tries to bless a nonreference value.  But I can't get it to
work if I fix that.

So I provide the optional FILTERPROC to do the file filtering "by hand", as
it were.  This is more flexible anyway ... if you want to open any TEXT
file, you need to use the FILTERPROC method, I think.  I think the other
method will only open files of type TEXT for a given application.

    #!perl -w
    use Mac::Navigation;
    use Mac::Files;
    use strict;
    my($text, $default, @types, $options, $nav, $file) =
        ('Select file', 'Bourque:Desktop Folder:', qw(APPL TEXT clpt));

    $options = NavGetDefaultDialogOptions();
    $options->message($text);
    $options->windowTitle($text);
    local($^W) = undef;
    $nav = NavGetFile($default, $options,
        bless({}, 'NavTypeListHandle'), 0, 0, sub{
            return unless (my $ft = $_[1]->fileInfo->finderInfo->fdType);
            return 1 if   ($_[1]->isFolder());
            foreach my $type (@types) {return 1 if $ft eq $type}
            return;
        }
    );
    $file = $nav->file(1) if ($nav && $nav->file(1));

    print $file;

    __END__

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org