/usr/share/perl5/Curses/UI/Dialog/Dirbrowser.pm is in libcurses-ui-perl 0.9609-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | # ----------------------------------------------------------------------
# Curses::UI::Dialog::Dirbrowser
# (C) 2003 by Roberto De Leo based on work
# (c) 2001-2002 by Maurice Makaay. All rights reserved.
# This file is part of Curses::UI. Curses::UI is free software.
# You can redistribute it and/or modify it under the same terms
# as perl itself.
#
# Currently maintained by Marcus Thiesen
# e-mail: marcus@cpan.thiesenweb.de
# ----------------------------------------------------------------------
package Curses::UI::Dialog::Dirbrowser;
use strict;
use Curses;
use Curses::UI::Window;
use Curses::UI::Common;
use Cwd;
use vars qw(
$VERSION
@ISA
);
@ISA = qw(
Curses::UI::Window
Curses::UI::Common
);
$VERSION = '1.0';
sub new ()
{
my $class = shift;
my %userargs = @_;
keys_to_lowercase(\%userargs);
my %args = (
-title => undef,
-path => undef,
-bg => -1,
-fg => -1,
%userargs,
-border => 1,
-centered => 1,
-titleinverse => 0,
-ipad => 1,
-selected_cache => {},
);
# Does -path not contain a path? Then use the
# current working directory.
if (not defined $args{-path} or $args{-path} =~ /^\s*$/) {
$args{-path} = cwd;
}
my $this = $class->SUPER::new(%args);
$this->layout();
my $l = $this->root->lang;
# Start at home? Goto the homedirectory of the current user
# if the -path is not defined.
$this->goto_homedirectory unless defined $this->{-path};
my $buttons = $this->add(
'buttons', 'Buttonbox',
-y => -1,
-x => 0,
-width => undef,
-buttonalignment => 'middle',
-buttons => [ 'ok', 'cancel' ],
-bg => $this->{-bg},
-fg => $this->{-fg},
);
# Let the window in which the buttons are loose focus
# if a button is pressed.
$buttons->set_routine( 'press-button', \&press_button_callback );
my $one_up = $l->get('file_dirup');
my $dirbrowser = $this->add(
'dirbrowser', 'Listbox',
-y => 0,
-border => 1,
-width => $this->canvaswidth - 2,
-padbottom => 6,
-values => [],
-vscrollbar => 1,
-labels => { '..' => ".. ($one_up)" },
-bg => $this->{-bg},
-fg => $this->{-fg},
-bbg => $this->{-bg},
-bfg => $this->{-fg},
);
$dirbrowser->set_routine('option-select',\&dirselect);
$dirbrowser->set_routine('goto-homedirectory',\&select_homedirectory);
$dirbrowser->set_binding('goto-homedirectory', '~');
# Get language specific data.
my $l_path = $l->get('file_path');
my $l_mask = $l->get('file_mask');
my $l_file = $l->get('file_file');
my $l_len = $l->get('file_labelsize');
my $labeloffset = 1;
my $textoffset = $l_len + 2;
$this->add(
'pathlabel', 'Label',
-x => $labeloffset,
-y => $this->canvasheight - 5,
-text => $l_path,
-bg => $this->{-bg},
-fg => $this->{-fg},
);
$this->add(
'pathvalue', 'Label',
-x => $textoffset,
-y => $this->canvasheight - 5,
-width => $this->canvaswidth - 6,
-text => $this->{-path},
-bg => $this->{-bg},
-fg => $this->{-fg},
);
$this->set_binding(sub{
my $this = shift;
$this->getobj('buttons')->{-selected} = 1;
$this->loose_focus;
}, CUI_ESCAPE);
$this->layout();
$this->get_dir;
return bless $this, $class;
}
sub layout()
{
my $this = shift;
my $w = 50;
my $h = 18;
$this->{-width} = $w,
$this->{-height} = $h,
$this->SUPER::layout() or return;
return $this;
}
sub get_dir()
{
my $this = shift;
# Get pathvalue, filevalue, dirbrowser and filebrowser objects.
my $pv = $this->getobj('pathvalue');
my $db = $this->getobj('dirbrowser');
my $path = $pv->text;
# Resolve path.
$path =~ s|/+|/|g;
my @path = split /\//, $path;
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 = ();
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";
}
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);
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 $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");
# Get the selected directory.
unless ($this->get_dir) {
$pv->text($savepath);
}
return $db;
}
sub maskbox_onchange()
{
my $maskbox = shift;
my $this = $maskbox->parent;
$this->{-activemask} = $maskbox->get;
$this->get_dir;
return $maskbox;
}
sub draw(;$)
{
my $this = shift;
my $no_doupdate = shift || 0;
# Draw Window
$this->SUPER::draw(1) or return $this;
$this->{-canvasscr}->noutrefresh();
doupdate() unless $no_doupdate;
return $this;
}
sub get()
{
my $this = shift;
if ($this->getobj('buttons')->get) {
my $file = $this->getobj('pathvalue')->get;
$file =~ s|/+|/|g;
return $file;
} else {
return;
}
}
sub press_button_callback()
{
my $buttons = shift;
my $this = $buttons->parent;
my $file = $this->get;
my $ok_pressed = $buttons->get;
if ($ok_pressed and $file =~ m|/$|) {
my $l = $this->root->lang;
$this->root->error($l->get('file_err_nofileselected'));
return;
} else {
$this->loose_focus;
}
}
1;
=pod
=head1 NAME
Curses::UI::Dialog::Dirbrowser - Create and manipulate filebrowser dialogs
=head1 CLASS HIERARCHY
Curses::UI::Widget
|
+----Curses::UI::Container
|
+----Curses::UI::Window
|
+----Curses::UI::Dialog::Dirbrowser
=head1 SYNOPSIS
use Curses::UI;
my $cui = new Curses::UI;
my $win = $cui->add('window_id', 'Window');
# The hard way.
# -------------
my $dialog = $win->add(
'mydialog', 'Dialog::Dirbrowser'
);
$dialog->focus;
my $file = $dialog->get();
$win->delete('mydialog');
# The easy way (see Curses::UI documentation).
# --------------------------------------------
$file = $cui->filebrowser();
$file = $cui->loadfilebrowser();
$file = $cui->savefilebrowser();
=head1 DESCRIPTION
Curses::UI::Dialog::Dirbrowser is a dirbrowser dialog.
This type of dialog can be used to select a directory, anywhere
on the filesystem.
See exampes/demo-Curses::UI::Dialog::Dirbrowser in the
distribution for a short demo.
=head1 OPTIONS
=over 4
=item * B<-title> < TEXT >
Set the title of the dialog window to TEXT.
=item * B<-path> < PATH >
Set the path to start with to PATH. If this path
does not exist, the filebrowser will start in the
rootdirectory.
=item * B<-show_hidden> < BOOLEAN >
If BOOLEAN has a true value, hidden files (the filename
starts with a dot) will also be shown. By default this
option is set to false.
=back
=head1 METHODS
=over 4
=item * B<new> ( OPTIONS )
=item * B<layout> ( )
=item * B<draw> ( BOOLEAN )
=item * B<focus> ( )
These are standard methods. See L<Curses::UI::Container|Curses::UI::Container>
for an explanation of these.
=item * B<get> ( )
This method will return the complete path to the file that was
selected using the filebrowser. If no file was selected, this
method will return an undefined value.
=back
=head1 SPECIAL BINDINGS
=over 4
=item * B<escape>
This will invoke the cancel button, so the filebrowser widget
returns without selecting any file.
=item * B<~>
If the directory- or filelistbox of the dialog window has the
focus and the tilde (~) button is pressed, the filebrowser
will chdir to the homedirectory of the current user.
=back
=head1 SEE ALSO
L<Curses::UI|Curses::UI>,
L<Curses::UI::Container|Curses::UI::Container>,
L<Curses::UI::Buttonbox|Curses::UI::Buttonbox>
=head1 AUTHOR
Copyright (c) 2001-2002 Maurice Makaay. All rights reserved.
Maintained by Marcus Thiesen (marcus@cpan.thiesenweb.de)
This package is free software and is provided "as is" without express
or implied warranty. It may be used, redistributed and/or modified
under the same terms as perl itself.
|