| 1 | package TUI::Dialogs::ListBox; | ||||||||||
| 2 | # ABSTRACT: Provides a list box dialog with selection handling | ||||||||||
| 3 | |||||||||||
| 4 | 11 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 11 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 11 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 11 | our $VERSION = '2.000002'; | |||||||||
| 9 | 11 | $VERSION =~ tr/_//d; | |||||||||
| 10 | 11 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||
| 11 | |||||||||||
| 12 | 11 | ▶ | use Exporter 'import'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 11 | our @EXPORT = qw( | |||||||||
| 15 | TListBox | ||||||||||
| 16 | new_TListBox | ||||||||||
| 17 | ); | ||||||||||
| 18 | |||||||||||
| 19 | 11 | ▶ | use Class::Struct; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 11 | ▶ | use TUI::toolkit; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 11 | ▶ | use TUI::toolkit::Types qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | Maybe | ||||||||||
| 23 | is_Object | ||||||||||
| 24 | :types | ||||||||||
| 25 | 11 | ); | |||||||||
| 26 | |||||||||||
| 27 | 11 | ▶ | use TUI::Const qw( EOS ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 11 | ▶ | use TUI::Objects::NSCollection; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 11 | ▶ | use TUI::Views::ListViewer; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | 11 | struct TListBoxRec => [ | |||||||||
| 32 | items => TNSCollection, | ||||||||||
| 33 | selection => '$', | ||||||||||
| 34 | ]; | ||||||||||
| 35 | |||||||||||
| 36 | sub TListBox() { __PACKAGE__ } | ||||||||||
| 37 | sub name() { 'TListBox' } | ||||||||||
| 38 | 0 | ▶ | sub new_TListBox { __PACKAGE__->from( @_ ) } | ||||||||
|
Subroutine
new_TListBox: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 39 | |||||||||||
| 40 | 11 | extends TListViewer; | |||||||||
| 41 | |||||||||||
| 42 | # protected attributes | ||||||||||
| 43 | 11 | has items => ( is => 'ro' ); | |||||||||
| 44 | |||||||||||
| 45 | 0 | ▶ | sub BUILDARGS { # \%args (%args) | ||||||||
|
Subroutine
BUILDARGS: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 46 | 0 | state $sig = signature( | |||||||||
| 47 | method => 1, | ||||||||||
| 48 | named => [ | ||||||||||
| 49 | bounds => Object, | ||||||||||
| 50 | numCols => PositiveOrZeroInt, { alias => 'aNumCols' }, | ||||||||||
| 51 | vScrollBar => Maybe[Object], { alias => 'aScrollBar' }, | ||||||||||
| 52 | ], | ||||||||||
| 53 | caller_level => +1, | ||||||||||
| 54 | ); | ||||||||||
| 55 | 0 | my ( $class, $args ) = $sig->( @_ ); | |||||||||
| 56 | 0 | return { %$args }; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 0 | ▶ | sub BUILD { # void (\%args) | ||||||||
|
Subroutine
BUILD: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 60 | 0 | my ( $self, $args ) = @_; | |||||||||
| 61 | 0 | ▶ | assert ( @_ == 2 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 0 | ▶ | assert ( is_Object $self ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | $self->setRange( 0 ); | |||||||||
| 64 | 0 | return; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 0 | ▶ | sub from { # $obj ($bounds, $aNumCols, $aVScrollBar|undef) | ||||||||
|
Subroutine
from: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 68 | 0 | state $sig = signature( | |||||||||
| 69 | method => 1, | ||||||||||
| 70 | pos => [Object, PositiveOrZeroInt, Maybe[Object]], | ||||||||||
| 71 | ); | ||||||||||
| 72 | 0 | my ( $class, @args ) = $sig->( @_ ); | |||||||||
| 73 | 0 | return $class->new( bounds => $args[0], numCols => $args[1], | |||||||||
| 74 | vScrollBar => $args[2] ); | ||||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 0 | ▶ | sub list { # $collection () | ||||||||
|
Subroutine
list: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 78 | 0 | state $sig = signature( | |||||||||
| 79 | method => Object, | ||||||||||
| 80 | pos => [], | ||||||||||
| 81 | ); | ||||||||||
| 82 | 0 | my ( $self ) = $sig->( @_ ); | |||||||||
| 83 | 0 | return $self->{items}; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 0 | ▶ | sub dataSize { # $size () | ||||||||
|
Subroutine
dataSize: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 87 | 0 | state $sig = signature( | |||||||||
| 88 | method => Object, | ||||||||||
| 89 | pos => [], | ||||||||||
| 90 | ); | ||||||||||
| 91 | 0 | $sig->( @_ ); | |||||||||
| 92 | 0 | state $size = @{ TListBoxRec->new() }; | |||||||||
| 93 | 0 | return $size; | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 0 | ▶ | sub getData { # void (\@rec) | ||||||||
|
Subroutine
getData: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 97 | 0 | state $sig = signature( | |||||||||
| 98 | method => Object, | ||||||||||
| 99 | pos => [ArrayLike], | ||||||||||
| 100 | ); | ||||||||||
| 101 | 0 | my ( $self, $rec ) = $sig->( @_ ); | |||||||||
| 102 | my $p = TListBoxRec->new( | ||||||||||
| 103 | items => $self->{items}, | ||||||||||
| 104 | selection => $self->{focused}, | ||||||||||
| 105 | 0 | ); | |||||||||
| 106 | 0 | @$rec[ 0 .. $#$p ] = @$p; | |||||||||
| 107 | 0 | return; | |||||||||
| 108 | } #/ sub getData | ||||||||||
| 109 | |||||||||||
| 110 | 0 | ▶ | sub getText { # void (\$dest, $item, $maxChars) | ||||||||
|
Subroutine
getText: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 111 | 0 | state $sig = signature( | |||||||||
| 112 | method => Object, | ||||||||||
| 113 | pos => [ScalarRef, Int, Int], | ||||||||||
| 114 | ); | ||||||||||
| 115 | 0 | my ( $self, $dest, $item, $maxChars ) = $sig->( @_ ); | |||||||||
| 116 | 0 | ▶ | if ( $self->{items} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 117 | 0 | my $src = $self->{items}->at( $item ); | |||||||||
| 118 | 0 | ▶ | $src = '' unless defined $src; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 119 | 0 | $$dest = substr( $src, 0, $maxChars ); | |||||||||
| 120 | } | ||||||||||
| 121 | else { | ||||||||||
| 122 | 0 | $$dest = EOS; | |||||||||
| 123 | } | ||||||||||
| 124 | 0 | return; | |||||||||
| 125 | } | ||||||||||
| 126 | |||||||||||
| 127 | 0 | ▶ | sub newList { # void ($aList) | ||||||||
|
Subroutine
newList: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 128 | 0 | state $sig = signature( | |||||||||
| 129 | method => Object, | ||||||||||
| 130 | pos => [Object], | ||||||||||
| 131 | ); | ||||||||||
| 132 | 0 | my ( $self, $aList ) = $sig->( @_ ); | |||||||||
| 133 | 0 | $self->destroy( $self->{items} ); | |||||||||
| 134 | 0 | $self->{items} = $aList; | |||||||||
| 135 | 0 | ▶ | if ( $aList ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 136 | 0 | $self->setRange( $aList->getCount() ); | |||||||||
| 137 | } | ||||||||||
| 138 | else { | ||||||||||
| 139 | 0 | $self->setRange( 0 ); | |||||||||
| 140 | } | ||||||||||
| 141 | 0 | ▶ | if ( $self->{range} > 0 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 142 | 0 | $self->focusItem( 0 ); | |||||||||
| 143 | } | ||||||||||
| 144 | 0 | $self->drawView(); | |||||||||
| 145 | 0 | return; | |||||||||
| 146 | } #/ sub newList | ||||||||||
| 147 | |||||||||||
| 148 | 0 | ▶ | sub setData { # void (\@rec) | ||||||||
|
Subroutine
setData: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 149 | 0 | state $sig = signature( | |||||||||
| 150 | method => Object, | ||||||||||
| 151 | pos => [ArrayLike], | ||||||||||
| 152 | ); | ||||||||||
| 153 | 0 | my ( $self, $rec ) = $sig->( @_ ); | |||||||||
| 154 | 0 | my $p = TListBoxRec->new(); | |||||||||
| 155 | 0 | @$p = @$rec[ 0 .. $#$p ]; | |||||||||
| 156 | 0 | $self->newList( $p->items ); | |||||||||
| 157 | 0 | $self->focusItem( $p->selection ); | |||||||||
| 158 | 0 | $self->drawView(); | |||||||||
| 159 | 0 | return; | |||||||||
| 160 | } #/ sub setData | ||||||||||
| 161 | |||||||||||
| 162 | 11 | 1 | |||||||||
| 163 | |||||||||||
| 164 | __END__ | ||||||||||