At 16:53 Uhr +0200 28.06.2002, Axel Rose wrote:
>Is there an example for NavPutFile available?
>
>I think this is a clear documentation problem. The example Thomas
>mentioned "ChooseObjects.t" is only in the source tree. The POD
>on the other hand always points to Inside Macintosh. The mailing
>list archives don't offer a search interface. My personal archive
>of the list doesn't contain "NavPutFile". The MacPerl book has no
>index entry for navigation services.
>
>Non C programmers are out of luck but also out of the 520r4
>function.
>
>Can anyone post a NavPutFile sample here?
>
>
>Axel

I agree. Without examples, Navigation Services are a bit complicated 
to program, even in C. However, I thought that all Mac:: test files 
were distributed with the standard MacPerl distribution. If not, they 
should, I think. But even with examples, access to Inside Mac is 
highly recommended, since there are tons of options in Nav Services. 
Hardcore MacPerl programmers should look at:

     http://developer.apple.com/techpubs/macos8/pdf/NavServices.pdf

And here is an example that shows the NavPutFile basics (use at your 
own risk :-). I would not even try to write Perl code that adds a 
custom type popup to the dialog, though ...


#!perl -w

use Mac::Navigation;

$options = NavGetDefaultDialogOptions();

$options->savedFileName("Untitled"); # suggested filename
$options->message("Where should the file be saved?"); # prompt 
(comment out if you don't want a prompt)

# uncomment if you don't want a type popup menu
#$options->dialogOptionFlags( $options->dialogOptionFlags | kNavNoTypePopup );

$defaultlocation = "MacintoshHD:"; # where should Nav Services start
$filettype = "TEXT";
$filecreator = "McPL";

$reply = NavPutFile ($defaultlocation, $options, $filettype, 
$filecreator, undef);

if ($reply) {
        if ($reply->validRecord) {
                print "User saved.\n";
                $path = $reply->file(1);
                print "path = $path\n";

                if ($reply->replacing) {
                        print "file will be replaced\n";
                }

                # do save stuff here
        }
} else {
        print "User canceled.\n";
}


HTH.


--Thomas


Reply via email to