Curses-UI
view release on metacpan or search on metacpan
lib/Curses/UI/Dialog/Filebrowser.pm view on Meta::CPAN
my @resolved = ();
foreach my $dir (@path)
{
if ($dir eq '.') { next }
elsif ($dir eq '..') { pop @resolved if @resolved }
else { push @resolved, $dir }
}
$path = join "/", @resolved;
# Catch totally bogus paths.
if (not -d $path) { $path = "/" }
$pv->text($path);
my @dirs = ();
my @files = ();
unless (opendir D, $path)
{
my $l = $this->root->lang();
my $error = $l->get('file_err_opendir_pre')
. $path
. $l->get('file_err_opendir_post')
. ":\n$!";
$this->root->error($error);
return;
}
foreach my $f (sort readdir D)
{
next if $f =~ /^\.$|^\.\.$/;
next if $f =~ /^\./ and not $this->{-show_hidden};
push @dirs, $f if -d "$path/$f";
if (-f "$path/$f")
{
$this->{-activemask} = '.'
unless defined $this->{-activemask};
push @files, $f if $f =~ /$this->{-activemask}/i;
}
}
closedir D;
unshift @dirs, ".." if $path ne '/';
$db->values(\@dirs);
$db->{-ypos} = $this->{-selected_cache}->{$path};
$db->{-ypos} = 0 unless defined $db->{-ypos};
$db->{-selected} = undef;
$db->layout_content->draw(1);
$fb->values(\@files);
$fb->{-ypos} = $fb->{-yscrpos} = 0;
$fb->layout_content->draw(1);
return $this;
}
# Set $this->{-path} to the homedirectory of the current user.
sub goto_homedirectory()
{
my $this = shift;
my @pw = getpwuid($>);
if (@pw) {
if (-d $pw[7]) {
$this->{-path} = $pw[7];
} else {
$this->{-path} = '/';
$this->root->error("Homedirectory $pw[7] not found");
return;
}
} else {
$this->{-path} = '/';
$this->root->error("Can't find a passwd entry for uid $>");
return;
}
return $this;
}
sub select_homedirectory()
{
my $b = shift; # dir-/filebrowser
my $this = $b->parent;
my $pv = $this->getobj('pathvalue');
$this->goto_homedirectory or return $b;
$pv->text($this->{-path});
$this->get_dir;
return $b;
}
sub dirselect()
{
my $db = shift; # dirbrowser
my $this = $db->parent;
my $fv = $this->getobj('filevalue');
my $pv = $this->getobj('pathvalue');
# Find the new path.
my $add = $db->values->[$db->{-ypos}];
my $savepath = $pv->text;
$this->{-selected_cache}->{$savepath} = $db->{-ypos};
$pv->text("/$savepath/$add");
# Clear the filename field if the filename
# may not be edited.
$fv->text('') unless $this->{-editfilename};
# Get the selected directory.
unless ($this->get_dir) {
$pv->text($savepath);
}
return $db;
}
sub fileselect()
{
my $filebrowser = shift;
my $this = $filebrowser->parent;
( run in 0.743 second using v1.01-cache-2.11-cpan-39bf76dae61 )