#!/usr/bin/env perl
require
5.002;
sub
browse;
sub
invokeself
{
my
@args
= ($^X,__FILE__,
@_
);
system
(
join
(
' '
,
@args
));
}
my
$MW
= MainWindow->new;
my
$scroll
=
$MW
->Scrollbar();
$scroll
->
pack
(
-side
=>
'right'
,
-fill
=>
'y'
);
my
$list
=
$MW
->Listbox(
-yscrollcommand
=> [
'set'
,
$scroll
],
-relief
=>
'sunken'
,
-width
=> 20,
-height
=> 20,
-setgrid
=>
'yes'
,
);
$list
->
pack
(
-side
=>
'left'
,
-fill
=>
'both'
,
-expand
=>
'yes'
);
$scroll
->configure(
-command
=> [
'yview'
,
$list
]);
$MW
->minsize(1, 1);
my
$dir
;
if
(
scalar
@ARGV
> 0) {
$dir
=
$ARGV
[0];
}
else
{
$dir
=
'.'
;
}
foreach
(<${dir}/*>) {
$list
->insert(
'end'
, basename($::ARG));
}
$list
->
bind
(
'all'
,
'<Control-c>'
=> \
&exit
);
$list
->
bind
(
'<Double-Button-1>'
=>
sub
{
my
(
$listbox
) =
@_
;
foreach
(
split
' '
,
$listbox
->get(
'active'
)) {
browse
$dir
, $::ARG;
}
});
MainLoop;
sub
browse {
my
(
$dir
,
$file
) =
@_
;
if
(
$dir
ne
'.'
) {
$file
=
"$dir/$file"
;
}
if
(-d
$file
) {
invokeself(
"$file &"
);
}
else
{
if
(-f
$file
) {
print
STDOUT
"Viewing file $file ...\n"
;
if
(
defined
$ENV
{
'EDITOR'
}) {
system
"$ENV{'EDITOR'} $file &"
;
}
else
{
system
"vi $file &"
;
}
}
else
{
print
STDOUT
"\"$file\" isn't a directory or regular file\n"
;
}
}
}