Unitialized errors in FileSelect.pm
by Amit Didwania other posts by this author
Jul 20 2007 1:51AM messages near this date
RE: State in Button Widget
|
GetOpenFile problem
SOURCE Hello All,
TK Version : 804.027
Platform : 5.8 Generic_117350-46 sun4u sparc SUNW,Sun-Fire-V440
Perl Version : 5.8.7
I get a unitialized error in FileSelect.pm in Accept_dir method. It
happens if you use this package to open a File browser, and randomly
click in the dir select widget. Reason is a double click without any
selection cause the $new argument to be uninitalized in Accept_dir
method as given below. I did a slight modification, which work for me.
Does any body else knows ay other solution for this issue?
########################################################################
########
####################### ACCEPT_DIR
#
sub Accept_dir
{
my ($cw,$new) = @_;
my $dir = $cw-> cget('-directory');
if(defined $new) {
$cw-> configure(-directory => "$dir/$new");
} else {
$cw-> configure(-directory => "$dir");
}
} # end sub ACCEPT_DIR
Similary for File selection. Glob_to_re method should be modified as
follows
sub glob_to_re
{
my $regex = shift;
$regex =~ s/(\\?)(.)/&translate($1,$2)/ge;
#Old code doesn't check if $_ is defined.
#return sub { shift =~ /^${regex}$/ };
return sub {
my $str = shift;
if(!defined($str)) {
return 0;
}
if($str =~ /^$regex$/) {
return 1;
} else {
return 0;
}
}
}
Sample test code to reproduce the problem, is attached.
Thanks and Regards
Amit
Thread:
Steve Waltner
Jack D
Steve Waltner
Amit Didwania
Slaven Rezic
Amit Didwania
Amit Didwania
|