Orac-alpha
view release on metacpan or search on metacpan
orac_FileSelect.pm view on Meta::CPAN
Changes the directory path, or at least gets the process going.
=cut
sub SetPath {
my $self = shift;
my($stub) = @_;
$self->{selectPath} = $stub;
$self->Update();
}
=head2 Update
Continues process of changing directory. Once there, fills the IconList
widget with the appropriate icons.
=cut
sub Update {
my $self = shift;
# This proc may be called within an idle handler. Make sure that the
# window has not been destroyed before this proc is called
$self->get_img( \$self->{window}->{text}, \$folderImage, 'folder');
$self->get_img( \$self->{window}->{text}, \$fileImage, 'text');
$self->get_img( \$self->{window}->{text}, \$imageImage, 'image');
$self->get_img( \$self->{window}->{text}, \$pImage, 'p');
my $appPWD = Cwd::cwd();
if ($self->{selectPath} eq $start_directory)
{
$upBtn->configure(-state=>'disabled');
}
else
{
$upBtn->configure(-state=>'normal');
}
if (!chdir $self->{selectPath}) {
# We cannot change directory to $data(selectPath). $data(selectPath)
# should have been checked before tkFDialog_Update is called, so
# we normally won't come to here. Anyways, give an error and abort
# action.
main::mes($self->{window},
qq{Cannot change to the directory } .
$self->{selectPath} . qq{\. \nPermission denied?}
);
return;
}
# Turn on the busy cursor.
$self->{window}->Busy(-recurse=>1);
$self->{window}->idletasks;
$self->{window}->{text}->DeleteAll;
# Make the dir list
my %hasDoneDir;
foreach my $f (sort { lc($a) cmp lc($b) } glob('.* *')) {
next if $f eq '.' or $f eq '..';
if (-d "./$f" and not exists $hasDoneDir{$f}) {
$self->{window}->{text}->Add($folderImage, $f);
$hasDoneDir{$f}++;
}
}
# Make the file list
my @files = sort { lc($a) cmp lc($b) } glob('.* *');
my $top = 0;
my %hasDoneFile;
foreach my $ffile (@files) {
if (-f "./$ffile" and not exists $hasDoneFile{$ffile}) {
my $image;
my ($file, $path, $suffix) = fileparse( $ffile, q{.\w+$} );
if ($suffix =~ /\.gif$/i)
{
$image = $imageImage;
}
elsif ($suffix =~ m/p[lm]$|pod$/i)
{
$image = $pImage;
}
else
{
$image = $fileImage;
}
$self->{window}->{text}->Add($image, $ffile);
$hasDoneFile{$ffile}++;
}
}
$self->{window}->{text}->Arrange;
$self->{window}->Unbusy;
}
1;
( run in 0.766 second using v1.01-cache-2.11-cpan-39bf76dae61 )