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

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



Not to say your solution isn't good, but here is a version that does not use
a filterproc, and therefore is faster:

#!perl
#
# ChooseFiles - Choose (text) files
#

use Mac::Navigation;

$options = NavGetDefaultDialogOptions();
$options->dialogOptionFlags(
  $options->dialogOptionFlags | kNavNoTypePopup);
$options->message("WH3R3 R 7H3 F1L3Z?");

$types = new NavTypeListHandle "McPL", ["TEXT"];

$reply   = NavGetFile("", $options, $types, undef, undef, undef) or die $^E;

for ($i = 0; $i++<$reply->count; ) {
   print $reply->file($i), "\n";
}
__END__


-----BEGIN GEEK CODE BLOCK----
Version: 3.12
GCS d s:+ !a C++++ U*+++ P++++ L+ E-- W+++ N++ o+ K- w--- O? M++ V? PS PE-
Y-- PGP++ t+ 5 X R tv++ b+++ D I- D? G! e h! r
-----END GEEK CODE BLOCK-----

----------
>From: Chris Nandor <pudge@pobox.com>
>To: "Mark Yannuzzi" <myannuzzi@aya.yale.edu>
>Cc: MacPerl List <mac-perl@iis.ee.ethz.ch>
>Subject: Re: [MacPerl] Using Mac:: '...' Modules
>Date: Wed, Mar 24, 1999, 8:56 AM
>

> 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
>
> 

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