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

[MacPerl] dialog box problems



Hi all,

I'm progressing through the MacPerl book and am writing a script to search
files in various directories of a CD.   I have written  dialogue box with
descriptive text, a cancel button, a "search" button and an edit text
field.   The dialog window comes up, but then seem not to be invoking the
handlers.   The search framework (still a skeleton) seems never to be
reached.   I am unable to abort the script with command-period, and have to
force MacPerl to quit.   If I try running the script with debug on, I get
an out of memory error.   I'm running MacPerl 5.2.0r4 with System 8.5 on a
PowerBook 1400c with a Newer G3 upgrade and 64 Megs of RAM.  I'm including
the code.  Any help would be appreciated.  Hopefully it's some dumb,
simple, newbie error.

***********
#!perl -w

#
#use strict;
use Mac::Windows;
use Mac::QuickDraw;
use Mac::Events;
use Mac::StandardFile;
use Mac::Dialogs;
#******************************************************
$DoSearch = 0;

ShowDialog();
while ($dlg->window() ) {
  $dlg->modal();
}

if ($DoSearch == 1) {
	SearchDirs();
}
dispose $dlg;

#***************************************************
sub ShowDialog {


#------ SET UP DIALOG FOR SEARCH

$dlg = MacDialog->new(
	 Rect->new(50,50,450,155),    # dialog rectangle
  'Search ACIP CD',            # dialog title
		1,                           # is visible?
		movableDBoxProc(),           # window style
		0,                           # has go away box?
		[ kButtonDialogItem(),
   Rect->new(300, 30,380,50),  'Cancel'],
   [ kButtonDialogItem(),
     Rect->new(300, 70, 380,90),'Search'],
  [kStaticTextDialogItem(),
     Rect->new(10, 10, 220, 30),
     'Search Any or All Directories'],
  [ kEditTextDialogItem(),
     Rect->new(15,50,180,65), ' '],
 );
}

#-----Define dialog items

SetDialogCancelItem ($dlg->window(), 1);
SetDialogDefaultItem($dlg->window(), 2);
SetDialogTextDialogItemText($dlg->window(), 4);


#------Define handlers for each button and text input area

$dlg->item_hit(1 => \&d1);
$dlg->item_hit(2 => \&d2);
$dlg->item_hit(3 => \&d3);


#***************************************************
#
#    SUBROUTINES
#
#***************************************************
sub d1 {
  my($dlg, $item) = @_;
	 $DoSearch = 0;
  return(1)
}

sub d2 {
  my($dlg, $item) = @_;

  if ($dlg->item_text(4) == ' ') {
     print "No search string entered\n";
     $DoSearch = 3;
   }
	  else {
      $DoSearch = 1;
	  }

   return(1);
}

sub d3 {
  my($dlg, $item) = @_;
  return(1);
{


sub SearchDirs()
  {

    $myDisk = 'ACIP R4 Mac';

    print ("\nroot volume -  $myDisk:\n");
    $rootdir = "$myDisk:Texts:";

    opendir(DIR, $rootdir) or die "cannot open $myDisk";
    @files = readdir(DIR);
    foreach $file (@files)
    {
         print("$file\n");
     				$newdir = $rootdir . $file;
     				opendir(NEWDIR,$newdir);

     				@newfiles = readdir(NEWDIR);
     				foreach $newfile(@newfiles)
         {
    							print("\t $newfile\n");
    				 }


     }
   closedir(DIR);

 }

****************************************




}}

	Noe

	          \\\
	         (@v@)  W
	          (  O )  //
	            |  | //
	          /  ? |/
	         //     |
	         |||     \
	         M| /\ |
	            ||   ||
	            ||   ||
	            LL  LL
		



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