| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Wx::Perl::EntryList; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Wx::Perl::EntryList - dynamic list that can be displayed in various controls |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $list = Wx::Perl::EntryList->new; |
|
10
|
|
|
|
|
|
|
$list->add_entries_at( 0, [ 'a', 'b', 'c', 'd', 'e' ] ); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# create a view to display it |
|
13
|
|
|
|
|
|
|
my $view = Wx::Perl::EntryList::ListBoxView->new |
|
14
|
|
|
|
|
|
|
( $list, sub { return $_[0] }, $parent ); |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
A dynamic list that can be observed (using C) for |
|
19
|
|
|
|
|
|
|
changes and can be displayed in various controls. |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 METHODS |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
|
24
|
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
1408
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
35
|
|
|
26
|
1
|
|
|
1
|
|
4
|
use base qw(Class::Publisher Class::Accessor::Fast); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
980
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( qw(entries) ); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 new |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $list = Wx::Perl::EntryList->new; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Creates a list object. |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub new { |
|
41
|
0
|
|
|
0
|
1
|
|
my( $class ) = @_; |
|
42
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new( { entries => [] } ); |
|
43
|
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
return $self; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 get_entry_at |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $entry = $list->get_entry_at( $index ); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Returns the nth entry of the list. |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
|
|
0
|
1
|
|
sub get_entry_at { return $_[0]->entries->[ $_[1] ] } |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 add_entries_at |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$list->add_entries_at( $index, [ $entry1, $entry2, ... ] ); |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Add some entries to the list, notifying any listeners. |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _add_entries_at { |
|
66
|
0
|
|
|
0
|
|
|
my( $self, $index, $entries ) = @_; |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
splice @{$self->entries}, $index, 0, @$entries; |
|
|
0
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub add_entries_at { |
|
72
|
0
|
|
|
0
|
1
|
|
my( $self, $index, $entries ) = @_; |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
$self->_add_entries_at( $index, $entries ); |
|
75
|
0
|
|
|
|
|
|
$self->notify_subscribers( 'add_entries', |
|
76
|
|
|
|
|
|
|
index => $index, |
|
77
|
|
|
|
|
|
|
count => scalar @$entries, |
|
78
|
|
|
|
|
|
|
); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 delete_entry |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$list->delete_entry( $index ); |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Deletes a single entry from the list, notifying any listeners. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _delete_entries { |
|
90
|
0
|
|
|
0
|
|
|
my( $self, $index, $count ) = @_; |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
return splice @{$self->entries}, $index, $count; |
|
|
0
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub delete_entry { |
|
96
|
0
|
|
|
0
|
1
|
|
my( $self, $index ) = @_; |
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
$self->_delete_entries( $index, 1 ); |
|
99
|
0
|
|
|
|
|
|
$self->notify_subscribers( 'delete_entries', |
|
100
|
|
|
|
|
|
|
index => $index, |
|
101
|
|
|
|
|
|
|
count => 1, |
|
102
|
|
|
|
|
|
|
); |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 move_entry |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
$list->move_entry( $from_index, $to_index ); |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Moves an entry of the list, notifying any listeners. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub move_entry { |
|
114
|
0
|
|
|
0
|
1
|
|
my( $self, $from, $to ) = @_; |
|
115
|
0
|
|
|
|
|
|
my( $entry ) = $self->_delete_entries( $from, 1 ); |
|
116
|
0
|
|
|
|
|
|
$self->_add_entries_at( $to, [ $entry ] ); |
|
117
|
0
|
|
|
|
|
|
$self->notify_subscribers( 'move_entries', |
|
118
|
|
|
|
|
|
|
from => $from, |
|
119
|
|
|
|
|
|
|
to => $to, |
|
120
|
|
|
|
|
|
|
count => 1, |
|
121
|
|
|
|
|
|
|
); |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 count |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
my $count = $list->count; |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
The number of items in the list. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
|
131
|
|
|
|
|
|
|
|
|
132
|
0
|
|
|
0
|
1
|
|
sub count { scalar @{$_[0]->entries} } |
|
|
0
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub _fixup_iterator { |
|
135
|
0
|
|
|
0
|
|
|
my( $self, $it, $event, %args ) = @_; |
|
136
|
|
|
|
|
|
|
|
|
137
|
0
|
0
|
|
|
|
|
if( $event eq 'add_entries' ) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
|
if( $it->current >= $args{index} ) { |
|
139
|
0
|
|
|
|
|
|
$it->current( $it->current + $args{count} ); |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
} elsif( $event eq 'delete_entries' ) { |
|
142
|
0
|
0
|
|
|
|
|
if( $it->current >= $args{index} ) { |
|
143
|
0
|
0
|
|
|
|
|
if( $it->current < $args{index} + $args{count} ) { |
|
144
|
0
|
|
|
|
|
|
$it->current( 0 ); |
|
145
|
|
|
|
|
|
|
} else { |
|
146
|
0
|
|
|
|
|
|
$it->current( $it->current - $args{count} ); |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
} elsif( $event eq 'move_entries' ) { |
|
150
|
0
|
0
|
0
|
|
|
|
if( $it->current >= $args{from} |
|
151
|
|
|
|
|
|
|
&& $it->current < $args{from} + $args{count} ) { |
|
152
|
0
|
|
|
|
|
|
$it->current( $it->current - $args{from} + $args{to} ); |
|
153
|
|
|
|
|
|
|
} else { |
|
154
|
0
|
|
|
|
|
|
$self->_fixup_iterator( $it, 'delete_entries', |
|
155
|
|
|
|
|
|
|
index => $args{from}, |
|
156
|
|
|
|
|
|
|
count => $args{count}, |
|
157
|
|
|
|
|
|
|
); |
|
158
|
0
|
|
|
|
|
|
$self->_fixup_iterator( $it, 'add_entries', |
|
159
|
|
|
|
|
|
|
index => $args{to}, |
|
160
|
|
|
|
|
|
|
count => $args{count}, |
|
161
|
|
|
|
|
|
|
); |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 AUTHOR |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Mattia Barbon . |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 LICENSE |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
|
173
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
L, |
|
178
|
|
|
|
|
|
|
L, L, |
|
179
|
|
|
|
|
|
|
L |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=cut |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
1; |