lib/TUI/StdDlg/ChDirDialog.pm

filter: Statementstmt 42.2% 93 / 220 Branchbran 0.0% 0 / 54 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 66.6% 24 / 36 Podpod 90.0% 9 / 10 totaltotal 36.5% 126 / 345 CC 34 SCAR 38.4
CC
34
Cov
32%
handleEvent
156.0
valid
56.0
__ANON__
56.0
CRAP 46.3
« lib/TUI/Views/View/Cursor.pm ↑ Summary lib/TUI/Gadgets/EventViewer.pm »
1 package TUI::StdDlg::ChDirDialog;
2 # ABSTRACT: Common dialog box for selecting a directory
3
4 4 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 4 our $VERSION = '2.000002';
9 4 $VERSION =~ tr/_//d;
10 4 our $AUTHORITY = 'cpan:BRICKPOOL';
11
12 4 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 our @EXPORT = qw(
14 TChDirDialog
15 new_TChDirDialog
16 );
17
18 4 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use TUI::toolkit;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
21 Maybe
22 :is
23 :types
24 4 );
25
26 4 ▶use TUI::Const qw( EOS );
Subroutine BEGIN: called CC=1 SCAR=0.0
27 4 ▶use TUI::Dialogs::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
28 bfDefault
29 bfNormal
30 4 );
31 4 ▶use TUI::Dialogs::Button;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 4 ▶use TUI::Dialogs::Dialog;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 4 ▶use TUI::Dialogs::Label;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 4 ▶use TUI::Dialogs::InputLine;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 4 ▶use TUI::Dialogs::History;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 4 ▶use TUI::Drivers::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
37 evBroadcast
38 evCommand
39 4 );
40 4 ▶use TUI::MsgBox::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
41 mfError
42 mfOKButton
43 4 );
44 4 ▶use TUI::MsgBox::MsgBoxText qw( messageBox );
Subroutine BEGIN: called CC=1 SCAR=0.0
45 4 ▶use TUI::Objects::Rect;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 4 ▶use TUI::StdDlg::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
47 :cmXXXX
48 cdHelpButton
49 cdNoLoadDir
50 4 );
51 4 ▶use TUI::StdDlg::Dir qw( setdisk );
Subroutine BEGIN: called CC=1 SCAR=0.0
52 4 ▶use TUI::StdDlg::DirListBox;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 4 ▶use TUI::StdDlg::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
54 driveValid
55 fexpand
56 getCurDir
57 4 );
58 4 ▶use TUI::Views::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
59 cmHelp
60 cmOK
61 ofCentered
62 4 );
63 4 ▶use TUI::Views::ScrollBar;
Subroutine BEGIN: called CC=1 SCAR=0.0
64
65 sub TChDirDialog() { __PACKAGE__ }
66 sub name() { 'TChDirDialog' }
67 0 ▶sub new_TChDirDialog { __PACKAGE__->from(@_) }
Subroutine new_TChDirDialog: not called CC=1 SCAR=6.9
Pod documented
68
69 4 extends TDialog;
70
71 # declare global variables
72 4 our $changeDirTitle = "Change Directory";
73 4 our $dirNameText = "Directory ~n~ame";
74 4 our $dirTreeText = "Directory ~t~ree";
75 4 our $okText = "O~K~";
76 4 our $chdirText = "~C~hdir";
77 4 our $revertText = "~R~evert";
78 4 our $helpText = "Help";
79 4 our $drivesText = "Drives";
80 4 our $invalidText = "Invalid directory";
81
82 # private attributes
83 4 has dirInput => ( is => 'bare' );
84 4 has dirList => ( is => 'bare' );
85 4 has okButton => ( is => 'bare' );
86 4 has chDirButton => ( is => 'bare' );
87
88 # predeclare private methods
89 my (
90 4 $setUpDialog,
91 );
92
93 0 ▶sub BUILDARGS { # \%args (%args)
Subroutine BUILDARGS: not called CC=1 SCAR=6.9
Pod documented
94 0 state $sig = signature(
95 method => 1,
96 named => [
97 options => PositiveOrZeroInt, { alias => 'aOptions' },
98 histId => PositiveOrZeroInt,
99 ],
100 caller_level => +1,
101 );
102 0 my ( $class, $args1 ) = $sig->( @_ );
103 0 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
104 0 my $args2 = $class->SUPER::BUILDARGS(
105 bounds => TRect->new( ax => 16, ay => 2, bx => 64, by => 20 ),
106 title => $changeDirTitle,
107 );
108 0 return { %$args1, %$args2 };
109 }
110
111 0 ▶sub BUILD { # void (\%args)
Subroutine BUILD: not called CC=6 SCAR=37.4
Pod documented
112 0 my ( $self, $args ) = @_;
113 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
114 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
115 0 ▶ assert ( is_HashRef $args );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_HashRef($args) 0 0 0
116 0 $self->{options} |= ofCentered;
117
118 0 $self->{dirInput} = TInputLine->new(
119 bounds => TRect->new( ax => 3, ay => 3, bx => 30, by => 4 ),
120 maxLen => 68,
121 );
122 0 $self->insert( $self->{dirInput} );
123 $self->insert( TLabel->new(
124 bounds => TRect->new( ax => 2, ay => 2, bx => 17, by => 3 ),
125 text => $dirNameText,
126 link => $self->{dirInput},
127 0 ));
128 $self->insert( THistory->new(
129 bounds => TRect->new( ax => 30, ay => 3, bx => 33, by => 4 ),
130 link => $self->{dirInput},
131 historyId => $args->{histId},
132 0 ));
133
134 0 my $sb = TScrollBar->new(
135 bounds => TRect->new( ax => 32, ay => 6, bx => 33, by => 16 )
136 );
137 0 $self->insert( $sb );
138 0 $self->{dirList} = TDirListBox->new(
139 bounds => TRect->new( ax => 3, ay => 6, bx => 32, by => 16 ),
140 vScrollBar => $sb,
141 );
142 0 $self->insert( $self->{dirList} );
143 $self->insert( TLabel->new(
144 bounds => TRect->new( ax => 2, ay => 5, bx => 17, by => 6 ),
145 text => $dirTreeText,
146 link => $self->{dirList},
147 0 ));
148
149 0 $self->{okButton} = TButton->new(
150 bounds => TRect->new( ax => 35, ay => 3, bx => 46, by => 5 ),
151 title => $okText,
152 command => cmOK,
153 flags => bfDefault,
154 );
155 0 $self->insert( $self->{okButton} );
156 0 $self->{chDirButton} = TButton->new(
157 bounds => TRect->new( ax => 35, ay => 9, bx => 45, by => 11 ),
158 title => $chdirText,
159 command => cmChangeDir,
160 flags => bfNormal,
161 );
162 0 $self->insert( $self->{chDirButton} );
163 0 $self->insert( TButton->new(
164 bounds => TRect->new( ax => 35, ay => 12, bx => 45, by => 14 ),
165 title => $revertText,
166 command => cmRevert,
167 flags => bfNormal,
168 ));
169 0 ▶ if ( $args->{options} & cdHelpButton ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"options"} & 2) 0 0 0
170 0 $self->insert( TButton->new(
171 bounds => TRect->new( ax => 35, ay => 15, bx => 45, by => 17 ),
172 title => $helpText,
173 command => cmHelp,
174 flags => bfNormal,
175 ));
176 }
177 $self->$setUpDialog()
178 0 ▶ unless $args->{options} & cdNoLoadDir;
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"options"} & 1 0 0 0
179 0 $self->selectNext( false );
180
181 0 return;
182 }
183
184 0 ▶sub from { # $obj ($aOptions, $histId)
Subroutine from: not called CC=1 SCAR=6.9
Pod undocumented
185 0 state $sig = signature(
186 method => 1,
187 pos => [PositiveOrZeroInt, PositiveOrZeroInt],
188 );
189 0 my ( $class, @args ) = $sig->( @_ );
190 0 return $class->new( options => $args[0], histId => $args[1] );
191 }
192
193 0 ▶sub dataSize { # $dSize ()
Subroutine dataSize: not called CC=1 SCAR=6.9
Pod documented
194 0 state $sig = signature(
195 method => Object,
196 pos => [],
197 );
198 0 $sig->( @_ );
199 0 return 0;
200 }
201
202 0 ▶sub getData { # void (\@rec)
Subroutine getData: not called CC=1 SCAR=6.9
Pod documented
203 0 state $sig = signature(
204 method => Object,
205 pos => [ArrayLike],
206 );
207 0 $sig->( @_ );
208 0 return;
209 }
210
211 0 ▶sub handleEvent { # void ($event)
Subroutine handleEvent: not called CC=12 SCAR=50.5
Pod documented
212 0 state $sig = signature(
213 method => Object,
214 pos => [Object],
215 );
216 0 my ( $self, $event ) = $sig->( @_ );
217 0 $self->SUPER::handleEvent( $event );
218 0 ▶ if ( $event->{what} == evCommand ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event->{"what"} == 256) 0 0 0
219 0 my $curDir = '';
220 0 SWITCH: for ( $event->{message}{command} ) {
221 0 ▶ cmRevert == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
1006 == $_ and do { getCurDir($curDir); last } 0 0 0
222 0 getCurDir( $curDir );
223 0 last;
224 };
225 0 ▶ cmChangeDir == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
1005 == $_ and do { my $p = $self->{"dirList"}->list->at($self->{"dirList"}{"focused"}); $curDir = $p->dir; if ($curDir eq $TUI::StdDlg::ChDirDialog::drivesText) { last; } elsif (length $curDir and driveValid(substr($curDir, 0, 1))) { $curDir .= '\\' if substr($curDir, -1, 1) ne "\\"; } else { return; } ; last } 0 0 0
226 0 my $p = $self->{dirList}->list()->at( $self->{dirList}{focused} );
227 0 $curDir = $p->dir();
228 0 ▶ if ( $curDir eq $drivesText ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($curDir eq $TUI::StdDlg::ChDirDialog::drivesText) { } 0 0 0
elsif (length $curDir and driveValid(substr($curDir, 0, 1))) { } 0 0 0
229 0 last;
230 }
231 ▶ elsif ( length( $curDir ) && driveValid( substr( $curDir, 0, 1 ) ) ) {
Condition0%0/3
length $curDir and driveValid(substr($curDir, 0, 1))
!ll&&!rl&&r
000
MC/DC0%0/2
length $curDir and driveValid(substr($curDir, 0, 1))
length $curDir driveValid(substr($curDir, 0, 1))
Truth table0%0/3
A and B
A= length $curDirB= driveValid(substr($curDir, 0, 1))
ABresult
0X0
100
111
232 0 ▶ $curDir .= "\\"
Branch: 1 branch
BranchTrueFalseTotal
if substr($curDir, -1, 1) ne "\\" 0 0 0
233 if substr( $curDir, -1, 1 ) ne '\\';
234 }
235 else {
236 0 return;
237 }
238 0 last;
239 };
240 # Handle directory selection.
241 0 ▶ cmDirSelection == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
1007 == $_ and do { $self->{"chDirButton"}->makeDefault(!!$event->{"message"}{"infoPtr"}); return } 0 0 0
242 0 $self->{chDirButton}->makeDefault( !!$event->{message}{infoPtr} );
243 0 return; # Note: return (not last) like in the original code
244 };
245 DEFAULT: {
246 0 return;
247 };
248 }
249 0 $self->{dirList}->newDirectory( $curDir );
250 0 my $len = length( $curDir );
251 0 ▶ if ( $len > 3 && substr( $curDir, -1, 1 ) eq '\\' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > 3 and substr($curDir, -1, 1) eq "\\") 0 0 0
Condition0%0/3
$len > 3 and substr($curDir, -1, 1) eq "\\"
!ll&&!rl&&r
000
MC/DC0%0/2
$len > 3 and substr($curDir, -1, 1) eq "\\"
$len > 3 substr($curDir, -1, 1) eq "\\"
Truth table0%0/3
A and B
A= $len > 3B= substr($curDir, -1, 1) eq "\\"
ABresult
0X0
100
111
252 0 substr( $curDir, $len - 1 ) = EOS;
253 }
254 0 $self->{dirInput}{data} = $curDir;
255 0 $self->{dirInput}->drawView();
256 0 $self->{dirList}->select();
257 0 $self->clearEvent( $event );
258 }
259
260 0 return;
261 } #/ sub handleEvent
262
263 0 ▶sub setData { # void (\@rec)
Subroutine setData: not called CC=1 SCAR=6.9
Pod documented
264 0 state $sig = signature(
265 method => Object,
266 pos => [ArrayLike],
267 );
268 0 $sig->( @_ );
269 0 return;
270 }
271
272 0 ▶my $changeDir = sub { # $int ($path)
Subroutine __ANON__: not called CC=6 SCAR=37.4
273 0 my ( $path ) = @_;
274 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
275 0 ▶ assert ( is_Str $path );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($path) 0 0 0
276 0 ▶ if ( length( $path ) && substr( $path, 1, 1 ) eq ':' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $path and substr($path, 1, 1) eq ":") 0 0 0
Condition0%0/3
length $path and substr($path, 1, 1) eq ":"
!ll&&!rl&&r
000
MC/DC0%0/2
length $path and substr($path, 1, 1) eq ":"
length $path substr($path, 1, 1) eq ":"
Truth table0%0/3
A and B
A= length $pathB= substr($path, 1, 1) eq ":"
ABresult
0X0
100
111
277 0 setdisk( ord( uc substr( $path, 0, 1 ) ) - ord( 'A' ) );
278 }
279 0 ▶ return chdir( $path ) ? 0 : -1;
Branch: 1 branch
BranchTrueFalseTotal
chdir $path ? : 0 0 0
280 4 };
281
282 0 ▶sub valid { # $bool ($command)
Subroutine valid: not called CC=7 SCAR=40.3
Pod documented
283 0 state $sig = signature(
284 method => Object,
285 pos => [PositiveOrZeroInt],
286 );
287 0 my ( $self, $command ) = $sig->( @_ );
288
289 0 ▶ return true
Branch: 1 branch
BranchTrueFalseTotal
if $command == 10 0 0 0
290 if $command == cmOK;
291
292 0 my $path = $self->{dirInput}{data};
293
294 # BUG FIX - EFW - Tue 05/16/95
295 # Ignore "Drives" line if switching drives.
296 0 ▶ $path = ''
Branch: 1 branch
BranchTrueFalseTotal
if $path ne $TUI::StdDlg::ChDirDialog::drivesText 0 0 0
297 if $path ne $drivesText;
298
299 # If it was "Drives" or the input line was blank, issue a
300 # cmChangeDir event to select the current drive/directory.
301 0 ▶ if ( $path ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path ne "") 0 0 0
302 0 my $event = TEvent->new();
303 0 $event->{what} = evCommand;
304 0 $event->{message}{command} = cmChangeDir;
305 0 $self->putEvent( $event );
306 0 return false;
307 }
308
309 # Otherwise, expand and check the path.
310 0 fexpand( $path );
311
312 0 my $len = length( $path );
313 0 ▶ if ( $len > 3 && substr( $path, -1, 1 ) eq '\\' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > 3 and substr($path, -1, 1) eq "\\") 0 0 0
Condition0%0/3
$len > 3 and substr($path, -1, 1) eq "\\"
!ll&&!rl&&r
000
MC/DC0%0/2
$len > 3 and substr($path, -1, 1) eq "\\"
$len > 3 substr($path, -1, 1) eq "\\"
Truth table0%0/3
A and B
A= $len > 3B= substr($path, -1, 1) eq "\\"
ABresult
0X0
100
111
314 0 substr( $path, $len - 1 ) = EOS;
315 }
316
317 0 ▶ if ( &$changeDir( $path ) != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$changeDir($path) != 0) 0 0 0
318 0 messageBox( $invalidText, mfError | mfOKButton );
319 0 return false;
320 }
321 0 return true;
322 }
323
324 0 ▶sub shutDown { # void ($self)
Subroutine shutDown: not called CC=1 SCAR=6.9
Pod documented
325 0 state $sig = signature(
326 method => Object,
327 pos => [],
328 );
329 0 my ( $self ) = $sig->( @_ );
330 0 $self->{dirList} = undef;
331 0 $self->{dirInput} = undef;
332 0 $self->{okButton} = undef;
333 0 $self->{chDirButton} = undef;
334 0 $self->SUPER::shutDown();
335 0 return;
336 }
337
338 0 ▶$setUpDialog = sub { # void ()
Subroutine __ANON__: not called CC=7 SCAR=40.3
339 0 my ( $self ) = @_;
340 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
341 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
342
343 0 ▶ if ( $self->{dirList} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"dirList"}) 0 0 0
344 0 my $curDir = '';
345 0 getCurDir( $curDir );
346 0 $self->{dirList}->newDirectory( $curDir );
347 0 ▶ if ( $self->{dirInput} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"dirInput"}) 0 0 0
348 0 my $len = length $curDir;
349 0 ▶ if ( $len > 3 && substr( $curDir, $len - 1, 1 ) eq '\\' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > 3 and substr($curDir, $len - 1, 1) eq "\\") 0 0 0
Condition0%0/3
$len > 3 and substr($curDir, $len - 1, 1) eq "\\"
!ll&&!rl&&r
000
MC/DC0%0/2
$len > 3 and substr($curDir, $len - 1, 1) eq "\\"
$len > 3 substr($curDir, $len - 1, 1) eq "\\"
Truth table0%0/3
A and B
A= $len > 3B= substr($curDir, $len - 1, 1) eq "\\"
ABresult
0X0
100
111
350 0 substr( $curDir, $len - 1 ) = EOS;
351 }
352 0 $self->{dirInput}{data} = $curDir;
353 0 $self->{dirInput}->drawView();
354 }
355 }
356
357 0 return;
358 4 }; #/ $setUpDialog = sub
359
360 4 1
361
362 __END__
« lib/TUI/Views/View/Cursor.pm ↑ Summary lib/TUI/Gadgets/EventViewer.pm »